[FIX] {purchase_,}stock: merge fields of several moves
If `_merge_moves_fields` is called with a recordset of several SM, and if there are more than one `self.picking_id`, the method will trigger a `ValueError` (Expected singleton) OPW-2861605 closes odoo/odoo#100087 X-original-commit: d3924054437cb2add044f51a3c03346a67f24674 Signed-off-by: William Henrotin (whe) <whe@odoo.com> Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
@@ -776,3 +776,51 @@ class TestReorderingRule(TransactionCase):
|
||||
{'location_id': supplier_location_id, 'location_dest_id': input_location_id, 'product_qty': 4},
|
||||
{'location_id': input_location_id, 'location_dest_id': stock_location_id, 'product_qty': 4},
|
||||
])
|
||||
|
||||
def test_decrease_qty_multi_step_receipt02(self):
|
||||
"""
|
||||
Two-steps receipt. An orderpoint generates a move from Input to Stock
|
||||
with 4 x Product01 and a purchase order to fulfill the need of that SM.
|
||||
Then, the user increases and decreases the qty on the PO. The existing
|
||||
SMs should be updated.
|
||||
"""
|
||||
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1)
|
||||
warehouse.reception_steps = 'two_steps'
|
||||
input_location_id = warehouse.wh_input_stock_loc_id.id
|
||||
stock_location_id = warehouse.lot_stock_id.id
|
||||
supplier_location_id = self.ref('stock.stock_location_suppliers')
|
||||
|
||||
self.product_01.description = False
|
||||
|
||||
op = self.env['stock.warehouse.orderpoint'].create({
|
||||
'name': self.product_01.name,
|
||||
'location_id': stock_location_id,
|
||||
'product_id': self.product_01.id,
|
||||
'product_min_qty': 4,
|
||||
'product_max_qty': 4,
|
||||
'trigger': 'manual',
|
||||
})
|
||||
op.action_replenish()
|
||||
|
||||
purchase = self.env['purchase.order'].search([('partner_id', '=', self.partner.id)], order="id desc", limit=1)
|
||||
with Form(purchase) as form:
|
||||
with form.order_line.edit(0) as line:
|
||||
line.product_qty = 10
|
||||
purchase.button_confirm()
|
||||
|
||||
moves = self.env['stock.move'].search([('product_id', '=', self.product_01.id)], order='id desc')
|
||||
self.assertRecordValues(moves, [
|
||||
{'location_id': input_location_id, 'location_dest_id': stock_location_id, 'product_qty': 6},
|
||||
{'location_id': supplier_location_id, 'location_dest_id': input_location_id, 'product_qty': 10},
|
||||
{'location_id': input_location_id, 'location_dest_id': stock_location_id, 'product_qty': 4},
|
||||
])
|
||||
|
||||
with Form(purchase) as form:
|
||||
with form.order_line.edit(0) as line:
|
||||
line.product_qty = 1
|
||||
|
||||
moves = self.env['stock.move'].search([('product_id', '=', self.product_01.id)], order='id desc')
|
||||
self.assertRecordValues(moves, [
|
||||
{'location_id': supplier_location_id, 'location_dest_id': input_location_id, 'product_qty': 1},
|
||||
{'location_id': input_location_id, 'location_dest_id': stock_location_id, 'product_qty': 1},
|
||||
])
|
||||
|
||||
@@ -813,7 +813,7 @@ class StockMove(models.Model):
|
||||
origin = '/'.join(set(self.filtered(lambda m: m.origin).mapped('origin')))
|
||||
return {
|
||||
'product_uom_qty': sum(self.mapped('product_uom_qty')),
|
||||
'date': min(self.mapped('date')) if self.mapped('picking_id').move_type == 'direct' else max(self.mapped('date')),
|
||||
'date': min(self.mapped('date')) if all(p.move_type == 'direct' for p in self.picking_id) else max(self.mapped('date')),
|
||||
'move_dest_ids': [(4, m.id) for m in self.mapped('move_dest_ids')],
|
||||
'move_orig_ids': [(4, m.id) for m in self.mapped('move_orig_ids')],
|
||||
'state': state,
|
||||
|
||||
Reference in New Issue
Block a user