Skip to content

Commit

Permalink
IMP: backport document checkin check
Browse files Browse the repository at this point in the history
with this back port we improve the capability in odoo plm to check in
only the drawing that are more young
  • Loading branch information
mboscolo committed Aug 28, 2024
1 parent bef07fa commit 6d5e3d3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
50 changes: 47 additions & 3 deletions plm/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,19 @@ def _get_n_rel_doc(self):
revision_user = fields.Many2one('res.users', string=_("User Revision"))
revision_date = fields.Datetime(string=_('Datetime Revision'))

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""")

def _compute_must_update_from_cad(self):
for source_attachment_id in self:
source_attachment_id.must_update_from_cad=False
if source_attachment_id.is2D():
for referenced_attached_id in self.browse(list(set(self.getRelatedLyTree(source_attachment_id.id)))):
if referenced_attached_id.lastSavedDate() > source_attachment_id.lastSavedDate():
source_attachment_id.must_update_from_cad=True


def _compute_linkedcomponents(self):
for record in self:
if record.linkedcomponents:
Expand Down Expand Up @@ -2601,7 +2614,11 @@ def CheckInRecursive2(self, involved_docs_dict, **kargs):
return True

@api.model
def preCheckInRecursive(self, doc_props, forceCheckInModelByDrawing=True, recursion=True, onlyActiveDoc=False):
def preCheckInRecursive(self,
doc_props,
forceCheckInModelByDrawing=True,
recursion=True,
onlyActiveDoc=False):
out = {
'to_check_in': [],
'to_ask': [],
Expand Down Expand Up @@ -2741,7 +2758,12 @@ def recursionf(doc_id,
if onlyActiveDoc:
return
is_root = False
docs3D = self.browse(list(set(self.getRelatedLyTree(docs3D.id))))
referenced_attachment_ids = self.browse(list(set(self.getRelatedLyTree(docs3D.id))))
for referenced_attached in referenced_attachment_ids:
if referenced_attached.must_update_from_cad:
raise Exception(_(f"3D model {referenced_attached}:{referenced_attached.name} must be saved before the 2d Layout {docs3D.id}:{docs3D.name}"))
docs3D=referenced_attachment_ids

for doc3D in docs3D:
doc_id_3d = doc3D.id
if doc_id_3d in evaluated:
Expand Down Expand Up @@ -2801,6 +2823,17 @@ def recursionf(doc_id,
recursion)
return json.dumps(out)

def lastSavedDate(self):
"""
check the last saved date for the document
"""
self.ensure_one()
cad_open = self.sudo().env['plm.cad.open']
for cad_open_id in cad_open.search([('document_id','=', self.id),
('operation_type','=','save')], limit=1,order='write_date DESC'):
return cad_open_id.create_date
raise Exception("Attacment not saved")

@api.model
def preCheckOutRecursive(self, comp_vals):
comp_vals = json.loads(comp_vals)
Expand Down Expand Up @@ -2943,6 +2976,17 @@ def convert_printout_attachment(self):
if index%1000==0:
self._cr.commit()


def related_not_update(self):
for attachment_id in self:
relation_ids = self.env['ir.attachment.relation'].search(["|",('parent_id','=',attachment_id.id),
('child_id','=',attachment_id.id),
('link_kind', '=', 'LyTree')])
return {'name': _('Attachment Relations.'),
'res_model': 'ir.attachment.relation',
'view_type': 'form',
'view_mode': 'kanban,tree,form',
'type': 'ir.actions.act_window',
'domain': [('id', 'in', relation_ids.ids)],
'context': {}}

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
19 changes: 18 additions & 1 deletion plm/views/ir_attachment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
icon="fa-bars"/>
<button name="open_related_document_revisions"
type="object"
string="BOM Rev."
string="N.Rev."
class="oe_stat_button"
icon="fa-tasks"
attrs="{'invisible':[('attachment_revision_count','&lt;=','1')]}">
Expand All @@ -277,6 +277,16 @@
<button name="check_out_user" icon="fa-user" attrs="{'invisible': ['|',('checkout_user', '=', 'False'),('checkout_user', '=', '')]}">
<field name="checkout_user"/>
</button>
<field name="must_update_from_cad" invisible="1"></field>
<button name="related_not_update"
icon="fa-warning"
type="object"
attrs="{'invisible':[('must_update_from_cad','=',False)]}"
>
<div class="o_field_widget o_stat_info o_readonly_modifier">
<span style="color:orange">Not.Update</span>
</div>
</button>
</div>
<group>
<group string= "PLM Infos:" name="main_doc_info">
Expand Down Expand Up @@ -482,6 +492,7 @@
<field name="description"/>
<field name="state"/>
<field name="document_type"/>
<field name="must_update_from_cad" invisible="True"/>
<field name="is_checkout" invisible="True"/>
<field name="is_linkedcomponents" invisible="True"/>
<templates>
Expand All @@ -502,6 +513,12 @@
</strong>
</td>
<td name="Component" style="text-align: right; width: 100%; padding:1px;">
<button name="related_not_update"
type="object"
attrs="{'invisible':[('must_update_from_cad','=',False)]}"
class="fa fa-warning fa-2x btn-warning"
/>
<!--invisible="must_update_from_cad==False"-->
<div class="fa fa-lock fa-2x"
style="color:red;display: inline;"
attrs="{'invisible': ['|',('checkout_user', '=', 'False'),('checkout_user', '=', '')]}"/>
Expand Down

0 comments on commit 6d5e3d3

Please sign in to comment.