Skip to content

Commit

Permalink
[MOD] update plm_pdf_workorder
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Jan 22, 2025
1 parent 43cdb7d commit dbc9c9d
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 240 deletions.
3 changes: 3 additions & 0 deletions plm/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class IrAttachment(models.Model):
must_update_from_cad = fields.Boolean("Must Update form CAD",
compute="_compute_must_update_from_cad",
help="""When this flag is enabled the 2d document must be updated in order to guaranteey the update betwin 2d and 3d document""")
preview_related = fields.Image(max_height=1920, max_width=1920,
string=_("Child Parent Preview"))


def _compute_must_update_from_cad(self):
ir_attachment_relation = self.env['ir.attachment.relation']
Expand Down
13 changes: 6 additions & 7 deletions plm/models/ir_attachment_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ class PlmDocumentRelations(models.Model):
default=False,
readonly=True)
notes = fields.Char(string="Notes: ")
preview_related = fields.Image(
compute="_compute_preview_related",
store=True, attachment=False,
max_height=1920, max_width=1920,
string=_("Child Parent Preview")
)
preview_related = fields.Image(compute="_compute_preview_related",
store=True, attachment=False,
max_height=1920, max_width=1920,
string=_("Child Parent Preview"))

_sql_constraints = [
('relation_uniq', 'unique (parent_id,child_id,link_kind)', _('The Document Relation must be unique !')),
Expand All @@ -99,8 +97,9 @@ def _compute_preview_related(self):
for rec in self:
if not rec.child_preview and rec.child_id and rec.link_kind == 'ExtraTree' and rec.parent_id.preview:
rec.preview_related = rec.parent_id.preview
rec.child_id.preview_related = rec.parent_id.preview
else:
rec.preview_related = False
rec.preview_related = rec.preview_related

def copy(self, default=None):
if not default:
Expand Down
43 changes: 20 additions & 23 deletions plm/models/mrp_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def _father_compute(self, name='', arg={}):
if not (bom_line_brws.bom_id.id in result):
result.extend([bom_line_brws.bom_id.id])
bom_obj.father_complete_ids = self.env['mrp.bom'].browse(list(set(result)))

engineering_state = fields.Selection(related="product_id.engineering_state",
string=_("Status"),
help=_("The status of the product in its LifeCycle."),
store=False)

description = fields.Char(related="product_tmpl_id.name",
string=_("Description"),
store=False)
Expand Down Expand Up @@ -99,9 +99,9 @@ def _father_compute(self, name='', arg={}):
store=True)

bom_revision_count = fields.Integer(related='product_tmpl_id.engineering_revision_count')

att_count = fields.Integer(compute='attch_count')

def attch_count(self):
for bom in self:
doc_ids = bom.get_related_attachments()
Expand All @@ -120,7 +120,7 @@ def get_related_attachments(self):
return self.env['ir.attachment']

def open_attachments(self):
out_att = self.get_related_attachments()
out_att = self.get_related_attachments()
return {
'name': _('Attachments'),
'domain': [('id', 'in', out_att.ids)],
Expand All @@ -131,7 +131,7 @@ def open_attachments(self):
(self.env.ref('plm.document_kanban_view').id, 'kanban'),
(self.env.ref('plm.view_attachment_form_plm_hinerit').id, 'form'),
(self.env.ref('plm.ir_attachment_list').id, 'list'),
],
],
'help': _('''<p class="o_view_nocontent_smiling_face">
Upload files to your product
</p><p>
Expand Down Expand Up @@ -319,7 +319,6 @@ 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 @@ -419,7 +418,6 @@ 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 @@ -610,13 +608,14 @@ def clean_empty_boms():
for _bom_id, bom_brws in evaluated_boms.items():
if not bom_brws.bom_line_ids:
bom_brws.unlink()

if len(relations) < 1: # no relation to save
return False

parent_name, _parent_id, _child_name, child_id, _source_id, rel_args = relations[0]
if eco_module_installed is None:
clean_old_eng_bom_lines(relations)
if len(relations) == 1 and not child_id: # Case of not children, so no more BOM for this product
if len(relations) == 1 and not child_id: # Case of not children, so no more BOM for this product
return False
bom_id = to_compute(parent_name, relations, kind_bom)
clean_empty_boms()
Expand Down Expand Up @@ -653,7 +652,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):
vals = self.plm_sanitize(vals)
ret = super(MrpBomExtension, self).write(vals)
Expand All @@ -663,14 +662,13 @@ def write(self, vals):

@api.model_create_multi
def create(self, vals):
to_create=[]
to_create = []
for vals_dict in vals:
to_create.append(self.plm_sanitize(vals_dict))
ret = super().create(to_create)
ret.rebase_bom_weight()
return ret


def copy(self, default={}):
"""
Return new object copied (removing source_id)
Expand All @@ -680,7 +678,7 @@ def copy(self, default={}):
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({'engineering_state': 'draft',
'source_id': False,})
'source_id': False, })
continue
late_rev_id_c = self.env['product.product'].GetLatestIds([
(bom_line.product_id.product_tmpl_id.engineering_code,
Expand Down Expand Up @@ -758,7 +756,7 @@ def recursion(bom_brws_list):
'context': {},
}


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 All @@ -768,10 +766,10 @@ def open_related_bom_revisions(self):
'type': 'ir.actions.act_window',
'domain': [('id', 'in', bom_ids.ids)],
'context': {}}

def saveRelationNewGetBom(self, product_tmpl_id, bomType, parent_product_product_id):
return self._saveRelationNewGetBom(product_tmpl_id, bomType, parent_product_product_id)

def _saveRelationNewGetBom(self, product_tmpl_id, bomType, parent_product_product_id):
prod_template = self.env['product.template'].browse(product_tmpl_id)
if parent_product_product_id.kit_bom:
Expand All @@ -792,18 +790,18 @@ def _saveRelationNewGetBom(self, product_tmpl_id, bomType, parent_product_produc
'product_id': parent_product_product_id.id,
'type': bomType})
return mrp_bom_found_id

def custom_exclude(self, product_product_id, ir_attachment_id, relationAttributes, mrp_bom_found_id):
"""
this function is very importand for customizing the bom line creation
:product_product_id id of product_product
:product_product_id id of product_product
:ir_attachment_id id of ir_attachment
:relationAttributes dixt like with all creation attributes
:mrp_bom_found_id browse(mrp.bom) for the current bom
:mrp_bom_found_id browse(mrp.bom) for the current bom
:return: bool True -> create the bom line False -> jump to next
"""
return False

@api.model
def saveRelationNew(self,
clientArgs):
Expand All @@ -815,7 +813,7 @@ def saveRelationNew(self,
bomType = 'normal'
if apps:
bomType = 'ebom'
parentOdooTuple, childrenOdooTuple = clientArgs
parentOdooTuple, childrenOdooTuple = clientArgs
l_tree_document_id, parent_product_product_id, parent_ir_attachment_id = parentOdooTuple
if not parent_ir_attachment_id:
parent_ir_attachment_id = l_tree_document_id
Expand All @@ -829,7 +827,7 @@ def saveRelationNew(self,
#
# add rows
#
summarize_bom = self.env.context.get('SUMMARIZE_BOM', False)
summarize_bom = self.env.context.get('SUMMARIZE_BOM', False)
cache_row = {}
for product_product_id, ir_attachment_id, relationAttributes in childrenOdooTuple:
if self.custom_exclude(product_product_id, ir_attachment_id, relationAttributes, mrp_bom_found_id):
Expand Down Expand Up @@ -883,4 +881,3 @@ def _bom_find_domain(self, products, picking_type=None, company_id=False, bom_ty
available_types = ['engineering', 'spare']
domain = AND([domain, [('type', 'not in', available_types)]])
return domain

3 changes: 1 addition & 2 deletions plm/report/document_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
<record id="report_ir_attachment_pdf" model="ir.actions.report">
<field name="name">Print Pdf</field>
<field name="model">ir.attachment</field>
<field name="binding_model_id" ref="model_ir_attachment"/>
<field name="binding_model_id" ref="model_ir_attachment"/>
<field name="report_type">qweb-html</field>
<field name="report_name">plm.ir_attachment_pdf</field>
<field name="binding_type">report</field>
</record>

</data>
</odoo>
Loading

0 comments on commit dbc9c9d

Please sign in to comment.