diff --git a/plm_box/models/ir_attachment.py b/plm_box/models/ir_attachment.py index db6f5dba..536ca1f1 100755 --- a/plm_box/models/ir_attachment.py +++ b/plm_box/models/ir_attachment.py @@ -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: diff --git a/plm_box/models/plm_box.py b/plm_box/models/plm_box.py index ef8f03d1..475f27b0 100755 --- a/plm_box/models/plm_box.py +++ b/plm_box/models/plm_box.py @@ -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( { @@ -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): """ @@ -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()