From 5e4a6a561bd7d986923100cd86465e96ba0a32c6 Mon Sep 17 00:00:00 2001 From: Yoshi Tashiro Date: Wed, 27 Jan 2021 14:45:14 +0800 Subject: [PATCH] [IMP] stock_quant_manual_assign: make quant search flexible This is to make it easier to manipulate with the domain conditions and search results for available quants. --- .../wizard/assign_manual_quants.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py index 9e600a446..4badf27d8 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants.py +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -66,17 +66,24 @@ class AssignManualQuants(models.TransientModel): move.mapped("picking_id")._compute_state() return {} + @api.model + def _domain_for_available_quants(self, move): + return [ + ("location_id", "child_of", move.location_id.id), + ("product_id", "=", move.product_id.id), + ("quantity", ">", 0), + ] + + @api.model + def _get_available_quants(self, move): + domain = self._domain_for_available_quants(move) + return self.env["stock.quant"].search(domain) + @api.model def default_get(self, fields): res = super(AssignManualQuants, self).default_get(fields) move = self.env["stock.move"].browse(self.env.context["active_id"]) - available_quants = self.env["stock.quant"].search( - [ - ("location_id", "child_of", move.location_id.id), - ("product_id", "=", move.product_id.id), - ("quantity", ">", 0), - ] - ) + available_quants = self._get_available_quants(move) quants_lines = [] for quant in available_quants: line = self._prepare_wizard_line(move, quant)