From c975dc3a78d2a4c48feb7b9ca7749b8f92f1619d Mon Sep 17 00:00:00 2001 From: Matteo Boscolo Date: Thu, 6 Mar 2025 11:06:09 +0100 Subject: [PATCH] IMP: missing commit --- plm/migrations/__init__.py | 0 plm/models/ir_attachment.py | 60 ++++++++++++++++++-------------- plm/models/plm_mixin.py | 23 ++++++++---- plm/views/ir_attachment_view.xml | 3 -- 4 files changed, 49 insertions(+), 37 deletions(-) create mode 100644 plm/migrations/__init__.py diff --git a/plm/migrations/__init__.py b/plm/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/plm/models/ir_attachment.py b/plm/models/ir_attachment.py index 6eb3ae31..4808fd8c 100755 --- a/plm/models/ir_attachment.py +++ b/plm/models/ir_attachment.py @@ -1761,9 +1761,9 @@ def saveStructure(self, arguments): documentAttribute = objStructure.get('DOCUMENT_ATTRIBUTES', {}) if documentAttribute: - for brwItem in self.search([('engineering_code', '=', documentAttribute.get('engineering_code', '')), + for pp_id in self.search([('engineering_code', '=', documentAttribute.get('engineering_code', '')), ('engineering_revision', '=', documentAttribute.get('engineering_revision', -1))]): - brwItem.canBeSaved(raiseError=True) + pp_id.canBeSaved(raiseError=True) def populateStructure(parentItem=False, structure={}, parentCreateBOM=True): documentId = False @@ -1819,18 +1819,18 @@ def populateStructure(parentItem=False, structure={}, parentCreateBOM=True): documentAttribute['TO_UPDATE'] = False skipCheckOut = documentAttribute.get('SKIP_CHECKOUT', False) docBrws = False - for brwItem in self.search([('engineering_code', '=', documentAttribute.get('engineering_code')), + for pp_id in self.search([('engineering_code', '=', documentAttribute.get('engineering_code')), ('engineering_revision', '=', documentAttribute.get('engineering_revision'))]): - if brwItem.id in alreadyEvaluated: - docBrws = brwItem # To skip creation + if pp_id.id in alreadyEvaluated: + docBrws = pp_id # To skip creation documentAttribute[ 'TO_UPDATE'] = False # To skip same document preview/pdf uploading by the client break - if brwItem.engineering_state not in [RELEASED_STATUS, OBSOLATED_STATUS]: - if brwItem.needUpdate(): - brwItem.write(documentAttribute) + if pp_id.engineering_state not in [RELEASED_STATUS, OBSOLATED_STATUS]: + if pp_id.needUpdate(): + pp_id.write(documentAttribute) documentAttribute['TO_UPDATE'] = True - docBrws = brwItem + docBrws = pp_id alreadyEvaluated.append(docBrws.id) if not docBrws: docBrws = self.create(documentAttribute) @@ -1850,35 +1850,35 @@ def populateStructure(parentItem=False, structure={}, parentCreateBOM=True): # Save product - document relation logging.info("Saving Product") productsEvaluated = [] - productTemplate = self.env['product.product'] + product_product = self.env['product.product'] for refId, productAttribute in list(productAttributes.items()): try: linkedDocuments = set() for refDocId in productDocumentRelations.get(refId, []): linkedDocuments.add((4, documentAttributes[refDocId].get('id', 0))) - prodBrws = False - for brwItem in productTemplate.search( + product_product_id = False + for pp_id in product_product.search( [('engineering_code', '=', productAttribute.get('engineering_code')), ('engineering_revision', '=', productAttribute.get('engineering_revision'))]): - if brwItem.id in productsEvaluated: - prodBrws = brwItem + if pp_id.id in productsEvaluated: + product_product_id = pp_id break - if brwItem.engineering_state not in [RELEASED_STATUS, OBSOLATED_STATUS]: - brwItem.write(productAttribute) - prodBrws = brwItem - productsEvaluated.append(brwItem.id) + if pp_id.engineering_state not in [RELEASED_STATUS, OBSOLATED_STATUS]: + pp_id.write(productAttribute) + product_product_id = pp_id + productsEvaluated.append(pp_id.id) break - if not prodBrws: + if not product_product_id: if not productAttribute.get('name', False): productAttribute['name'] = productAttribute.get('engineering_code', False) if not productAttribute.get('engineering_code', False): # I could have a document without component, so not create product continue - prodBrws = productTemplate.create(productAttribute) - productsEvaluated.append(prodBrws.id) + product_product_id = product_product.create(productAttribute) + productsEvaluated.append(product_product_id.id) if linkedDocuments: - prodBrws.write({'linkeddocuments': list(linkedDocuments)}) - productAttribute['id'] = prodBrws.id + product_product_id.write({'linkeddocuments': list(linkedDocuments)}) + productAttribute['id'] = product_product_id.id except Exception as ex: logging.error(ex) raise ex @@ -1926,7 +1926,7 @@ def populateStructure(parentItem=False, structure={}, parentCreateBOM=True): for parentId, childRelations in list(productRelations.items()): try: trueParentId = productAttributes[parentId].get('id') - brwProduct = productTemplate.search([('id', '=', trueParentId)]) + brwProduct = product_product.search([('id', '=', trueParentId)]) productTempId = brwProduct.product_tmpl_id.id brwBoml = mrpBomTemplate.search([('product_tmpl_id', '=', productTempId)]) if not brwBoml: @@ -3270,17 +3270,23 @@ def GetCloneDocumentValues(self, args): """ return the new attributes to be used for cloning the document """ - _old_product_attrs, old_attachment_attrs, new_product_attrs = args + 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_attachment_value=self.customGetCloneDocumentValues(out_attachment_value) + out_attachment_value=self.customGetCloneDocumentValues(out_attachment_value, + json.loads(old_product_attrs), + new_product_attrs) else: # - out_attachment_value['engineering_code'] = f"{new_product_attrs['engineering_code']}-{self.env['ir.sequence'].next_by_code('ir.attachment.progress')}" + engineering_code = new_product_attrs.get('engineering_code','') + if engineering_code: + out_attachment_value['engineering_code'] = f"{engineering_code}-{self.env['ir.sequence'].next_by_code('ir.attachment.progress')}" + else: + out_attachment_value['engineering_code'] = f"{self.env['ir.sequence'].next_by_code('ir.attachment.progress')}" out_attachment_value['engineering_revision']=0 # _, exte = os.path.splitext(out_attachment_value['name']) diff --git a/plm/models/plm_mixin.py b/plm/models/plm_mixin.py index b86fbba5..533b7f96 100644 --- a/plm/models/plm_mixin.py +++ b/plm/models/plm_mixin.py @@ -453,12 +453,21 @@ def get_all_translation(self, object_id, fields): get all field translated in all available languages """ out = {} - obj = self.env[self._name].browse([object_id]) - for field_name in fields: - for code in self.env['res.lang'].search([('active','=', True)]).mapped("code"): - propKey = f"{field_name}@-@-@{code}" - out[propKey] = getattr(obj.with_context(lang=code), field_name) + obj = self.env[self._name].search([('id','=',object_id)]) + if obj: + for field_name in fields: + for code in self.env['res.lang'].search([('active','=', True)]).mapped("code"): + propKey = f"{field_name}@-@-@{code}" + out[propKey] = getattr(obj.with_context(lang=code), field_name) return out - - \ No newline at end of file + @api.model + def get_possible_status(self): + out=[] + for model_id in self.env['ir.model'].sudo().search([('model','=', self._name)]): + for filed_id in self.env['ir.model.fields'].sudo().search([('model_id','=', model_id.id), + ('name', '=', 'engineering_state')]): + for ir_model_fields_selection in self.env['ir.model.fields.selection'].sudo().search([('field_id','=',filed_id.id)]): + out.append((ir_model_fields_selection.name, + ir_model_fields_selection.value)) + return out diff --git a/plm/views/ir_attachment_view.xml b/plm/views/ir_attachment_view.xml index 1d0a0ea0..039c797f 100755 --- a/plm/views/ir_attachment_view.xml +++ b/plm/views/ir_attachment_view.xml @@ -202,9 +202,6 @@ - - -