summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indoteknik_custom/models/sourcing_job_order.py59
1 files changed, 31 insertions, 28 deletions
diff --git a/indoteknik_custom/models/sourcing_job_order.py b/indoteknik_custom/models/sourcing_job_order.py
index d5446c83..04d693f8 100644
--- a/indoteknik_custom/models/sourcing_job_order.py
+++ b/indoteknik_custom/models/sourcing_job_order.py
@@ -1050,52 +1050,55 @@ class SourcingJobOrderLine(models.Model):
self.tax_id = False
self.now_price = 0
self.last_updated_price = False
- else:
+ elif self.product_id.x_manufacture.override_vendor_id:
+ # Memanggil fungsi yang sudah kita perbaiki pengecekannya
price, taxes, vendor_id, last_updated = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id)
+
+ # Nilai ini akan mengosongkan field jika data tidak ditemukan (0.0 atau False)
self.price = price
self.now_price = price
self.tax_id = taxes
self.last_updated_price = last_updated
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)
+ purchase_price = self.env['purchase.pricelist'].search([
+ ('product_id', '=', product_id.id),
+ ('vendor_id', '=', vendor_id.id),
+ ], limit=1)
+ # Jika tidak ketemu di pricelist, kembalikan nilai kosong (reset)
+ if not purchase_price:
+ return 0.0, False, False, False
+
return self._get_valid_purchase_price(purchase_price)
def _get_valid_purchase_price(self, purchase_price):
- if not purchase_price:
- return 0, False, False, False
-
current_time = datetime.now()
delta_time = current_time - timedelta(days=365)
+
+ # Inisialisasi default kosong
+ price = 0.0
+ taxes = False
+ vendor_id = False
+ last_updated = False
human_last_update = purchase_price.human_last_update or False
system_last_update = purchase_price.system_last_update or False
- price = purchase_price.product_price
- taxes = purchase_price.taxes_product_id.id or False
- vendor_id = purchase_price.vendor_id.id
- last_updated = human_last_update
-
- if human_last_update and delta_time > human_last_update:
- price = 0
- taxes = False
- vendor_id = False
-
- if system_last_update and human_last_update and system_last_update > human_last_update:
- price = purchase_price.system_price
- taxes = purchase_price.taxes_system_id.id or False
+ # Logika pengecekan Human Update
+ if human_last_update and human_last_update > delta_time:
+ price = purchase_price.product_price
+ taxes = purchase_price.taxes_product_id.id
vendor_id = purchase_price.vendor_id.id
- last_updated = system_last_update
-
- if system_last_update and delta_time > system_last_update:
- price = 0
- taxes = False
- vendor_id = False
+ last_updated = human_last_update
+
+ # Logika pengecekan System Update (Timpa jika lebih baru)
+ if system_last_update and system_last_update > delta_time:
+ if not last_updated or system_last_update > last_updated:
+ price = purchase_price.system_price
+ taxes = purchase_price.taxes_system_id.id
+ vendor_id = purchase_price.vendor_id.id
+ last_updated = system_last_update
return price, taxes, vendor_id, last_updated