From edb3c1c80931078d40a8f56149aeca9efdcdc07d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 6 Feb 2024 15:53:19 +0700 Subject: change request purchasing job --- indoteknik_custom/models/automatic_purchase.py | 28 +++++++++++++++----------- indoteknik_custom/views/automatic_purchase.xml | 1 + 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 4161d895..94dd9cdf 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -284,7 +284,7 @@ class AutomaticPurchase(models.Model): purchase_pricelist = self.env['purchase.pricelist'].search(domain, order=orderby, limit=1) vendor_id = purchase_pricelist.vendor_id - price = self._get_valid_purchase_price(purchase_pricelist) + price, taxes = self._get_valid_purchase_price(purchase_pricelist) last_po_line = self.env['purchase.order.line'].search([('product_id', '=', job.product_id.id), ('order_id.state', '=', 'done')], order='id desc', limit=1) self.env['automatic.purchase.line'].create([{ @@ -294,6 +294,7 @@ class AutomaticPurchase(models.Model): 'qty_available': qty_available, 'partner_id': vendor_id.id, 'last_price': price, + 'taxes_id': taxes, 'subtotal': qty_purchase * price, 'last_order_id': last_po_line.order_id.id, 'last_orderline_id': last_po_line.id, @@ -414,17 +415,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 - else: - p_price = purchase_price.system_price - elif purchase_price.system_price > 0 and purchase_price.product_price == 0: - p_price = purchase_price.system_price - elif purchase_price.system_price == 0 and purchase_price.product_price > 0: - p_price = purchase_price.product_price - return p_price + 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): @@ -447,6 +450,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('account.tax', string='Taxes') @api.onchange('last_price', 'qty_purchase') def _calculate_subtotal(self): diff --git a/indoteknik_custom/views/automatic_purchase.xml b/indoteknik_custom/views/automatic_purchase.xml index edf966d9..244d1caa 100644 --- a/indoteknik_custom/views/automatic_purchase.xml +++ b/indoteknik_custom/views/automatic_purchase.xml @@ -30,6 +30,7 @@ + -- cgit v1.2.3