-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] product_replenishment_cost_mrp: Migration to 16.0
- Loading branch information
Showing
5 changed files
with
50 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 38 additions & 69 deletions
107
product_replenishment_cost_mrp/report/mrp_report_bom_structure.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,48 @@ | ||
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 | ||
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) | ||
res = super()._get_bom_data(bom, warehouse, product, line_qty, bom_line, level, parent_bom, index, product_info, ignore_stock) | ||
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, self.env.company.currency_id, self.env.company, fields.Date.today(), round=True) | ||
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 | ||
# 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, self.env.company.currency_id, self.env.company, fields.Date.today(), round=True) | ||
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_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) | ||
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, self.env.company.currency_id, self.env.company, fields.Date.today(), round=True) | ||
res['prod_cost'] = price | ||
res['bom_cost'] = price | ||
return res | ||
|
||
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_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) | ||
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 | ||
byproduct['prod_cost'] = byproduct_id.product_id.currency_id._convert( | ||
price, self.env.company.currency_id, self.env.company, fields.Date.today(), round=True) | ||
return byproducts, byproduct_cost_portion |
4 changes: 2 additions & 2 deletions
4
product_replenishment_cost_mrp/report/mrp_report_bom_structure.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters