From 7ad7c2a6c7cc7106d1c21f0f8da009f586015bc3 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 19 Dec 2023 13:51:21 +0700 Subject: refactor qty on purchase --- indoteknik_custom/models/product_template.py | 22 ++++++++++++++++++++-- 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): -- cgit v1.2.3 From a09aa1f1c42f568cd6cbf08e2244a00097b8bb69 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 19 Dec 2023 14:08:46 +0700 Subject: approval status on so --- indoteknik_custom/models/sale_order.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 9f31c0fd..1b51f44b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -412,8 +412,10 @@ class SaleOrder(models.Model): return self._create_notification_action('Notification', 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') if order._requires_approval_margin_leader(): + order.approval_status = 'pengajuan2' return self._create_approval_notification('Pimpinan') elif order._requires_approval_margin_manager(): + order.approval_status = 'pengajuan1' return self._create_approval_notification('Sales Manager') order.approval_status = 'approved' -- cgit v1.2.3 From 80afbdeecd286c990ddc80c277287df6c95f5ee8 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 19 Dec 2023 17:01:53 +0700 Subject: fix compute onhand bandengan --- indoteknik_custom/models/product_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index d34702fd..34aff4fa 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -427,7 +427,7 @@ class ProductProduct(models.Model): ('product_id', '=', product.id), ('location_id', '=', 57) ]) - qty = sum(qty_onhand.mapped('inventory_quantity')) + qty = sum(qty_onhand.mapped('quantity')) product.qty_onhand_bandengan = qty def _get_qty_available_bandengan(self): -- cgit v1.2.3