diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-05 11:43:02 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-05 11:43:02 +0700 |
| commit | add53c91a49d43b20438b14cf48aaececbabf2cd (patch) | |
| tree | 7738041e1c872baa9fd4215d5152df91cd33a0b6 | |
| parent | 9a3b6feba01b1d27524484f5e612e49412942414 (diff) | |
<miqdad> add before margin in order line
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 25 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 6 |
2 files changed, 31 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' \ diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 03c978a7..4b74825e 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -208,6 +208,11 @@ <label for="item_percent_margin"/> <field name="item_percent_margin"/> </div> + <div name="item_percent_margin_before" groups="base.group_no_one" + attrs="{'invisible': [('display_type', '!=', False)]}"> + <label for="item_percent_margin_before"/> + <field name="item_percent_margin_before"/> + </div> </div> <div name="invoice_lines" position="before"> <div name="price_subtotal" groups="base.group_no_one" @@ -239,6 +244,7 @@ attrs="{'readonly': [('parent.approval_status', '!=', False)]}" domain="[('type_tax_use','=','purchase')]" options="{'no_create':True}"/> <field name="item_percent_margin"/> + <field name="item_percent_margin_before"/> <field name="item_margin" optional="hide"/> <field name="margin_md" optional="hide"/> <field name="note" optional="hide"/> |
