From 7be11b56799d45e044f5af5927f63180c419e36e Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Fri, 23 Jan 2026 11:07:11 +0700 Subject: fix hitung qty purchase --- indoteknik_custom/models/automatic_purchase.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (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 4b0ce325..0b2f7d1b 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -499,7 +499,8 @@ class AutomaticPurchase(models.Model): # _logger.info('test %s' % point.product_id.name) if point.product_id.qty_available_bandengan > point.product_min_qty: continue - qty_purchase = point.product_max_qty - point.product_id.qty_incoming_bandengan - point.product_id.qty_available_bandengan + # qty_purchase = point.product_max_qty - point.product_id.qty_incoming_bandengan - point.product_id.qty_available_bandengan + qty_purchase = point.product_max_qty - point.product_id.qty_available_bandengan po_line = self.env['purchase.order.line'].search([('product_id', '=', point.product_id.id), ('order_id.state', '=', 'done')], order='id desc', limit=1) if self.vendor_id: -- cgit v1.2.3 From 316b8257845d0df10153fa7e5e294a699ad17c56 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 24 Feb 2026 13:20:33 +0700 Subject: push --- indoteknik_custom/models/automatic_purchase.py | 3 +++ 1 file changed, 3 insertions(+) (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 0b2f7d1b..3035ceab 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -744,7 +744,10 @@ class SaleNotInMatchPO(models.Model): select distinct coalesce(posm.sale_line_id,0) from purchase_order_sales_match posm join purchase_order po on po.id = posm.purchase_order_id + join purchase_order_line pol on pol.order_id = posm.purchase_order_id and pol.product_id = posm.product_id + join stock_move sm on sm.purchase_line_id = pol.id where po.state not in ('cancel') + and sm.state not in ('cancel') ) ) """ % self._table) \ No newline at end of file -- cgit v1.2.3 From 68040bdf60a35486ed1015421679310df742b74d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 27 Feb 2026 09:36:15 +0700 Subject: push api altama odoo indo --- indoteknik_custom/models/automatic_purchase.py | 56 +++++++++++++++++++++----- 1 file changed, 47 insertions(+), 9 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 3035ceab..f4ecdcd6 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -315,6 +315,53 @@ class AutomaticPurchase(models.Model): sale_ids_set = set() sale_ids_name = set() for sale_order in matches_so: + exist = self.env['purchase.order.sales.match'].search([ + ('product_id', '=', sale_order.product_id.id), + ('sale_line_id', '=', sale_order.sale_line_id.id), + ('sale_id', '=', sale_order.sale_id.id), + ('purchase_order_id.state', '!=', 'cancel'), + ]) + + skip_line = False + + for existing in exist: + if existing.purchase_order_id.state in ['done', 'purchase']: + # if existing.purchase_line_id.qty_received != existing.purchase_line_id.product_qty: + # break + + incoming = self.env['stock.move'].search([ + ('reference', 'ilike', 'BU/INPUT'), + ('state', 'not in', ['done','cancel']), + ('product_id', '=', existing.product_id.id), + ('purchase_line_id', '=', existing.purchase_line_id.id), + ], limit=1) + + if incoming: + skip_line = True + break + + retur = self.env['stock.move'].search([ + ('reference', 'ilike', 'BU/INPUT'), + ('state', 'in', ['done']), + ('product_id', '=', existing.product_id.id), + ('purchase_line_id', '=', existing.purchase_line_id.id), + ], limit=1) + + if retur and existing.purchase_line_id.qty_received == existing.purchase_line_id.product_qty: + skip_line = True + break + + if skip_line: + continue + + stock_move = self.env['stock.move'].search([ + ('reference', 'ilike', 'BU/PICK'), + ('state', 'in', ['confirmed','waiting','partially_available']), + ('product_id', '=', sale_order.product_id.id), + ('sale_line_id', '=', sale_order.sale_line_id.id), + ]) + if not stock_move: + continue # @stephan skip so line yang sudah pernah ada di purchase order sales match sebelumnya salesperson_name = sale_order.sale_id.user_id.name @@ -740,14 +787,5 @@ class SaleNotInMatchPO(models.Model): apsm.create_date, apsm.write_uid, apsm.write_date, apsm.purchase_price, apsm.purchase_tax_id, apsm.note_procurement from automatic_purchase_sales_match apsm - where apsm.sale_line_id not in ( - select distinct coalesce(posm.sale_line_id,0) - from purchase_order_sales_match posm - join purchase_order po on po.id = posm.purchase_order_id - join purchase_order_line pol on pol.order_id = posm.purchase_order_id and pol.product_id = posm.product_id - join stock_move sm on sm.purchase_line_id = pol.id - where po.state not in ('cancel') - and sm.state not in ('cancel') - ) ) """ % self._table) \ No newline at end of file -- cgit v1.2.3 From 4d8b06efe10c33d44301b05d86bf96a62033820a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 27 Feb 2026 14:42:29 +0700 Subject: push --- indoteknik_custom/models/automatic_purchase.py | 72 ++++++++++++++++---------- 1 file changed, 46 insertions(+), 26 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 f4ecdcd6..7e324061 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -314,6 +314,8 @@ class AutomaticPurchase(models.Model): sale_ids_set = set() sale_ids_name = set() + retur_cache = {} + incoming_cache = {} for sale_order in matches_so: exist = self.env['purchase.order.sales.match'].search([ ('product_id', '=', sale_order.product_id.id), @@ -324,32 +326,50 @@ class AutomaticPurchase(models.Model): skip_line = False - for existing in exist: - if existing.purchase_order_id.state in ['done', 'purchase']: - # if existing.purchase_line_id.qty_received != existing.purchase_line_id.product_qty: - # break - - incoming = self.env['stock.move'].search([ - ('reference', 'ilike', 'BU/INPUT'), - ('state', 'not in', ['done','cancel']), - ('product_id', '=', existing.product_id.id), - ('purchase_line_id', '=', existing.purchase_line_id.id), - ], limit=1) - - if incoming: - skip_line = True - break - - retur = self.env['stock.move'].search([ - ('reference', 'ilike', 'BU/INPUT'), - ('state', 'in', ['done']), - ('product_id', '=', existing.product_id.id), - ('purchase_line_id', '=', existing.purchase_line_id.id), - ], limit=1) - - if retur and existing.purchase_line_id.qty_received == existing.purchase_line_id.product_qty: - skip_line = True - break + sale_line_id = sale_order.sale_line_id.id + + if sale_line_id not in incoming_cache: + + qty_incoming = 0 + + for existing in exist: + if existing.purchase_order_id.state in ['done', 'purchase']: + + incoming_moves = self.env['stock.move'].search([ + ('reference', 'ilike', 'BU/INPUT'), + ('state', 'not in', ['done','cancel']), + ('product_id', '=', existing.product_id.id), + ('purchase_line_id', '=', existing.purchase_line_id.id), + ]) + + qty_incoming += sum(incoming_moves.mapped('product_uom_qty')) + + incoming_cache[sale_line_id] = qty_incoming + + + qty_need = sale_order.sale_line_id.product_uom_qty + + if incoming_cache[sale_line_id] >= qty_need: + skip_line = True + + sale_line_id = sale_order.sale_line_id.id + + if sale_line_id not in retur_cache: + + fully_received = True + + for existing in exist: + if existing.purchase_order_id.state in ['done', 'purchase']: + + if existing.purchase_line_id.qty_received != existing.purchase_line_id.product_qty: + fully_received = False + break + + retur_cache[sale_line_id] = fully_received + + + if retur_cache[sale_line_id]: + skip_line = True if skip_line: continue -- cgit v1.2.3 From deba773edb01799a13a047dcae080272145badc7 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 27 Feb 2026 14:59:16 +0700 Subject: push --- indoteknik_custom/models/automatic_purchase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 7e324061..f7c0d75e 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -368,7 +368,7 @@ class AutomaticPurchase(models.Model): retur_cache[sale_line_id] = fully_received - if retur_cache[sale_line_id]: + if retur_cache[sale_line_id] and exist: skip_line = True if skip_line: -- cgit v1.2.3