Skip to content

Commit

Permalink
[MOD] plm_box
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Dec 18, 2024
1 parent c65cfeb commit 5abc8a3
Showing 1 changed file with 49 additions and 32 deletions.
81 changes: 49 additions & 32 deletions plm_box/models/plm_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@


def correctDate(fromTimeStr, context):
serverUtcTime = parser.parse(fromTimeStr.strftime(DEFAULT_SERVER_DATETIME_FORMAT))

if isinstance(fromTimeStr, str):
serverUtcTime = parser.parse(fromTimeStr)
else:
serverUtcTime = fromTimeStr

utcDate = serverUtcTime.replace(tzinfo=pytz.utc).astimezone(
pytz.timezone(context.get("tz", "Europe/Rome"))
)
Expand All @@ -53,6 +58,7 @@ class Plm_box(models.Model):
_name = "plm.box"
_description = "Model to manage a box inside the plm module"
_inherit = "revision.plm.mixin"
_rec_name = "engineering_code"


box_id = fields.Integer(_("Box ID"))
Expand Down Expand Up @@ -375,27 +381,6 @@ def getBoxes(self, boxes={}):
outBoxDict[plm_box_id.engineering_code]["boxPrimary"] = boxPrimary
return outBoxDict

@api.model
def getDocDictValues(self, docBrws):
getCheckOutUser = ""
plmDocObj = self.env.get("ir.attachment")
docState = plmDocObj.getDocumentState({"docName": docBrws.name})
if docState in ["check-out", "check-out-by-me"]:
getCheckOutUser = docBrws.getCheckOutUser()
writeVal = datetime.datetime.strptime(
docBrws.write_date, DEFAULT_SERVER_DATETIME_FORMAT
)
return {
"engineering_revision": docBrws.engineering_revision,
"datas_fname": docBrws.name,
"create_date": docBrws.create_date,
"write_date": correctDate(writeVal, self.env.context),
"description": docBrws.description,
"fileName": docBrws.name,
"state": docBrws.engineering_state,
"readonly": self.docReadonlyCompute(docBrws.id),
"checkoutUser": getCheckOutUser,
}

@api.model
def getDocs(self, docsToUpdate=[]):
Expand Down Expand Up @@ -670,12 +655,14 @@ def getBoxesStructureFromServer(self, primaryBoxes, parameters, kwargs):
notFoundBoxes = []
if not primaryBoxes:
return (outDict, notFoundBoxes)
for boxName in primaryBoxes:
plm_box_id = self.search([("engineering_code", "=", boxName)])
for id in primaryBoxes:
plm_box_id = self.search([("id", "=", id)])
boxName = plm_box_id[0].engineering_code
if plm_box_id:
outDict[boxName] = plm_box_id[0].getBoxStructure(True)
else:
notFoundBoxes.append(boxName)

return (outDict, notFoundBoxes)

def getBoxStructure(self, primary=False):
Expand All @@ -684,6 +671,8 @@ def getBoxStructure(self, primary=False):
Used in the client in "Add" button procedure
"""
outDict = {
"headers" : {'name': 'Name','description': 'Description','state': 'State'},
'id':0,
"children": {},
"documents": {},
"entities": [],
Expand All @@ -693,19 +682,47 @@ def getBoxStructure(self, primary=False):
"primary": primary,
}
for boxBrws in self:
outDict['id'] = boxBrws.id
for boxChildBrws in boxBrws.plm_box_rel:
outDict["children"][
boxChildBrws.engineering_code
] = boxChildBrws.getBoxStructure(primary)
for docBrws in boxBrws.document_rel:
outDict["documents"][docBrws.engineering_code] = self.getDocDictValues(
docBrws
)
outDict["children"][boxChildBrws.engineering_code] = boxChildBrws.getBoxStructure(primary)
for docBrws in boxBrws.document_rel.filtered(lambda e_code: e_code.engineering_code):
outDict["documents"][docBrws.engineering_code] = self.getDocDictValues(docBrws)

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

return outDict

@api.model
def getDocDictValues(self, docBrws):
getCheckOutUser = ""
plmDocObj = self.env.get("ir.attachment")

docState = plmDocObj.getDocumentState({"docName": docBrws.name})
if docState in ["check-out", "check-out-by-me"]:
getCheckOutUser = docBrws.getCheckOutUser()
writeVal = docBrws.write_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)

return {
"engineering_revision": docBrws.engineering_revision,
"datas_fname": docBrws.name,
"create_date": docBrws.create_date,
"write_date": correctDate(writeVal, self.env.context),
"description": docBrws.description,
"fileName": docBrws.name,
"state": docBrws.engineering_state,
"readonly": self.docReadonlyCompute(docBrws.id),
"checkoutUser": getCheckOutUser,
}

@api.model
def verifyBoxesPermissions(self, box_ids):
to_del = []
available_boxes = self.getAvaiableBoxIds()
for box_id in box_ids:
if box_id not in available_boxes:
to_del.append(box_id)
return to_del

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

0 comments on commit 5abc8a3

Please sign in to comment.