summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-06-05 11:43:02 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-06-05 11:43:02 +0700
commitadd53c91a49d43b20438b14cf48aaececbabf2cd (patch)
tree7738041e1c872baa9fd4215d5152df91cd33a0b6 /indoteknik_custom/models
parent9a3b6feba01b1d27524484f5e612e49412942414 (diff)
<miqdad> add before margin in order line
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/sale_order_line.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index c8066961..da66465e 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -10,6 +10,8 @@ class SaleOrderLine(models.Model):
help="Total Margin in Sales Order Header")
item_percent_margin = fields.Float('%Margin', compute='compute_item_margin',
help="Total % Margin in Sales Order Header")
+ item_percent_margin_before = fields.Float('%Margin Before', compute='_compute_item_percent_margin_before',
+ help="Total % Margin excluding third party in Sales Order Header")
initial_discount = fields.Float('Initial Discount')
vendor_id = fields.Many2one(
'res.partner', string='Vendor', readonly=True,
@@ -134,6 +136,29 @@ class SaleOrderLine(models.Model):
else:
line.item_percent_margin_without_deduction = 0
+ def _compute_item_percent_margin_before(self):
+ for line in self:
+ if not line.product_id or line.product_id.type == 'service' \
+ or line.price_unit <= 0 or line.product_uom_qty <= 0 \
+ or not line.vendor_id:
+ line.item_percent_margin_before = 0
+ continue
+
+ sales_price = line.price_reduce_taxexcl * line.product_uom_qty
+
+ purchase_price = line.purchase_price
+ if line.purchase_tax_id and line.purchase_tax_id.price_include:
+ purchase_price = line.purchase_price / 1.11
+
+ purchase_price = purchase_price * line.product_uom_qty
+
+ margin_before = sales_price - purchase_price
+
+ if sales_price > 0:
+ line.item_percent_margin_before = round((margin_before / sales_price), 4) * 100
+ else:
+ line.item_percent_margin_before = 0
+
def compute_item_margin(self):
for line in self:
if not line.product_id or line.product_id.type == 'service' \