diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-01-23 15:32:58 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-01-23 15:32:58 +0700 |
| commit | 331671549aacb0d8f6b4448a4e788fd530f78654 (patch) | |
| tree | c26a61431b046ecdd4126f4013ef3f1713a7e984 | |
| parent | 3ba2dce46cb057125ff6ca2f54d8fbeae0af375c (diff) | |
fix automatic purchase
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 31 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_pricelist.py | 2 | ||||
| -rw-r--r-- | 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 @@ <tree> <field name="brand_id"/> <field name="product_id"/> + <field name="taxes_id"/> <field name="qty_purchase"/> <field name="qty_min"/> <field name="qty_max"/> |
