From a37bc839612b5162b4446182ac23c1dfd1c3253e Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 12 Sep 2024 14:17:36 +0700 Subject: calculate margin after purchase delivery deduction --- indoteknik_custom/models/purchase_order.py | 11 +++++++++++ 1 file changed, 11 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 edcbbb19..afa67cf2 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -69,6 +69,17 @@ class PurchaseOrder(models.Model): date_done_picking = fields.Datetime(string='Date Done Picking', compute='get_date_done') bills_dp_id = fields.Many2one('account.move', string='Bills DP') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') + total_margin_match = fields.Float(string='Total Margin Match', compute='_compute_total_margin_match') + + def _compute_total_margin_match(self): + for purchase in self: + match = self.env['purchase.order.sales.match'] + result = match.read_group( + [('purchase_order_id.id', '=', purchase.id)], + ['margin_item'], + [] + ) + purchase.total_margin_match = result[0].get('margin_item', 0.0) def _compute_grand_total(self): for order in self: -- cgit v1.2.3 From 98bdb05daa79c46b0a1f4284d19e65ed3a7d2f48 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 14 Sep 2024 13:30:14 +0700 Subject: bug fix delete purchase order line cause of calculate margin match --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 afa67cf2..8a47482a 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -75,7 +75,7 @@ class PurchaseOrder(models.Model): for purchase in self: match = self.env['purchase.order.sales.match'] result = match.read_group( - [('purchase_order_id.id', '=', purchase.id)], + [('purchase_order_id', '=', purchase.id)], ['margin_item'], [] ) -- cgit v1.2.3