From cd629ed3f891910aa0e3effbe54372172cb30b46 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 30 Apr 2024 11:33:34 +0700 Subject: filter search matches so and matches so on stock picking --- indoteknik_custom/models/automatic_purchase.py | 8 +++++++ indoteknik_custom/models/purchase_order.py | 21 +++++++++++++++++++ indoteknik_custom/models/sale_order_line.py | 29 +++++--------------------- indoteknik_custom/models/stock_picking.py | 1 + indoteknik_custom/views/purchase_order.xml | 3 +++ indoteknik_custom/views/sale_order.xml | 1 + indoteknik_custom/views/stock_picking.xml | 1 + 7 files changed, 40 insertions(+), 24 deletions(-) diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index dae1c6a4..479d4e42 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -279,7 +279,10 @@ class AutomaticPurchase(models.Model): ('sale_line_id.product_id', 'in', matches_so_product_ids), ]) + sale_ids = [] for sale_order in matches_so: + sale_ids.append(str(sale_order.sale_id.name)) + matches_so_line = { 'purchase_order_id': purchase_order.id, 'sale_id': sale_order.sale_id.id, @@ -295,6 +298,11 @@ class AutomaticPurchase(models.Model): 'margin_so': sale_order.sale_line_id.item_percent_margin } po_matches_so_line = self.env['purchase.order.sales.match'].create([matches_so_line]) + + sale_ids_str = ','.join(sale_ids) + + purchase_order.sale_order = sale_ids_str + self.create_sales_order_purchase_match(purchase_order) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index caad90d3..8d9141dd 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -55,6 +55,27 @@ class PurchaseOrder(models.Model): revisi_po = fields.Boolean(string='Revisi', tracking=3) from_apo = fields.Boolean(string='From APO', tracking=3) approval_edit_line = fields.Boolean(string='Approval Edit Line', tracking=3) + sale_order = fields.Char(string='Sale Order') + + def _prepare_picking(self): + if not self.group_id: + self.group_id = self.group_id.create({ + 'name': self.name, + 'partner_id': self.partner_id.id + }) + if not self.partner_id.property_stock_supplier.id: + raise UserError(_("You must set a Vendor Location for this partner %s", self.partner_id.name)) + return { + 'picking_type_id': self.picking_type_id.id, + 'partner_id': self.partner_id.id, + 'user_id': False, + 'date': self.date_order, + 'origin': self.name, + 'location_dest_id': self._get_destination_location(), + 'location_id': self.partner_id.property_stock_supplier.id, + 'company_id': self.company_id.id, + 'sale_order': self.sale_order, + } @api.model def action_multi_cancel(self): diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 39366028..7fb4a024 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -31,30 +31,11 @@ class SaleOrderLine(models.Model): qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved') reserved_from = fields.Char(string='Reserved From', copy=False) - # def get_reserved_from(self): - # for line in self: - # current_stock = self.env['stock.quant'].search([ - # ('product_id', '=', line.product_id.id), - # ('location_id', '=', line.order_id.warehouse_id.lot_stock_id.id) - # ]) - - # po_stock = self.env['purchase.order.line'].search([ - # ('product_id', '=', line.product_id.id), - # ('order_id.sale_order_id', '=', line.order_id.id), - # ('state', '=', 'done') - # ]) - - # available_quantity = current_stock.available_quantity if current_stock else 0 - # product_qty = po_stock.product_qty if po_stock else 0 - - # if available_quantity >= line.product_uom_qty: - # line.reserved_from = 'From Stock' - # elif product_qty >= line.product_uom_qty: - # line.reserved_from = 'From PO' - # elif (available_quantity + product_qty) >= line.product_uom_qty: - # line.reserved_from = 'From Stock and PO' - # else: - # line.reserved_from = None + @api.onchange('product_uom', 'product_uom_qty') + def product_uom_change(self): + + super(SaleOrderLine, self).product_uom_change() + return False def _compute_qty_reserved(self): for line in self: diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index c2508660..43b3bfad 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -84,6 +84,7 @@ class StockPicking(models.Model): ], string='Printed?', copy=False) date_unreserve = fields.Datetime(string="Date Unreserved", copy=False, tracking=True) date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True) + sale_order = fields.Char(string='Sale Order') def do_unreserve(self): res = super(StockPicking, self).do_unreserve() diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 33603216..eedd9ec9 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -28,6 +28,7 @@ + @@ -158,6 +159,7 @@ + @@ -170,6 +172,7 @@ + diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 23905ef7..3ecccf29 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -49,6 +49,7 @@ + diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index a8772906..e4b7596f 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -61,6 +61,7 @@ + -- cgit v1.2.3