Skip to content

Commit

Permalink
IMP: add new widget to bom
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Jan 27, 2025
1 parent eb8d14b commit 19ba1d1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 54 deletions.
2 changes: 1 addition & 1 deletion plm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
##############################################################################
{
"name": "Product Lifecycle Management",
"version": "18.0.2.0.0",
"version": "18.0.3.0.0",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand Down
4 changes: 1 addition & 3 deletions plm/models/mrp_bom_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def openRelatedBoms(self):
domain.append(('type', 'in', ['normal','subcontract', 'phantom']))
out_act_dict['view_ids'] = [
(5, 0, 0),
(0, 0, {'view_mode': 'list', 'view_id': self.env.ref('plm.plm_bom_tree_view').id}),
(0, 0, {'view_mode': 'list', 'view_id': self.env.ref('plm.plm_bom_list_view').id}),
(0, 0, {'view_mode': 'form', 'view_id': self.env.ref('plm.plm_bom_form_view').id})
]
elif line_brws.type == 'spbom':
Expand Down Expand Up @@ -222,8 +222,6 @@ def _related_doc_ids(self):

product_tag_ids = fields.Many2many(related='product_tmpl_id.product_tag_ids')

product_tumbnail = fields.Image(related="product_id.product_tmpl_id.image_1920")

def go_to_product(self):
return {'name': _('Product'),
'res_model': 'product.product',
Expand Down
2 changes: 1 addition & 1 deletion plm/models/plm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ def attachmentCheckOut(self,
return brwItem.checkout(hostName=hostName,
hostPws=hostPws,
showError=showError)
return True, ''
return True, ''

10 changes: 8 additions & 2 deletions plm/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ class ProductTemplate(models.Model):
compute=lambda self: self._compute_eng_code_editable()
)
kit_bom = fields.Boolean(_('KIT Bom Type'))

linkeddocuments = fields.Many2many(related="product_variant_id.linkeddocuments")

def action_open_linked_field(self, related_field):
return self.product_variant_id.action_open_linked_field(related_field)

def unlinkCheckBomRelations(self):

def print_where_struct(self, where_struct):
Expand Down Expand Up @@ -207,15 +212,16 @@ def init(self):
""")

def getSequenceFrom(self, prefix, digit, start_number= 0):
plm_prefix = "PLM_SEQUENCE_%s" % prefix
plm_prefix = f"PLM_SEQUENCE_{prefix}"
sequence=None
for sequence in self.env['ir.sequence'].sudo().search([('code','=', plm_prefix)]):
break
return sequence.next_by_id()
if not sequence:
sequence = self.env['ir.sequence'].sudo().create({
'name': "Plm Autocreate sequence %s " % prefix,
'name': f"Plm Autocreate sequence {prefix} ",
'code': plm_prefix,
'prefix':prefix,
'number_increment':1,
'number_next_actual':start_number,
'padding': digit
Expand Down
2 changes: 1 addition & 1 deletion plm/static/src/js/many2one_widget/many2one_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class PlmMany2oneWidget extends Many2OneField {
});
if (this.props && this.props.record && this.props.record.data && this.props.record.data[this.props.name] && this.props.record.data[this.props.name].length != 0) {


let imageData = await this.env.model.orm.call(this.relation, "search_read", [], {
domain: [["id", "=", this.props.record.data[this.props.name][0]]],
fields: [this.props.options.image_field],
Expand Down
67 changes: 21 additions & 46 deletions plm/views/mrp_extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<field name="model">mrp.bom.line</field>
<field name="arch" type="xml">
<list>
<field name="product_tumbnail" widget="image" options="{ 'size': [60, 60]}"/>
<field name="product_id"/>
<field name="product_id"
widget="plm_many2one_image"
options="{'image_field':'image_1920','linked_field':'linkeddocuments'}"/>
<button name="go_to_product"
icon="fa-external-link"
type="object"
Expand Down Expand Up @@ -44,9 +45,11 @@
<field name="inherit_id" ref="mrp.mrp_bom_line_view_form"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="product_id" position="before">
<field name="product_id" position="replace">
<field name="itemnum"/>
<field name="product_tumbnail" widget="image" options="{ 'size': [60, 60]}"/>
<field name="product_id"
widget="plm_many2one_image"
options="{'image_field':'image_1920','linked_field':'linkeddocuments'}"/>
</field>
<field name="product_id" position="after">
<field name="engineering_revision" readonly="True"/>
Expand All @@ -70,18 +73,13 @@
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_tree_view"/>
<field name="arch" type="xml">
<field name="product_tmpl_id" position="before">
<field name="att_count" column_invisible="1" />
<button
name="open_attachments"
type="object"
string=""
icon="fa-folder-open"
class="float-right"
invisible="att_count in [False,0]"/>
</field>
<field name="product_id" position="after">
<field name="product_id" widget="many2one"/>
<field name="product_tmpl_id" position="replace">
<field name="product_tmpl_id"
widget="plm_many2one_image"
options="{'image_field':'image_1920','linked_field':'linkeddocuments'}"/>
</field>
<field name="product_id" position="replace">
<field name="product_id" widget="many2one"/>
<field name="code"/>
<field name="source_id" string="Source Relation"/>
<field name="description" select="True"/>
Expand Down Expand Up @@ -125,23 +123,9 @@
</button>
</div>
<field name="product_tmpl_id" position="replace">
<label for="product_tmpl_id"/>
<div class="o_row no-gutters d-flex">
<field name="product_tmpl_id"
context="{'default_type': 'product'}"
options="{'no_open':True,'no_create':True}"
class="oe_inline text-left"
colspan="2"/>
<field name="att_count" invisible="True"/>
<button
name="open_attachments"
type="object"
aria-label="Product Attachments"
title="Open Attachment"
icon="fa-folder-open"
class="float-right"
invisible="att_count in [False,0]"/>
</div>
<field name="product_tmpl_id"
widget="plm_many2one_image"
options="{'image_field':'image_1920','linked_field':'linkeddocuments'}"/>
</field>
<field name="code" position="replace">
<field name="code" colspan="2"/>
Expand All @@ -163,24 +147,18 @@
<attribute name="decoration-warning">engineering_state == 'undermodify'</attribute>
<attribute name="decoration-muted">engineering_state == 'obsoleted'</attribute>
</xpath>
<xpath expr="//field[@name='bom_line_ids']/list/field[@name='product_id']" position="before">
<xpath expr="//field[@name='bom_line_ids']/list/field[@name='product_id']" position="replace">
<field name="related_bom_ids" column_invisible="1" />
<field name="hasChildBoms" column_invisible="1" />
<field name="product_tumbnail" widget="image" options="{ 'size': [60, 60]}"/>
<button name="openRelatedBoms"
type="object"
icon="fa-level-down"
title="Open Related Boms"
class="btn btn-sm oe_stat_button"
invisible="hasChildBoms==False"/>
<field name="related_document_ids" column_invisible="1"/>
<button
name="openRelatedDocuments"
type="object"
icon="fa-box-open"
title="Open related document"
class="float-right btn"
invisible="related_document_ids == []"/>
<field name="product_id"
widget="plm_many2one_image"
options="{'image_field':'image_1920','linked_field':'linkeddocuments'}"/>
</xpath>
<xpath expr="//field[@name='bom_line_ids']/list/field[@name='product_id']" position="after">
<field name="description" readonly="True"/>
Expand All @@ -193,9 +171,6 @@
'list_view_ref':'plm.ir_attachment_list',
'form_view_ref':'plm.view_attachment_form_plm_hinerit'}"/>
</xpath>
<xpath expr="//field[@name='bom_line_ids']/list/field[@name='product_id']" position="attributes">
<attribute name="widget">many2one</attribute>
</xpath>
<xpath expr="//field[@name='bom_line_ids']/list/field[@name='product_uom_id']" position="after">
<field name="itemnum"/>
<field name="itemlbl" optional="hide"/>
Expand Down

0 comments on commit 19ba1d1

Please sign in to comment.