summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-02-13 13:51:36 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-02-13 13:51:36 +0700
commit78a7df26d09b64fb9b3b45084212cbf19c1907a1 (patch)
tree96ce6f6717be998518102ff432493c3c06baff7b
parentdce36bb896e89a763b182924b0cfa9cec4f39735 (diff)
returns the code to the beginning
-rw-r--r--indoteknik_custom/models/sale_order_line.py44
1 files changed, 18 insertions, 26 deletions
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index af521c2c..aed95aab 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -159,7 +159,7 @@ class SaleOrderLine(models.Model):
# [('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')
- price, taxes, vendor_id = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id, manual=True)
+ price, taxes, vendor_id = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id)
self.purchase_price = price
self.purchase_tax_id = taxes
# else:
@@ -202,49 +202,40 @@ class SaleOrderLine(models.Model):
# self.price_unit = selling_price
# self.tax_id = tax_id
- def _get_purchase_price(self, product_id, manual=False):
+ def _get_purchase_price(self, product_id):
purchase_price = self.env['purchase.pricelist'].search(
- [('product_id', '=', product_id.id)],
- limit=1
- )
-
- vendor_id = purchase_price.brand_id.override_vendor_id
-
- if vendor_id:
- return self._get_purchase_price_by_vendor(product_id, vendor_id, manual)
-
- return self._get_valid_purchase_price(purchase_price, manual)
+ [('product_id', '=', product_id.id),
+ ('is_winner', '=', True)],
+ limit=1)
+ return self._get_valid_purchase_price(purchase_price)
- def _get_purchase_price_by_vendor(self, product_id, vendor_id, manual=False):
+ def _get_purchase_price_by_vendor(self, product_id, vendor_id):
purchase_price = self.env['purchase.pricelist'].search(
[('product_id', '=', product_id.id),
- ('vendor_id', '=', vendor_id.id)],
- limit=1
- )
-
- if purchase_price:
- return self._get_valid_purchase_price(purchase_price, manual)
-
- # Return default values when no purchase_price is found
- return 0, '', None # Ensure 3 values are always returned
+ ('vendor_id', '=', vendor_id.id),
+ # ('is_winner', '=', True)
+ ],
+ limit=1)
+ return self._get_valid_purchase_price(purchase_price)
- def _get_valid_purchase_price(self, purchase_price, manual):
+ def _get_valid_purchase_price(self, purchase_price):
current_time = datetime.now()
delta_time = current_time - timedelta(days=365)
# delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
price = 0
taxes = ''
- vendor_id = purchase_price.vendor_id.id or ''
+ vendor_id = ''
human_last_update = purchase_price.human_last_update or datetime.min
system_last_update = purchase_price.system_last_update or datetime.min
if purchase_price.taxes_product_id.type_tax_use == 'purchase':
price = purchase_price.product_price
taxes = purchase_price.taxes_product_id.id
- if delta_time > human_last_update or (not purchase_price.brand_id.override_vendor_id and manual == False):
+ vendor_id = purchase_price.vendor_id.id
+ if delta_time > human_last_update:
price = 0
taxes = ''
vendor_id = ''
@@ -253,7 +244,8 @@ class SaleOrderLine(models.Model):
if purchase_price.taxes_system_id.type_tax_use == 'purchase':
price = purchase_price.system_price
taxes = purchase_price.taxes_system_id.id
- if delta_time > human_last_update or (not purchase_price.brand_id.override_vendor_id and manual == False):
+ vendor_id = purchase_price.vendor_id.id
+ if delta_time > system_last_update:
price = 0
taxes = ''
vendor_id = ''