diff options
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index bee7d6a7..89ed0327 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -239,8 +239,14 @@ class SaleOrder(models.Model): @api.constrains('fee_third_party', 'delivery_amt', 'biaya_lain_lain') def _check_total_margin_excl_third_party(self): for rec in self: - if rec.fee_third_party == 0: - rec.total_margin_excl_third_party = rec.total_percent_margin + if rec.fee_third_party == 0 and rec.total_margin_excl_third_party != rec.total_percent_margin: + # Gunakan direct SQL atau flag context untuk menghindari rekursi + self.env.cr.execute(""" + UPDATE sale_order + SET total_margin_excl_third_party = %s + WHERE id = %s + """, (rec.total_percent_margin, rec.id)) + self.invalidate_cache() @api.constrains('shipping_option_id') def _check_shipping_option(self): @@ -1692,7 +1698,7 @@ class SaleOrder(models.Model): order._compute_etrts_date() order._validate_expected_ready_ship_date() order._validate_delivery_amt() - order._check_total_margin_excl_third_party() + # order._check_total_margin_excl_third_party() # order._update_partner_details() return order @@ -1736,7 +1742,7 @@ class SaleOrder(models.Model): res = super(SaleOrder, self).write(vals) self._validate_delivery_amt() - self._check_total_margin_excl_third_party() + # self._check_total_margin_excl_third_party() if any(field in vals for field in ["order_line", "client_order_ref"]): self._calculate_etrts_date() if 'order_line' in vals: |
