diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-01-15 16:19:58 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-01-15 16:19:58 +0700 |
| commit | b764acbc595dd68fe1aeeda3f8f92977d0f6d4bc (patch) | |
| tree | 8cbc3cbc9af13b17fce0bc4571d55c438ac5c5d4 | |
| parent | 4ad4ee17e29d9583b1d2da76af93a1c28fbc8874 (diff) | |
fix margin po
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index a69bfc15..777e8ed2 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -965,17 +965,25 @@ class PurchaseOrder(models.Model): sales_price -= (sale_order_line.fee_third_party_line / sale_order_line.product_uom_qty) * line.qty_po sum_sales_price += sales_price - if po_line.ending_price > 0: - price = po_line.ending_price - else: - price = po_line.price_subtotal - purchase_price = price / po_line.product_qty * line.qty_po + purchase_price = po_line.price_subtotal / po_line.product_qty * line.qty_po if line.purchase_order_id.delivery_amount > 0: purchase_price += (po_line.delivery_amt_line / po_line.product_qty) * line.qty_po if line.purchase_order_id.delivery_amt > 0: purchase_price += line.purchase_order_id.delivery_amt real_item_margin = sales_price - purchase_price sum_margin += real_item_margin + + if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: + self.total_so_margin = sum_so_margin + self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 + self.total_margin = sum_margin + self.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 + + else: + self.total_margin = 0 + self.total_percent_margin = 0 + self.total_so_margin = 0 + self.total_so_percent_margin = 0 if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: |
