Skip to content

Commit

Permalink
[MOD] update plm_box
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Dec 18, 2024
1 parent 5abc8a3 commit 431b319
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
34 changes: 34 additions & 0 deletions plm_box/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,38 @@ def getDocumentState(self, vals):
return "check-in"
return "check-out-by-me"

@api.model
def checkDocumentPresent(self, doc_dict={}):
for str_box_id, vals in doc_dict.items():
box_id = int(str_box_id)
box_brws = self.env['plm.box'].browse(box_id)
for str_doc_id, doc_vals in vals.items():
doc_id = int(str_doc_id)
for doc_brws in self.search([('id', '=', doc_id)]):
checksum = doc_vals.get('checksum', '')
doc_dict[str_box_id][str_doc_id]['check_mode'] = doc_brws.getDocumentState()
if doc_id in box_brws.document_rel.ids:
if not checksum:
doc_dict[str_box_id][str_doc_id]['update'] = 'download'
elif doc_brws.checksum != checksum:
doc_condition = doc_brws.getDocumentState()
if doc_condition == 'check-out-by-me':
doc_dict[str_box_id][str_doc_id]['update'] = 'upload'
else:
doc_dict[str_box_id][str_doc_id]['update'] = 'download'
else:
doc_dict[str_box_id][str_doc_id]['update'] = 'none'
else:
cad_opens = self.env['plm.cad.open'].search([
('document_id', '=', doc_id)
])
if len(cad_opens.ids) > 1:
doc_dict[str_box_id][str_doc_id]['update'] = 'delete'
elif doc_brws:
doc_dict[str_box_id][str_doc_id]['update'] = 'delete'
else:
doc_dict[str_box_id][str_doc_id]['update'] = 'upload'
logging.info('Box sincronize res %r' % (doc_dict))
return doc_dict

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
19 changes: 17 additions & 2 deletions plm_box/models/plm_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@ def setRelatedDocs(self, parentBrws):
@api.model
def getRelatedEntities(self, parentBrws):
objRelList = []
document_data = dict()
for doc in parentBrws.document_rel:

document_data[str(doc.id)]={
"name": doc.engineering_code or '',
"description": doc.description or '',
"state": doc.engineering_state or '',
"readonly": self.docReadonlyCompute(doc.id),
"write_date": doc.write_date or '',
"revisionid": doc.engineering_revision or '',
"fileName": doc.name or '',
"checkoutUser": doc.checkout_user or False,
}
objRelList.append({'document_rel': document_data})

for product_product_id in parentBrws.product_id:
objRelList.append(
{
Expand Down Expand Up @@ -662,8 +677,7 @@ def getBoxesStructureFromServer(self, primaryBoxes, parameters, kwargs):
outDict[boxName] = plm_box_id[0].getBoxStructure(True)
else:
notFoundBoxes.append(boxName)

return (outDict, notFoundBoxes)
return outDict, notFoundBoxes

def getBoxStructure(self, primary=False):
"""
Expand All @@ -689,6 +703,7 @@ def getBoxStructure(self, primary=False):
outDict["documents"][docBrws.engineering_code] = self.getDocDictValues(docBrws)

outDict["entities"] = self.getRelatedEntities(boxBrws)
outDict["document_rel"] = self.document_rel.ids
outDict["description"] = boxBrws.description
outDict["state"] = boxBrws.engineering_state
outDict["readonly"] = boxBrws.boxReadonlyCompute()
Expand Down

0 comments on commit 431b319

Please sign in to comment.