diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2024-06-20 13:52:27 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2024-06-20 13:52:27 +0700 |
| commit | fe7087deb15d6dfa0d815c2e391cce9e753fd3cf (patch) | |
| tree | df7c86443e71c475a42daf974738ea8f9ac5e517 | |
| parent | 5b3145bc1b56c423629f579e4eab8997e48cb1ad (diff) | |
fix purchase price logic in sale order
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 509e3d1c..d362d573 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -110,9 +110,13 @@ class SaleOrderLine(models.Model): 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: + purchase_price = self.env['purchase.pricelist'].search( + [('vendor_id', '=', self.product_id.x_manufacture.override_vendor_id.id), + ('product_id', '=', self.product_id.id)], + limit=1, order='count_trx_po desc, count_trx_po_vendor desc') + self.purchase_price = self._get_valid_purchase_price(purchase_price) else: - # purchase_price = self.env['purchase.pricelist'].search( - # [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1) 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') @@ -136,11 +140,15 @@ class SaleOrderLine(models.Model): super(SaleOrderLine, self).product_id_change() for line in self: if line.product_id and line.product_id.type == 'product': + query = [('product_id', '=', line.product_id.id)] + if line.product_id.x_manufacture.override_vendor_id: + query = [('product_id', '=', line.product_id.id), + ('vendor_id', '=', line.product_id.x_manufacture.override_vendor_id.id)] purchase_price = self.env['purchase.pricelist'].search( - [('product_id', '=', self.product_id.id)], limit=1, order='count_trx_po desc, count_trx_po_vendor desc') + query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc') line.vendor_id = purchase_price.vendor_id line.tax_id = line.order_id.sales_tax_id - line.purchase_price = self._get_valid_purchase_price(purchase_price) + line.purchase_price = line._get_valid_purchase_price(purchase_price) line_name = ('[' + line.product_id.default_code + ']' if line.product_id.default_code else '') + ' ' + (line.product_id.name if line.product_id.name else '') + ' ' + \ ('(' + line.product_id.product_template_attribute_value_ids.name + ')' if line.product_id.product_template_attribute_value_ids.name else '') + ' ' + \ |
