summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-10-23 19:06:32 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-10-23 19:06:32 +0700
commitc35137e5a43afeb6a45b7f213f9ab40afb75fb4c (patch)
tree0ffd81602112cd77c19d593fa261cc116410b8ab
parent5ddda2a380e9aeaf63241e8f6b1c35e3005a3468 (diff)
change logic of valid purchase pricelist in sales order
-rw-r--r--indoteknik_custom/models/sale_order_line.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index d0985de5..748153ad 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -72,21 +72,33 @@ class SaleOrderLine(models.Model):
cost = self.product_id.standard_price
self.purchase_price = cost
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)
- self.purchase_price = purchase_price.product_price
+ [('vendor_id', '=', self.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)
self.purchase_tax_id = 22
+ def _get_valid_purchase_price(self, purchase_price):
+ p_price = 0
+ if purchase_price.system_price > 0 and purchase_price.product_price > 0:
+ if purchase_price.human_last_update > purchase_price.system_last_update:
+ p_price = purchase_price.product_price
+ else:
+ p_price = purchase_price.system_price
+ return p_price
+
@api.onchange('product_id')
def product_id_change(self):
super(SaleOrderLine, self).product_id_change()
for line in self:
if line.product_id and line.product_id.type == 'product':
purchase_price = self.env['purchase.pricelist'].search(
- [('product_id', '=', self.product_id.id)], limit=1, order='product_price ASC')
+ [('product_id', '=', self.product_id.id)], 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 = purchase_price.product_price
+ line.purchase_price = self._get_valid_purchase_price(purchase_price)
def compute_delivery_amt_line(self):
for line in self: