Skip to content

Commit

Permalink
Merge pull request #81 from archeti-org/14.0-fix_plm
Browse files Browse the repository at this point in the history
fix issue when duplicating boms (partial backport from 15.0)
  • Loading branch information
OmniaGit authored Jul 19, 2024
2 parents 4fbac06 + c223dcc commit de03b7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
##############################################################################
{
"name": "Product Lifecycle Management",
"version": "14.0.6",
"version": "14.0.7",
"author": "OmniaSolutions",
"website": "https://github.com/OmniaGit/odooplm",
"category": "Manufacturing/Product Lifecycle Management",
Expand Down
24 changes: 14 additions & 10 deletions plm/models/mrp_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _explode_bom(self, bids, check=True, last_rev=False):
output.append([prod_id, inner_ids])
return output


def get_last_comp_id(self, comp_id):
prod_prod_obj = self.env['product.product']
comp_brws = prod_prod_obj.browse(comp_id)
Expand Down Expand Up @@ -367,7 +367,7 @@ def GetWhereUsedSum(self, res_ids):
prt_datas = self._get_pack_datas(rel_datas)
return rel_datas, prt_datas, self._get_pack_rel_datas(rel_datas, prt_datas)


def get_exploded_bom(self, level=0, curr_level=0):
"""
Return a list of all children in a Bom ( level = 0 one level only, level = 1 all levels)
Expand Down Expand Up @@ -601,7 +601,7 @@ def rebase_bom_weight(self):
def read(self, fields=[], load='_classic_read'):
fields = self.plm_sanitize(fields)
return super(MrpBomExtension, self).read(fields=fields, load=load)

def write(self, vals, check=True):
vals = self.plm_sanitize(vals)
ret = super(MrpBomExtension, self).write(vals)
Expand All @@ -616,27 +616,31 @@ def create(self, vals):
ret.rebase_bom_weight()
return ret


def copy(self, default={}):
"""
Return new object copied (removing source_id)
"""
new_bom_brws = super(MrpBomExtension, self).copy(default)
if new_bom_brws:
for bom_line in new_bom_brws.bom_line_ids:
if not bom_line.product_id.product_tmpl_id.engineering_code:
bom_line.sudo().write({'state': 'draft',
'source_id': False,})
continue
late_rev_id_c = self.env['product.product'].GetLatestIds([
(bom_line.product_id.product_tmpl_id.engineering_code,
False,
False)
]) # Get Latest revision of each Part
bom_line.sudo().write({'state': 'draft'})
write_vals = {
'state': 'draft',
'source_id': False,
'name': bom_line.product_id.product_tmpl_id.name,
}
if late_rev_id_c:
write_vals['product_id'] = late_rev_id_c[0]
bom_line.write(write_vals)
bom_line.sudo().write(write_vals)
new_bom_brws.sudo().with_context({'check': False}).write({
'source_id': False,
'name': new_bom_brws.product_tmpl_id.name
Expand Down Expand Up @@ -698,7 +702,7 @@ def recursion(bom_brws_list):
'context': {"group_by": ['bom_id']},
}


def open_related_bom_revisions(self):
bom_ids = self.search([('product_tmpl_id', 'in', self.product_tmpl_id.getAllVersionTemplate().ids)])
return {'name': _('B.O.M.S'),
Expand Down Expand Up @@ -749,7 +753,7 @@ def saveRelationNew(self,
product_tmpl_id = parent_product_product_id.product_tmpl_id.id
ir_attachment_relation.removeChildRelation(parent_ir_attachment_id) # perform default unlink to HiTree, need to perform RfTree also
ir_attachment_relation.removeChildRelation(parent_ir_attachment_id, linkType='RfTree')

mrp_bom_found_id = self.saveRelationNewGetBom(product_tmpl_id, bomType, parent_product_product_id)
if mrp_bom_found_id:
mrp_bom_found_id.delete_child_row(parent_ir_attachment_id)
Expand Down Expand Up @@ -804,11 +808,11 @@ def plm_sanitize(self, vals):
@api.model
def _bom_find_domain(self, product_tmpl=None, product=None, picking_type=None, company_id=False, bom_type=False):
domain = super(MrpBomExtension, self)._bom_find_domain(product_tmpl=product_tmpl,
product=product,
product=product,
picking_type=picking_type,
company_id=company_id,
bom_type=bom_type)
if not bom_type:
available_types = ['engineering', 'spare']
domain = AND([domain, [('type', 'not in', available_types)]])
return domain
return domain

0 comments on commit de03b7d

Please sign in to comment.