mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] add posibility to move only not reserved quantity
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import UserError
|
||||
from itertools import groupby
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user