From a194c6f5186ef455e6a94b5d002e89607b5a5e64 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 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py index fe45f89dd..15e2e214f 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants.py +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -61,14 +61,23 @@ class AssignManualQuants(models.TransientModel): return {} @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([ + 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._get_available_quants(move) quants_lines = [] for quant in available_quants: line = {}