From 1136a7dc61b1341635e03168a6006e8122b4dcf5 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Sat, 2 Jul 2022 07:10:36 +0200 Subject: [PATCH] [IMP] rma_filter_lot: show only the lots shipped to the particular customer in the RMA. If nothing was shipped to that customer, fall back to showing all the lots available in the customer location. --- rma_filter_lot/README.rst | 1 + rma_filter_lot/__manifest__.py | 6 ++---- rma_filter_lot/models/rma_order_line.py | 23 ++++++++++++++++++++++- rma_filter_lot/views/rma_order_view.xml | 1 - 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/rma_filter_lot/README.rst b/rma_filter_lot/README.rst index e36debc6..f30b5a16 100644 --- a/rma_filter_lot/README.rst +++ b/rma_filter_lot/README.rst @@ -27,6 +27,7 @@ Contributors * Mateu Griful * Lois Rilo +* Jordi Ballester Maintainers ~~~~~~~~~~~ diff --git a/rma_filter_lot/__manifest__.py b/rma_filter_lot/__manifest__.py index 3773e24d..09754d92 100644 --- a/rma_filter_lot/__manifest__.py +++ b/rma_filter_lot/__manifest__.py @@ -3,15 +3,13 @@ { "name": "RMA Filter Lot", - "version": "14.0.1.0.0", + "version": "14.0.1.1.0", "license": "LGPL-3", "category": "RMA", "summary": "Filter RMA lots", "author": "ForgeFlow", "website": "https://github.com/ForgeFlow/stock-rma", "depends": ["rma"], - "data": [ - "views/rma_order_view.xml", - ], + "data": ["views/rma_order_view.xml"], "installable": True, } diff --git a/rma_filter_lot/models/rma_order_line.py b/rma_filter_lot/models/rma_order_line.py index d3283271..3dcd5913 100644 --- a/rma_filter_lot/models/rma_order_line.py +++ b/rma_filter_lot/models/rma_order_line.py @@ -16,7 +16,20 @@ class RmaOrderLine(models.Model): compute="_compute_domain_lot_ids", ) - @api.depends("product_id") + def _get_filter_lot_customer_domain(self): + self.ensure_one() + return [ + ("location_dest_id.usage", "=", "customer"), + ("product_id", "=", self.product_id.id), + ("state", "=", "done"), + ( + "move_id.partner_id", + "child_of", + self.partner_id.commercial_partner_id.ids, + ), + ] + + @api.depends("product_id", "operation_id") def _compute_domain_lot_ids(self): for rec in self: lots = rec.env["stock.production.lot"].search( @@ -39,6 +52,14 @@ class RmaOrderLine(models.Model): valid_ids |= quant.lot_id if valid_ids: lots = valid_ids + # Check if the lot has ever been shipped to that customer. + # In that case restrict to those. + mls = rec.env["stock.move.line"].search( + rec._get_filter_lot_customer_domain() + ) + moved_lots = mls.mapped("lot_id") + if moved_lots: + lots = lots.filtered(lambda l: l in moved_lots) rec.valid_lot_ids = lots def _onchange_product_id(self): diff --git a/rma_filter_lot/views/rma_order_view.xml b/rma_filter_lot/views/rma_order_view.xml index cef3c835..f846026a 100644 --- a/rma_filter_lot/views/rma_order_view.xml +++ b/rma_filter_lot/views/rma_order_view.xml @@ -1,4 +1,3 @@ - rma.order.line.form