From 3246d242a3044c2fb010aa6bf219bf3ca5ae3d5a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 16 Jun 2023 16:54:14 +0700 Subject: refactor code qty incoming and onhand for bandengan only and fix suggestion in purchase order line --- indoteknik_custom/models/product_template.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'indoteknik_custom/models/product_template.py') 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: -- cgit v1.2.3