summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order_line.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-07-28 15:09:55 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-07-28 15:09:55 +0700
commitd15ce4e186e2b77f01e8dfd03886298cc733d4c1 (patch)
tree1b32a4c29c4fcea85070fcecb5b77a7d55d30029 /indoteknik_custom/models/sale_order_line.py
parentdeba962d7368a5c4e30441b5a640102608e3dde6 (diff)
parent36a53535dbdc5777266fd9276b4c557259dab6be (diff)
<hafid> merging odoo-backup
Diffstat (limited to 'indoteknik_custom/models/sale_order_line.py')
-rw-r--r--indoteknik_custom/models/sale_order_line.py117
1 files changed, 79 insertions, 38 deletions
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index 9247d1c1..5e9fc362 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -5,20 +5,26 @@ from datetime import datetime, timedelta
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
+
item_margin = fields.Float('Margin', compute='compute_item_margin', help="Total Margin in Sales Order Header")
- item_before_margin = fields.Float('Before Margin', compute='compute_item_before_margin', 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_before_margin = fields.Float('Before Margin', compute='compute_item_before_margin',
+ 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,
change_default=True, index=True, tracking=1,
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]"
- )
- vendor_md_id = fields.Many2one('res.partner', string='MD Vendor')
+ )
+ vendor_md_id = fields.Many2one('res.partner', string='MD Vendor')
purchase_price = fields.Float('Purchase', required=True, digits='Product Price', default=0.0)
purchase_price_md = fields.Float('MD Purchase')
- purchase_tax_id = fields.Many2one('account.tax', string='Tax', domain=['|', ('active', '=', False), ('active', '=', True)])
+ purchase_tax_id = fields.Many2one('account.tax', string='Tax',
+ domain=['|', ('active', '=', False), ('active', '=', True)])
delivery_amt_line = fields.Float('DeliveryAmtLine', compute='compute_delivery_amt_line')
fee_third_party_line = fields.Float('FeeThirdPartyLine', compute='compute_fee_third_party_line', default=0)
line_no = fields.Integer('No', default=0, copy=False)
@@ -28,13 +34,15 @@ class SaleOrderLine(models.Model):
('info_vendor', 'Info Vendor'),
('penggabungan', 'Penggabungan'),
], string='Note', help="Harap diisi jika ada keterangan tambahan dari Procurement, agar dapat dimonitoring")
- note_procurement = fields.Char(string='Note Detail', help="Harap diisi jika ada keterangan tambahan dari Procurement, agar dapat dimonitoring")
+ note_procurement = fields.Char(string='Note Detail',
+ help="Harap diisi jika ada keterangan tambahan dari Procurement, agar dapat dimonitoring")
vendor_subtotal = fields.Float(string='Vendor Subtotal', compute="_compute_vendor_subtotal")
amount_voucher_disc = fields.Float(string='Voucher Discount')
qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved')
- product_available_quantity = fields.Float(string='Qty pickup by user',)
+ product_available_quantity = fields.Float(string='Qty pickup by user', )
reserved_from = fields.Char(string='Reserved From', copy=False)
- item_percent_margin_without_deduction = fields.Float('Margin Without Deduction', compute='_compute_item_margin_without_deduction')
+ item_percent_margin_without_deduction = fields.Float('Margin Without Deduction',
+ compute='_compute_item_margin_without_deduction')
weight = fields.Float(string='Weight')
md_vendor_id = fields.Many2one('res.partner', string='MD Vendor', readonly=True)
margin_md = fields.Float(string='Margin MD')
@@ -45,7 +53,8 @@ class SaleOrderLine(models.Model):
outgoing_moves = self.env['stock.move']
incoming_moves = self.env['stock.move']
- for move in self.move_ids.filtered(lambda r: r.state != 'cancel' and not r.scrapped and self.product_id == r.product_id):
+ for move in self.move_ids.filtered(
+ lambda r: r.state != 'cancel' and not r.scrapped and self.product_id == r.product_id):
if move.location_dest_id.usage == "customer":
if not move.origin_returned_move_id or (move.origin_returned_move_id and move.to_refund):
outgoing_moves |= move
@@ -80,7 +89,7 @@ class SaleOrderLine(models.Model):
if not self.product_uom or not self.product_id:
self.price_unit = 0.0
return
-
+
self.price_unit = self.price_unit
def _compute_qty_reserved(self):
@@ -128,6 +137,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), 2) * 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' \
@@ -141,8 +173,8 @@ class SaleOrderLine(models.Model):
# minus with delivery if covered by indoteknik
if line.order_id.shipping_cost_covered == 'indoteknik':
sales_price -= line.delivery_amt_line
- if line.order_id.fee_third_party > 0:
- sales_price -= line.fee_third_party_line
+ # if line.order_id.fee_third_party > 0:
+ # sales_price -= line.fee_third_party_line
purchase_price = line.purchase_price
if line.purchase_tax_id.price_include:
@@ -158,7 +190,7 @@ class SaleOrderLine(models.Model):
line.item_percent_margin = 0
if not line.margin_md:
- line.margin_md = line.item_percent_margin
+ line.margin_md = line.item_percent_margin
def compute_item_before_margin(self):
for line in self:
@@ -169,7 +201,7 @@ class SaleOrderLine(models.Model):
continue
# calculate margin without tax
sales_price = line.price_reduce_taxexcl * line.product_uom_qty
-
+
purchase_price = line.purchase_price
if line.purchase_tax_id.price_include:
purchase_price = line.purchase_price / 1.11
@@ -183,7 +215,7 @@ class SaleOrderLine(models.Model):
# TODO : need to change this logic @stephan
if not self.product_id or self.product_id.type == 'service':
return
- elif self.product_id.categ_id.id == 34: # finish good / manufacturing only
+ elif self.product_id.categ_id.id == 34: # finish good / manufacturing only
cost = self.product_id.standard_price
self.purchase_price = cost
elif self.product_id.x_manufacture.override_vendor_id:
@@ -195,12 +227,12 @@ class SaleOrderLine(models.Model):
self.purchase_price = price
self.purchase_tax_id = taxes
# else:
- # purchase_price = self.env['purchase.pricelist'].search(
- # [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)],
- # limit=1, order='count_trx_po desc, count_trx_po_vendor desc')
- # price, taxes = self._get_valid_purchase_price(purchase_price)
- # self.purchase_price = price
- # self.purchase_tax_id = taxes
+ # purchase_price = self.env['purchase.pricelist'].search(
+ # [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)],
+ # limit=1, order='count_trx_po desc, count_trx_po_vendor desc')
+ # price, taxes = self._get_valid_purchase_price(purchase_price)
+ # self.purchase_price = price
+ # self.purchase_tax_id = taxes
# def _calculate_selling_price(self):
# rec_purchase_price, rec_taxes, rec_vendor_id = self._get_purchase_price(self.product_id)
@@ -260,7 +292,7 @@ class SaleOrderLine(models.Model):
price = 0
taxes = 24
- vendor_id = ''
+ vendor_id = False
human_last_update = purchase_price.human_last_update or datetime.min
system_last_update = purchase_price.system_last_update or datetime.min
@@ -271,18 +303,18 @@ class SaleOrderLine(models.Model):
if delta_time > human_last_update:
price = 0
taxes = 24
- vendor_id = ''
+ vendor_id = False
if system_last_update > human_last_update:
- #if purchase_price.taxes_system_id.type_tax_use == 'purchase':
+ # if purchase_price.taxes_system_id.type_tax_use == 'purchase':
price = purchase_price.system_price
taxes = purchase_price.taxes_system_id.id or 24
vendor_id = purchase_price.vendor_id.id
if delta_time > system_last_update:
price = 0
taxes = 24
- vendor_id = ''
-
+ vendor_id = False
+
return price, taxes, vendor_id
@api.onchange('product_id')
@@ -302,11 +334,11 @@ class SaleOrderLine(models.Model):
line.tax_id = line.order_id.sales_tax_id
# price, taxes = line._get_valid_purchase_price(purchase_price)
line.purchase_price = price
- line.purchase_tax_id = taxes
+ line.purchase_tax_id = taxes
attribute_values = line.product_id.product_template_attribute_value_ids.mapped('name')
attribute_values_str = ', '.join(attribute_values) if attribute_values else ''
-
+
line_name = ('[' + line.product_id.default_code + ']' if line.product_id.default_code else '') + ' ' + \
(line.product_id.name if line.product_id.name else '') + ' ' + \
('(' + attribute_values_str + ')' if attribute_values_str else '') + ' ' + \
@@ -324,7 +356,7 @@ class SaleOrderLine(models.Model):
price, taxes, vendor_id = self._get_purchase_price(line.product_id)
line.vendor_md_id = vendor_id if vendor_id else None
line.margin_md = line.item_percent_margin
- line.purchase_price_md = price
+ line.purchase_price_md = price
def compute_delivery_amt_line(self):
for line in self:
@@ -363,11 +395,15 @@ class SaleOrderLine(models.Model):
fiscal_position=self.env.context.get('fiscal_position')
)
- product_context = dict(self.env.context, partner_id=self.order_id.partner_id.id, date=self.order_id.date_order, uom=self.product_uom.id)
+ product_context = dict(self.env.context, partner_id=self.order_id.partner_id.id, date=self.order_id.date_order,
+ uom=self.product_uom.id)
price, rule_id = self.order_id.pricelist_id.with_context(product_context).get_product_price_rule(
self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_id)
- new_list_price, currency = self.with_context(product_context)._get_real_price_currency(product, rule_id, self.product_uom_qty, self.product_uom, self.order_id.pricelist_id.id)
+ new_list_price, currency = self.with_context(product_context)._get_real_price_currency(product, rule_id,
+ self.product_uom_qty,
+ self.product_uom,
+ self.order_id.pricelist_id.id)
new_list_price = product.web_price
if new_list_price != 0:
@@ -390,8 +426,8 @@ class SaleOrderLine(models.Model):
no_variant_attributes_price_extra = [
ptav.price_extra for ptav in self.product_no_variant_attribute_value_ids.filtered(
lambda ptav:
- ptav.price_extra and
- ptav not in product.product_template_attribute_value_ids
+ ptav.price_extra and
+ ptav not in product.product_template_attribute_value_ids
)
]
if no_variant_attributes_price_extra:
@@ -401,10 +437,15 @@ class SaleOrderLine(models.Model):
if self.order_id.pricelist_id.discount_policy == 'with_discount':
return product.with_context(pricelist=self.order_id.pricelist_id.id, uom=self.product_uom.id).price
- product_context = dict(self.env.context, partner_id=self.order_id.partner_id.id, date=self.order_id.date_order, uom=self.product_uom.id)
-
- final_price, rule_id = self.order_id.pricelist_id.with_context(product_context).get_product_price_rule(product or self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_id)
- base_price, currency = self.with_context(product_context)._get_real_price_currency(product, rule_id, self.product_uom_qty, self.product_uom, self.order_id.pricelist_id.id)
+ product_context = dict(self.env.context, partner_id=self.order_id.partner_id.id, date=self.order_id.date_order,
+ uom=self.product_uom.id)
+
+ final_price, rule_id = self.order_id.pricelist_id.with_context(product_context).get_product_price_rule(
+ product or self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_id)
+ base_price, currency = self.with_context(product_context)._get_real_price_currency(product, rule_id,
+ self.product_uom_qty,
+ self.product_uom,
+ self.order_id.pricelist_id.id)
base_price = product.web_price
if currency != self.order_id.pricelist_id.currency_id:
base_price = currency._convert(
@@ -413,7 +454,7 @@ class SaleOrderLine(models.Model):
# negative discounts (= surcharge) are included in the display price
return max(base_price, final_price)
-
+
def validate_line(self):
for line in self:
if line.product_id.id in [385544, 224484, 417724]: