Skip to content

Commit

Permalink
[MIG] product_replenishment_cost_mrp: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelZilli authored and vib-adhoc committed May 3, 2023
1 parent 554e18b commit edd5706
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 75 deletions.
4 changes: 2 additions & 2 deletions product_replenishment_cost_mrp/__manifest__.py
@@ -1,6 +1,6 @@
{
'name': 'Integration between Replenishment Cost and Manufacture',
'version': "15.0.1.0.0",
'version': "16.0.1.0.0",
'author': "ADHOC SA, Odoo Community Association (OCA)",
'license': 'AGPL-3',
'category': 'Products',
Expand All @@ -13,5 +13,5 @@
'views/product_template_views.xml',
'report/mrp_report_bom_structure.xml'
],
'installable': False,
'installable': True,
}
5 changes: 3 additions & 2 deletions product_replenishment_cost_mrp/i18n/es.po
Expand Up @@ -31,9 +31,10 @@ msgid "Basado en Ldm"
msgstr "Basado en Ldm"

#. module: product_replenishment_cost_mrp
#: model:ir.actions.client,name:mrp.action_report_mrp_bom
#: model_terms:ir.ui.view,arch_db:product_replenishment_cost_mrp.report_mrp_bom_inherit
msgid "Estructura de Lista de Materiales y Costo (Según Costo de Reposición)"
msgstr ""
msgid "BoM Overview (Based on Replenishment Cost)"
msgstr "Estructura de Lista de Materiales y Costo (Según Costo de Reposición)"

#. module: product_replenishment_cost_mrp
#: model_terms:ir.ui.view,arch_db:product_replenishment_cost_mrp.mrp_bom_form_view
Expand Down
135 changes: 67 additions & 68 deletions product_replenishment_cost_mrp/report/mrp_report_bom_structure.py
@@ -1,79 +1,78 @@
from odoo import models, fields
from odoo import models, fields, api
from odoo.tools import float_round


class ReportReplenishmentBomStructure(models.AbstractModel):
_inherit = 'report.mrp.report_bom_structure'

def _get_bom(self, bom_id=False, product_id=False, line_qty=False, line_id=False, level=False):
@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 replenishment cost for the uom unit"""
res = super()._get_bom(bom_id=bom_id, product_id=product_id, line_qty=line_qty, line_id=line_id, level=level)
bom = self.env['mrp.bom'].browse(bom_id)
bom_quantity = line_qty
if line_id:
current_line = self.env['mrp.bom.line'].browse(int(line_id))
bom_quantity = current_line.product_uom_id._compute_quantity(line_qty, bom.product_uom_id) or 0
if res.get('product_id', False) and res['product_id']:
product = self.env['product.product'].browse(res['product_id'])
res['price'] = product.uom_id._compute_price(product.replenishment_cost, bom.product_uom_id) * bom_quantity
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.replenishment_cost, bom.product_uom_id) * current_quantity
res['prod_cost'] = product.currency_id._convert(
price, currency, self.env.company, fields.Date.today(), round=True)
else:
# Use the product template instead of the variant
price = bom.product_tmpl_id.uom_id._compute_price(bom.product_tmpl_id.replenishment_cost, 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

def _get_bom_lines(self, bom, bom_quantity, product, line_id, level):
components, total = super()._get_bom_lines(bom, bom_quantity, product, line_id, level)
total = 0
for line in bom.bom_line_ids:
line_quantity = (
bom_quantity / (bom.product_qty or 1.0)) * line.product_qty
if line._skip_bom_line(product):
continue
price = line.product_id.uom_id._compute_price(
line.product_id.replenishment_cost, line.product_uom_id) * line_quantity
price = line.product_id.currency_id._convert(
price, product.currency_id, self.env.company, fields.Date.today(), round=True)
if line.child_bom_id:
factor = line.product_uom_id._compute_quantity(
line_quantity, line.child_bom_id.product_uom_id) / line.child_bom_id.product_qty
sub_total = self._get_price(
line.child_bom_id, factor, line.product_id)
else:
sub_total = price
sub_total = line.product_id.currency_id.round(sub_total)
for comp in components:
if comp['line_id'] == line.id:
comp['prod_cost'] = price
comp['total'] = sub_total
break
total += sub_total
return components, total
@api.model
def _get_component_data(self, parent_bom, warehouse, bom_line, line_quantity, level, index, product_info, ignore_stock=False):
res = super()._get_component_data(parent_bom, warehouse, bom_line, line_quantity, level, index, product_info, ignore_stock)
currency = self.env.context.get('force_currency') or self.env.company.currency_id
price = bom_line.product_id.uom_id._compute_price(
bom_line.product_id.replenishment_cost, bom_line.product_uom_id) * line_quantity
price = bom_line.product_id.currency_id._convert(
price, currency, self.env.company, fields.Date.today(), round=True)
res.update({
'bom_cost': price,
'currency': currency,
'currency_id': currency.id,
'prod_cost': price,
})
return res

def _get_price(self, bom, factor, product):
price = 0
if bom.routing_id:
# routing are defined on a BoM and don't have a concept of quantity.
# It means that the operation time are defined for the quantity on
# the BoM (the user produces a batch of products). E.g the user
# product a batch of 10 units with a 5 minutes operation, the time
# will be the 5 for a quantity between 1-10, then doubled for
# 11-20,...
operation_cycle = float_round(
factor, precision_rounding=1, rounding_method='UP')
operations = self._get_operation_line(
bom.routing_id, operation_cycle, 0)
price += sum([op['total'] for op in operations])
@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.replenishment_cost, 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

for line in bom.bom_line_ids:
if line._skip_bom_line(product):
continue
if line.child_bom_id:
qty = line.product_uom_id._compute_quantity(
line.product_qty * factor, line.child_bom_id.product_uom_id) / line.child_bom_id.product_qty
sub_price = self._get_price(
line.child_bom_id, qty, line.product_id)
price += sub_price
else:
prod_qty = line.product_qty * factor
not_rounded_price = line.product_id.uom_id._compute_price(
line.product_id.replenishment_cost, line.product_uom_id) * prod_qty
price += product.currency_id.round(
not_rounded_price)
return price
@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
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_mrp_bom_inherit" inherit_id="mrp.report_mrp_bom">
<xpath expr="//div[hasclass('row')]//div[hasclass('col-lg-12')]//h1" position="replace">
<h1>Estructura de Lista de Materiales y Costo (Según Costo de Reposición)</h1>
<xpath expr="//h1" position="replace">
<h1>BoM Overview (Based on Replenishment Cost)</h1>
</xpath>
</template>
</odoo>
6 changes: 5 additions & 1 deletion product_replenishment_cost_mrp/views/mrp_bom_views.xml
@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="mrp.action_report_mrp_bom" model="ir.actions.client">
<field name="name">BoM Overview (Based on Replenishment Cost)</field>
</record>

<record id="mrp_bom_form_view" model="ir.ui.view">
<field name="name">mrp.bom.inherit.view.form</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']//button[@type='action']" position="attributes">
<xpath expr="//div[@name='button_box']/button[2]" position="attributes">
<attribute name="help">Estructura y costo según costo de reposición</attribute>
</xpath>
</field>
Expand Down

0 comments on commit edd5706

Please sign in to comment.