[IMP] repair: consolidate creation from sale order
Main changes:
Consolidate the relation between a sale order line and the repair
order it has created.
Before:
When a product trigger the creation of a repair order from a
sale order line, the 'Repair Request' field of the repair order
is defined by the product name.
After:
When a product trigger the creation of a repair order from a
sale order line, set the product and its quantity on the created
repair order if the product is of type storable or consumable.
Moreover, define the 'Repair Request' field of the repair order
by the description of the sale line rather than by the product
name.
closes odoo/odoo#139177
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
committed by
William Henrotin
parent
9701d15596
commit
41c09796cd
@@ -148,10 +148,10 @@ class Repair(models.Model):
|
||||
sale_order_line_id = fields.Many2one(
|
||||
'sale.order.line', check_company=True, readonly=True,
|
||||
copy=False, help="Sale Order Line from which the Repair Order comes from.")
|
||||
repair_request = fields.Char(
|
||||
related='sale_order_line_id.product_id.display_name',
|
||||
repair_request = fields.Text(
|
||||
related='sale_order_line_id.name',
|
||||
string='Repair Request',
|
||||
help="Product from which the Repair Order was created.")
|
||||
help="Sale Order Line Description.")
|
||||
|
||||
# Return Binding
|
||||
picking_id = fields.Many2one(
|
||||
@@ -431,8 +431,12 @@ class Repair(models.Model):
|
||||
})
|
||||
|
||||
product_moves = self.env['stock.move'].create(product_move_vals)
|
||||
self.move_id = product_moves.id
|
||||
|
||||
repair_move = {m.repair_id.id: m for m in product_moves}
|
||||
for repair in self:
|
||||
move_id = repair_move.get(repair.id, False)
|
||||
if move_id:
|
||||
repair.move_id = move_id
|
||||
self.sale_order_line_id.move_ids.picked = True
|
||||
all_moves = self.move_ids + product_moves
|
||||
all_moves._action_done()
|
||||
|
||||
|
||||
@@ -101,6 +101,13 @@ class SaleOrderLine(models.Model):
|
||||
'sale_order_line_id': line.id,
|
||||
'picking_type_id': order.warehouse_id.repair_type_id.id,
|
||||
})
|
||||
if line.product_template_id.type in ('consu', 'product'):
|
||||
new_repair_vals[-1].update({
|
||||
'product_id': line.product_id.id,
|
||||
'product_qty': line.product_uom_qty,
|
||||
'product_uom': line.product_uom.id,
|
||||
})
|
||||
|
||||
if new_repair_vals:
|
||||
self.env['repair.order'].sudo().create(new_repair_vals)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user