[FIX] repair, sale_*: set cost in SO when creating SO from repair
Steps to reproduce the bug:
- Create a storable product “P1”
- cost= $100
- Create a repair order:
- select any product in the product to repair
- add “P1” as component
- create the quotation from the repair order
Problem:
The cost is not computed correctly and is set at 0 in the
`sale.order.line`
opw-3502317
closes odoo/odoo#135822
X-original-commit: b95ed3617f465a655c8f918bee8edc673c8f202b
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -110,3 +110,7 @@ class SaleOrderLine(models.Model):
|
||||
for line in self:
|
||||
binded_ro_ids |= line.order_id.sudo().repair_order_ids.filtered(lambda ro: ro.sale_order_line_id.id == line.id and ro.state != 'done')
|
||||
binded_ro_ids.action_repair_cancel()
|
||||
|
||||
def has_valued_move_ids(self):
|
||||
res = super().has_valued_move_ids()
|
||||
return res and not self.move_ids.repair_id
|
||||
|
||||
@@ -473,3 +473,23 @@ class TestRepair(common.TransactionCase):
|
||||
], limit=1)
|
||||
self.assertEqual(repair.move_ids[0].location_dest_id, location_dest_id)
|
||||
|
||||
def test_purchase_price_so_create_from_repair(self):
|
||||
"""
|
||||
Test that the purchase price is correctly set on the SO line,
|
||||
when creating a SO from a repair order.
|
||||
"""
|
||||
self.product_product_11.standard_price = 10
|
||||
repair = self.env['repair.order'].create({
|
||||
'partner_id': self.res_partner_1.id,
|
||||
'product_id': self.product_product_3.id,
|
||||
'picking_type_id': self.stock_warehouse.repair_type_id.id,
|
||||
'move_ids': [
|
||||
(0, 0, {
|
||||
'repair_line_type': 'add',
|
||||
'product_id': self.product_product_11.id,
|
||||
})
|
||||
],
|
||||
})
|
||||
repair.action_create_sale_order()
|
||||
self.assertEqual(repair.sale_order_id.order_line.product_id, self.product_product_11)
|
||||
self.assertEqual(repair.sale_order_id.order_line.purchase_price, 10)
|
||||
|
||||
@@ -1274,3 +1274,6 @@ class SaleOrderLine(models.Model):
|
||||
round=False,
|
||||
)
|
||||
return amount
|
||||
|
||||
def has_valued_move_ids(self):
|
||||
return self.move_ids
|
||||
|
||||
@@ -12,7 +12,7 @@ class SaleOrderLine(models.Model):
|
||||
lines_without_moves = self.browse()
|
||||
for line in self:
|
||||
product = line.product_id.with_company(line.company_id)
|
||||
if not line.move_ids:
|
||||
if not line.has_valued_move_ids():
|
||||
lines_without_moves |= line
|
||||
elif product and product.categ_id.property_cost_method != 'standard':
|
||||
purch_price = product._compute_average_price(0, line.product_uom_qty, line.move_ids)
|
||||
|
||||
Reference in New Issue
Block a user