summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-05-06 15:30:04 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-05-06 15:30:04 +0700
commit2bb2ead5a6ee0a76a088f7e522cabc74ac8809be (patch)
treec5d53a9c9b1e5f28a28f3bf7473ebffe07073bcc /indoteknik_custom/models/sale_order.py
parentc1d93cfcef61276db77b9943c38e242141dc41f3 (diff)
push
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
-rwxr-xr-xindoteknik_custom/models/sale_order.py40
1 files changed, 28 insertions, 12 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 1e744f18..0d86019e 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -133,8 +133,9 @@ class SaleOrder(models.Model):
reject_line = fields.One2many('sales.order.reject', 'sale_order_id', string='Reject Lines')
order_sales_match_line = fields.One2many('sales.order.purchase.match', 'sales_order_id', string='Purchase Match Lines', states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True)
total_margin = fields.Float('Total Margin', compute='_compute_total_margin', help="Total Margin in Sales Order Header")
+ total_before_margin = fields.Float('Total Before Margin', compute='_compute_total_before_margin', help="Total Margin in Sales Order Header")
total_percent_margin = fields.Float('Total Percent Margin', compute='_compute_total_percent_margin', help="Total % Margin in Sales Order Header")
- total_margin_excl_third_party = fields.Float('Before Margin', help="Before Margin in Sales Order Header")
+ total_margin_excl_third_party = fields.Float('Before Margin', help="Before Margin in Sales Order Header", compute='_compute_total_margin_excl_third_party')
approval_status = fields.Selection([
('pengajuan1', 'Approval Manager'),
('pengajuan2', 'Approval Pimpinan'),
@@ -302,6 +303,16 @@ class SaleOrder(models.Model):
('approve', 'Approve')
], tracking=True, string='State Cancel', copy=False)
+ def _compute_total_margin_excl_third_party(self):
+ for order in self:
+ if order.amount_untaxed == 0:
+ order.total_margin_excl_third_party = 0
+ continue
+
+ # order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-delivery_amt-order.fee_third_party)) * 100, 2)
+ order.total_margin_excl_third_party = round((order.total_before_margin / (order.amount_untaxed)) * 100, 2)
+ # order.total_percent_margin = round((order.total_margin / (order.amount_untaxed)) * 100, 2)
+
def ask_retur_cancel_purchasing(self):
for rec in self:
if self.env.user.has_group('indoteknik_custom.group_role_purchasing'):
@@ -345,17 +356,17 @@ class SaleOrder(models.Model):
if len(tax_sets) > 1:
raise ValidationError("Semua produk dalam Sales Order harus memiliki kombinasi pajak yang sama.")
- @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 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('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 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):
@@ -1607,6 +1618,11 @@ class SaleOrder(models.Model):
order.total_margin = total_margin
+ def _compute_total_before_margin(self):
+ for order in self:
+ total_before_margin = sum(line.item_before_margin for line in order.order_line if line.product_id)
+ order.total_before_margin = total_before_margin
+
def _compute_total_percent_margin(self):
for order in self:
if order.amount_untaxed == 0: