From 7b3e1ebd2ec82125cc3509d9e2ca051bb141426f Mon Sep 17 00:00:00 2001 From: Matteo Boscolo Date: Tue, 30 Apr 2024 11:42:21 +0200 Subject: [PATCH] Add new support function --- plm_cutted_parts/models/product_product.py | 85 ---------------------- 1 file changed, 85 deletions(-) diff --git a/plm_cutted_parts/models/product_product.py b/plm_cutted_parts/models/product_product.py index b06e54da..d96268bf 100755 --- a/plm_cutted_parts/models/product_product.py +++ b/plm_cutted_parts/models/product_product.py @@ -47,88 +47,3 @@ def onchange_row_material_x_length(self): def onchange_row_material_y_length(self): if not self.row_material_y_length or self.row_material_y_length == 0.0: raise UserError(_('"Raw Material y length" cannot have zero value.')) - - @api.model - def createCuttedPartsBOM(self, bom_structure): - - def checkCreateProd(odoo_vals): - err = '' - eng_code = odoo_vals.get('engineering_code', '') - eng_rev = odoo_vals.get('engineering_revision', 0) - prod = self.search([('engineering_code', '=', eng_code), - ('engineering_revision', '=', eng_rev), - ], limit=1) - if not prod: - try: - if not odoo_vals.get('name'): - odoo_vals['name'] = odoo_vals.get('engineering_code', '') - prod = self.create(odoo_vals) - except Exception as ex: - err = 'Cannot create product with values %r due to error %r' % (odoo_vals, ex) - else: - prod.write(odoo_vals) - return prod, err - - def checkCreateBOM(prod, bom_vals={}, bomType='normal'): - err = '' - bom_obj = self.env['mrp.bom'] - bom = bom_obj.search([ - ('product_tmpl_id', '=', prod.product_tmpl_id.id), - ('type', '=', bomType) - ]) - if bom: - try: - bom.unlink() - except Exception as ex: - err += 'Cannot create BOM for product %r due to error %r' % (prod, ex) - if not err: - try: - bom_vals['product_tmpl_id'] = prod.product_tmpl_id.id - bom_vals['type'] = bomType - bom = bom_obj.create(bom_vals) - except Exception as ex: - err = 'Cannot create BOM for product %r due to error %r' % (prod, ex) - return bom, err - - def checkCreateBOMLine(parent_bom, vals, child_prod_id, bomType): - bom_line = self.env['mrp.bom.line'] - try: - vals['product_id'] = child_prod_id.id - vals['bom_id'] = parent_bom.id - vals['type'] = bomType - new_line = bom_line.create(vals) - return new_line, '' - except Exception as ex: - return None, 'Cannot create BOM line with values %r, error %r' % (vals, ex) - - def recursion(vals, parent_bom, bomType): - errors = [] - for odoo_vals, children in vals: - bom = None - prod, err = checkCreateProd(odoo_vals.get('product.product', {})) - if err: - errors.append(err) - if children: - bom, err = checkCreateBOM(prod, odoo_vals.get('mrp.bom', {}), bomType) - if err: - errors.append(err) - else: - continue - if parent_bom: - _bom_line, err = checkCreateBOMLine(parent_bom, odoo_vals.get('mrp.bom.line', {}), prod, bomType) - if err: - errors.append(err) - if prod: - childErrors = recursion(children, bom, bomType) - errors.extend(childErrors) - return errors - - domain = [('state', 'in', ['installed', 'to upgrade', 'to remove']), ('name', '=', 'plm_engineering')] - apps = self.env['ir.module.module'].sudo().search_read(domain, ['name']) - bomType = 'normal' - if apps: - bomType = 'ebom' - res = recursion(bom_structure, None, bomType) - for err in res: - logging.info('Error during generating cutted part %s' % (err)) - return res