Skip to content

Commit

Permalink
IMP: custom workflow action adding domain for custom action
Browse files Browse the repository at this point in the history
  • Loading branch information
mboscolo committed Oct 23, 2023
1 parent 5056ad8 commit 97e450c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 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": "16.0.23",
"version": "16.0.24",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand Down
28 changes: 26 additions & 2 deletions plm/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,14 +670,34 @@ def action_create_normalBom_WF(self):
self._create_normalBom(prodId, processedIds)
self.message_post(body=_('Created Normal Bom.'))
return False

def _jump_document_wf(self,
documentBrws,
check_state):
"""
this function is here in order to customize the document workflow
:documentBrws <ir_attachment>
:check_in_check bool shuld I move also the document
:return: True will jump the workflow for the current document / False will performe the workflow
"""
return False

def checkWorkflow(self, docInError, linkeddocuments, check_state,check_in_check=True):
def checkWorkflow(self,
docInError,
linkeddocuments,
check_state,
check_in_check=True):
docIDs = []
attachment = self.env['ir.attachment']
for documentBrws in linkeddocuments:
if documentBrws.engineering_state in check_state:
if check_in_check and documentBrws.is_checkout:
docInError.append(_("Document %r : %r is checked out by user %r") % (documentBrws.name, documentBrws.engineering_revision, documentBrws.checkout_user))
if check_in_check:
logging.info(f"{documentBrws.name} workflow jump for custom rule check_in_check")
else:
docInError.append(_(f"Document {documentBrws.name} : {documentBrws.engineering_revision} is checked out by user {documentBrws.checkout_user}") )
continue
if self._jump_document_wf(documentBrws,check_state):
continue
docIDs.append(documentBrws.id)
if documentBrws.is3D():
Expand Down Expand Up @@ -749,6 +769,10 @@ def customMoveDocumentWorkflow(self,
status):
"""
Customization use this function for further customizations on product workflow
:ir_attachment_ids [<ir_attachment>]
:status str state to move to
REMARK:
the current status is on the self object and on the attachment ids
"""
return

Expand Down
1 change: 1 addition & 0 deletions plm/views/product_product_first.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<field name="priority" eval="5"/>
<field name="arch" type="xml">
<tree string="Engineering Parts"
default_order="write_date desc"
decoration-bf="engineering_state != ''"
decoration-info="engineering_state == 'confirmed'"
decoration-success="engineering_state == 'released'"
Expand Down
2 changes: 1 addition & 1 deletion plm_workflow_custom_action/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
##############################################################################
{
"name": "Workflow Custom Actions",
"version": "16.0.1",
"version": "16.0.2",
"author": "OmniaSolutions",
"website": "https://odooplm.omniasolutions.website",
"category": "Manufacturing/Product Lifecycle Management (PLM)",
Expand Down
19 changes: 16 additions & 3 deletions plm_workflow_custom_action/models/plm_automated_wf_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# along with this prograIf not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from tkinter.ttk import _list_from_statespec
'''
Created on 24 Apr 2023
@author: mboscolo
'''
import json
import logging
import datetime
from odoo import models
Expand Down Expand Up @@ -52,6 +52,9 @@ class PlmAutomatedWFAction(models.Model):
('ir.attachment', 'Attachment')],
string="Apply To",
help="Apply this action to the workflow model")

domain = fields.Char("Domain", help="""specifie the domain of the action""")

child_ids = fields.Many2many('ir.actions.server',
'rel_plm_server_actions',
'server_id',
Expand All @@ -66,8 +69,18 @@ def name_get(self):

def _run(self):
res = False
for act in self.child_ids.sorted():
res = act.run() or res
active_id = self.env.context['active_id']
active_model = self.env.context['active_model']
if active_model ==self.apply_to:
base_domain = [('id', '=', active_id)]
for act in self.child_ids.sorted():
if self.domain:
base_domain = base_domain + json.loads(self.domain.replace("\'",""))
obj_id = self.env[active_model].search(base_domain)
else:
obj_id = self.env[active_model].browse(active_id)
if obj_id:
res = act.run() or res
return res


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<field name="to_state"/>
<field name="apply_to"/>
<field name="before_after"/>
<field name="domain"/>
</group>
<group>
<field name="child_ids"/>
Expand Down

0 comments on commit 97e450c

Please sign in to comment.