Skip to content

Commit

Permalink
ADD support for presentation file
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Oct 11, 2023
1 parent 9443d30 commit ccfb83f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
##############################################################################
{
"name": "Product Lifecycle Management",
"version": "16.0.20",
"version": "16.0.21",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand Down
66 changes: 61 additions & 5 deletions plm/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class IrAttachment(models.Model):
document_type = fields.Selection([('other', _('Other')),
('2d', _('2D')),
('3d', _('3D')),
('pr', _('Presentation')),
],
compute='_compute_document_type',
store=True,
Expand Down Expand Up @@ -368,7 +369,44 @@ def getRelatedLyTree(self, doc_id):
elif doc_rel_id.child_id.id==doc_id and doc_rel_id.parent_id.document_type =='3d':
out.append(doc_rel_id.parent_id.id)
return list(set(out))


@api.model
def getRelatedPrTree(self,
root_doc_id,
recursion=False):
out = []
def _getRelatedPrTree(doc_id):
if not doc_id:
logging.warning('Cannot get links from %r document' % (doc_id))
return []
doc_brws = self.browse(doc_id)
doc_type = doc_brws.document_type
to_search = [('link_kind', 'in', ['LyTree']),
'|',
('parent_id', '=', doc_id),
('child_id', '=', doc_id)]
doc_rel_ids = self.env['ir.attachment.relation'].search(to_search)
for doc_rel_id in doc_rel_ids:
good_id = None
if doc_type in ['3d','2d']:
if doc_rel_id.parent_id.id==doc_id and doc_rel_id.child_id.document_type =='pr':
good_id = doc_rel_id.child_id.id
if doc_rel_id.child_id.id==doc_id and doc_rel_id.parent_id.document_type =='pr':
good_id = doc_rel_id.parent_id.id
elif doc_type=='pr':
if doc_rel_id.parent_id.id==doc_id and doc_rel_id.child_id.document_type =='3d':
good_id = doc_rel_id.child_id.id
elif doc_rel_id.child_id.id==doc_id and doc_rel_id.parent_id.document_type =='3d':
good_id = doc_rel_id.parent_id.id
if good_id and good_id not in out:
out.append(good_id)
if recursion:
for recursion_id in _getRelatedPrTree(good_id):
if recursion_id not in out:
out.append(recursion_id)
_getRelatedPrTree(root_doc_id)
return list(set(out))

@api.model
def getRelatedRfTree(self, doc_id, recursion=True, evaluated=[]):
out = []
Expand Down Expand Up @@ -1172,12 +1210,17 @@ def _compute_document_type(self):
configParamObj = self.env['ir.config_parameter'].sudo()
file_exte_2d_param = configParamObj._get_param('file_exte_type_rel_2D')
file_exte_3d_param = configParamObj._get_param('file_exte_type_rel_3D')
file_exte_pr_param = configParamObj._get_param('file_exte_type_rel_PR')

extensions2D = []
extensions3D = []
extensionsPR = []
if file_exte_2d_param:
extensions2D = eval(file_exte_2d_param)
if file_exte_3d_param:
extensions3D = eval(file_exte_3d_param)
if file_exte_pr_param:
extensionsPR = eval(file_exte_pr_param)
for docBrws in self:
try:
fileExtension = docBrws.getFileExtension(docBrws)
Expand All @@ -1186,6 +1229,8 @@ def _compute_document_type(self):
docBrws.document_type = '2d'
elif fileExtension in [x.upper() for x in extensions3D]:
docBrws.document_type = '3d'
elif fileExtension in [x.upper() for x in extensionsPR]:
docBrws.document_type = 'pr'
else:
docBrws.document_type = 'other'
except Exception as ex:
Expand Down Expand Up @@ -1375,19 +1420,29 @@ def CheckAllFiles(self, request, default=None):
return self._data_check_files(outIds, listedFiles, forceFlag, False, hostname, hostpws)

def is2D(self):
self.ensure_one()
for docBrws in self:
if docBrws.document_type.upper() == '2D':
return True
break
return False

def is3D(self):
self.ensure_one()
for docBrws in self:
if docBrws.document_type.upper() == '3D':
return True
break
return False

def isPresentation(self):
self.ensure_one()
for docBrws in self:
if docBrws.document_type.upper() == 'PR':
return True
break
return False

@api.model
def CheckInRecursive(self, request, default=None):
"""
Expand Down Expand Up @@ -1463,9 +1518,10 @@ def GetRelatedDocs(self, default=None, getBrowse=False):
related_documents = []
read_docs = []
for oid in self.ids:
rfTree = self.getRelatedRfTree(oid, recursion=False)
read_docs.extend(rfTree)
read_docs.extend(self.getRelatedRfTree(oid, recursion=False))
read_docs.extend(self.getRelatedLyTree(oid))
read_docs.extend(self.getRelatedPrTree(oid))

#for rfModel in rfTree:
# read_docs.extend(self.getRelatedLyTree(rfModel))
read_docs = list(set(read_docs))
Expand Down Expand Up @@ -2610,7 +2666,7 @@ def _preCheckInRecursive_all(self,
doc_2d_ids=self.env[self._name]
doc_3d_ids=self.env[self._name]
#
for doc_id in self.browse(list(set(self.getRelatedLyTree(root_id.id)))):
for doc_id in self.browse(list(set(self.getRelatedLyTree(root_id.id)+self.getRelatedPrTree(root_id.id,recursion=True)))):
if doc_id.is3D():
doc_3d_ids+=doc_id
else:
Expand Down Expand Up @@ -2638,7 +2694,7 @@ def _preCheckInRecursive_all(self,
PLM_DT_DELTA,
is_root = s_doc_id.id==root_id.id)
if out_status =='to_check':
if data_info['document_type']=='2D':
if data_info['document_type'] in ['2D','PR']:
out['to_check_2d'].append(data_info)
elif data_info['document_type']=='3D':
out['to_check_3d'].append(data_info)
Expand Down
5 changes: 5 additions & 0 deletions plm/views/ir_config_parameter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
'.psm']</field>
</record>

<record id="file_exte_type_rel_PR" model="ir.config_parameter">
<field name="key">file_exte_type_rel_PR</field>
<field name="value">['.ipn']</field>
</record>

<record id="report_indentation_key" model="ir.config_parameter">
<field name="key">REPORT_INDENTATION_KEY</field>
<field name="value">- </field>
Expand Down

0 comments on commit ccfb83f

Please sign in to comment.