-
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] mrp_bom_line_product_brand_info: Improve code
- Loading branch information
1 parent
8845cfc
commit 3817dc6
Showing
4 changed files
with
43 additions
and
39 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,46 +1,33 @@ | ||
# Copyright 2024 Alfredo de la Fuente - AvanzOSC | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
from odoo import fields, models | ||
|
||
|
||
class MrpBomLine(models.Model): | ||
_inherit = "mrp.bom.line" | ||
|
||
manufacturer_codes = fields.Text( | ||
string="Manufacturer codes", compute="_compute_product_brand_info" | ||
) | ||
markings = fields.Text(compute="_compute_product_brand_info") | ||
|
||
def _compute_product_brand_info(self): | ||
for line in self.filtered(lambda c: c.product_tmpl_id): | ||
texto = "" | ||
markings = "" | ||
for seller in line.product_tmpl_id.seller_ids: | ||
partner_name = seller.partner_id.name | ||
code = ( | ||
"" | ||
if not seller.product_brand_id.code | ||
else seller.product_brand_id.code | ||
) | ||
marking = ( | ||
"" | ||
if not seller.product_brand_id.marking | ||
else seller.product_brand_id.marking | ||
) | ||
if not texto: | ||
texto = "{}: {} - {}".format(partner_name, code, marking) | ||
else: | ||
texto = "{} // {}: {} - {}".format( | ||
texto, partner_name, code, marking | ||
) | ||
if not markings: | ||
markings = "{}: {}".format(partner_name, marking) | ||
for idx, seller in enumerate( | ||
line.product_tmpl_id.seller_ids.filtered(lambda s: s.product_brand_id) | ||
): | ||
marking = seller.product_brand_id | ||
brand_code = seller.brand_code | ||
|
||
if brand_code: | ||
marking_info = "[{}] {}".format(brand_code, marking.name) | ||
else: | ||
markings = "{} // {}: {}".format(markings, partner_name, marking) | ||
line.manufacturer_codes = texto | ||
marking_info = "{}".format(marking.name) | ||
|
||
if idx > 0: | ||
markings += "\n" | ||
|
||
markings += marking_info | ||
|
||
line.markings = markings | ||
|
||
def get_datas_to_print_bom(self): | ||
result = super().get_datas_to_print_bom() | ||
result["manufacturer_codes"] = self.manufacturer_codes | ||
result["markings"] = self.markings | ||
return result |
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,14 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<template | ||
<template | ||
id="report_mrp_bom_customized_document" | ||
inherit_id="mrp_bom_report.report_mrp_bom_customized_document" | ||
> | ||
<span id="product_name" position="after"> | ||
<span t-if="line['manufacturer_codes']"> | ||
<br /> | ||
<span t-esc="line['manufacturer_codes']" /> | ||
</span> | ||
</span> | ||
</template> | ||
<!-- <span id="product_name" position="after"> | ||
<span t-if="line and 'manufacturer_codes' in line and line['manufacturer_codes']"> | ||
<br /> | ||
<span t-esc="line['manufacturer_codes']" /> | ||
</span> | ||
</span> --> | ||
<xpath expr="//table/thead/tr" position="inside"> | ||
<!-- <th class="text-start">Product Code</th> --> | ||
<th class="text-start">Brand</th> | ||
</xpath> | ||
<xpath expr="//table/tbody//tr" position="inside"> | ||
<!-- <td class="text-start"> | ||
<span | ||
t-esc="bom_line_id['product_code'] or ''" | ||
/> | ||
</td> --> | ||
<td class="text-start"> | ||
<t t-if="bom_line_id['markings']"> | ||
<t t-foreach="bom_line_id['markings'].split('\n')" t-as="split_line"> | ||
<span t-esc="split_line" /> <br /> | ||
</t> | ||
</t> | ||
</td> | ||
|
||
</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
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