[FIX] {purchase_,}mrp: convert costs when different currencies

Steps to reproduce:
- Enable a second currency (e.g. EUR)
- Create a product P with a supplier using EUR as currency
- Create a MO with this product P as component and confirm it
- Open the Overview

Issue:
In the MO Cost column, the cost will be displayed in the company
currency but without converting its value.

Task-3251506

Part-of: odoo/odoo#114536
This commit is contained in:
clesgow
2023-10-20 14:59:09 +00:00
parent abe7725baa
commit 57e31b7c82
2 changed files with 11 additions and 7 deletions
+6 -4
View File
@@ -450,7 +450,7 @@ class ReportMoOverview(models.AbstractModel):
# Need to order more products to fulfill the need
resupply_rules = self._get_resupply_rules(production, product, replenish_data)
rules_delay = sum(rule.delay for rule in resupply_rules)
resupply_data = self._get_resupply_data(resupply_rules, rules_delay, missing_quantity, move_raw.product_uom, product, production.warehouse_id)
resupply_data = self._get_resupply_data(resupply_rules, rules_delay, missing_quantity, move_raw.product_uom, product, production)
to_order_line = {'summary': {
'level': level + 1,
@@ -468,7 +468,8 @@ class ReportMoOverview(models.AbstractModel):
'currency': currency,
}}
if resupply_data:
to_order_line['summary']['mo_cost'] = currency.round(resupply_data['cost'])
mo_cost = resupply_data['currency']._convert(resupply_data['cost'], currency, (production.company_id or self.env.company), fields.Date.today())
to_order_line['summary']['mo_cost'] = mo_cost
to_order_line['summary']['receipt'] = self._check_planned_start(production.date_start, self._format_receipt_date('estimated', fields.datetime.today() + timedelta(days=resupply_data['delay'])))
else:
to_order_line['summary']['mo_cost'] = currency.round(product.standard_price * move_raw.product_uom._compute_quantity(missing_quantity, product.uom_id))
@@ -700,11 +701,11 @@ class ReportMoOverview(models.AbstractModel):
def _get_extra_replenishments(self, product):
return []
def _get_resupply_data(self, rules, rules_delay, quantity, uom_id, product, warehouse):
def _get_resupply_data(self, rules, rules_delay, quantity, uom_id, product, production):
manufacture_rules = [rule for rule in rules if rule.action == 'manufacture']
if manufacture_rules:
# Need to get rules from Production location to get delays before production
wh_manufacture_rules = product._get_rules_from_location(product.property_stock_production, route_ids=warehouse.route_ids)
wh_manufacture_rules = product._get_rules_from_location(product.property_stock_production, route_ids=production.warehouse_id.route_ids)
wh_manufacture_rules -= rules
rules_delay += sum(rule.delay for rule in wh_manufacture_rules)
related_bom = self.env['mrp.bom']._bom_find(product)[product]
@@ -713,6 +714,7 @@ class ReportMoOverview(models.AbstractModel):
return {
'delay': related_bom.produce_delay + rules_delay,
'cost': product.standard_price * uom_id._compute_quantity(quantity, product.uom_id),
'currency': (production.company_id or self.env.company).currency_id,
}
return False
@@ -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 fields, models
class ReportMoOverview(models.AbstractModel):
_inherit = 'report.mrp.report_mo_overview'
@@ -53,14 +53,15 @@ class ReportMoOverview(models.AbstractModel):
return self._format_receipt_date('expected', planned_date)
return res
def _get_resupply_data(self, rules, rules_delay, quantity, uom_id, product, warehouse):
res = super()._get_resupply_data(rules, rules_delay, quantity, uom_id, product, warehouse)
def _get_resupply_data(self, rules, rules_delay, quantity, uom_id, product, production):
res = super()._get_resupply_data(rules, rules_delay, quantity, uom_id, product, production)
if any(rule for rule in rules if rule.action == 'buy' and product.seller_ids):
supplier = product._select_seller(quantity=quantity, uom_id=product.uom_id)
if supplier:
return {
'delay': supplier.delay + rules_delay,
'cost': supplier.price * uom_id._compute_quantity(quantity, supplier.product_uom),
'currency': supplier.currency_id,
}
return res
@@ -82,5 +83,6 @@ class ReportMoOverview(models.AbstractModel):
po_line.price_unit, currency=po.currency_id, quantity=uom_id._compute_quantity(quantity, move_in.purchase_line_id.product_uom),
product=po_line.product_id, partner=po.partner_id
)['total_void']
price = po_line.currency_id._convert(price, currency, (move_in.company_id or self.env.company), fields.Date.today())
return currency.round(price)
return super()._get_replenishment_mo_cost(product, quantity, uom_id, currency, move_in)