summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-04-16 15:45:32 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-04-16 15:45:32 +0700
commit5eee94e7c5fbf71143fd8bad78baae3853e71f2d (patch)
tree45aff39cf35aba227639b01f97fdcca6e66db081
parent5d23cbb6ba8e6fda650a83774b6f6b09234f64e3 (diff)
fix bug compute total margin
-rwxr-xr-xindoteknik_custom/models/purchase_order.py93
1 files changed, 48 insertions, 45 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 098d05cb..d7d83af0 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -488,54 +488,57 @@ class PurchaseOrder(models.Model):
purchase_price_dict = {}
for lines in self.order_line:
- product_id = lines.product_id.id
+ # product_id = lines.product_id.id
- if product_id not in purchase_price_dict:
- purchase_price_dict[product_id] = lines.price_subtotal
-
- sum_so_margin = sum_sales_price = sum_margin = 0
- for line in self.order_sales_match_line:
- 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')
-
- sum_so_margin += sale_order_line.item_margin
-
- sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty
-
- if sale_order_line.order_id.shipping_cost_covered == 'indoteknik':
- sales_price -= sale_order_line.delivery_amt_line
-
- if sale_order_line.order_id.fee_third_party > 0:
- sales_price -= sale_order_line.fee_third_party_line
-
- sum_sales_price += sales_price
-
- product_id = sale_order_line.product_id.id
-
- purchase_price = purchase_price_dict.get(product_id, 0)
-
- if line.purchase_order_id.delivery_amount > 0:
- purchase_price += line.delivery_amt_line
-
- real_item_margin = sales_price - purchase_price
- sum_margin += real_item_margin
+ # if product_id not in purchase_price_dict:
+ # purchase_price_dict[product_id] = lines.price_subtotal
+ sum_so_margin = sum_sales_price = sum_margin = 0
+ for line in self.order_sales_match_line:
+ 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')
- 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
+ sum_so_margin += sale_order_line.item_margin
+
+ # sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty
+ sales_price = sale_order_line.price_reduce_taxexcl * lines.product_qty
+
+ if sale_order_line.order_id.shipping_cost_covered == 'indoteknik':
+ sales_price -= sale_order_line.delivery_amt_line
+
+ if sale_order_line.order_id.fee_third_party > 0:
+ sales_price -= sale_order_line.fee_third_party_line
+
+ sum_sales_price += sales_price
+
+ product_id = sale_order_line.product_id.id
+
+ # purchase_price = purchase_price_dict.get(product_id, 0)
+ purchase_price = lines.price_subtotal
+ if lines.order_id.delivery_amount > 0:
+ purchase_price += lines.delivery_amt_line
+
+ if line.purchase_order_id.delivery_amount > 0:
+ purchase_price += line.delivery_amt_line
+
+ 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
def compute_amt_total_without_service(self):
for order in self: