mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[ADD] base_exception_user,sale_exception_user,stock_exception: backported from 13.0 to 12.0
H7287
This commit is contained in:
2
base_exception_user/__init__.py
Normal file
2
base_exception_user/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import models
|
||||
from . import wizard
|
||||
24
base_exception_user/__manifest__.py
Normal file
24
base_exception_user/__manifest__.py
Normal 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': '12.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,
|
||||
}
|
||||
1
base_exception_user/models/__init__.py
Normal file
1
base_exception_user/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import base_exception
|
||||
7
base_exception_user/models/base_exception.py
Normal file
7
base_exception_user/models/base_exception.py
Normal 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')
|
||||
13
base_exception_user/security/base_exception_security.xml
Normal file
13
base_exception_user/security/base_exception_security.xml
Normal 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>
|
||||
26
base_exception_user/views/base_exception_views.xml
Normal file
26
base_exception_user/views/base_exception_views.xml
Normal 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>
|
||||
1
base_exception_user/wizard/__init__.py
Normal file
1
base_exception_user/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import base_exception_confirm
|
||||
36
base_exception_user/wizard/base_exception_confirm.py
Normal file
36
base_exception_user/wizard/base_exception_confirm.py
Normal 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'}
|
||||
18
base_exception_user/wizard/base_exception_confirm_view.xml
Normal file
18
base_exception_user/wizard/base_exception_confirm_view.xml
Normal 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>
|
||||
1
sale_exception_user/__init__.py
Normal file
1
sale_exception_user/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import wizard
|
||||
23
sale_exception_user/__manifest__.py
Normal file
23
sale_exception_user/__manifest__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
{
|
||||
'name': 'Sale Exception Rule User',
|
||||
'version': '12.0.1.0.0',
|
||||
'author': 'Hibou Corp.',
|
||||
'license': 'OPL-1',
|
||||
'category': 'Generic Modules',
|
||||
'summary': 'Allow users to ignore sale exceptions',
|
||||
'description': """
|
||||
Allow users to ignore sale exceptions
|
||||
""",
|
||||
'website': 'https://hibou.io/',
|
||||
'depends': [
|
||||
'base_exception_user',
|
||||
'sale_exception',
|
||||
],
|
||||
'data': [
|
||||
'wizard/sale_exception_confirm_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
}
|
||||
1
sale_exception_user/wizard/__init__.py
Normal file
1
sale_exception_user/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import sale_exception_confirm
|
||||
16
sale_exception_user/wizard/sale_exception_confirm.py
Normal file
16
sale_exception_user/wizard/sale_exception_confirm.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SaleExceptionConfirm(models.TransientModel):
|
||||
_inherit = 'sale.exception.confirm'
|
||||
|
||||
def action_confirm(self):
|
||||
res = super().action_confirm()
|
||||
if self.ignore:
|
||||
self.related_model_id.action_confirm()
|
||||
return res
|
||||
|
||||
def _action_ignore(self):
|
||||
self.related_model_id.ignore_exception = True
|
||||
self.related_model_id.action_confirm()
|
||||
return super()._action_ignore()
|
||||
18
sale_exception_user/wizard/sale_exception_confirm_view.xml
Normal file
18
sale_exception_user/wizard/sale_exception_confirm_view.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_sale_exception_confirm" model="ir.ui.view">
|
||||
<field name="name">Sale Exceptions User</field>
|
||||
<field name="model">sale.exception.confirm</field>
|
||||
<field name="inherit_id" ref="sale_exception.view_sale_exception_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>
|
||||
4
stock_exception/__init__.py
Normal file
4
stock_exception/__init__.py
Normal 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
|
||||
27
stock_exception/__manifest__.py
Normal file
27
stock_exception/__manifest__.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
{
|
||||
'name': 'Stock Exception Rule',
|
||||
'version': '12.0.1.0.0',
|
||||
'author': 'Hibou Corp.',
|
||||
'license': 'OPL-1',
|
||||
'category': 'Generic Modules',
|
||||
'summary': 'Custom exceptions on delivery orders',
|
||||
'description': """
|
||||
Custom exceptions on delivery orders
|
||||
""",
|
||||
'website': 'https://hibou.io/',
|
||||
'depends': [
|
||||
'base_exception_user',
|
||||
'stock',
|
||||
],
|
||||
'data': [
|
||||
'views/stock_views.xml',
|
||||
'wizard/stock_exception_confirm_views.xml',
|
||||
],
|
||||
'demo': [
|
||||
'demo/stock_exception_demo.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
}
|
||||
13
stock_exception/demo/stock_exception_demo.xml
Normal file
13
stock_exception/demo/stock_exception_demo.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="excep_no_zip" model="exception.rule">
|
||||
<field name="name">No ZIP code on destination</field>
|
||||
<field name="description">No ZIP code on destination</field>
|
||||
<field name="sequence">50</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="code">if not picking.partner_id.zip: failed=True</field>
|
||||
<field name="active" eval="False"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
3
stock_exception/models/__init__.py
Normal file
3
stock_exception/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from . import stock
|
||||
42
stock_exception/models/stock.py
Normal file
42
stock_exception/models/stock.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# 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=[
|
||||
('stock.picking', 'Transfer'),
|
||||
]
|
||||
)
|
||||
picking_ids = fields.Many2many(
|
||||
'stock.picking',
|
||||
string="Transfers")
|
||||
|
||||
class Picking(models.Model):
|
||||
_inherit = ['stock.picking', 'base.exception']
|
||||
_name = 'stock.picking'
|
||||
_order = 'main_exception_id asc, priority desc, date asc, id desc'
|
||||
|
||||
@api.model
|
||||
def _exception_rule_eval_context(self, rec):
|
||||
res = super(Picking, self)._exception_rule_eval_context(rec)
|
||||
res['picking'] = rec
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _reverse_field(self):
|
||||
return 'picking_ids'
|
||||
|
||||
def button_validate(self):
|
||||
self.ensure_one()
|
||||
if self.detect_exceptions():
|
||||
return self._popup_exceptions()
|
||||
return super().button_validate()
|
||||
|
||||
@api.model
|
||||
def _get_popup_action(self):
|
||||
return self.env.ref('stock_exception.action_stock_exception_confirm')
|
||||
|
||||
3
stock_exception/tests/__init__.py
Normal file
3
stock_exception/tests/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from . import test_stock_exception
|
||||
47
stock_exception/tests/test_stock_exception.py
Normal file
47
stock_exception/tests/test_stock_exception.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestStockException(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.env = self.env(context=dict(self.env.context, tracking_disable=True))
|
||||
|
||||
def test_delivery_order_exception(self):
|
||||
exception = self.env.ref('stock_exception.excep_no_zip')
|
||||
exception.active = True
|
||||
partner = self.env.ref('base.res_partner_12') # Azure Interior
|
||||
partner.zip = False
|
||||
p = self.env.ref('product.product_product_6')
|
||||
stock_location = self.env.ref('stock.stock_location_stock')
|
||||
customer_location = self.env.ref('stock.stock_location_customers')
|
||||
self.env['stock.quant']._update_available_quantity(p, stock_location, 100)
|
||||
delivery_order = self.env['stock.picking'].create({
|
||||
'partner_id': partner.id,
|
||||
'picking_type_id': self.ref('stock.picking_type_out'),
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
|
||||
'move_line_ids': [(0, 0, {'product_id': p.id,
|
||||
'product_uom_id': p.uom_id.id,
|
||||
'qty_done': 3.0,
|
||||
'location_id': stock_location.id,
|
||||
'location_dest_id': customer_location.id})],
|
||||
})
|
||||
|
||||
# validate delivery order
|
||||
delivery_order.button_validate()
|
||||
self.assertEqual(delivery_order.state, 'draft')
|
||||
|
||||
# Simulation the opening of the wizard sale_exception_confirm and
|
||||
# set ignore_exception to True
|
||||
stock_exception_confirm = self.env['stock.exception.confirm'].with_context(
|
||||
{
|
||||
'active_id': delivery_order.id,
|
||||
'active_ids': [delivery_order.id],
|
||||
'active_model': delivery_order._name
|
||||
}).create({'ignore': True})
|
||||
stock_exception_confirm.action_confirm()
|
||||
self.assertTrue(delivery_order.ignore_exception)
|
||||
self.assertEqual(delivery_order.state, 'done')
|
||||
65
stock_exception/views/stock_views.xml
Normal file
65
stock_exception/views/stock_views.xml
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="action_stock_test_tree" model="ir.actions.act_window">
|
||||
<field name="name">Stock Exception Rules</field>
|
||||
<field name="res_model">exception.rule</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="base_exception.view_exception_rule_tree"/>
|
||||
<field name="domain">[('model', '=', 'stock.picking')]</field>
|
||||
<field name="context">{'active_test': False, 'default_model' : 'stock.picking'}</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
action="action_stock_test_tree"
|
||||
id="menu_stock_test"
|
||||
sequence="10"
|
||||
parent="stock.menu_stock_config_settings"
|
||||
groups="base_exception.group_exception_rule_manager"
|
||||
/>
|
||||
|
||||
<record id="view_picking_form" model="ir.ui.view">
|
||||
<field name="name">stock.picking.form.inherit.exception</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="stock.view_picking_form"/>
|
||||
<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 Delivery Order:</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 Delivery Order regardless of the exceptions."
|
||||
groups="base_exception.group_exception_rule_manager"/>
|
||||
</div>
|
||||
</sheet>
|
||||
<xpath expr="//field[@name='origin']/.." position="inside">
|
||||
<field name="ignore_exception" states="done" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_picking_tree" model="ir.ui.view">
|
||||
<field name="name">stock.picking.tree.inherit.exception</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="stock.vpicktree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="state" position="after">
|
||||
<field name="main_exception_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_picking_internal_search" model="ir.ui.view">
|
||||
<field name="name">stock.picking.internal.search.inherit.exception</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="stock.view_picking_internal_search" />
|
||||
<field name="arch" type="xml">
|
||||
<filter name="backorder" position="after">
|
||||
<separator orientation="vertical"/>
|
||||
<filter icon="terp-emblem-important" name="tofix" string="Blocked by exceptions" domain="[('main_exception_id','!=',False)]"/>
|
||||
</filter>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
3
stock_exception/wizard/__init__.py
Normal file
3
stock_exception/wizard/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from . import stock_exception_confirm
|
||||
25
stock_exception/wizard/stock_exception_confirm.py
Normal file
25
stock_exception/wizard/stock_exception_confirm.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockExceptionConfirm(models.TransientModel):
|
||||
_name = 'stock.exception.confirm'
|
||||
_inherit = ['exception.rule.confirm']
|
||||
|
||||
related_model_id = fields.Many2one('stock.picking', 'Transfer')
|
||||
|
||||
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 self.related_model_id.button_validate()
|
||||
else:
|
||||
return res
|
||||
|
||||
def _action_ignore(self):
|
||||
self.related_model_id.ignore_exception = True
|
||||
super()._action_ignore()
|
||||
return self.related_model_id.button_validate()
|
||||
25
stock_exception/wizard/stock_exception_confirm_views.xml
Normal file
25
stock_exception/wizard/stock_exception_confirm_views.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_stock_exception_confirm" model="ir.ui.view">
|
||||
<field name="name">Stock Exceptions Rules</field>
|
||||
<field name="model">stock.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_stock_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">stock.exception.confirm</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_stock_exception_confirm"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user