diff options
| author | HafidBuroiroh <hafidburoiroh09@gmail.com> | 2026-02-28 09:56:26 +0700 |
|---|---|---|
| committer | HafidBuroiroh <hafidburoiroh09@gmail.com> | 2026-02-28 09:56:26 +0700 |
| commit | 8d953f913aceb97faa026253b65d6159759f5a62 (patch) | |
| tree | 0ff82faa484cae7c87f75df556966e0da49ee088 /indoteknik_custom/models/automatic_purchase.py | |
| parent | 7bfc92fdb73a89c5bc0b4c711315cbd5ea3ff268 (diff) | |
| parent | 7cd31c8dab49c59f8c6e67528d528514cc13932c (diff) | |
<hafid> change request sourcing job order
Diffstat (limited to 'indoteknik_custom/models/automatic_purchase.py')
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 0b2f7d1b..f7c0d75e 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -314,7 +314,74 @@ 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), + ('sale_line_id', '=', sale_order.sale_line_id.id), + ('sale_id', '=', sale_order.sale_id.id), + ('purchase_order_id.state', '!=', 'cancel'), + ]) + + skip_line = False + + 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] and exist: + skip_line = True + + 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,11 +807,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 - where po.state not in ('cancel') - ) ) """ % self._table)
\ No newline at end of file |
