[FIX] mrp_subcontracting: compute bom price into company currency
Steps to reproduce the bug:
- Enable “subcontracting” in the mrp settings
- Create a storable product “P1”:
- Add a vendor:
- supplier: “Azure interior”
- currency: euro
- price: 20
- Add a BoM:
- Type: subcontracting
- add any product as component
- Save
- Check that the currency of the company is in dollars
- Click on Compute Price from BoM button in the product form
Problem:
The seller's price is not converted into dollars
opw-3321346
closes odoo/odoo#121327
X-original-commit: f60fac0afa9b87baa68328c5755a7fe84494cb10
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
from odoo import models, fields
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
@@ -13,5 +13,6 @@ class ProductProduct(models.Model):
|
||||
if bom and bom.type == 'subcontract':
|
||||
seller = self._select_seller(quantity=bom.product_qty, uom_id=bom.product_uom_id, params={'subcontractor_ids': bom.subcontractor_ids})
|
||||
if seller:
|
||||
price += seller.product_uom._compute_price(seller.price, self.uom_id)
|
||||
seller_price = seller.currency_id._convert(seller.price, self.env.company.currency_id, (bom.company_id or self.env.company), fields.Date.today())
|
||||
price += seller.product_uom._compute_price(seller_price, self.uom_id)
|
||||
return price
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import Command
|
||||
from odoo import Command, fields
|
||||
from odoo.tests.common import Form
|
||||
from odoo.tools.float_utils import float_round, float_compare
|
||||
|
||||
@@ -306,3 +306,48 @@ class TestBomPriceSubcontracting(TestBomPriceCommon):
|
||||
self.Product.browse([self.dining_table.id, self.table_head.id]).action_bom_cost()
|
||||
self.assertEqual(float_compare(self.table_head.standard_price, 478.75, precision_digits=2), 0, "After computing price from BoM price should be 878.75")
|
||||
self.assertEqual(float_compare(self.dining_table.standard_price, 878.75, precision_digits=2), 0, "After computing price from BoM price should be 878.75")
|
||||
|
||||
def test_02_compute_price_subcontracting_cost(self):
|
||||
"""Test calculation of bom cost with subcontracting and supplier in different currency."""
|
||||
currency_a = self.env['res.currency'].create({
|
||||
'name': 'ZEN',
|
||||
'symbol': 'Z',
|
||||
'rounding': 0.01,
|
||||
'currency_unit_label': 'Zenny',
|
||||
'rate_ids': [(0, 0, {
|
||||
'name': fields.Date.today(),
|
||||
'company_rate': 0.5,
|
||||
})],
|
||||
})
|
||||
|
||||
partner = self.env['res.partner'].create({
|
||||
'name': 'supplier',
|
||||
})
|
||||
product = self.env['product.product'].create({
|
||||
'name': 'product',
|
||||
'type': 'product',
|
||||
'standard_price': 100,
|
||||
'company_id': self.env.company.id,
|
||||
})
|
||||
supplier = self.env['product.supplierinfo'].create([{
|
||||
'partner_id': partner.id,
|
||||
'product_tmpl_id': product.product_tmpl_id.id,
|
||||
'price': 120.0,
|
||||
'currency_id': currency_a.id,
|
||||
}])
|
||||
self.env['mrp.bom'].create({
|
||||
'product_tmpl_id': product.product_tmpl_id.id,
|
||||
'product_qty': 1,
|
||||
'type': 'subcontract',
|
||||
'subcontractor_ids': [Command.link(partner.id)],
|
||||
'bom_line_ids': [
|
||||
(0, 0, {'product_id': self.table_head.id, 'product_qty': 1}),
|
||||
],
|
||||
})
|
||||
self.table_head.standard_price = 100
|
||||
self.assertEqual(supplier.is_subcontractor, True)
|
||||
self.assertEqual(product.standard_price, 100, "Initial price of the Product should be 100")
|
||||
product.button_bom_cost()
|
||||
# 120 Zen = 240 USD (120 * 2)
|
||||
# price = 240 + 100 (1 unit of component "table_head") = 340
|
||||
self.assertEqual(product.standard_price, 340, "After computing price from BoM price should be 340")
|
||||
|
||||
Reference in New Issue
Block a user