From 1edd55b85c24b8f9a36349fa34793cb65a554851 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 15 Jun 2023 11:50:08 +0700 Subject: add qty reserved in sale monitoring and sale monitoring detail --- indoteknik_custom/models/sale_monitoring.py | 9 +++++++-- indoteknik_custom/models/sale_monitoring_detail.py | 10 +++++++--- indoteknik_custom/views/sale_monitoring.xml | 6 ++++-- indoteknik_custom/views/sale_monitoring_detail.xml | 6 ++++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py index a3265a8b..ea1e490c 100755 --- a/indoteknik_custom/models/sale_monitoring.py +++ b/indoteknik_custom/models/sale_monitoring.py @@ -20,6 +20,7 @@ class SaleMonitoring(models.Model): date_order = fields.Datetime(string="Date Order") status = fields.Char(string="Status") po_number = fields.Char(string="PO Number") + qty_reserved = fields.Integer(string="Qty Reserved") def init(self): tools.drop_view_if_exists(self.env.cr, self._table) @@ -36,9 +37,13 @@ class SaleMonitoring(models.Model): SUM(smd.qty_po_received) AS qty_po_received, SUM(smd.qty_so_delivered) AS qty_so_delivered, SUM(smd.qty_so_invoiced) AS qty_so_invoiced, + sum(smd.qty_reserved) as qty_reserved, CASE - WHEN SUM(qty_po) < SUM(qty_so) AND SUM(qty_po) <= 0 THEN 'Belum PO sama sekali' - WHEN SUM(qty_po) < SUM(qty_so) THEN 'Belum PO full' + WHEN SUM(qty_so) = SUM(qty_reserved) then 'SIAP KIRIM' + WHEN SUM(qty_so) = SUM(qty_so_delivered) then 'Delivered' + WHEN SUM(qty_so) = SUM(qty_so_invoiced) then 'Done' + WHEN SUM(qty_reserved) < SUM(qty_so) and SUM(qty_reserved) > 0 THEN 'Belum PO full' + WHEN SUM(qty_reserved) = SUM(qty_so) THEN 'Belum PO sama sekali' WHEN SUM(qty_po_received) < SUM(qty_so) AND SUM(qty_po_received) <= 0 THEN 'Belum Received sama sekali' WHEN SUM(qty_po_received) < SUM(qty_so) THEN 'Belum Received full' WHEN SUM(qty_to_delivered) = SUM(qty_so) THEN 'SIAP KIRIM' diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index a578f67b..908ccb68 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -21,6 +21,7 @@ class SaleMonitoringDetail(models.Model): qty_so_invoiced = fields.Integer(string="Qty SO Invoiced") date_order = fields.Datetime(string="Date Order") status = fields.Char(string="Status") + qty_reserved = fields.Integer(string="Qty Reserved") def init(self): tools.drop_view_if_exists(self.env.cr, self._table) @@ -29,9 +30,11 @@ class SaleMonitoringDetail(models.Model): SELECT *, CASE + WHEN qty_so = qty_reserved then 'SIAP KIRIM' + WHEN qty_so = qty_so_delivered then 'Delivered' WHEN qty_so = qty_so_invoiced then 'Done' - WHEN qty_po < qty_so AND qty_po <= 0 THEN 'Belum PO sama sekali' - WHEN qty_po < qty_so THEN 'Belum PO full' + WHEN qty_reserved < qty_so and qty_reserved > 0 THEN 'Belum PO full' + WHEN qty_reserved = qty_so THEN 'Belum PO sama sekali' WHEN qty_po_received < qty_so and qty_po_received <= 0 THEN 'Belum Received sama sekali' WHEN qty_po_received < qty_so THEN 'Belum Received full' WHEN qty_to_delivered = qty_so THEN 'SIAP KIRIM' @@ -52,7 +55,8 @@ class SaleMonitoringDetail(models.Model): sol.qty_invoiced AS qty_so_invoiced, so.date_order AS date_order, get_qty_po(so.id, sol.product_id) AS qty_po, - get_qty_received(so.id, sol.product_id) AS qty_po_received + get_qty_received(so.id, sol.product_id) AS qty_po_received, + get_qty_reserved(so.id, sol.product_id) as qty_reserved FROM sale_order so JOIN sale_order_line sol ON sol.order_id = so.id JOIN product_product p ON p.id = sol.product_id diff --git a/indoteknik_custom/views/sale_monitoring.xml b/indoteknik_custom/views/sale_monitoring.xml index b3b186e9..fffd140f 100755 --- a/indoteknik_custom/views/sale_monitoring.xml +++ b/indoteknik_custom/views/sale_monitoring.xml @@ -13,6 +13,7 @@ + @@ -22,7 +23,7 @@ decoration-danger="status == 'Belum PO sama sekali' or status == 'Belum PO full'" decoration-warning="status == 'Belum Received sama sekali' or status == 'Belum Received full'" decoration-success="status == 'SIAP KIRIM' or status == 'KIRIM SISANYA'" - decoration-info="status == 'Belum Invoiced'" + decoration-info="status == 'Belum Invoiced' or status == 'Done' or status == 'Delivered'" /> @@ -44,12 +45,13 @@ decoration-danger="status == 'Belum PO sama sekali' or status == 'Belum PO full'" decoration-warning="status == 'Belum Received sama sekali' or status == 'Belum Received full'" decoration-success="status == 'SIAP KIRIM' or status == 'KIRIM SISANYA'" - decoration-info="status == 'Belum Invoiced'" + decoration-info="status == 'Belum Invoiced' or status == 'Done' or status == 'Delivered'" /> + diff --git a/indoteknik_custom/views/sale_monitoring_detail.xml b/indoteknik_custom/views/sale_monitoring_detail.xml index b9602abd..78bb92c7 100755 --- a/indoteknik_custom/views/sale_monitoring_detail.xml +++ b/indoteknik_custom/views/sale_monitoring_detail.xml @@ -11,6 +11,7 @@ + @@ -20,7 +21,7 @@ decoration-danger="status == 'Belum PO sama sekali' or status == 'Belum PO full'" decoration-warning="status == 'Belum Received sama sekali' or status == 'Belum Received full'" decoration-success="status == 'SIAP KIRIM' or status == 'KIRIM SISANYA'" - decoration-info="status == 'Belum Invoiced' or status == 'Done'" + decoration-info="status == 'Belum Invoiced' or status == 'Done' or status == 'Delivered'" /> @@ -43,11 +44,12 @@ decoration-danger="status == 'Belum PO sama sekali' or status == 'Belum PO full'" decoration-warning="status == 'Belum Received sama sekali' or status == 'Belum Received full'" decoration-success="status == 'SIAP KIRIM' or status == 'KIRIM SISANYA'" - decoration-info="status == 'Belum Invoiced'" + decoration-info="status == 'Belum Invoiced' or status == 'Done' or status == 'Delivered'" /> + -- cgit v1.2.3 From 64507a0c199721fee5e3fc8c808adec5a3ee6a5d Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 15 Jun 2023 11:54:20 +0700 Subject: revert code nathan --- indoteknik_custom/models/purchase_order.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index ea75539a..7e18bd8f 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -151,10 +151,11 @@ 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) + # qty_available = self.env['stock.quant'].search([ + # ('product_id', '=', order_line.product_id.id), + # ('location_id', '=', "BU/Stock") + # ], limit=1) + qty_available = order_line.product_id.virtual_available suggest = 'harus beli' if order_line.product_id.virtual_available > order_line.product_qty: suggest = 'masih cukup' @@ -163,10 +164,10 @@ class PurchaseOrder(models.Model): '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, + 'qty_available_store': qty_available, 'suggest': suggest, } - self.order_line.create(values) + self.env['purchase.order.line'].sudo().create(values) def compute_count_line_product(self): for order in self: -- cgit v1.2.3 From d32accf86a2baffcf7ce90554d1f8868ab518cf4 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 15 Jun 2023 15:07:24 +0700 Subject: change logic of sales monitoring --- indoteknik_custom/models/sale_monitoring.py | 16 ++++++---------- indoteknik_custom/models/sale_monitoring_detail.py | 16 ++++++---------- indoteknik_custom/views/sale_monitoring.xml | 16 ++++++++-------- indoteknik_custom/views/sale_monitoring_detail.xml | 16 ++++++++-------- 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py index ea1e490c..e79ff9ab 100755 --- a/indoteknik_custom/models/sale_monitoring.py +++ b/indoteknik_custom/models/sale_monitoring.py @@ -39,16 +39,12 @@ class SaleMonitoring(models.Model): SUM(smd.qty_so_invoiced) AS qty_so_invoiced, sum(smd.qty_reserved) as qty_reserved, CASE - WHEN SUM(qty_so) = SUM(qty_reserved) then 'SIAP KIRIM' - WHEN SUM(qty_so) = SUM(qty_so_delivered) then 'Delivered' - WHEN SUM(qty_so) = SUM(qty_so_invoiced) then 'Done' - WHEN SUM(qty_reserved) < SUM(qty_so) and SUM(qty_reserved) > 0 THEN 'Belum PO full' - WHEN SUM(qty_reserved) = SUM(qty_so) THEN 'Belum PO sama sekali' - WHEN SUM(qty_po_received) < SUM(qty_so) AND SUM(qty_po_received) <= 0 THEN 'Belum Received sama sekali' - WHEN SUM(qty_po_received) < SUM(qty_so) THEN 'Belum Received full' - WHEN SUM(qty_to_delivered) = SUM(qty_so) THEN 'SIAP KIRIM' - WHEN SUM(qty_to_delivered) < SUM(qty_so) and SUM(qty_to_delivered) > 0 THEN 'KIRIM SISANYA' - ELSE 'Belum Invoiced' + when sum(qty_so_invoiced) = sum(qty_so) then 'Invoiced' + when sum(qty_so_delivered) = sum(qty_so) then 'Delivered' + when sum(qty_reserved) >= sum(qty_so) then 'Siap kirim' + when sum(qty_po) + sum(qty_reserved) - sum(qty_po_received) < sum(qty_so) then 'Belum/Kurang PO' + when sum(qty_po_received) = 0 then 'Belum terima' + when sum(qty_po_received) < sum(qty_po) then 'Terima sebagian' END AS status, get_po_number(smd.sale_order_id) as po_number FROM sale_monitoring_detail smd diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index 908ccb68..2bcda50c 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -30,16 +30,12 @@ class SaleMonitoringDetail(models.Model): SELECT *, CASE - WHEN qty_so = qty_reserved then 'SIAP KIRIM' - WHEN qty_so = qty_so_delivered then 'Delivered' - WHEN qty_so = qty_so_invoiced then 'Done' - WHEN qty_reserved < qty_so and qty_reserved > 0 THEN 'Belum PO full' - WHEN qty_reserved = qty_so THEN 'Belum PO sama sekali' - WHEN qty_po_received < qty_so and qty_po_received <= 0 THEN 'Belum Received sama sekali' - WHEN qty_po_received < qty_so THEN 'Belum Received full' - WHEN qty_to_delivered = qty_so THEN 'SIAP KIRIM' - WHEN qty_to_delivered < qty_so and qty_to_delivered > 0 THEN 'KIRIM SISANYA' - ELSE 'Belum Invoiced' + when qty_so_invoiced = qty_so then 'Invoiced' + when qty_so_delivered = qty_so then 'Delivered' + when qty_reserved >= qty_so then 'Siap kirim' + when qty_po + qty_reserved - qty_po_received < qty_so then 'Belum/Kurang PO' + when qty_po_received = 0 then 'Belum terima' + when qty_po_received < qty_po then 'Terima sebagian' END AS status FROM ( diff --git a/indoteknik_custom/views/sale_monitoring.xml b/indoteknik_custom/views/sale_monitoring.xml index fffd140f..956e4a24 100755 --- a/indoteknik_custom/views/sale_monitoring.xml +++ b/indoteknik_custom/views/sale_monitoring.xml @@ -20,10 +20,10 @@ @@ -42,10 +42,10 @@ diff --git a/indoteknik_custom/views/sale_monitoring_detail.xml b/indoteknik_custom/views/sale_monitoring_detail.xml index 78bb92c7..736920b3 100755 --- a/indoteknik_custom/views/sale_monitoring_detail.xml +++ b/indoteknik_custom/views/sale_monitoring_detail.xml @@ -18,10 +18,10 @@ @@ -41,10 +41,10 @@ -- cgit v1.2.3 From 24649f8e939484759ef34e5e68f251d951f63c02 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 15 Jun 2023 15:41:18 +0700 Subject: paid if using midtrans --- indoteknik_api/models/account_move.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/indoteknik_api/models/account_move.py b/indoteknik_api/models/account_move.py index 54e06f84..23a7076c 100644 --- a/indoteknik_api/models/account_move.py +++ b/indoteknik_api/models/account_move.py @@ -6,6 +6,10 @@ class AccountMove(models.Model): _inherit = 'account.move' def api_v1_single_response(self, account_move, context=False): + sale_order = self.env['sale.order'].search([('name', '=', account_move.invoice_origin), ('state', '=', 'done')], limit=1) + amount_residual = account_move.amount_residual + if sale_order.payment_status == 'settlement' or sale_order.payment_status == 'capture': + amount_residual = 0 data = { 'token': self.env['rest.api'].md5_salt(account_move.id, 'account.move'), 'id': account_move.id, @@ -14,7 +18,7 @@ class AccountMove(models.Model): 'payment_term': account_move.invoice_payment_term_id.name or '', 'sales': account_move.invoice_user_id.name, 'amount_total': account_move.amount_total, - 'amount_residual': account_move.amount_residual, + 'amount_residual': amount_residual, 'invoice_date': account_move.invoice_date.strftime('%d/%m/%Y') or '', 'efaktur': True if account_move.efaktur_document else False, } @@ -30,7 +34,7 @@ class AccountMove(models.Model): 'payment_term': account_move.invoice_payment_term_id.name or '', 'sales': account_move.invoice_user_id.name, 'amount_total': account_move.amount_total, - 'amount_residual': account_move.amount_residual, + 'amount_residual': amount_residual, 'invoice_date_due': account_move.invoice_date_due.strftime('%d/%m/%Y') or '', 'customer': res_users.api_address_response(account_move.partner_id), 'products': [], -- cgit v1.2.3 From 92fae861a362ad49bb299ceeac62d517108880de Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Jun 2023 08:52:48 +0700 Subject: Update sale_order shipping paid by and shipping cost covered required when create_date > 2023-06-15 --- indoteknik_custom/views/sale_order.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index ea13c954..53740dd5 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -19,8 +19,9 @@ type="action" attrs="{'invisible': [('approval_status', '!=', 'approved')]}"/> - - + + + -- cgit v1.2.3 From d22fb25a88cacabd470780588c200c065e0633cd Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 16 Jun 2023 09:28:11 +0700 Subject: add filter sale monitoring --- indoteknik_custom/views/sale_monitoring.xml | 15 +++++++++++++++ indoteknik_custom/views/sale_monitoring_detail.xml | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/indoteknik_custom/views/sale_monitoring.xml b/indoteknik_custom/views/sale_monitoring.xml index 956e4a24..0a9a5aa5 100755 --- a/indoteknik_custom/views/sale_monitoring.xml +++ b/indoteknik_custom/views/sale_monitoring.xml @@ -63,10 +63,25 @@ + + sale.monitoring.list.select + sale.monitoring + + + + + + + + + + + Sale Monitoring ir.actions.act_window sale.monitoring + tree,form diff --git a/indoteknik_custom/views/sale_monitoring_detail.xml b/indoteknik_custom/views/sale_monitoring_detail.xml index 736920b3..824e65e8 100755 --- a/indoteknik_custom/views/sale_monitoring_detail.xml +++ b/indoteknik_custom/views/sale_monitoring_detail.xml @@ -61,10 +61,26 @@ + + sale.monitoring.detail.list.select + sale.monitoring.detail + + + + + + + + + + + + Sale Monitoring Detail ir.actions.act_window sale.monitoring.detail + tree,form -- cgit v1.2.3 From ad2e6cc9d119e0b72ccdb353eb8a2e0fa304e359 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 16 Jun 2023 10:35:48 +0700 Subject: comment temporary validation --- indoteknik_custom/models/sale_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index cbc6a60a..52b959db 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -336,8 +336,8 @@ class SaleOrder(models.Model): raise UserError("Invoice harus di Cancel dahulu") elif self.have_outstanding_picking: raise UserError("DO harus di Cancel dahulu") - elif self.have_outstanding_po: - raise UserError("PO harus di Cancel dahulu") + # elif self.have_outstanding_po: + # raise UserError("PO harus di Cancel dahulu") self.approval_status = False return super(SaleOrder, self).action_cancel() -- cgit v1.2.3 From 777d925ec89357b0f5bd11faa8bfb5adfcd6b151 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Jun 2023 11:08:47 +0700 Subject: Fix sales tax id on checkout api --- indoteknik_api/controllers/api_v1/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 35361ba4..ec33495e 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -246,7 +246,7 @@ class SaleOrder(controller.Controller): parameters = { 'warehouse_id': 8, 'carrier_id': 1, - 'sales_tax_id': 21, + 'sales_tax_id': 23, 'pricelist_id': product_pricelist_default_discount_id, 'payment_term_id': 26, 'team_id': 2, -- cgit v1.2.3 From fd63ff133764477f39c9dd32c5177dd67f293abb Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 16 Jun 2023 11:36:00 +0700 Subject: optional hide for line no in sale and purchase --- indoteknik_custom/views/purchase_order.xml | 2 +- indoteknik_custom/views/sale_order.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index a4c77c58..7a397ff6 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -43,7 +43,7 @@ - + diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 53740dd5..94073fd7 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -63,7 +63,7 @@ - + -- cgit v1.2.3 From e2ccd5719de9cf03a422e93fbef9a7f035b854a5 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Jun 2023 15:59:46 +0700 Subject: Fix shipping cost and paid by required when create_date false or greater than 15 Juni 2023 --- indoteknik_custom/views/sale_order.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 94073fd7..b160d9b1 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -20,8 +20,8 @@ - - + + -- cgit v1.2.3 From aab8e1f3e1c6b05e7dc57060efd1f9fe586d092d Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Jun 2023 16:43:24 +0700 Subject: Add notify_internal_users function on users --- indoteknik_custom/models/users.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/indoteknik_custom/models/users.py b/indoteknik_custom/models/users.py index 4904a33d..a2074c46 100644 --- a/indoteknik_custom/models/users.py +++ b/indoteknik_custom/models/users.py @@ -9,3 +9,7 @@ class Users(models.Model): is_sales_manager = fields.Boolean(String='Sales Manager', help='Berhak melakukan Approval SO dengan margin 15-25') is_leader = fields.Boolean(String='Leader', help='Berhak Approval SO Margin < 15 dan Approval PO') is_accounting = fields.Boolean(String='Accounting', help='Berhak Approval Internal Use') + + def notify_internal_users(self, message, title): + users = self.search([('share', '=', False)]) + users.notify_info(message=message, title=title) \ No newline at end of file -- cgit v1.2.3 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 +++++++++++++++++++++ indoteknik_custom/models/purchase_order.py | 27 ++++----------------------- 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) -- cgit v1.2.3