diff --git a/account_exception/__init__.py b/account_exception/__init__.py new file mode 100644 index 00000000..9b429614 --- /dev/null +++ b/account_exception/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/account_exception/__manifest__.py b/account_exception/__manifest__.py new file mode 100644 index 00000000..b3350d0b --- /dev/null +++ b/account_exception/__manifest__.py @@ -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, +} diff --git a/account_exception/demo/account_exception_demo.xml b/account_exception/demo/account_exception_demo.xml new file mode 100644 index 00000000..6a1317fd --- /dev/null +++ b/account_exception/demo/account_exception_demo.xml @@ -0,0 +1,13 @@ + + + + + No phone + No phone number on customer + 50 + account.move + failed = journal_entry.move_type == 'out_invoice' and not journal_entry.partner_id.phone + + + + diff --git a/account_exception/models/__init__.py b/account_exception/models/__init__.py new file mode 100644 index 00000000..400b3b45 --- /dev/null +++ b/account_exception/models/__init__.py @@ -0,0 +1,3 @@ +# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. + +from . import account_move diff --git a/account_exception/models/account_move.py b/account_exception/models/account_move.py new file mode 100644 index 00000000..0a3075a7 --- /dev/null +++ b/account_exception/models/account_move.py @@ -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() diff --git a/account_exception/security/ir.model.access.csv b/account_exception/security/ir.model.access.csv new file mode 100644 index 00000000..d95c3447 --- /dev/null +++ b/account_exception/security/ir.model.access.csv @@ -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 \ No newline at end of file diff --git a/account_exception/tests/__init__.py b/account_exception/tests/__init__.py new file mode 100644 index 00000000..107d3eb4 --- /dev/null +++ b/account_exception/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_move_exception diff --git a/account_exception/tests/test_account_move_exception.py b/account_exception/tests/test_account_move_exception.py new file mode 100644 index 00000000..22b6717d --- /dev/null +++ b/account_exception/tests/test_account_move_exception.py @@ -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) diff --git a/account_exception/views/account_move_views.xml b/account_exception/views/account_move_views.xml new file mode 100644 index 00000000..7e3887df --- /dev/null +++ b/account_exception/views/account_move_views.xml @@ -0,0 +1,65 @@ + + + + + Journal Entry Exception Rules + exception.rule + tree,form + + [('model', '=', 'account.move')] + {'active_test': False, 'default_model' : 'account.move'} + + + + + + account.move.form.inherit.exception + account.move + + + + + + + + + + + + + account.move.tree.inherit.exception + account.move + + + + + + + + + + account.invoice.select.inherit.exception + account.move + + + + + + + + + + diff --git a/account_exception/wizard/__init__.py b/account_exception/wizard/__init__.py new file mode 100644 index 00000000..3eaeda76 --- /dev/null +++ b/account_exception/wizard/__init__.py @@ -0,0 +1 @@ +from . import account_move_exception_confirm diff --git a/account_exception/wizard/account_move_exception_confirm.py b/account_exception/wizard/account_move_exception_confirm.py new file mode 100644 index 00000000..3ef20ac2 --- /dev/null +++ b/account_exception/wizard/account_move_exception_confirm.py @@ -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() diff --git a/account_exception/wizard/account_move_exception_confirm_views.xml b/account_exception/wizard/account_move_exception_confirm_views.xml new file mode 100644 index 00000000..0762289f --- /dev/null +++ b/account_exception/wizard/account_move_exception_confirm_views.xml @@ -0,0 +1,25 @@ + + + + + Journal Entry Exception Rules + account.move.exception.confirm + + primary + + +