Skip to content

Commit

Permalink
Merge branch '9.0-workflow-task-sbi' of ssh://github.com/acsone/acson…
Browse files Browse the repository at this point in the history
…e-addons into 9.0-slg_master
  • Loading branch information
lmignon committed Oct 24, 2016
2 parents 8a4a1d5 + 121001a commit 55a06f4
Show file tree
Hide file tree
Showing 40 changed files with 1,689 additions and 0 deletions.
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
account-financial-reporting
connector
hr-timesheet
server-tools
1 change: 1 addition & 0 deletions setup/workflow_activity_action/odoo_addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
6 changes: 6 additions & 0 deletions setup/workflow_activity_action/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions setup/workflow_task/odoo_addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
1 change: 1 addition & 0 deletions setup/workflow_task/odoo_addons/workflow_task
6 changes: 6 additions & 0 deletions setup/workflow_task/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
88 changes: 88 additions & 0 deletions workflow_activity_action/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

========================
Workflow activity action
========================

This module adds the concept of actions directly on the activities of an object.

It is now possible to define a list of actions on workflow activities.
Currently, these actions are configured as Odoo server action.

Once defined actions on activities, it is possible to use these ones directly on the object associated with the activity.
technically, it is necessary to make an inheritance of an abstract model and to add a field in the view of the object concerned.

You can define two types of security rules for the actions of management.

1) It is possible to define a security group list on the activity. For a user to perform an action on that activity, it must be defined in at least one group.
2) In addition to the first level, it is possible to define a list of activity record rule. The evaluation process of these security rules is similar to the ir.rule model.

Once the rules are evaluated, the actions are performed by super user (with base_suspend_security module)

Usage
=====

Here is an example implementation on account.invoice model.

* A python class ::

from openerp import fields, models


class AccountInvoice(models.Model)
_name = 'account.invoice'
_inherit = ['accont.invoice', 'workflow.action.model']

* An XML view ::

<record model="ir.ui.view" id="invoice_form">
<field name="name">account.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form" />
<field name="arch" type="xml">
<xpath expr="//header" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//header" position="after">
<header>
<field name="activity_action_ids" widget="many2many_action_buttons" />
<field name="state" widget="statusbar"/>
</header>
</xpath>
</field>
</record>

* Configuration of activities:

.. figure:: static/description/workflow_activity_action_1.png
:alt: Configuration of activities

* Add a server action on activity

.. figure:: static/description/workflow_activity_action_2.png
:alt: Add a server action on activity

* Using actions directly on the object:

.. figure:: static/description/workflow_activity_action_3.png
:alt: Using actions directly on the object

Credits
=======

Contributors
------------

* Stéphane Bidoul <stephane.bidoul@acsone.eu>
* Adrien Peiffer <adrien.peiffer@acsone.eu>

Maintainer
----------

.. image:: https://www.acsone.eu/logo.png
:alt: ACSONE SA/NV
:target: http://www.acsone.eu

This module is maintained by ACSONE SA/NV.
2 changes: 2 additions & 0 deletions workflow_activity_action/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import models
48 changes: 48 additions & 0 deletions workflow_activity_action/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This file is part of workflow_activity_action,
# an Odoo module.
#
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
#
# workflow_activity_action is free software:
# you can redistribute it and/or modify it under the terms of the GNU
# Affero General Public License as published by the Free Software
# Foundation,either version 3 of the License, or (at your option) any
# later version.
#
# workflow_activity_action is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with workflow_activity_action.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': "Workflow activity action",

'summary': """
Manage object action from its activities""",
'author': 'ACSONE SA/NV',
'website': "http://acsone.eu",
'category': 'Technical Settings',
'version': '9.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'base',
'base_suspend_security',
],
'data': [
'security/ir.model.access.csv',
'views/wkf_activity.xml',
'views/workflow_activity_action.xml',
'views/activity_record_rule_view.xml',
],
'qweb': [
'static/src/xml/base.xml',
],
}
4 changes: 4 additions & 0 deletions workflow_activity_action/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import wkf_action_model
from . import wkf_activity
from . import activity_record_rule
96 changes: 96 additions & 0 deletions workflow_activity_action/models/activity_record_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import time

