summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-09-29 10:58:52 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-09-29 10:58:52 +0700
commitc8295772706a8e27d4633706b357ade5c4a8bba8 (patch)
treeaa12aa91c4b9a79676c0cddc301f3934517d7ac0
parent7f1d89998467de2b2519bc17dffb5f9c2723c230 (diff)
Update purchase_order.py and sale_order.py
-rwxr-xr-xindoteknik_custom/models/purchase_order.py3
-rwxr-xr-xindoteknik_custom/models/sale_order.py8
2 files changed, 7 insertions, 4 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index ff07d32c..6b038e69 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -171,8 +171,7 @@ class PurchaseOrder(models.Model):
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 -= round(
- (sale_order_line.order_id.delivery_amt / sale_order_line.order_id.count_line_product), 2)
+ sales_price -= round((sale_order_line.order_id.delivery_amt / sale_order_line.order_id.count_line_product), 2)
sum_sales_price += sales_price
purchase_price = line.price_subtotal
if line.order_id.delivery_amount > 0:
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 9f70f05b..4ab8aa17 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -95,16 +95,20 @@ class SaleOrder(models.Model):
def compute_total_margin(self):
for order in self:
- total_margin = total_percent_margin = 0
+ total_margin = total_percent_margin = sum_sales_price = 0
for line in order.order_line:
if not line.product_id:
order.total_margin = 0
order.total_percent_margin = 0
continue
total_margin += line.item_margin
+ sales_price = line.price_reduce_taxexcl * line.product_uom_qty
+ if line.order_id.shipping_cost_covered == 'indoteknik':
+ sales_price -= round((line.order_id.delivery_amt / line.order_id.count_line_product), 2)
+ sum_sales_price += sales_price
order.total_margin = total_margin
if order.amount_untaxed > 0:
- total_percent_margin = round((total_margin / order.amount_untaxed), 2) * 100
+ total_percent_margin = round((total_margin / sum_sales_price), 2) * 100
order.total_percent_margin = total_percent_margin
def compute_count_line_product(self):