From e5dbcd62560f4083d413d474b123ed971926a2a0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 22 Jan 2024 16:58:11 +0700 Subject: final fix bug purchase pricelist --- indoteknik_custom/models/automatic_purchase.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models/automatic_purchase.py') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 502761e0..7b02a13e 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -89,9 +89,9 @@ class AutomaticPurchase(models.Model): query = [ ('product_min_qty', '>', 0), - ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id) + # ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id) ] - orderpoints = self.env['stock.warehouse.orderpoint'].search(query) + orderpoints = self.env['stock.warehouse.orderpoint'].search(query, limit=100) count = 0 for point in orderpoints: # _logger.info('test %s' % point.product_id.name) @@ -113,7 +113,7 @@ class AutomaticPurchase(models.Model): ], order='count_trx_po desc, count_trx_po_vendor desc', limit=1) vendor_id = purchase_price.vendor_id.id - price = self._get_valid_purchase_price(purchase_price) + price, taxes = self._get_valid_purchase_price(purchase_price) if self.vendor_id and self.vendor_id.id != vendor_id: continue @@ -129,6 +129,7 @@ class AutomaticPurchase(models.Model): # 'last_price': po_line.price_unit, 'partner_id': vendor_id, 'last_price': price, + 'taxes_id': taxes, 'subtotal': qty_purchase * price, 'last_order_id': po_line.order_id.id, 'last_orderline_id': po_line.id, @@ -142,14 +143,19 @@ class AutomaticPurchase(models.Model): 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 + 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 - return p_price + taxes = purchase_price.taxes_product_id + + return p_price, taxes class AutomaticPurchaseLine(models.Model): @@ -172,6 +178,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') class AutomaticPurchaseMatch(models.Model): -- cgit v1.2.3 From f7fe2253a8c79ff5172cf74c1f1aa341c9bf4f07 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 23 Jan 2024 10:03:42 +0700 Subject: fix bug purchase pricelist, bug automatic purchase, bug log saleorder eta date --- indoteknik_custom/models/automatic_purchase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/automatic_purchase.py') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 7b02a13e..3ab56e50 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -89,9 +89,9 @@ class AutomaticPurchase(models.Model): query = [ ('product_min_qty', '>', 0), - # ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id) + ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id) ] - orderpoints = self.env['stock.warehouse.orderpoint'].search(query, limit=100) + orderpoints = self.env['stock.warehouse.orderpoint'].search(query) count = 0 for point in orderpoints: # _logger.info('test %s' % point.product_id.name) -- cgit v1.2.3 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 ++++++++++++-------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'indoteknik_custom/models/automatic_purchase.py') 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): -- cgit v1.2.3 From f38eba228ef0e95ce3a0d1079f4d81153fc1b2ab Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 6 Feb 2024 16:16:13 +0700 Subject: fix error taxes --- indoteknik_custom/models/automatic_purchase.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/automatic_purchase.py') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index bf6901d3..ff566aa9 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -24,6 +24,7 @@ class AutomaticPurchase(models.Model): raise UserError('Tidak ada Lines, belum bisa create PO') if self.is_po: raise UserError('Sudah pernah di create PO') + current_time = datetime.now() vendor_ids = self.env['automatic.purchase.line'].read_group([('automatic_purchase_id', '=', self.id), ('partner_id', '!=', False)], fields=['partner_id'], groupby=['partner_id']) @@ -47,6 +48,8 @@ class AutomaticPurchase(models.Model): ], order='brand_id') count = brand_id = 0 for product in products_vendors: + if not product.taxes_id: + raise UserError('Tidak ada Taxes') if count == 200 or brand_id != product.brand_id.id: count = 0 counter_po_number += 1 @@ -74,6 +77,7 @@ class AutomaticPurchase(models.Model): 'qty_available_store': qty_available, 'suggest': suggest, 'product_uom_qty': product.qty_purchase, + 'taxes_id': [product.taxes_id.id], 'price_unit': product.last_price, } new_line = self.env['purchase.order.line'].create([param_line]) @@ -145,12 +149,12 @@ class AutomaticPurchase(models.Model): human_last_update = purchase_price.human_last_update or datetime.min system_last_update = purchase_price.system_last_update or datetime.min + price = purchase_price.product_price + taxes = purchase_price.taxes_product_id.id + 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 -- cgit v1.2.3