[FIX] stock: uom in lot m2m with serial
Consider move uom different from serial product uom to set up move lines with product uom closes odoo/odoo#59986 X-original-commit: ee966998fa986936a0407676bb4d54f61c7fce1f Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
committed by
William Henrotin
parent
294142bdbf
commit
4e50999d87
@@ -481,6 +481,7 @@ class StockMove(models.Model):
|
||||
move_line_vals = self._prepare_move_line_vals(quantity=0)
|
||||
move_line_vals['lot_id'] = lot.id
|
||||
move_line_vals['lot_name'] = lot.name
|
||||
move_line_vals['product_uom_id'] = move.product_id.uom_id.id
|
||||
move_line_vals['qty_done'] = 1
|
||||
move_lines_commands.append((0, 0, move_line_vals))
|
||||
move.write({'move_line_ids': move_lines_commands})
|
||||
@@ -851,6 +852,9 @@ class StockMove(models.Model):
|
||||
|
||||
@api.onchange('lot_ids')
|
||||
def _onchange_lot_ids(self):
|
||||
quantity_done = sum(ml.product_uom_id._compute_quantity(ml.qty_done, self.product_uom) for ml in self.move_line_ids.filtered(lambda ml: not ml.lot_id and ml.lot_name))
|
||||
quantity_done += self.product_id.uom_id._compute_quantity(len(self.lot_ids), self.product_uom)
|
||||
self.update({'quantity_done': quantity_done})
|
||||
used_lots = self.env['stock.move.line'].search([
|
||||
('company_id', '=', self.company_id.id),
|
||||
('product_id', '=', self.product_id.id),
|
||||
@@ -858,15 +862,6 @@ class StockMove(models.Model):
|
||||
('move_id', '!=', self._origin.id),
|
||||
('state', '!=', 'cancel')
|
||||
])
|
||||
|
||||
counter = self.env['stock.move.line'].search_count([
|
||||
('company_id', '=', self.company_id.id),
|
||||
('product_id', '=', self.product_id.id),
|
||||
('move_id', '=', self._origin.id),
|
||||
('lot_id', '=', False),
|
||||
('lot_name', '!=', False),
|
||||
])
|
||||
self.update({'quantity_done': len(self.lot_ids) + counter})
|
||||
if used_lots:
|
||||
return {
|
||||
'warning': {'title': _('Warning'), 'message': _('Existing Serial numbers (%s). Please correct the serial numbers encoded.') % ','.join(used_lots.lot_id.mapped('display_name'))}
|
||||
|
||||
@@ -2815,3 +2815,17 @@ class TestAutoAssign(TestStockCommon):
|
||||
self.assertEqual(move.quantity_done, 3.0)
|
||||
move.lot_ids = [(3, lot2.id)]
|
||||
self.assertEqual(move.quantity_done, 2.0)
|
||||
|
||||
self.uom_dozen = self.env.ref('uom.product_uom_dozen')
|
||||
move = self.env['stock.move'].create({
|
||||
'name': 'TestReceiveDozen',
|
||||
'location_id': self.supplier_location.id,
|
||||
'location_dest_id': self.stock_location.id,
|
||||
'product_id': self.product_serial.id,
|
||||
'product_uom': self.uom_dozen.id,
|
||||
'picking_type_id': self.env.ref('stock.picking_type_in').id,
|
||||
})
|
||||
move.lot_ids = [(4, lot1.id)]
|
||||
move.lot_ids = [(4, lot2.id)]
|
||||
move.lot_ids = [(4, lot3.id)]
|
||||
self.assertEqual(move.quantity_done, 3.0/12.0)
|
||||
|
||||
Reference in New Issue
Block a user