Skip to content

Commit

Permalink
Merge branch '14.0' of https://github.com/OmniaGit/odooplm.git into 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Mar 7, 2024
2 parents ce5bb1a + e688d89 commit 3f9073c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 58 deletions.
73 changes: 44 additions & 29 deletions plm/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
import itertools
import logging


def all_equal_and_true(iterable):
for item in iterable:
if not item[0]:
return False
return True

_logger = logging.getLogger(__name__)

# To be adequated to plm.component class states
Expand Down Expand Up @@ -719,23 +726,24 @@ def commonWFAction(self, writable, state, check):
for ir_attachment_id in self:
if not ir_attachment_id.exists():
continue
ir_attachment_id.setCheckContextWrite(check)
newContext = self.env.context.copy()
newContext['check'] = False
objId = ir_attachment_id.with_context(newContext).write({'writable': writable,
'state': state,
'workflow_user': self.env.uid,
'workflow_date': datetime.now()
})
if objId:
available_status = self._fields.get('state')._description_selection(self.env)
dict_status = dict(available_status)
status_lable = dict_status.get(state, '')
ir_attachment_id.wf_message_post(body=_('Status moved to: %s by %s.' % (status_lable, self.env.user.name)))
out.append(objId)
if not ir_attachment_id.state==state:
ir_attachment_id.setCheckContextWrite(check)
newContext = self.env.context.copy()
newContext['check'] = False
objId = ir_attachment_id.with_context(newContext).write({'writable': writable,
'state': state,
'workflow_user': self.env.uid,
'workflow_date': datetime.now()
})
if objId:
available_status = self._fields.get('state')._description_selection(self.env)
dict_status = dict(available_status)
status_lable = dict_status.get(state, '')
ir_attachment_id.wf_message_post(body=_('Status moved to: %s by %s.' % (status_lable, self.env.user.name)))
out.append(objId)
if ir_attachment_id.is3D():
pkg_doc_ids = self.getRelatedPkgTree(ir_attachment_id.id)
self.browse(pkg_doc_ids).commonWFAction(writable, state, check)
out+=self.browse(pkg_doc_ids).commonWFAction(writable, state, check)
return out


Expand Down Expand Up @@ -889,7 +897,17 @@ def read(self, fields=[], load='_classic_read'):
return res
except Exception as ex:
raise ex


@api.model
def check(self, mode, values=None):
if self.env.user.has_group('plm.group_plm_integration_user'):
if self.ids:
self._cr.execute('SELECT is_plm FROM ir_attachment WHERE id IN %s', [tuple(self.ids)])
if all_equal_and_true(self._cr.fetchall()):
return True
else:
return True
return super(PlmDocument, self).check(mode, values)

