-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] Add rounding to 0.001 and column Prod Qty * Prod Price
[IMP] Improvements [IMP] Improvements [IMP] Improvements
- Loading branch information
Showing
5 changed files
with
223 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import mrp_bom_line_extension | ||
from . import mrp_report_bom_structure | ||
from . import uom_uom |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from odoo import models | ||
from odoo.tools import float_round | ||
|
||
class ReportBomStructurePrecision(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): | ||
bom = self.env['mrp.bom'].browse(bom_id) | ||
company = bom.company_id or self.env.company | ||
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 | ||
# Display bom components for current selected product variant | ||
if product_id: | ||
product = self.env['product.product'].browse(int(product_id)) | ||
else: | ||
product = bom.product_id or bom.product_tmpl_id.product_variant_id | ||
if product: | ||
price = product.uom_id._compute_price(product.with_company(company).standard_price, bom.product_uom_id) * bom_quantity | ||
attachments = self.env['mrp.document'].search(['|', '&', ('res_model', '=', 'product.product'), | ||
('res_id', '=', product.id), '&', ('res_model', '=', 'product.template'), ('res_id', '=', product.product_tmpl_id.id)]) | ||
else: | ||
# Use the product template instead of the variant | ||
price = bom.product_tmpl_id.uom_id._compute_price(bom.product_tmpl_id.with_company(company).standard_price, bom.product_uom_id) * bom_quantity | ||
attachments = self.env['mrp.document'].search([('res_model', '=', 'product.template'), ('res_id', '=', bom.product_tmpl_id.id)]) | ||
operations = self._get_operation_line(bom, float_round(bom_quantity, precision_rounding=1, rounding_method='UP'), 0) | ||
lines = { | ||
'bom': bom, | ||
'bom_qty': bom_quantity, | ||
'bom_prod_name': product.display_name, | ||
'currency': company.currency_id, | ||
'product': product, | ||
'code': bom and bom.display_name or '', | ||
'price': round(price, 4), # Set precision to 4 decimals for price | ||
'total': sum([op['total'] for op in operations]), | ||
'level': level or 0, | ||
'operations': operations, | ||
'operations_cost': sum([op['total'] for op in operations]), | ||
'attachments': attachments, | ||
'operations_time': sum([op['duration_expected'] for op in operations]) | ||
} | ||
components, total = self._get_bom_lines(bom, bom_quantity, product, line_id, level) | ||
lines['components'] = components | ||
lines['total'] += total | ||
return lines | ||
|
||
def _get_bom_lines(self, bom, bom_quantity, product, line_id, level): | ||
components = [] | ||
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 | ||
company = bom.company_id or self.env.company | ||
price = line.product_id.uom_id._compute_price(line.product_id.with_company(company).standard_price, line.product_uom_id) * line_quantity | ||
if line.child_bom_id: | ||
factor = line.product_uom_id._compute_quantity(line_quantity, line.child_bom_id.product_uom_id) | ||
sub_total = self._get_price(line.child_bom_id, factor, line.product_id) | ||
else: | ||
sub_total = price | ||
sub_total = self.env.company.currency_id.round(sub_total) | ||
components.append({ | ||
'prod_id': line.product_id.id, | ||
'prod_name': line.product_id.display_name, | ||
'code': line.child_bom_id and line.child_bom_id.display_name or '', | ||
'prod_qty': line_quantity, | ||
'prod_uom': line.product_uom_id.name, | ||
'prod_cost': round(price, 4), # Set precision to 4 decimals for price | ||
'parent_id': bom.id, | ||
'line_id': line.id, | ||
'level': level or 0, | ||
'total': sub_total, | ||
'child_bom': line.child_bom_id.id, | ||
'phantom_bom': line.child_bom_id and line.child_bom_id.type == 'phantom' or False, | ||
'attachments': self.env['mrp.document'].search(['|', '&', | ||
('res_model', '=', 'product.product'), ('res_id', '=', line.product_id.id), '&', ('res_model', '=', 'product.template'), ('res_id', '=', line.product_id.product_tmpl_id.id)]), | ||
|
||
}) | ||
total += sub_total | ||
return components, total |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from odoo import models | ||
|
||
class UomUom(models.Model): | ||
_inherit = 'uom.uom' | ||
|
||
def _compute_price(self, price, to_unit): | ||
self.ensure_one() | ||
|
||
# Establecer el atributo rounding a 0.001 | ||
self.rounding = 0.001 | ||
to_unit.rounding = 0.001 | ||
|
||
|
||
if not self or not price or not to_unit or self == to_unit: | ||
return price | ||
if self.category_id.id != to_unit.category_id.id: | ||
return price | ||
|
||
|
||
amount = price * self.factor | ||
if to_unit: | ||
amount = amount / to_unit.factor | ||
return amount |
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,16 +1,128 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<template id="report_mrp_bom_line_inherit" inherit_id="mrp.report_mrp_bom_line"> | ||
<xpath expr="//td[@name='td_mrp_bom']" position="after"> | ||
<xpath expr="//t[@t-as='l']/tr/td[6]" position="after"> | ||
<td class="text-right"> | ||
<span t-esc="round(l['prod_qty'] * l['prod_cost'], 4)"/> | ||
<span t-if="data['report_structure'] != 'bom_structure'"> | ||
<t t-if="currency.position == 'before'"> | ||
<t t-esc="currency.symbol" /> | ||
<t t-esc="'{:.4f}'.format(round(l['prod_qty'] * l['prod_cost'], 4)).replace('.', ',')" /> | ||
</t> | ||
<t t-else=""> | ||
<t t-esc="'{:.4f}'.format(round(l['prod_qty'] * l['prod_cost'], 4)).replace('.', ',')" /> | ||
<t t-esc="currency.symbol" /> | ||
</t> | ||
</span> | ||
</td> | ||
</xpath> | ||
|
||
<xpath expr="//t[@t-as='l']/tr/td[3]" position="replace"> | ||
<td class="text-right"> | ||
<span t-if="data['report_structure'] != 'bom_structure'"> | ||
<t t-esc="'{:.4f}'.format(round(l['prod_qty'], 4)).replace('.', ',')" /> | ||
</span> | ||
</td> | ||
</xpath> | ||
|
||
<xpath expr="//t[@t-as='l']/tr/td[5]" position="replace"> | ||
<td class="text-right"> | ||
<span t-if="data['report_structure'] != 'bom_structure'"> | ||
<t t-if="currency.position == 'before'"> | ||
<t t-esc="currency.symbol" /> | ||
<t t-esc="'{:.4f}'.format(round(l['prod_cost'], 4)).replace('.', ',')" /> | ||
</t> | ||
<t t-else=""> | ||
<t t-esc="'{:.4f}'.format(round(l['prod_cost'], 4)).replace('.', ',')" /> | ||
<t t-esc="currency.symbol" /> | ||
</t> | ||
</span> | ||
</td> | ||
</xpath> | ||
|
||
<xpath expr="//t[@t-as='l']/tr/td[6]" position="replace"> | ||
<td class="text-right"> | ||
<span t-if="data['report_structure'] != 'bom_structure'"> | ||
<t t-if="currency.position == 'before'"> | ||
<t t-esc="currency.symbol" /> | ||
<t t-esc="'{:.4f}'.format(round(l['total'], 4)).replace('.', ',')" /> | ||
</t> | ||
<t t-else=""> | ||
<t t-esc="'{:.4f}'.format(round(l['total'], 4)).replace('.', ',')" /> | ||
<t t-esc="currency.symbol" /> | ||
</t> | ||
</span> | ||
</td> | ||
</xpath> | ||
</template> | ||
|
||
<template id="report_mrp_bom_inherit" inherit_id="mrp.report_mrp_bom"> | ||
<xpath expr="//thead/tr/th[3]" position="before"> | ||
<th class="text-right">Prod Qty * Prod Price</th> | ||
<xpath expr="//thead/tr/th[6]" position="after"> | ||
<th t-if="data['report_structure'] != 'bom_structure'" class="text-right">Prod Qty * Prod Price</th> | ||
</xpath> | ||
|
||
<xpath expr="//tfoot/tr/td[5]" position="replace"> | ||
<td class="o_mrp_prod_cost text-right"> | ||
<span t-if="data['report_structure'] != 'bom_structure'"> | ||
<t t-if="currency.position == 'before'"> | ||
<t t-esc="currency.symbol" /> | ||
<t t-esc="'{:.4f}'.format(round(data['price']/data['bom_qty'], 4)).replace('.', ',')" /> | ||
</t> | ||
<t t-else=""> | ||
<t t-esc="'{:.4f}'.format(round(data['price']/data['bom_qty'], 4)).replace('.', ',')" /> | ||
<t t-esc="currency.symbol" /> | ||
</t> | ||
</span> | ||
</td> | ||
</xpath> | ||
|
||
<xpath expr="//tfoot/tr/td[6]" position="replace"> | ||
<td class="o_mrp_prod_cost text-right"> | ||
<span t-if="data['report_structure'] != 'bom_structure'"> | ||
<t t-if="currency.position == 'before'"> | ||
<t t-esc="currency.symbol" /> | ||
<t t-esc="'{:.4f}'.format(round(data['total']/data['bom_qty'], 4)).replace('.', ',')" /> | ||
</t> | ||
<t t-else=""> | ||
<t t-esc="'{:.4f}'.format(round(data['total']/data['bom_qty'], 4)).replace('.', ',')" /> | ||
<t t-esc="currency.symbol" /> | ||
</t> | ||
</span> | ||
</td> | ||
</xpath> | ||
|
||
<xpath expr="//tbody/tr/td[3]/span" position="replace"> | ||
<span t-if="data['report_structure'] != 'bom_structure'"> | ||
<t t-esc="'{:.4f}'.format(round(data['bom_qty'], 4)).replace('.', ',')" /> | ||
</span> | ||
</xpath> | ||
|
||
<xpath expr="//tbody/tr/td[5]" position="replace"> | ||
<td class="o_mrp_prod_cost text-right"> | ||
<span t-if="data['report_structure'] != 'bom_structure'"> | ||
<t t-if="currency.position == 'before'"> | ||
<t t-esc="currency.symbol" /> | ||
<t t-esc="'{:.4f}'.format(round(data['price'], 4)).replace('.', ',')" /> | ||
</t> | ||
<t t-else=""> | ||
<t t-esc="'{:.4f}'.format(round(data['price'], 4)).replace('.', ',')" /> | ||
<t t-esc="currency.symbol" /> | ||
</t> | ||
</span> | ||
</td> | ||
</xpath> | ||
|
||
<xpath expr="//tbody/tr/td[6]" position="replace"> | ||
<td class="o_mrp_bom_cost text-right"> | ||
<span t-if="data['report_structure'] != 'bom_structure'"> | ||
<t t-if="currency.position == 'before'"> | ||
<t t-esc="currency.symbol" /> | ||
<t t-esc="'{:.4f}'.format(round(data['total'], 4)).replace('.', ',')" /> | ||
</t> | ||
<t t-else=""> | ||
<t t-esc="'{:.4f}'.format(round(data['total'], 4)).replace('.', ',')" /> | ||
<t t-esc="currency.symbol" /> | ||
</t> | ||
</span> | ||
</td> | ||
</xpath> | ||
</template> | ||
</odoo> |