From 331671549aacb0d8f6b4448a4e788fd530f78654 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 23 Jan 2024 15:32:58 +0700 Subject: fix automatic purchase --- indoteknik_custom/models/automatic_purchase.py | 31 ++++++++++++-------------- indoteknik_custom/models/purchase_pricelist.py | 2 +- indoteknik_custom/views/automatic_purchase.xml | 1 + 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 3ab56e50..bf6901d3 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -140,22 +140,19 @@ class AutomaticPurchase(models.Model): self.notification = "Automatic PO Created %s Lines" % count 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 - taxes = purchase_price.taxes_product_id - else: - p_price = purchase_price.system_price - taxes = purchase_price.taxes_system_id - elif purchase_price.system_price > 0 and purchase_price.product_price == 0: - p_price = purchase_price.system_price - taxes = purchase_price.taxes_system_id - elif purchase_price.system_price == 0 and purchase_price.product_price > 0: - p_price = purchase_price.product_price - taxes = purchase_price.taxes_product_id - - return p_price, taxes + price = 0 + taxes = None + human_last_update = purchase_price.human_last_update or datetime.min + system_last_update = purchase_price.system_last_update or datetime.min + + if system_last_update > human_last_update: + price = purchase_price.system_price + taxes = purchase_price.taxes_system_id.id + else: + price = purchase_price.product_price + taxes = purchase_price.taxes_product_id.id + + return price, taxes class AutomaticPurchaseLine(models.Model): @@ -178,7 +175,7 @@ class AutomaticPurchaseLine(models.Model): current_po_id = fields.Many2one('purchase.order', string='Current') current_po_line_id = fields.Many2one('purchase.order.line', string='Current Line') brand_id = fields.Many2one('x_manufactures', string='Brand') - taxes_id = fields.Many2one('x_manufactures', string='Brand') + taxes_id = fields.Many2one('account.tax', string='Taxes') class AutomaticPurchaseMatch(models.Model): diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index 43efb7b5..c756c301 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -23,7 +23,7 @@ class PurchasePricelist(models.Model): def _compute_name(self): self.name = self.vendor_id.name + ', ' + self.product_id.name - @api.constrains('product_price','system_price','vendor_id','product_id') + @api.constrains('product_price','system_price','vendor_id','product_id','taxes_system_id','taxes_product_id') def _contrains_product_price(self): current_time = fields.Datetime.now(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S') update_by = self._context.get('update_by') diff --git a/indoteknik_custom/views/automatic_purchase.xml b/indoteknik_custom/views/automatic_purchase.xml index 0478304e..245fda90 100644 --- a/indoteknik_custom/views/automatic_purchase.xml +++ b/indoteknik_custom/views/automatic_purchase.xml @@ -22,6 +22,7 @@ + -- cgit v1.2.3