def readMany2oneFields(self, readVals, fields):
return self.env['product.product']._readMany2oneFields(self.env['ir.attachment'], readVals, fields)
Expand Down Expand Up @@ -2044,13 +2062,13 @@ def clientCanCheckOut(self, doc_attrs):
def canCheckOut1(self):
for docBrws in self:
if docBrws.isCheckedOutByMe():
msg = _(f"Unable to check-Out a document that is already checked Out By {docBrws.checkout_user}")
msg = _(f"Unable to check-Out {docBrws.id}:{docBrws.name} that is already checked Out By {docBrws.checkout_user}")
return docBrws.id, 'check_out_by_me', msg
if docBrws.is_checkout:
msg = _(f"Unable to check-Out a document that is already checked IN by user {docBrws.checkout_user}")
msg = _(f"Unable to check-Out {docBrws.id}:{docBrws.name} that is already checked IN by user {docBrws.checkout_user}")
return docBrws.id, 'check_out_by_user', msg
if docBrws.state not in ['draft', False]:
msg = _(f"Unable to check-Out a document that is in state {docBrws.state}")
msg = _(f"Unable to check-Out {docBrws.id}:{docBrws.name} that is in state {docBrws.state}")
return docBrws.id, 'check_out_released', msg
return docBrws.id, 'check_in', ''
raise Exception()
Expand Down Expand Up @@ -2531,10 +2549,9 @@ def appendItem(resDict, to_append):
return
else:
appendItem(out['to_check'], doc_dict_3d)
tmp_dict['options'] = {
'discard': 'Discard and check-in',
'keep_and_go': 'Keep check-out and check-in children'
}
tmp_dict['options'] = {'keep_and_go': 'Keep check-out and check-in children',
'discard': 'Discard and check-in'
}
if is_root:
if tmp_dict['check_in']:
if tmp_dict['plm_cad_open_newer']:
Expand All @@ -2545,9 +2562,8 @@ def appendItem(resDict, to_append):
appendItem(out['already_checkin'], tmp_dict)
elif tmp_dict['check_out_by_me']:
appendItem(out['to_check'], tmp_dict)
tmp_dict['options'] = {
'discard': 'Discard and check-in',
'keep_and_go': 'Keep check-out and check-in children'
tmp_dict['options'] = {'keep_and_go': 'Keep check-out and check-in children',
'discard': 'Discard and check-in',
}
else:
tmp_dict['msg'] = 'Document %r is in check-out by another user. Cannot check-in.' % (tmp_dict['name'])
Expand All @@ -2562,9 +2578,8 @@ def appendItem(resDict, to_append):
appendItem(out['already_checkin'], tmp_dict)
elif tmp_dict['check_out_by_me']:
appendItem(out['to_check'], tmp_dict)
tmp_dict['options'] = {
'discard': 'Discard and check-in',
'keep_and_go': 'Keep check-out and check-in children'
tmp_dict['options'] = {'keep_and_go': 'Keep check-out and check-in children',
'discard': 'Discard and check-in'
}
else:
tmp_dict['msg'] = 'Document %r is in check-out by another user. Cannot check-in, skipped.' % (tmp_dict['name'])
Expand Down
71 changes: 42 additions & 29 deletions plm/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,14 @@ def checkWorkflow(self, docInError, linkeddocuments, check_state, docIDs=[]):
docIDs.extend(self.checkWorkflow(docInError, attachment.browse(raw_doc_ids), check_state, docIDs))
return list(set(docIDs))

def _action_ondocuments(self, action_name, include_statuses=[]):
def _action_ondocuments(self,
action_name,
include_statuses=[]):
"""
move workflow on documents having the same state of component
"""
docIDs = []
docInError = []
documentType = self.env['ir.attachment']
for oldObject in self:
if (action_name != 'transmit') and (action_name != 'reject') and (action_name != 'release'):
check_state = oldObject.state
Expand All @@ -675,32 +676,32 @@ def _action_ondocuments(self, action_name, include_statuses=[]):
msg = msg + "\n" + e
msg = msg + _("\n\nCheck-In All the document in order to proceed !!")
raise UserError(msg)
self.moveDocumentWorkflow(docIDs, action_name)
self.moveDocumentWorkflow(list(set(docIDs)), action_name)

def moveDocumentWorkflow(self, docIDs, action_name):
documentType = self.env['ir.attachment']
ir_attachment = self.env['ir.attachment']
if len(docIDs) > 0:
docBrws = documentType.browse(docIDs)
ir_attachment_id = ir_attachment.browse(docIDs)
if action_name == 'confirm':
docBrws.action_confirm()
ir_attachment_id.action_confirm()
elif action_name == 'transmit': # TODO: Why is used? Is correct?
docBrws.action_confirm()
ir_attachment_id.action_confirm()
elif action_name == 'draft':
docBrws.action_draft()
ir_attachment_id.action_draft()
elif action_name == 'correct': # TODO: Why is used? Is correct?
docBrws.action_draft()
ir_attachment_id.action_draft()
elif action_name == 'reject':
docBrws.action_draft()
ir_attachment_id.action_draft()
elif action_name == 'release':
docBrws.action_release()
ir_attachment_id.action_release()
elif action_name == 'undermodify':
docBrws.action_cancel()
ir_attachment_id.action_cancel()
elif action_name == 'suspend':
docBrws.action_suspend()
ir_attachment_id.action_suspend()
elif action_name == 'reactivate':
docBrws.action_reactivate()
ir_attachment_id.action_reactivate()
elif action_name == 'obsolete':
docBrws.action_obsolete()
ir_attachment_id.action_obsolete()
return docIDs

@api.model
Expand Down Expand Up @@ -891,7 +892,14 @@ def canMoveWFByParam(self):
if WORKFLOW_ONLY_CLIENT and is_odooplm and odoo_side_call:
raise UserError('You can move workflow only by the client side')

def commonWFAction(self, status, action, doc_action, defaults=[], exclude_statuses=[], include_statuses=[], recursive=True):
def commonWFAction(self,
status,
action,
doc_action,
defaults=[],
exclude_statuses=[],
include_statuses=[],
recursive=True):
self.canMoveWFByParam()
product_product_ids = []
product_template_ids = []
Expand All @@ -904,25 +912,30 @@ def commonWFAction(self, status, action, doc_action, defaults=[], exclude_status
allIdsBrwsList = self.browse(allIDs)
allIdsBrwsList = allIdsBrwsList.filtered(lambda x: x.engineering_code not in [False, ''])
allIdsBrwsList._action_ondocuments(doc_action, include_statuses)
to_state = defaults.get('state', '')
for currId in allIdsBrwsList:
if not(currId.id in self.ids):
product_product_ids.append(currId.id)
product_template_ids.append(currId.product_tmpl_id.id)
defaults['workflow_user'] = self.env.uid
defaults['workflow_date'] = datetime.now()
currId.write(defaults)
if to_state!=currId.state:
if not(currId.id in self.ids):
product_product_ids.append(currId.id)
product_template_ids.append(currId.product_tmpl_id.id)
defaults['workflow_user'] = self.env.uid
defaults['workflow_date'] = datetime.now()
currId.write(defaults)
currId.wf_message_post(body=_('Status moved to: %s by %s.' % (to_state, self.env.user.name)))
if action:
product_ids = self.browse(product_product_ids)
product_ids.perform_action(action)
product_ids.workflow_user = self.env.uid
product_ids.workflow_date = datetime.now()
objId = self.env['product.template'].browse(product_template_ids).write(defaults)
if objId:
available_status = self._fields.get('state')._description_selection(self.env)
dict_status = dict(available_status)
status_lable = dict_status.get(defaults.get('state', ''), '')
self.browse(allIDs).wf_message_post(body=_('Status moved to: %s by %s.' % (status_lable, self.env.user.name)))
return objId
product_tmpl_ids = self.env['product.template'].browse(product_template_ids)
for product_tmpl_id in product_tmpl_ids:
if product_tmpl_id and to_state!=product_tmpl_id.state:
product_tmpl_id.write(defaults)
available_status = self._fields.get('state')._description_selection(self.env)
dict_status = dict(available_status)
status_lable = dict_status.get(defaults.get('state', ''), '')
product_tmpl_id.wf_message_post(body=_('Status moved to: %s by %s.' % (status_lable, self.env.user.name)))
return product_tmpl_ids

# ######################################################################################################################################33
def plm_sanitize(self, vals):
Expand Down

0 comments on commit 3f9073c

Please sign in to comment.