[FIX] mrp_repair: return move with owner

- Create Product A with 5 Unit(s) on hand
- Created SO for 5 Units(s) A, validate SO and picking
- Return of the same quantity, but assign an owner
- Created RMA for 5 Units(s)

A warning generated: 'A is not available in sufficient quantity in ...'.

By assigning an owner on the return, the product is not considered
available. However, this makes sense since we are not owner of the
product, so it should not be valued.

Ideally, we would need a field `owner_id` on the RMA. Since it is not
available, we use `partner_id`. the logic is the following:
- try to reserve with owner_id = partner_id
- if the available qty is not sufficient, try without owner

When the stock moves are created, we apply the same logic to know
whether we need to create the move with an owner. Note that this is not
really sufficient. Ideally, we should reserve the quantity to repair
when we check if the quantity available is sufficient.

opw-1854346
This commit is contained in:
Nicolas Martinelli
2018-06-11 10:02:09 +02:00
committed by Nicolas Martinelli
parent 9422b3272e
commit 61c9921596
+14 -3
View File
@@ -207,9 +207,11 @@ class Repair(models.Model):
def action_validate(self):
self.ensure_one()
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
available_qty = self.env['stock.quant']._get_available_quantity(self.product_id, self.location_id, self.lot_id, strict=True)
if float_compare(available_qty, self.product_qty, precision_digits=precision) >= 0:
return self.action_repair_confirm()
available_qty_owner = self.env['stock.quant']._get_available_quantity(self.product_id, self.location_id, self.lot_id, owner_id=self.partner_id, strict=True)
available_qty_noown = self.env['stock.quant']._get_available_quantity(self.product_id, self.location_id, self.lot_id, strict=True)
for available_qty in [available_qty_owner, available_qty_noown]:
if float_compare(available_qty, self.product_qty, precision_digits=precision) >= 0:
return self.action_repair_confirm()
else:
return {
'name': _('Insufficient Quantity'),
@@ -435,8 +437,15 @@ class Repair(models.Model):
if self.filtered(lambda repair: not repair.repaired):
raise UserError(_("Repair must be repaired in order to make the product moves."))
res = {}
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
Move = self.env['stock.move']
for repair in self:
# Try to create move with the appropriate owner
owner_id = False
available_qty_owner = self.env['stock.quant']._get_available_quantity(repair.product_id, repair.location_id, repair.lot_id, owner_id=repair.partner_id, strict=True)
if float_compare(available_qty_owner, repair.product_qty, precision_digits=precision) >= 0:
owner_id = repair.partner_id.id
moves = self.env['stock.move']
for operation in repair.operations:
move = Move.create({
@@ -454,6 +463,7 @@ class Repair(models.Model):
'qty_done': operation.product_uom_qty,
'package_id': False,
'result_package_id': False,
'owner_id': owner_id,
'location_id': operation.location_id.id, #TODO: owner stuff
'location_dest_id': operation.location_dest_id.id,})],
'repair_id': repair.id,
@@ -476,6 +486,7 @@ class Repair(models.Model):
'qty_done': repair.product_qty,
'package_id': False,
'result_package_id': False,
'owner_id': owner_id,
'location_id': repair.location_id.id, #TODO: owner stuff
'location_dest_id': repair.location_dest_id.id,})],
'repair_id': repair.id,