diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-10-18 11:27:24 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-10-18 11:27:24 +0700 |
| commit | 2a61388ec5938888710d7c15f660f19ed55def51 (patch) | |
| tree | 7e03c341fa857addba736abf5c4690bbc132c83e | |
| parent | e7707d60252b5e026b64597fc66cf867fa8d3a70 (diff) | |
push
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 51517437..7fc038a0 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1420,63 +1420,50 @@ class PurchaseOrder(models.Model): ('product_id', '=', line.product_id.id), ('order_id', '=', line.purchase_order_id.id) ], limit=1) - sale_order_line = line.sale_line_id - if not sale_order_line: - sale_order_line = self.env['sale.order.line'].search([ - ('product_id', '=', line.product_id.id), - ('order_id', '=', line.sale_id.id) - ], limit=1, order='price_reduce_taxexcl') + sale_order_line = line.sale_line_id or self.env['sale.order.line'].search([ + ('product_id', '=', line.product_id.id), + ('order_id', '=', line.sale_id.id) + ], limit=1, order='price_reduce_taxexcl') if sale_order_line and po_line: - so_margin = (line.qty_po / line.qty_so) * sale_order_line.item_margin + qty_so = line.qty_so or 0 + qty_po = line.qty_po or 0 + + # Hindari division by zero + so_margin = (qty_po / qty_so) * sale_order_line.item_margin if qty_so > 0 else 0 sum_so_margin += so_margin - sales_price = sale_order_line.price_reduce_taxexcl * line.qty_po + sales_price = sale_order_line.price_reduce_taxexcl * qty_po if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': - sales_price -= (sale_order_line.delivery_amt_line / sale_order_line.product_uom_qty) * line.qty_po + sales_price -= (sale_order_line.delivery_amt_line / sale_order_line.product_uom_qty) * qty_po if sale_order_line.order_id.fee_third_party > 0: - sales_price -= (sale_order_line.fee_third_party_line / sale_order_line.product_uom_qty) * line.qty_po + sales_price -= (sale_order_line.fee_third_party_line / sale_order_line.product_uom_qty) * qty_po sum_sales_price += sales_price - purchase_price = po_line.price_subtotal if po_line.ending_price > 0: if po_line.taxes_id.id == 22: - ending_price = po_line.ending_price / 1.11 - purchase_price = ending_price + purchase_price = po_line.ending_price / 1.11 else: purchase_price = po_line.ending_price if line.purchase_order_id.delivery_amount > 0: - purchase_price += (po_line.delivery_amt_line / po_line.product_qty) * line.qty_po + purchase_price += (po_line.delivery_amt_line / po_line.product_qty) * 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: + # Akumulasi hasil akhir + if sum_sales_price != 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 - + self.total_margin = self.total_percent_margin = 0 + self.total_so_margin = self.total_so_percent_margin = 0 - 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 def compute_amt_total_without_service(self): for order in self: |
