summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2025-05-30 02:10:42 +0000
committerIT Fixcomart <it@fixcomart.co.id>2025-05-30 02:10:42 +0000
commitcf659eab17c38994334badb8c332450aaf0bf5c9 (patch)
treee2ff0856dba58066cb1f34222d6ce1f885369c79
parent5d1aeb8f94e9fadeaa9eb4357ad76ff6940409e5 (diff)
parent76c8db3d444197af6e29a9b4071054383db9d4f7 (diff)
Merged in fix/vendor_id (pull request #315)
<miqdad> vendor_id return false/null instead of empty string
-rw-r--r--indoteknik_custom/models/sale_order_line.py87
1 files changed, 51 insertions, 36 deletions
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index 9247d1c1..c8066961 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -6,19 +6,22 @@ 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")
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 +31,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 +50,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 +86,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):
@@ -158,7 +164,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 +175,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 +189,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 +201,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 +266,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 +277,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 +308,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 +330,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 +369,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 +400,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 +411,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 +428,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]: