[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 @@
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>