diff options
Diffstat (limited to 'indoteknik_custom')
| -rw-r--r-- | indoteknik_custom/models/sourcing_job_order.py | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/indoteknik_custom/models/sourcing_job_order.py b/indoteknik_custom/models/sourcing_job_order.py index 9729fc45..04d693f8 100644 --- a/indoteknik_custom/models/sourcing_job_order.py +++ b/indoteknik_custom/models/sourcing_job_order.py @@ -1051,53 +1051,54 @@ class SourcingJobOrderLine(models.Model): self.now_price = 0 self.last_updated_price = False 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): 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 + + # 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 - # if purchase_price.taxes_product_id.type_tax_use == 'purchase': - price = purchase_price.product_price - taxes = purchase_price.taxes_product_id.id or 24 - vendor_id = purchase_price.vendor_id.id - last_updated = human_last_update - if delta_time > human_last_update: - price = 0 - taxes = 24 - vendor_id = False - - if system_last_update > human_last_update: - # if purchase_price.taxes_system_id.type_tax_use == 'purchase': - price = purchase_price.system_price - taxes = purchase_price.taxes_system_id.id or 24 + # 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 delta_time > system_last_update: - price = 0 - taxes = 24 - 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 |
