Merge branch 'new/15.0/H11045_project_exception__generate_exception_while_creating_task' into '15.0-test'

new/15.0/H11045_project_exception__generate_exception_while_creating_task into 15.0-test

See merge request hibou-io/hibou-odoo/suite!1484
This commit is contained in:
Hibou Bot
2022-09-30 00:51:52 +00:00
13 changed files with 287 additions and 0 deletions

View File

@@ -68,6 +68,26 @@
"--test-enable", "--no-xmlrpc", "--stop-after-init"],
"console": "integratedTerminal"
},
{
"name": "Odoo: INIT 'project_exception'",
"type": "python",
"request": "launch",
"program": "/opt/odoo/hibou-suite/odoo-run.py",
"args": ["-i", "project_exception",
"-u", "project_exception",
"--stop-after-init"],
"console": "integratedTerminal"
},
{
"name": "Odoo: TEST 'project_exception'",
"type": "python",
"request": "launch",
"program": "/opt/odoo/hibou-suite/odoo-run.py",
"args": ["-i", "project_exception",
"-u", "project_exception",
"--test-enable", "--no-xmlrpc", "--stop-after-init"],
"console": "integratedTerminal"
},
{
"name": "Odoo: server",
"type": "python",

View File

@@ -0,0 +1,4 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from . import models
from . import wizard

View File

@@ -0,0 +1,29 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
{
'name': "Project Exception Rule",
'version': '15.0.1.0.0',
'author': "Hibou Corp.",
'license': 'OPL-1',
'category': 'Generic Modules',
'summary': """
Module for Project Exception Rule""",
'description': """
The ability to run and trigger exceptions to block the moving of a task based on rules
""",
'website': "http://www.hibou.io/",
'depends': [
'base_exception_user',
'project'
],
'data': [
'security/ir.model.access.csv',
'views/project_views.xml',
'wizard/project_exception_confirm_views.xml',
],
'demo': [
'demo/project_exception_demo.xml',
],
'installable': True,
'auto_install': False,
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="except_no_project_id" model="exception.rule">
<field name="name">No Project Id on task</field>
<field name="description">No Project Id on task</field>
<field name="sequence">50</field>
<field name="model">project.task</field>
<field name="code">if not task.project_id.name: failed=True</field>
<field name="active" eval="False"/>
</record>
</odoo>

View File

@@ -0,0 +1,3 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from . import project

View File

@@ -0,0 +1,59 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo import api, models, fields
class ExceptionRule(models.Model):
_inherit = 'exception.rule'
model = fields.Selection(
selection_add=[
('project.task', 'Task'),
],
ondelete={
'project.task': 'cascade',
},
)
task_ids = fields.Many2many(
'project.task',
string="Task")
class Task(models.Model):
_inherit = ['project.task', 'base.exception']
_name = 'project.task'
_order = 'main_exception_id asc, sequence, name, id'
@api.model
def create(self, values):
res = super().create(values)
res.detect_exceptions()
return res
@api.model
def _exception_rule_eval_context(self, rec):
res = super(Task, self)._exception_rule_eval_context(rec)
res['task'] = rec
return res
@api.model
def _reverse_field(self):
return 'task_ids'
def write(self, vals):
if not vals.get('ignore_exception'):
for task in self:
if task.detect_exceptions():
return self._popup_exceptions()
return super().write(vals)
@api.model
def _get_popup_action(self):
return self.env.ref('project_exception.action_project_exception_confirm')
def detect_exceptions(self):
res = False
if not self._context.get("detect_exceptions"):
self = self.with_context(detect_exceptions=True)
res = super(Task, self).detect_exceptions()
return res

View File

@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_project_task_exception_confirm_user,project.exception.confirm user,model_project_exception_confirm,project.group_project_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_project_task_exception_confirm_user project.exception.confirm user model_project_exception_confirm project.group_project_user 1 1 1 1

View File

@@ -0,0 +1,2 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from . import test_project_exception

View File

@@ -0,0 +1,35 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo.tests import common, Form
class TestProjectException(common.TransactionCase):
def setUp(self):
super().setUp()
self.env = self.env(context=dict(self.env.context, tracking_disable=True))
def test_project_task_creation_exception(self):
exception = self.env.ref('project_exception.except_no_project_id')
exception.active = True
task = self.env['project.task'].create({
'name': 'Test Task',
})
# Created exceptions on create.
self.assertTrue(task.exception_ids)
# Will return action on write, which may or not be followed.
action = task.write({
'name': 'Test Task - Test Written',
})
self.assertTrue(task.exception_ids)
self.assertTrue(action)
self.assertEqual(action.get('res_model'), 'project.exception.confirm')
# Simulation the opening of the wizard task_exception_confirm and
# set ignore_exception to True
project_exception_confirm = Form(self.env[action['res_model']].with_context(action['context'])).save()
project_exception_confirm.ignore = True
project_exception_confirm.action_confirm()
self.assertTrue(task.ignore_exception)

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="action_project_test_tree" model="ir.actions.act_window">
<field name="name">Project Exception Rules</field>
<field name="res_model">exception.rule</field>
<!-- What about kanban view?, because kanban is the default view type for Project -->
<field name="view_mode">tree,form</field>
<field name="view_id" ref="base_exception.view_exception_rule_tree"/>
<field name="domain">[('model', '=', 'project.task')]</field>
<field name="context">{'active_test': False, 'default_model' : 'project.task'}</field>
</record>
<menuitem
action="action_project_test_tree"
id="menu_project_test"
sequence="10"
parent="project.menu_project_config"
groups="base_exception.group_exception_rule_manager"
/>
<record id="view_task_form2" model="ir.ui.view">
<field name="name">project.task.form.inherit.exception</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<sheet position="before">
<div class="alert alert-danger" role="alert" style="margin-bottom:0px;"
attrs="{'invisible': [('exceptions_summary','=',False)]}">
<p><strong>There are exceptions blocking the confirmation of this Task:</strong></p>
<field name="exceptions_summary"/>
<button name="action_ignore_exceptions" type="object" class="btn-danger"
string="Ignore Exceptions" help="Click here to be able to confirm this Task regardless of the exceptions."
groups="base_exception.group_exception_rule_manager"/>
</div>
</sheet>
<xpath expr="//field[@name='tag_ids']" position="after">
<field name="ignore_exception" />
</xpath>
</field>
</record>
<record id="view_task_tree2" model="ir.ui.view">
<field name="name">project.task.tree.inherit.exception</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_tree2"/>
<field name="arch" type="xml">
<field name="stage_id" position="after">
<field name="main_exception_id"/>
</field>
</field>
</record>
<record id="view_task_search_form" model="ir.ui.view">
<field name="name">project.task.search.form.inherit.exception</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_search_form" />
<field name="arch" type="xml">
<filter name="inactive" position="before">
<separator orientation="vertical"/>
<filter icon="terp-emblem-important" name="tofix" string="Blocked by exceptions" domain="[('main_exception_id','!=',False)]"/>
</filter>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,3 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from . import project_exception_confim

View File

@@ -0,0 +1,26 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo import api, fields, models
class ProjectExceptionConfirm(models.TransientModel):
_name = 'project.exception.confirm'
_inherit = ['exception.rule.confirm']
_description = 'Project Exception Confirm Wizard'
related_model_id = fields.Many2one('project.task', 'Task')
def action_confirm(self):
self.ensure_one()
if self.ignore:
self.related_model_id.ignore_exception = True
res = super().action_confirm()
if self.ignore:
return True
else:
return res
def _action_ignore(self):
self.related_model_id.ignore_exception = True
super()._action_ignore()
return True

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_project_exception_confirm" model="ir.ui.view">
<field name="name">Project Exceptions Rules</field>
<field name="model">project.exception.confirm</field>
<field name="inherit_id" ref="base_exception.view_exception_rule_confirm"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//footer" position="inside">
<button class="oe_link" special="cancel" string="Cancel"/>
</xpath>
</field>
</record>
<record id="action_project_exception_confirm" model="ir.actions.act_window">
<field name="name">Blocked due to exceptions</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">project.exception.confirm</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_project_exception_confirm"/>
<field name="target">new</field>
</record>
</odoo>