Skip to content

Commit

Permalink
IMP: new functionality, and views
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Nov 6, 2024
1 parent 39cd57f commit 303fca3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 44 deletions.
91 changes: 54 additions & 37 deletions plm/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3166,18 +3166,31 @@ def open_related_dbthread(self):
@api.model
def getCloneStructure(self,
args):
json_main_root_attributes, cloneRelatedDocuments = args
def get_clone_info_attr(doc_id):
ir_attachment=self.browse(doc_id)
product_dict={}
for product_product_id in ir_attachment.linkedcomponents:
product_dict={
#
SUPPORT_MAIN_PRODUCT_ATTRIBUTES = [
'CONFIGURATION_NAME',
'CONFIGURATIONS',
'INTEGRATION_FILE_TYPE',
]
#
def getProduct_dict(product_product_id):
return {
'engineering_code': product_product_id.engineering_code,
'engineering_revision': product_product_id.engineering_revision,
'name':product_product_id.name,
'id':product_product_id.id
}
break
json_main_root_attributes, cloneRelatedDocuments = args
#
def get_clone_info_attr(doc_id, product_product_id=None):
ir_attachment=self.browse(doc_id)
if product_product_id:
product_dict=getProduct_dict(product_product_id)
else:
product_dict={}
for product_product_id in ir_attachment.linkedcomponents:
product_dict=getProduct_dict(product_product_id)
break

return {'document':{
'engineering_code': ir_attachment.engineering_code,
Expand All @@ -3188,33 +3201,37 @@ def get_clone_info_attr(doc_id):
},
'product':product_dict
}
#
out = {'MAIN':{},
'RF':[],
'LF':[]}
main_root_attributes = json.loads(json_main_root_attributes)
product_product_id, attachment_id = self._GetproductDocumentID(tuple(main_root_attributes.values()))
#
#
doc_ids_2d=[]
#
main_parent_attrs = get_clone_info_attr(attachment_id.id)
out['MAIN']=main_parent_attrs
#
for doc_id in self.getRelatedRfTree(attachment_id.id):
sub_attrs = get_clone_info_attr(doc_id)
out['RF'].append((main_parent_attrs,
sub_attrs))
for doc_id_2d in self.getRelatedLyTree(doc_id,
optional_return_type=['2d']):
doc_ids_2d.append((sub_attrs, doc_id_2d))
#
for doc_id_2d in self.getRelatedLyTree(attachment_id.id,
optional_return_type=['2d']):
doc_ids_2d.append((main_parent_attrs, doc_id_2d))
#
for parent_attrs, doc_id in doc_ids_2d:
out['LF'].append((parent_attrs,
get_clone_info_attr(doc_id)))
if attachment_id:
#
doc_ids_2d=[]
#
main_parent_attrs = get_clone_info_attr(attachment_id.id, product_product_id)
out['MAIN']=main_parent_attrs
for k in SUPPORT_MAIN_PRODUCT_ATTRIBUTES:
out['MAIN']['product'][k]=main_root_attributes.get('product',{}).get(k,'')
#
for doc_id in self.getRelatedRfTree(attachment_id.id):
sub_attrs = get_clone_info_attr(doc_id)
out['RF'].append((main_parent_attrs,
sub_attrs))
for doc_id_2d in self.getRelatedLyTree(doc_id,
optional_return_type=['2d']):
doc_ids_2d.append((sub_attrs, doc_id_2d))
#
for doc_id_2d in self.getRelatedLyTree(attachment_id.id,
optional_return_type=['2d']):
doc_ids_2d.append((main_parent_attrs, doc_id_2d))
#
for parent_attrs, doc_id in doc_ids_2d:
out['LF'].append((parent_attrs,
get_clone_info_attr(doc_id)))
#

return json.dumps(out)
Expand All @@ -3224,24 +3241,24 @@ def GetCloneDocumentValues(self, args):
"""
return the new attributes to be used for cloning the document
"""
old_product_attrs, old_document_attrs, new_product_attrs = args
out_value = json.loads(old_document_attrs)
_old_product_attrs, old_attachment_attrs, new_product_attrs = args
out_attachment_value = json.loads(old_attachment_attrs)
new_product_attrs = json.loads(new_product_attrs)
if hasattr(self, "customGetCloneDocumentValues"):
#
# If you implement the customGetCloneDocumentValues this call will be used to customize the value of the new cloned document from the client clone action
#
out_value=self.customGetCloneDocumentValues(out_value)
out_attachment_value=self.customGetCloneDocumentValues(out_attachment_value)
else:
#
out_value['engineering_code'] = f"{new_product_attrs['engineering_code']}-{self.env['ir.sequence'].next_by_code('ir.attachment.progress')}"
out_value['engineering_revision']=0
out_attachment_value['engineering_code'] = f"{new_product_attrs['engineering_code']}-{self.env['ir.sequence'].next_by_code('ir.attachment.progress')}"
out_attachment_value['engineering_revision']=0
#
_, exte = os.path.splitext(out_value['name'])
out_value['name'] = f"{out_value['engineering_code']}{exte}"
_, exte = os.path.splitext(out_attachment_value['name'])
out_attachment_value['name'] = f"{out_attachment_value['engineering_code']}{exte}"
#
del out_value['id']
del out_attachment_value['id']
#
return json.dumps(out_value)
return json.dumps(out_attachment_value)

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
24 changes: 17 additions & 7 deletions plm/views/mrp_extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
icon="plm/static/description/odoo_icon_small.png"
string="."
class="float-right"
column_invisible="False"
invisible="att_count in [False,0]"/>
</field>
<field name="product_id" position="after">
Expand Down Expand Up @@ -109,8 +110,11 @@
<field name="priority" eval="16"/>
<field name="arch" type="xml">
<div class="oe_button_box" name="button_box" position="inside">
<button name="open_related_bom_lines" type="object" string="Related BOM Lines"
class="oe_stat_button" icon="fa-tasks"/>
<button name="open_related_bom_lines"
type="object"
string="Related BOM Lines"
class="oe_stat_button"
icon="fa-tasks"/>
<button name="open_related_bom_revisions"
type="object"
string="BOM Rev."
Expand Down Expand Up @@ -160,22 +164,28 @@
<attribute name="decoration-muted">engineering_state == 'obsoleted'</attribute>
</xpath>
<xpath expr="//field[@name='bom_line_ids']/tree/field[@name='product_id']" position="before">
<field name="related_bom_ids" invisible="True"/>
<field name="hasChildBoms" invisible="True"/>
<field name="related_bom_ids"
column_invisible="True"
invisible="True"/>
<field name="hasChildBoms"
column_invisible="True"
invisible="True"/>
<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" invisible="True"/>
<field name="related_document_ids"
column_invisible="True"
invisible="True"/>
<button
name="openRelatedDocuments"
type="object"
icon="plm/static/description/odoo_icon_small.png"
string="."
class="float-right btn"
title="Open Related Documents"
class="btn btn-sm oe_stat_button"
invisible="related_document_ids == []"/>
</xpath>
<xpath expr="//field[@name='bom_line_ids']/tree/field[@name='product_id']" position="after">
Expand Down

0 comments on commit 303fca3

Please sign in to comment.