Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions product_currency_mrp/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
"name": "Product Currency MRP",
"version": "18.0.1.0.0",
"version": "18.0.1.1.0",
"category": "Products",
"sequence": 14,
"summary": "",
Expand All @@ -29,7 +29,7 @@
"images": [],
"depends": [
"product_currency",
"mrp",
"mrp_subcontracting",
],
"data": [],
"demo": [],
Expand Down
108 changes: 104 additions & 4 deletions product_currency_mrp/report/mrp_report_bom_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,48 @@
class ReportReplenishmentBomStructure(models.AbstractModel):
_inherit = "report.mrp.report_bom_structure"

@api.model
def _get_bom_data(
self,
bom,
warehouse,
product=False,
line_qty=False,
bom_line=False,
level=0,
parent_bom=False,
index=0,
product_info=False,
ignore_stock=False,
):
"""Here we use the product forced currency uom unit"""
if not self.env.context.get("force_currency"):
self = self.with_context(force_currency=product.currency_id)
res = super(ReportReplenishmentBomStructure, self)._get_bom_data(
bom, warehouse, product, line_qty, bom_line, level, parent_bom, index, product_info, ignore_stock
)
currency = self.env.context.get("force_currency") or self.env.company.currency_id
res.update({"currency": currency, "currency_id": currency.id})
is_minimized = self.env.context.get("minimized", False)
current_quantity = line_qty
if bom_line:
current_quantity = bom_line.product_uom_id._compute_quantity(line_qty, bom.product_uom_id) or 0
if not is_minimized:
if product:
price = product.uom_id._compute_price(product.standard_price, bom.product_uom_id) * current_quantity
res["prod_cost"] = product.currency_id._convert(
price, currency, self.env.company, fields.Date.today(), round=True
)
else:
price = (
bom.product_tmpl_id.uom_id._compute_price(bom.product_tmpl_id.standard_price, bom.product_uom_id)
* current_quantity
)
res["prod_cost"] = bom.product_tmpl_id.currency_id._convert(
price, currency, self.env.company, fields.Date.today(), round=True
)
return res

@api.model
def _get_component_data(
self,
Expand All @@ -28,15 +70,73 @@ def _get_component_data(
)
* line_quantity
)
price_converted = currency._convert(
price, self.env.company.currency_id, (parent_bom.company_id or self.env.company), fields.Date.today()
price = bom_line.product_id.currency_id._convert(
price, currency, (parent_bom.company_id or self.env.company), fields.Date.today()
)
rounded_price = currency.round(price_converted)
price = currency.round(price)
res.update(
{
"currency": currency,
"currency_id": currency.id,
"prod_cost": rounded_price,
"prod_cost": price,
"bom_cost": price,
}
)
return res

@api.model
def _get_byproducts_lines(self, product, bom, bom_quantity, level, total, index):
byproducts, byproduct_cost_portion = super()._get_byproducts_lines(
product, bom, bom_quantity, level, total, index
)
currency = self.env.context.get("force_currency") or self.env.company.currency_id
for byproduct in byproducts:
byproduct_id = self.env["mrp.bom.byproduct"].browse(byproduct["id"])
line_quantity = (bom_quantity / (bom.product_qty or 1.0)) * byproduct_id.product_qty
price = (
byproduct_id.product_id.uom_id._compute_price(
byproduct_id.product_id.standard_price, byproduct_id.product_uom_id
)
* line_quantity
)
price = byproduct_id.product_id.currency_id._convert(
price, currency, self.env.company, fields.Date.today(), round=True
)
byproduct.update(
{
"currency_id": currency.id,
"prod_cost": price,
}
)
return byproducts, byproduct_cost_portion

@api.model
def _get_operation_line(self, product, bom, qty, level, index):
operations = super()._get_operation_line(product, bom, qty, level, index)
currency = self.env.context.get("force_currency") or self.env.company.currency_id
for operation in operations:
bom_cost = self.env.company.currency_id._convert(
operation["bom_cost"], currency, self.env.company, fields.Date.today(), round=True
)
operation.update(
{
"currency_id": currency.id,
"bom_cost": bom_cost,
}
)
return operations

def _get_subcontracting_line(self, bom, seller, level, bom_quantity):
res = super()._get_subcontracting_line(bom, seller, level, bom_quantity)
ratio_uom_seller = seller.product_uom.ratio / bom.product_uom_id.ratio
currency = self.env.context.get("force_currency") or self.env.company.currency_id
price = seller.currency_id._convert(
seller.price, currency, (bom.company_id or self.env.company), fields.Date.today()
)
res.update(
{
"prod_cost": price / ratio_uom_seller * bom_quantity,
"bom_cost": price / ratio_uom_seller * bom_quantity,
}
)
return res