From fc5ed4aab391eb3ec09cae6179209fe30c1bc57f Mon Sep 17 00:00:00 2001 From: AndriFP Date: Tue, 22 Apr 2025 10:57:24 +0700 Subject: (andri) add min amount vendor payment --- indoteknik_custom/models/purchase_order.py | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index b107f389..5e9e509f 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -89,6 +89,39 @@ class PurchaseOrder(models.Model): store_name = fields.Char(string='Nama Toko') purchase_order_count = fields.Integer('Purchase Order Count', related='partner_id.purchase_order_count') + # cek payment term + def _check_payment_term(self): + _logger.info("Check Payment Term Terpanggil") + + cbd_term = self.env['account.payment.term'].search([ + ('name', 'ilike', 'Cash Before Delivery') + ], limit=1) + + for order in self: + if not order.partner_id or not order.partner_id.minimum_amount: + continue + + if not order.order_line or order.amount_total == 0: + continue + + if order.amount_total < order.partner_id.minimum_amount: + if cbd_term and order.payment_term_id != cbd_term: + order.payment_term_id = cbd_term.id + self.env.user.notify_info( + message="Total belanja PO belum mencapai minimum yang ditentukan vendor. " + "Payment Term telah otomatis diubah menjadi Cash Before Delivery (C.B.D).", + title="Payment Term Diperbarui" + ) + else: + vendor_term = order.partner_id.property_supplier_payment_term_id + if vendor_term and order.payment_term_id != vendor_term: + order.payment_term_id = vendor_term.id + self.env.user.notify_info( + message=f"Total belanja PO telah memenuhi jumlah minimum vendor. " + f"Payment Term otomatis dikembalikan ke pengaturan vendor awal: *{vendor_term.name}*.", + title="Payment Term Diperbarui" + ) + @api.onchange('total_cost_service') def _onchange_total_cost_service(self): for order in self: @@ -672,6 +705,7 @@ class PurchaseOrder(models.Model): raise UserError("Produk "+line.product_id.name+" memiliki vendor berbeda dengan SO (Vendor PO: "+str(self.partner_id.name)+", Vendor SO: "+str(line.so_line_id.vendor_id.name)+")") def button_confirm(self): + # self._check_payment_term() # check payment term res = super(PurchaseOrder, self).button_confirm() current_time = datetime.now() self.check_ppn_mix() @@ -1079,6 +1113,17 @@ class PurchaseOrder(models.Model): return super(PurchaseOrder, self).button_unlock() + @api.model #override custom create & write for check payment term + def create(self, vals): + order = super().create(vals) + order.with_context(skip_check_payment=True)._check_payment_term() + return order + + def write(self, vals): + res = super().write(vals) + if not self.env.context.get('skip_check_payment'): + self.with_context(skip_check_payment=True)._check_payment_term() + return res class PurchaseOrderUnlockWizard(models.TransientModel): _name = 'purchase.order.unlock.wizard' -- cgit v1.2.3 From 30382037882e15bb43f56fc0d81500faeb364fa5 Mon Sep 17 00:00:00 2001 From: AndriFP Date: Wed, 23 Apr 2025 08:59:23 +0700 Subject: (andri) add field min amt tax vendor PO --- indoteknik_custom/models/purchase_order.py | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 5e9e509f..60d26105 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -122,6 +122,80 @@ class PurchaseOrder(models.Model): title="Payment Term Diperbarui" ) + def _check_tax_rule(self): + _logger.info("Check Tax Rule Terpanggil") + + # Pajak 11% + tax_11 = self.env['account.tax'].search([ + ('type_tax_use', '=', 'purchase'), + ('name', 'ilike', '11%') + ], limit=1) + + # Pajak "No Tax" + no_tax = self.env['account.tax'].search([ + ('type_tax_use', '=', 'purchase'), + ('name', 'ilike', 'no tax') + ], limit=1) + + if not tax_11: + raise UserError("Pajak 11% tidak ditemukan. Mohon pastikan pajak 11% tersedia.") + + if not no_tax: + raise UserError("Pajak 'No Tax' tidak ditemukan. Harap buat tax dengan nama 'No Tax' dan tipe 'Purchase'.") + + for order in self: + partner = order.partner_id + minimum_tax = partner.minimum_amount_tax + + _logger.info("Partner ID: %s, Minimum Tax: %s, Untaxed Total: %s", partner.id, minimum_tax, order.amount_untaxed) + + if not minimum_tax or not order.order_line: + continue + + if order.amount_untaxed < minimum_tax: + _logger.info(">>> Total di bawah minimum → apply No Tax") + for line in order.order_line: + line.taxes_id = [(6, 0, [no_tax.id])] + + if self.env.context.get('notify_tax'): + self.env.user.notify_info( + message="Total belanja PO belum mencapai minimum pajak vendor. " + "Pajak diganti menjadi 'No Tax'.", + title="Pajak Diperbarui", + sticky=True + ) + else: + _logger.info(">>> Total memenuhi minimum → apply Pajak 11%") + for line in order.order_line: + line.taxes_id = [(6, 0, [tax_11.id])] + + if self.env.context.get('notify_tax'): + self.env.user.notify_info( + message="Total belanja sebelum pajak telah memenuhi minimum. " + "Pajak 11%% diterapkan", + title="Pajak Diperbarui", + sticky=True + ) + + @api.onchange('order_line') + def _onchange_order_line_tax_default(self): + _logger.info("Onchange Order Line Tax Default Terpanggil") + + no_tax = self.env['account.tax'].search([ + ('type_tax_use', '=', 'purchase'), + ('name', 'ilike', 'no tax') + ], limit=1) + + if not no_tax: + _logger.info("No Tax tidak ditemukan") + return + + for order in self: + for line in order.order_line: + if not line.taxes_id: + line.taxes_id = [(6, 0, [no_tax.id])] + _logger.info("Auto-set No tax ke baris product: %s", line.product_id.name) + @api.onchange('total_cost_service') def _onchange_total_cost_service(self): for order in self: @@ -1117,12 +1191,14 @@ class PurchaseOrder(models.Model): def create(self, vals): order = super().create(vals) order.with_context(skip_check_payment=True)._check_payment_term() + order.with_context(notify_tax=True)._check_tax_rule() return order def write(self, vals): res = super().write(vals) if not self.env.context.get('skip_check_payment'): self.with_context(skip_check_payment=True)._check_payment_term() + self.with_context(notify_tax=True)._check_tax_rule() return res class PurchaseOrderUnlockWizard(models.TransientModel): -- cgit v1.2.3 From f3854677b0f74db2fbb54ad012b3a6a6fc9e11df Mon Sep 17 00:00:00 2001 From: AndriFP Date: Wed, 23 Apr 2025 11:53:12 +0700 Subject: (andri) fix notify ganda pada PO --- indoteknik_custom/models/purchase_order.py | 39 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 60d26105..98b367d0 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -152,7 +152,7 @@ class PurchaseOrder(models.Model): if not minimum_tax or not order.order_line: continue - if order.amount_untaxed < minimum_tax: + if order.amount_total < minimum_tax: _logger.info(">>> Total di bawah minimum → apply No Tax") for line in order.order_line: line.taxes_id = [(6, 0, [no_tax.id])] @@ -162,7 +162,6 @@ class PurchaseOrder(models.Model): message="Total belanja PO belum mencapai minimum pajak vendor. " "Pajak diganti menjadi 'No Tax'.", title="Pajak Diperbarui", - sticky=True ) else: _logger.info(">>> Total memenuhi minimum → apply Pajak 11%") @@ -174,27 +173,27 @@ class PurchaseOrder(models.Model): message="Total belanja sebelum pajak telah memenuhi minimum. " "Pajak 11%% diterapkan", title="Pajak Diperbarui", - sticky=True ) - @api.onchange('order_line') - def _onchange_order_line_tax_default(self): - _logger.info("Onchange Order Line Tax Default Terpanggil") + # set default no_tax pada order line + # @api.onchange('order_line') + # def _onchange_order_line_tax_default(self): + # _logger.info("Onchange Order Line Tax Default Terpanggil") - no_tax = self.env['account.tax'].search([ - ('type_tax_use', '=', 'purchase'), - ('name', 'ilike', 'no tax') - ], limit=1) + # no_tax = self.env['account.tax'].search([ + # ('type_tax_use', '=', 'purchase'), + # ('name', 'ilike', 'no tax') + # ], limit=1) - if not no_tax: - _logger.info("No Tax tidak ditemukan") - return + # if not no_tax: + # _logger.info("No Tax tidak ditemukan") + # return - for order in self: - for line in order.order_line: - if not line.taxes_id: - line.taxes_id = [(6, 0, [no_tax.id])] - _logger.info("Auto-set No tax ke baris product: %s", line.product_id.name) + # for order in self: + # for line in order.order_line: + # if not line.taxes_id: + # line.taxes_id = [(6, 0, [no_tax.id])] + # _logger.info("Auto-set No tax ke baris product: %s", line.product_id.name) @api.onchange('total_cost_service') def _onchange_total_cost_service(self): @@ -1190,8 +1189,8 @@ class PurchaseOrder(models.Model): @api.model #override custom create & write for check payment term def create(self, vals): order = super().create(vals) - order.with_context(skip_check_payment=True)._check_payment_term() - order.with_context(notify_tax=True)._check_tax_rule() + # order.with_context(skip_check_payment=True)._check_payment_term() + # order.with_context(notify_tax=True)._check_tax_rule() return order def write(self, vals): -- cgit v1.2.3