From 3a9fb80e8224e106c30f4b796d6aea6ea183bb91 Mon Sep 17 00:00:00 2001 From: Iryna Vushnevska Date: Thu, 23 Apr 2020 16:10:14 +0300 Subject: [PATCH] [IMP] add posibility to move only not reserved quantity --- stock_move_location/models/stock_picking.py | 1 - .../wizard/stock_move_location.py | 46 +++++++++++++++---- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/stock_move_location/models/stock_picking.py b/stock_move_location/models/stock_picking.py index 3b8733472..7235230f4 100644 --- a/stock_move_location/models/stock_picking.py +++ b/stock_move_location/models/stock_picking.py @@ -4,7 +4,6 @@ from odoo import _, models from odoo.exceptions import UserError -from itertools import groupby class StockPicking(models.Model): diff --git a/stock_move_location/wizard/stock_move_location.py b/stock_move_location/wizard/stock_move_location.py index f30a91764..059af54fe 100644 --- a/stock_move_location/wizard/stock_move_location.py +++ b/stock_move_location/wizard/stock_move_location.py @@ -5,6 +5,7 @@ from odoo import api, fields, models from odoo.fields import first +from itertools import groupby class StockMoveLocationWizard(models.TransientModel): @@ -77,18 +78,45 @@ class StockMoveLocationWizard(models.TransientModel): # Load data directly from quants quants = self.env['stock.quant'].browse( self.env.context.get('active_ids', False)) - res['stock_move_location_line_ids'] = [(0, 0, { - 'product_id': quant.product_id.id, - 'move_quantity': quant.quantity, - 'max_quantity': quant.quantity, - 'origin_location_id': quant.location_id.id, - 'lot_id': quant.lot_id.id, - 'product_uom_id': quant.product_uom_id.id, - 'custom': False, - }) for quant in quants] + res['stock_move_location_line_ids'] = self._prepare_wizard_move_lines(quants) res['origin_location_id'] = first(quants).location_id.id return res + @api.model + def _prepare_wizard_move_lines(self, quants): + res = [] + exclude_reserved_qty = self.env.context.get('only_reserved_qty', False) + if not exclude_reserved_qty: + res = [(0, 0, { + 'product_id': quant.product_id.id, + 'move_quantity': quant.quantity, + 'max_quantity': quant.quantity, + 'origin_location_id': quant.location_id.id, + 'lot_id': quant.lot_id.id, + 'product_uom_id': quant.product_uom_id.id, + 'custom': False, + }) for quant in quants] + else: + # if need move only available qty per product on location + for product, quant in groupby(quants, lambda r: r.product_id): + # we need only one quant per product + quant = list(quant)[0] + qty = quant._get_available_quantity( + quant.product_id, + quant.location_id, + ) + if qty: + res.append((0, 0, { + 'product_id': quant.product_id.id, + 'move_quantity': qty, + 'max_quantity': qty, + 'origin_location_id': quant.location_id.id, + 'lot_id': quant.lot_id.id, + 'product_uom_id': quant.product_uom_id.id, + 'custom': False, + })) + return res + @api.onchange('origin_location_id') def _onchange_origin_location_id(self): if not self.env.context.get('origin_location_disable', False):