From e59d33ea416afbe5d2e531f524be37c1eeef6015 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 19 Jun 2023 17:08:38 +0700 Subject: Create due extension when approve so --- indoteknik_custom/models/sale_order.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index cbc6a60a..e2693688 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -282,7 +282,18 @@ class SaleOrder(models.Model): def sale_order_approve(self): # raise UserError("Bisa langsung Confirm") self.check_due() + invoices = self.env['account.move'].search([ + ('partner_id', '=', self.partner_id.id), + ('invoice_day_to_due', '<', 0) + ]) + due_extension_obj = self.env['due.extension'] for order in self: + for invoice in invoices: + if invoice.invoice_day_to_due < 0: + value = { + 'invoice_id': invoice.id + } + due_extension_obj.create(value) if order.warehouse_id.id != 8: #GD Bandengan raise UserError('Gudang harus Bandengan') if order.state == 'cancel' or order.state == 'done' or order.state == 'sale': @@ -323,7 +334,9 @@ class SaleOrder(models.Model): elif order.total_percent_margin <= 22 and not self.env.user.is_leader and not self.env.user.is_sales_manager: order.approval_status = 'pengajuan1' elif order._have_outstanding_invoices() and not self.env.user.is_leader and not self.env.user.is_sales_manager: - order.approval_status = 'pengajuan1' + order.approval_status = 'pengajuan1' + elif invoice.invoice_day_to_due < 0: + raise UserError("Anda Harus Memperbarui Due Date di Due Extension") else: raise UserError("Bisa langsung Confirm") -- cgit v1.2.3 From fb8abc000707a2b8ba1fb0d16c1d8cbbd640ea34 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 23 Jun 2023 14:12:49 +0700 Subject: Fiture Over Due Limit --- indoteknik_custom/models/sale_order.py | 120 ++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 25 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e99876c2..d531c869 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -78,6 +78,7 @@ class SaleOrder(models.Model): delivery_service_type = fields.Char(string='Delivery Service Type', help='data dari rajaongkir') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') + due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True) def generate_payment_link_midtrans_sales_order(self): # midtrans_url = 'https://app.sandbox.midtrans.com/snap/v1/transactions' # dev - sandbox @@ -282,18 +283,10 @@ class SaleOrder(models.Model): def sale_order_approve(self): # raise UserError("Bisa langsung Confirm") self.check_due() - invoices = self.env['account.move'].search([ - ('partner_id', '=', self.partner_id.id), - ('invoice_day_to_due', '<', 0) - ]) - due_extension_obj = self.env['due.extension'] + parent_id = self.partner_id.parent_id.id + parent_id = parent_id if parent_id else self.partner_id.id + for order in self: - for invoice in invoices: - if invoice.invoice_day_to_due < 0: - value = { - 'invoice_id': invoice.id - } - due_extension_obj.create(value) if order.warehouse_id.id != 8: #GD Bandengan raise UserError('Gudang harus Bandengan') if order.state == 'cancel' or order.state == 'done' or order.state == 'sale': @@ -329,14 +322,16 @@ class SaleOrder(models.Model): raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price: raise UserError(_('Isi Vendor dan Harga Beli sebelum Request Approval')) - if order.total_percent_margin <= 15 and not self.env.user.is_leader: + + if order.validate_partner_invoice_due(): + return self._notification_has_unapprove_due() + + if order._notification_margin_leader(): order.approval_status = 'pengajuan2' - elif order.total_percent_margin <= 22 and not self.env.user.is_leader and not self.env.user.is_sales_manager: + return self._notification_has_margin_leader() + elif order._notification_margin_manager(): order.approval_status = 'pengajuan1' - elif order._have_outstanding_invoices() and not self.env.user.is_leader and not self.env.user.is_sales_manager: - order.approval_status = 'pengajuan1' - elif invoice.invoice_day_to_due < 0: - raise UserError("Anda Harus Memperbarui Due Date di Due Extension") + return self._notification_has_margin_manager() else: raise UserError("Bisa langsung Confirm") @@ -354,9 +349,81 @@ class SaleOrder(models.Model): self.approval_status = False return super(SaleOrder, self).action_cancel() + + def validate_partner_invoice_due(self): + parent_id = self.partner_id.parent_id.id + parent_id = parent_id if parent_id else self.partner_id.id + if self.due_id and self.due_id.is_approve == False: + raise UserError('Document Over Due Yang Anda Buat Belum Di Approve') + + if not self.env.user.is_leader and not self.env.user.is_sales_manager: + query = [ + ('partner_id', '=', parent_id), + ('state', '=', 'posted'), + ('move_type', '=', 'out_invoice'), + ('amount_residual_signed', '>', 0) + ] + invoices = self.env['account.move'].search(query, order='invoice_date') + due_extension = self.env['due.extension'].create([{ + 'partner_id': parent_id, + 'day_extension': '3', + 'order_id': self.id, + }]) + due_extension.generate_due_line() + self.due_id = due_extension.id + if len(self.due_id.due_line) > 0: + return True + else: + due_extension.unlink() + return False + + def _notification_margin_leader(self): + if self.total_percent_margin <= 15 and not self.env.user.is_leader: + return True + else: + return False + + def _notification_margin_manager(self): + if self.total_percent_margin <= 22 and not self.env.user.is_leader and not self.env.user.is_sales_manager: + return True + else: + return False + + def _notification_has_unapprove_due(self): + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': 'Notification', + 'message': 'Ada Invoice Yang Sudah Over Due, Silahkan Memperbarui Over Due di Due Extension', + 'next': {'type': 'ir.actions.act_window_close'}, + } + } + + def _notification_has_margin_leader(self): + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': 'Notification', + 'message': 'SO Harus Di Approve Oleh Pimpinan', + 'next': {'type': 'ir.actions.act_window_close'}, + } + } + + def _notification_has_margin_manager(self): + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': 'Notification', + 'message': 'SO Harus Di Approve Oleh Sales Manager', + 'next': {'type': 'ir.actions.act_window_close'}, + } + } + def action_confirm(self): - res = super(SaleOrder, self).action_confirm() for order in self: if order.warehouse_id.id != 8: #GD Bandengan raise UserError('Gudang harus Bandengan') @@ -375,16 +442,19 @@ class SaleOrder(models.Model): raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) - if order.total_percent_margin <= 15 and not self.env.user.is_leader: - raise UserError("Harus diapprove oleh Pimpinan") - elif order.total_percent_margin <= 22 and not self.env.user.is_leader and not self.env.user.is_sales_manager: - raise UserError("Harus diapprove oleh Manager") - elif order._have_outstanding_invoices() and not self.env.user.is_leader and not self.env.user.is_sales_manager: - raise UserError("Ada invoice due date, harus diapprove oleh Manager") + + if order.validate_partner_invoice_due(): + return self._notification_has_unapprove_due() + + if order._notification_margin_leader(): + return self._notification_has_margin_leader() + elif order._notification_margin_manager(): + return self._notification_has_margin_manager() else: order.approval_status = 'approved' - order.calculate_line_no() + order.calculate_line_no() + res = super(SaleOrder, self).action_confirm() return res def _have_outstanding_invoices(self): -- cgit v1.2.3 From dbe06610522bea7ff86d517dea626d91a59a73c8 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 23 Jun 2023 15:31:23 +0700 Subject: non pkp and pkp --- indoteknik_custom/models/sale_order.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d531c869..6a040ff3 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -79,6 +79,13 @@ class SaleOrder(models.Model): grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True) + customer_type = fields.Selection([ + ('pkp', 'PKP'), + ('nonpkp', 'Non PKP') + ]) + sppkp = fields.Char(string="SPPKP") + npwp = fields.Char(string="NPWP") + def generate_payment_link_midtrans_sales_order(self): # midtrans_url = 'https://app.sandbox.midtrans.com/snap/v1/transactions' # dev - sandbox @@ -423,6 +430,17 @@ class SaleOrder(models.Model): } } + def _set_sppkp_npwp_contact(self): + for contact in self: + partner_customer_type = contact.customer_type + contact.partner_id.customer_type = partner_customer_type + + partner_npwp = contact.npwp + contact.partner_id.npwp = partner_npwp + + partner_sppkp = contact.sppkp + contact.partner_id.sppkp = partner_sppkp + def action_confirm(self): for order in self: if order.warehouse_id.id != 8: #GD Bandengan @@ -451,6 +469,7 @@ class SaleOrder(models.Model): elif order._notification_margin_manager(): return self._notification_has_margin_manager() else: + order._set_sppkp_npwp_contact() order.approval_status = 'approved' order.calculate_line_no() -- cgit v1.2.3 From 787fe14fc0b14ed67f3d25a634c7a5a7e1a27204 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 26 Jun 2023 09:45:46 +0700 Subject: invisible field due_id after action cancel --- indoteknik_custom/models/sale_order.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 6a040ff3..5bb93805 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -215,6 +215,12 @@ class SaleOrder(models.Model): def onchange_partner_shipping(self): self.real_shipping_id = self.partner_shipping_id + @api.onchange('partner_id') + def onchange_partner_contact(self): + self.npwp = self.partner_id.npwp + self.sppkp = self.partner_id.sppkp + self.customer_type = self.partner_id.customer_type + def _get_purchases(self): po_state = ['done', 'draft', 'purchase'] for order in self: @@ -290,8 +296,6 @@ class SaleOrder(models.Model): def sale_order_approve(self): # raise UserError("Bisa langsung Confirm") self.check_due() - parent_id = self.partner_id.parent_id.id - parent_id = parent_id if parent_id else self.partner_id.id for order in self: if order.warehouse_id.id != 8: #GD Bandengan @@ -355,6 +359,7 @@ class SaleOrder(models.Model): # raise UserError("PO harus di Cancel dahulu") self.approval_status = False + self.due_id = False return super(SaleOrder, self).action_cancel() def validate_partner_invoice_due(self): @@ -469,8 +474,8 @@ class SaleOrder(models.Model): elif order._notification_margin_manager(): return self._notification_has_margin_manager() else: - order._set_sppkp_npwp_contact() order.approval_status = 'approved' + order._set_sppkp_npwp_contact() order.calculate_line_no() res = super(SaleOrder, self).action_confirm() -- cgit v1.2.3 From 72888c5c59078195420f6a6da3ae1c65766390d7 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 27 Jun 2023 09:51:36 +0700 Subject: fix pkp non pkp quotation --- indoteknik_custom/models/sale_order.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 5bb93805..a17cf7c8 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -217,9 +217,12 @@ class SaleOrder(models.Model): @api.onchange('partner_id') def onchange_partner_contact(self): - self.npwp = self.partner_id.npwp - self.sppkp = self.partner_id.sppkp - self.customer_type = self.partner_id.customer_type + parent_id = self.partner_id.parent_id + parent_id = parent_id if parent_id else self.partner_id + + self.npwp = parent_id.npwp + self.sppkp = parent_id.sppkp + self.customer_type = parent_id.customer_type def _get_purchases(self): po_state = ['done', 'draft', 'purchase'] @@ -435,16 +438,19 @@ class SaleOrder(models.Model): } } - def _set_sppkp_npwp_contact(self): + def _set_sppkp_npwp_contact(self): + parent_id = self.partner_id.parent_id + parent_id = parent_id if parent_id else self.partner_id + for contact in self: partner_customer_type = contact.customer_type - contact.partner_id.customer_type = partner_customer_type + parent_id.customer_type = partner_customer_type partner_npwp = contact.npwp - contact.partner_id.npwp = partner_npwp + parent_id.npwp = partner_npwp partner_sppkp = contact.sppkp - contact.partner_id.sppkp = partner_sppkp + parent_id.sppkp = partner_sppkp def action_confirm(self): for order in self: -- cgit v1.2.3 From 0c7c0ad2e8dca7a1e47cd5a13642543f01a74afd Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 27 Jun 2023 11:45:07 +0700 Subject: add button cancel to due extension --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/sale_order.py') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 1a16f462..bf415dbb 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -78,7 +78,7 @@ class SaleOrder(models.Model): delivery_service_type = fields.Char(string='Delivery Service Type', help='data dari rajaongkir') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') - due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True) + due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True, tracking=True) customer_type = fields.Selection([ ('pkp', 'PKP'), ('nonpkp', 'Non PKP') -- cgit v1.2.3