mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'new/15.0/H11044_account_exception__account_exception_on_post' into '15.0-test'
new/15.0/H11044_account_exception__account_exception_on_post into 15.0-test See merge request hibou-io/hibou-odoo/suite!1488
This commit is contained in:
2
account_exception/__init__.py
Normal file
2
account_exception/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import models
|
||||
from . import wizard
|
||||
29
account_exception/__manifest__.py
Normal file
29
account_exception/__manifest__.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
{
|
||||
'name': 'Journal Entry Exception Rule',
|
||||
'version': '15.0.1.0.0',
|
||||
'author': 'Hibou Corp.',
|
||||
'license': 'OPL-1',
|
||||
'category': 'Generic Modules',
|
||||
'summary': 'Custom exceptions on Journal Entries',
|
||||
'description': """
|
||||
Custom exceptions on journal entries
|
||||
""",
|
||||
'website': 'https://hibou.io/',
|
||||
'depends': [
|
||||
'base_exception_user',
|
||||
'account',
|
||||
],
|
||||
'data': [
|
||||
# 'demo/account_exception_demo.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'views/account_move_views.xml',
|
||||
'wizard/account_move_exception_confirm_views.xml',
|
||||
],
|
||||
'demo': [
|
||||
'demo/account_exception_demo.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
}
|
||||
13
account_exception/demo/account_exception_demo.xml
Normal file
13
account_exception/demo/account_exception_demo.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="except_no_phone" model="exception.rule">
|
||||
<field name="name">No phone</field>
|
||||
<field name="description">No phone number on customer</field>
|
||||
<field name="sequence">50</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="code">failed = journal_entry.move_type == 'out_invoice' and not journal_entry.partner_id.phone</field>
|
||||
<field name="active" eval="True"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
3
account_exception/models/__init__.py
Normal file
3
account_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 account_move
|
||||
45
account_exception/models/account_move.py
Normal file
45
account_exception/models/account_move.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ExceptionRule(models.Model):
|
||||
_inherit = 'exception.rule'
|
||||
|
||||
model = fields.Selection(
|
||||
selection_add=[
|
||||
('account.move', 'Journal Entry'),
|
||||
],
|
||||
ondelete={
|
||||
'account.move': 'cascade',
|
||||
},
|
||||
)
|
||||
journal_entry_ids = fields.Many2many(
|
||||
'account.move',
|
||||
string="Journal Entries")
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = ['account.move', 'base.exception']
|
||||
_name = "account.move"
|
||||
_order = 'main_exception_id asc, date desc, name desc, id desc'
|
||||
|
||||
@api.model
|
||||
def _exception_rule_eval_context(self, rec):
|
||||
res = super(AccountMove, self)._exception_rule_eval_context(rec)
|
||||
res['journal_entry'] = rec
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _reverse_field(self):
|
||||
return 'journal_entry_ids'
|
||||
|
||||
@api.model
|
||||
def _get_popup_action(self):
|
||||
return self.env.ref('account_exception.action_account_move_exception_confirm')
|
||||
|
||||
def action_post(self):
|
||||
self.ensure_one()
|
||||
if self.detect_exceptions():
|
||||
return self._popup_exceptions()
|
||||
return super().action_post()
|
||||
2
account_exception/security/ir.model.access.csv
Normal file
2
account_exception/security/ir.model.access.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
account_exception.access_account_move_exception_confirm,access_account_move_exception_confirm,account_exception.model_account_move_exception_confirm,base.group_user,1,1,1,1
|
||||
|
1
account_exception/tests/__init__.py
Normal file
1
account_exception/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_account_move_exception
|
||||
24
account_exception/tests/test_account_move_exception.py
Normal file
24
account_exception/tests/test_account_move_exception.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# from odoo.tests import common
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
from odoo.tests import tagged
|
||||
# from odoo.tests.common import Form
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestAccountMoveException(AccountTestInvoicingCommon):
|
||||
|
||||
def test_10_validation_on_post(self):
|
||||
self.env.user.groups_id += self.env.ref('analytic.group_analytic_accounting')
|
||||
exception = self.env.ref('account_exception.except_no_phone').sudo()
|
||||
exception.active = True
|
||||
invoice = self.init_invoice('out_invoice', products=self.product_a)
|
||||
|
||||
# must be exceptions when no phone and posting
|
||||
invoice.partner_id.phone = False
|
||||
invoice.action_post()
|
||||
self.assertTrue(invoice.exception_ids)
|
||||
|
||||
# no exceptions when phone and posting
|
||||
invoice.partner_id.phone = '123'
|
||||
invoice.action_post()
|
||||
self.assertFalse(invoice.exception_ids)
|
||||
65
account_exception/views/account_move_views.xml
Normal file
65
account_exception/views/account_move_views.xml
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="action_account_move_test_tree" model="ir.actions.act_window">
|
||||
<field name="name">Journal Entry 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', '=', 'account.move')]</field>
|
||||
<field name="context">{'active_test': False, 'default_model' : 'account.move'}</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
action="action_account_move_test_tree"
|
||||
id="menu_account_move_test"
|
||||
sequence="10"
|
||||
parent="account.menu_finance_configuration"
|
||||
groups="base_exception.group_exception_rule_manager"
|
||||
/>
|
||||
|
||||
<record id="view_move_form" model="ir.ui.view">
|
||||
<field name="name">account.move.form.inherit.exception</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_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 post of this Journal Entry:</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 post this Invoice regardless of the exceptions."
|
||||
groups="base_exception.group_exception_rule_manager"/>
|
||||
</div>
|
||||
</sheet>
|
||||
<xpath expr="//div[@name='journal_div']" position="after">
|
||||
<field name="ignore_exception" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_move_tree" model="ir.ui.view">
|
||||
<field name="name">account.move.tree.inherit.exception</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="state" position="after">
|
||||
<field name="main_exception_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_account_invoice_filter" model="ir.ui.view">
|
||||
<field name="name">account.invoice.select.inherit.exception</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_account_invoice_filter" />
|
||||
<field name="arch" type="xml">
|
||||
<filter name="late" 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>
|
||||
1
account_exception/wizard/__init__.py
Normal file
1
account_exception/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import account_move_exception_confirm
|
||||
26
account_exception/wizard/account_move_exception_confirm.py
Normal file
26
account_exception/wizard/account_move_exception_confirm.py
Normal 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 AccountMoveExceptionConfirm(models.TransientModel):
|
||||
_name = 'account.move.exception.confirm'
|
||||
_inherit = ['exception.rule.confirm']
|
||||
_description = 'Journal Entry Exception Confirm Wizard'
|
||||
|
||||
related_model_id = fields.Many2one('account.move', 'Journal Entry')
|
||||
|
||||
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.action_post()
|
||||
else:
|
||||
return res
|
||||
|
||||
def _action_ignore(self):
|
||||
self.related_model_id.ignore_exception = True
|
||||
super()._action_ignore()
|
||||
return self.related_model_id.action_post()
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_account_move_exception_confirm" model="ir.ui.view">
|
||||
<field name="name">Journal Entry Exception Rules</field>
|
||||
<field name="model">account.move.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_account_move_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">account.move.exception.confirm</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_account_move_exception_confirm"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -16,6 +16,7 @@ Custom exceptions on delivery orders
|
||||
'stock',
|
||||
],
|
||||
'data': [
|
||||
'demo/stock_exception_demo.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'views/stock_views.xml',
|
||||
'wizard/stock_exception_confirm_views.xml',
|
||||
|
||||
Reference in New Issue
Block a user