From a699dd3899c9235b3dcc4de6ad277b687940e2b5 Mon Sep 17 00:00:00 2001 From: HafidBuroiroh Date: Sat, 14 Mar 2026 13:23:26 +0700 Subject: fix error purchase price --- indoteknik_custom/models/sourcing_job_order.py | 28 ++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/indoteknik_custom/models/sourcing_job_order.py b/indoteknik_custom/models/sourcing_job_order.py index 9729fc45..d5446c83 100644 --- a/indoteknik_custom/models/sourcing_job_order.py +++ b/indoteknik_custom/models/sourcing_job_order.py @@ -1050,7 +1050,7 @@ class SourcingJobOrderLine(models.Model): self.tax_id = False self.now_price = 0 self.last_updated_price = False - elif self.product_id.x_manufacture.override_vendor_id: + else: price, taxes, vendor_id, last_updated = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id) self.price = price self.now_price = price @@ -1067,36 +1067,34 @@ class SourcingJobOrderLine(models.Model): 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) - default_timestamp = datetime(1970, 1, 1, 0, 0, 0) - # delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') - price = 0 - taxes = 24 - vendor_id = False human_last_update = purchase_price.human_last_update or False system_last_update = purchase_price.system_last_update or False - # if purchase_price.taxes_product_id.type_tax_use == 'purchase': price = purchase_price.product_price - taxes = purchase_price.taxes_product_id.id or 24 + taxes = purchase_price.taxes_product_id.id or False vendor_id = purchase_price.vendor_id.id last_updated = human_last_update - if delta_time > human_last_update: + + if human_last_update and delta_time > human_last_update: price = 0 - taxes = 24 + taxes = False vendor_id = False - if system_last_update > human_last_update: - # if purchase_price.taxes_system_id.type_tax_use == 'purchase': + 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 24 + taxes = purchase_price.taxes_system_id.id or False vendor_id = purchase_price.vendor_id.id last_updated = system_last_update - if delta_time > system_last_update: + + if system_last_update and delta_time > system_last_update: price = 0 - taxes = 24 + taxes = False vendor_id = False return price, taxes, vendor_id, last_updated -- cgit v1.2.3 From a5dc9365c947388f7bafab84e0178d66643d32da Mon Sep 17 00:00:00 2001 From: HafidBuroiroh Date: Sat, 14 Mar 2026 14:07:33 +0700 Subject: fix error purchase price --- indoteknik_custom/models/sourcing_job_order.py | 59 ++++++++++++++------------ 1 file 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 -- cgit v1.2.3