summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-06-16 16:54:14 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-06-16 16:54:14 +0700
commit3246d242a3044c2fb010aa6bf219bf3ca5ae3d5a (patch)
tree1c01f99b601857aec20d80383c886be9d08051cd
parent2b55220a09fa15c22fb0a4e405c6495153604f54 (diff)
refactor code qty incoming and onhand for bandengan only and fix suggestion in purchase order line
-rwxr-xr-xindoteknik_custom/models/product_template.py21
-rwxr-xr-xindoteknik_custom/models/purchase_order.py27
2 files changed, 25 insertions, 23 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 9c480f4c..a4f8f031 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -211,7 +211,28 @@ class ProductProduct(models.Model):
usage = fields.Char(string='Usage')
specification = fields.Char(string='Specification')
material = fields.Char(string='Material')
+ qty_onhand_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_onhand_bandengan')
+ qty_incoming_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_incoming_bandengan')
+ def _get_qty_incoming_bandengan(self):
+ for product in self:
+ qty_incoming = self.env['stock.move'].search([
+ ('product_id', '=', product.id),
+ ('location_dest_id', '=', 57),
+ ('state', 'not in', ['done', 'cancel'])
+ ])
+ qty = sum(qty_incoming.mapped('product_uom_qty'))
+ product.qty_incoming_bandengan = qty
+
+ def _get_qty_onhand_bandengan(self):
+ for product in self:
+ qty_onhand = self.env['stock.quant'].search([
+ ('product_id', '=', product.id),
+ ('location_id', '=', 57)
+ ])
+ qty = sum(qty_onhand.mapped('quantity'))
+ product.qty_onhand_bandengan = qty
+
# def write(self, vals):
# if 'solr_flag' not in vals:
# for variant in self:
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 3b94e816..5aedb07b 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -151,38 +151,19 @@ 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:
- 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)
- ])
+ for order_line in self.sale_order_id.order_line:
- 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'))
+ qty_available = order_line.product_id.qty_onhand_bandengan + order_line.product_id.qty_incoming_bandengan - order_line.product_id.outgoing_qty
suggest = 'harus beli'
- if order_line.product_id.virtual_available > order_line.product_qty:
+ if qty_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,
+ 'qty_available_store': qty_available,
'suggest': suggest,
}
self.order_line.create(values)