[ADD] base_exception_user,sale_exception_user,stock_exception: allow certain users to ignore exceptions, add exceptions on delivery orders

This commit is contained in:
Cedric Collins
2021-09-17 15:23:06 -05:00
parent 1ee5b14ebb
commit 5274bf786f
9 changed files with 128 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
from . import models
from . import wizard

View File

@@ -0,0 +1,24 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
{
'name': 'Exception Rule User',
'version': '13.0.1.0.0',
'author': 'Hibou Corp.',
'license': 'OPL-1',
'category': 'Generic Modules',
'summary': 'Allow users to ignore exceptions',
'description': """
Allow users to ignore exceptions
""",
'website': 'https://hibou.io/',
'depends': [
'base_exception',
],
'data': [
'security/base_exception_security.xml',
'views/base_exception_views.xml',
'wizard/base_exception_confirm_view.xml',
],
'installable': True,
'auto_install': False,
}

View File

@@ -0,0 +1 @@
from . import base_exception

View File

@@ -0,0 +1,7 @@
from odoo import models, fields
class ExceptionRule(models.Model):
_inherit = 'exception.rule'
allow_user_ignore = fields.Boolean('Allow User Ignore')

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="group_exception_rule_user" model="res.groups">
<field name="name">Exception user</field>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>
<record id="base_exception.group_exception_rule_manager" model="res.groups">
<field name="implied_ids" eval="[(4, ref('base_exception_user.group_exception_rule_user'))]"/>
</record>
</odoo>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" ?>
<odoo>
<record id="view_exception_rule_tree" model="ir.ui.view">
<field name="name">exception.rule.tree.inherit.user</field>
<field name="model">exception.rule</field>
<field name="inherit_id" ref="base_exception.view_exception_rule_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='model']" position="after">
<field name="allow_user_ignore" widget="boolean_toggle"/>
</xpath>
</field>
</record>
<record id="view_exception_rule_form" model="ir.ui.view">
<field name="name">exception.rule.form.inherit.user</field>
<field name="model">exception.rule</field>
<field name="inherit_id" ref="base_exception.view_exception_rule_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='domain']" position="after">
<field name="allow_user_ignore" widget="boolean_toggle"/>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1 @@
from . import base_exception_confirm

View File

@@ -0,0 +1,36 @@
import html
from odoo import api, fields, models
class ExceptionRuleConfirm(models.AbstractModel):
_inherit = 'exception.rule.confirm'
show_ignore_button = fields.Boolean('Allow User Ignore', compute='_compute_show_ignore_button')
@api.depends('exception_ids')
def _compute_show_ignore_button(self):
for wiz in self:
wiz.show_ignore_button = (self.env.user.has_group('base_exception_user.group_exception_rule_user') and
all(wiz.exception_ids.mapped('allow_user_ignore')))
def action_confirm(self):
if self.ignore and 'message_ids' in self.related_model_id:
exceptions_summary = '<ul>%s</ul>' % ''.join(
['<li>%s: <i>%s</i></li>' % tuple(map(html.escape, (e.name, e.description))) for e in
self.exception_ids])
msg = '<p><strong>Exceptions ignored:</strong></p>' + exceptions_summary
self.related_model_id.message_post(body=msg)
return super().action_confirm()
def action_ignore(self):
self.ensure_one()
if self.show_ignore_button:
if 'message_ids' in self.related_model_id:
msg = '<p><strong>Exceptions ignored:</strong></p>' + self.related_model_id.exceptions_summary
self.related_model_id.message_post(body=msg)
return self._action_ignore()
return False
def _action_ignore(self):
return {'type': 'ir.actions.act_window_close'}

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_exception_rule_confirm" model="ir.ui.view">
<field name="name">Exceptions Rules</field>
<field name="model">exception.rule.confirm</field>
<field name="inherit_id" ref="base_exception.view_exception_rule_confirm"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='ignore']" position="after">
<field name="show_ignore_button" invisible="1"/>
</xpath>
<xpath expr="//button[@name='action_confirm']" position="after">
<button name="action_ignore" string="Ignore" colspan="1" type="object" attrs="{'invisible': [('show_ignore_button', '=', False)]}"/>
</xpath>
</field>
</record>
</odoo>