diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-12-19 13:51:21 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-12-19 13:51:21 +0700 |
| commit | 7ad7c2a6c7cc7106d1c21f0f8da009f586015bc3 (patch) | |
| tree | 5459965a70e80be1916bba0d0d368387f57b5e9f | |
| parent | 955f0eff6fb1917c3cf0fde8ee6994ee43148732 (diff) | |
refactor qty on purchase
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 22 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 10 |
2 files changed, 25 insertions, 7 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 90e8a144..d34702fd 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -339,8 +339,10 @@ 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_onhand_bandengan = fields.Float(string='Qty Onhand Bandengan', compute='_get_qty_onhand_bandengan') qty_incoming_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_incoming_bandengan') + qty_outgoing_bandengan = fields.Float(string='Qty Outgoing Bandengan', compute='_get_qty_outgoing_bandengan') + qty_available_bandengan = fields.Float(string='Qty Available Bandengan', compute='_get_qty_available_bandengan') qty_upcoming = fields.Float(string='Qty Upcoming', compute='_get_qty_upcoming') sla_version = fields.Integer(string="SLA Version", default=0) is_edited = fields.Boolean(string='Is Edited') @@ -408,15 +410,31 @@ class ProductProduct(models.Model): qty = sum(qty_incoming.mapped('product_uom_qty')) product.qty_incoming_bandengan = qty + def _get_qty_outgoing_bandengan(self): + for product in self: + qty_incoming = self.env['stock.move'].search([ + ('product_id', '=', product.id), + ('location_dest_id', '=', 5), + ('location_id', '=', 57), + ('state', 'not in', ['done', 'cancel']) + ]) + qty = sum(qty_incoming.mapped('product_uom_qty')) + product.qty_outgoing_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')) + qty = sum(qty_onhand.mapped('inventory_quantity')) product.qty_onhand_bandengan = qty + def _get_qty_available_bandengan(self): + for product in self: + qty_available = product.qty_incoming_bandengan + product.qty_onhand_bandengan - product.qty_outgoing_bandengan + product.qty_available_bandengan = qty_available + # def write(self, vals): # if 'solr_flag' not in vals: # for variant in self: diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index f1c20106..ca0e77ab 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -36,7 +36,7 @@ class PurchaseOrderLine(models.Model): def suggest_purchasing(self): for line in self: - if line.qty_available < 0: + if line.qty_available < line.product_qty: line.suggest = 'harus beli' else: line.suggest = 'masih cukup' @@ -57,10 +57,10 @@ class PurchaseOrderLine(models.Model): def _compute_qty_stock(self): for line in self: - line.qty_available = line.product_id.virtual_available - line.qty_onhand = line.product_id.qty_available - line.qty_incoming = line.product_id.incoming_qty - line.qty_outgoing = line.product_id.outgoing_qty + line.qty_available = line.product_id.qty_available_bandengan + line.qty_onhand = line.product_id.qty_onhand_bandengan + line.qty_incoming = line.product_id.qty_incoming_bandengan + line.qty_outgoing = line.product_id.qty_outgoing_bandengan @api.onchange('product_id') def _onchange_product_custom(self): |
