From 337e769c7eab63275b4114f48e789bdcf808bdf1 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 10 Feb 2023 11:04:07 +0700 Subject: add line no in so / po and stock picking --- indoteknik_custom/models/purchase_order.py | 2 ++ indoteknik_custom/models/sale_order.py | 1 + indoteknik_custom/models/stock_picking.py | 23 ++++++++++++++++++----- indoteknik_custom/views/sale_order.xml | 7 +++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index b4d671b6..2f3d2ec4 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -169,6 +169,8 @@ class PurchaseOrder(models.Model): self.approval_status = 'approved' self.po_status = 'menunggu' + self.calculate_line_no() + return res def po_approve(self): diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e85454da..f21554f7 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -281,6 +281,7 @@ class SaleOrder(models.Model): raise UserError("Harus diapprove oleh Manager") else: order.approval_status = 'approved' + order.calculate_line_no() return res diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 8a0ad71e..180e2500 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -95,13 +95,25 @@ class StockPicking(models.Model): pick.approval_return_status = 'pengajuan1' def calculate_line_no(self): - line_no = 0 for picking in self: for line in picking.move_ids_without_package: - if line.product_id.type == 'product': - line_no += 1 - line.line_no = line_no - # _logger.info('Calculate PO Line No %s' % line.id) + # order_lines = picking.group_id.order_line + name = picking.group_id.name + if picking.group_id.sale_id: + order = self.env['sale.order'].search([('name', '=', name)], limit=1) + else: + order = self.env['purchase.order'].search([('name', '=', name)], limit=1) + + order_lines = order.order_line + set_line = 0 + + for order_line in order_lines: + if line.product_id == order_line.product_id: + set_line = order_line.line_no + break + else: + continue + line.line_no = set_line def _compute_summary_qty(self): sum_qty_detail = sum_qty_operation = count_line_detail = count_line_operation = 0 @@ -153,6 +165,7 @@ class StockPicking(models.Model): self.approval_status = 'approved' res = super(StockPicking, self).button_validate() + self.calculate_line_no() return res @api.model diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 9dfd9805..1b6f31aa 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -7,6 +7,10 @@