from openerp import api, fields, models
from openerp.tools import SUPERUSER_ID
from openerp.addons.base_suspend_security.base_suspend_security import\
BaseSuspendSecurityUid
from openerp.osv import expression


class ActivityRecordRule(models.Model):
_inherit = 'ir.rule'
_name = 'activity.record.rule'

@api.model
def _eval_context(self):
"""Returns a dictionary to use as evaluation context for
ir.rule domains."""
return {'user': self.env.user,
'time': time}

@api.multi
def _domain_force_get(self):
eval_context = self._eval_context()
for rule in self:
if rule.domain_force:
rule.domain = expression.normalize_domain(
eval(rule.domain_force, eval_context))
else:
rule.domain = []

activity_id = fields.Many2one(comodel_name='workflow.activity',
string='Activity',
required=True)
model_id = fields.Many2one(required=False, readonly=True)
domain = fields.Binary(compute='_domain_force_get', string='Domain')
groups = fields.Many2many(
comodel_name='res.groups', relation='activity_rule_group_rel',
column1='rule_group_id', column2='group_id', string='Groups')

@api.model
def domain_get(self, model_name, activity_id):
dom = self._compute_activity_rule_domain(activity_id)
if dom:
# _where_calc is called as superuser. This means that rules can
# involve objects on which the real uid has no acces rights.
# This means also there is no implicit restriction (e.g. an object
# references another object the user can't see).
query = self.env[model_name].sudo()._where_calc(dom,
active_test=False)
return query.where_clause, query.where_clause_params, query.tables
return [], [], ['"' + self.pool[model_name]._table + '"']

@api.model
def _compute_activity_rule_domain(self, activity_id):
if self._uid == SUPERUSER_ID or isinstance(self.env.uid,
BaseSuspendSecurityUid):
return None
self._cr.execute("""SELECT r.id
FROM activity_record_rule r
WHERE r.active is True
AND r.activity_id = %s
AND (r.id IN (SELECT rule_group_id
FROM activity_rule_group_rel g_rel
JOIN res_groups_users_rel u_rel ON (g_rel.group_id = u_rel.gid)
WHERE u_rel.uid = %s) OR r.global)""", (activity_id,
self._uid))
rule_ids = [x[0] for x in self._cr.fetchall()]
if rule_ids:
# browse user as super-admin root to avoid access errors!
user = self.env['res.users'].sudo().browse([self._uid])
global_domains = [] # list of domains
group_domains = {} # map: group -> list of domains
for rule in self.sudo().browse(rule_ids):
# read 'domain' as UID to have the correct eval context for
# the rule.
rule_domain = rule.sudo(user=user.id)\
.read(['domain'])[0]['domain']
dom = expression.normalize_domain(rule_domain)
for group in rule.groups:
if group in user.groups_id:
group_domains.setdefault(group, []).append(dom)
if not rule.groups:
global_domains.append(dom)
# combine global domains and group domains
if group_domains:
group_domain = expression.OR(map(expression.OR,
group_domains.values()))
else:
group_domain = []
domain = expression.AND(global_domains + [group_domain])
return domain
return []
51 changes: 51 additions & 0 deletions workflow_activity_action/models/wkf_action_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This file is part of workflow_activity_action,
# an Odoo module.
#
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
#
# workflow_activity_action is free software:
# you can redistribute it and/or modify it under the terms of the GNU
# Affero General Public License as published by the Free Software
# Foundation,either version 3 of the License, or (at your option) any
# later version.
#
# workflow_activity_action is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with workflow_activity_action.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import models, fields, api


class WorkflowActionModel(models.AbstractModel):
_name = 'workflow.action.model'

activity_action_ids = fields.One2many(
comodel_name='workflow.activity.action',
compute='_get_action_ids', string="Action")

@api.multi
def _get_action_ids(self):
res_type = str(self._model)
for record in self:
if record.id:
workitem_ids = self.env['workflow.workitem']\
.search([('inst_id.res_id', '=', record.id),
('inst_id.res_type', '=', res_type)])
actions_ids = self.env['workflow.activity.action']
activity_ids = workitem_ids.mapped('act_id')
for activity in activity_ids:
if activity.use_action_object and\
activity._check_action_security(res_type,
record.id):
actions_ids = actions_ids + activity.action_ids
self.activity_action_ids = actions_ids

0 comments on commit 55a06f4

Please sign in to comment.