Skip to content

Commit

Permalink
[IMP] mrp_bom_line_product_brand_info: Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
unaiberis authored and anajuaristi committed Feb 18, 2025
1 parent 8845cfc commit 3817dc6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
45 changes: 16 additions & 29 deletions mrp_bom_line_product_brand_info/models/mrp_bom_line.py
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
35 changes: 27 additions & 8 deletions mrp_bom_line_product_brand_info/report/mrp_bom_report.xml
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>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<field name="inherit_id" ref="mrp.mrp_bom_line_view_form" />
<field name="arch" type="xml">
<field name="operation_id" position="after">
<field name="manufacturer_codes" readonly="1" />
<field name="markings" readonly="1" />
</field>
</field>
Expand Down
1 change: 0 additions & 1 deletion mrp_bom_line_product_brand_info/views/mrp_bom_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
expr="//field[@name='bom_line_ids']/tree/field[@name='attachments_count']"
position="after"
>
<field name="manufacturer_codes" optional="show" readonly="1" />
<field name="markings" optional="show" readonly="1" />
</xpath>
</field>
Expand Down

0 comments on commit 3817dc6

Please sign in to comment.