diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-06-16 15:26:23 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-06-16 15:26:23 +0700 |
| commit | ab71c4b64074ec7471954e3c8f652887549950b9 (patch) | |
| tree | 7995a4d3f49d73dde2b3aeb44d88be65f5ee018d | |
| parent | 66acad265bbb7edcc20bfe1cb5ee34dad53f28d9 (diff) | |
Quantity Available
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index ea75539a..3b94e816 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -137,7 +137,7 @@ class PurchaseOrder(models.Model): else: status = 'Menunggu Diproses' purchase_order.procurement_status = status - + def sale_order_sync(self): if not self.sale_order_id: return @@ -151,22 +151,41 @@ class PurchaseOrder(models.Model): self.order_line.unlink() for order_line in self.sale_order_id.order_line: if order_line.product_id.id and order_line.product_id.id not in products_exception: - qty_available = self.env['stock.quant'].search([ - ('product_id', '=', order_line.product_id.id), - ('location_id', '=', "BU/Stock") - ], limit=1) - suggest = 'harus beli' - if order_line.product_id.virtual_available > order_line.product_qty: - suggest = 'masih cukup' - values = { - 'order_id': self.id, - 'product_id': order_line.product_id.id, - 'name': order_line.product_id.display_name, - 'product_qty': order_line.product_qty, - 'qty_available_store': qty_available.available_quantity, - 'suggest': suggest, - } - self.order_line.create(values) + for order_line in self.sale_order_id.order_line: + + qty_onhand = self.env['stock.quant'].search([ + ('product_id', '=', order_line.product_id.id), + ('location_id', '=', 57) + ]) + + qty_incoming = self.env['stock.move'].search([ + ('product_id', '=', order_line.product_id.id), + ('location_dest_id', '=', 57), + ('state', 'not in', ['done', 'cancel']) + ]) + + qty_outgoing = self.env['stock.move'].search([ + ('product_id', '=', order_line.product_id.id), + ('location_id', '=', 57), + ('state', 'not in', ['done', 'cancel']) + ]) + + qty_total = sum(qty_onhand.mapped('quantity')) + sum(qty_incoming.mapped('product_uom_qty')) + + qty = qty_total - sum(qty_outgoing.mapped('product_uom_qty')) + + suggest = 'harus beli' + if order_line.product_id.virtual_available > order_line.product_qty: + suggest = 'masih cukup' + values = { + 'order_id': self.id, + 'product_id': order_line.product_id.id, + 'name': order_line.product_id.display_name, + 'product_qty': order_line.product_qty, + 'qty_available_store': qty, + 'suggest': suggest, + } + self.order_line.create(values) def compute_count_line_product(self): for order in self: |
