diff --git a/account_exception/demo/account_exception_demo.xml b/account_exception/demo/account_exception_demo.xml
index 0664ab15..5e35b696 100644
--- a/account_exception/demo/account_exception_demo.xml
+++ b/account_exception/demo/account_exception_demo.xml
@@ -1,13 +1,22 @@
-
+
No phone
No phone number on customer
50
account.move
- if journal_entry.move_type == 'out_customer' and not journal_entry.partner_id.phone: failed=True
+ failed = journal_entry.move_type == 'out_invoice' and not journal_entry.partner_id.phone
-
+
+
+
+ No phone when posting
+ No phone when posting
+ 50
+ account.move
+ failed = journal_entry._context.get('newState') == 'posted' and journal_entry.move_type == 'out_invoice' and not journal_entry.partner_id.phone
+
+
diff --git a/account_exception/models/account_move.py b/account_exception/models/account_move.py
index 66c1efe8..43a39b15 100644
--- a/account_exception/models/account_move.py
+++ b/account_exception/models/account_move.py
@@ -33,13 +33,23 @@ class AccountMove(models.Model):
def _reverse_field(self):
return 'journal_entry_ids'
- def action_post(self):
- self.ensure_one()
- if self.detect_exceptions():
- return self._popup_exceptions()
- return super().action_post()
-# TODO
@api.model
def _get_popup_action(self):
return self.env.ref('account_exception.action_account_move_exception_confirm')
+ def write(self, vals):
+ print(f'\n\nwrite()\ncontext={self._context}\n')
+ newState = vals.get('state', '')
+ if not vals.get('ignore_exception'):
+ for journal_entry in self:
+ if journal_entry.with_context(newState=newState).detect_exceptions():
+ return self._popup_exceptions()
+ return super().write(vals)
+
+ def detect_exceptions(self):
+ print(f'\n\ndetect_exceptions()\ncontext={self._context}\n')
+ res = False
+ if not self._context.get("detect_exceptions"):
+ self = self.with_context(detect_exceptions=True)
+ res = super(AccountMove, self).detect_exceptions()
+ return res
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..4e32c6c7
--- /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
+
+
+@tagged('post_install', '-at_install')
+class TestAccountMoveException(AccountTestInvoicingCommon):
+
+ def test_10_validation_on_write(self):
+ self.env.user.groups_id += self.env.ref('analytic.group_analytic_accounting')
+ exception = self.env.ref('account_exception.excep_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.assertTrue(invoice.exception_ids)
+ self.assertTrue(invoice.state='posted')
\ No newline at end of file
diff --git a/account_exception/views/account_move_views.xml b/account_exception/views/account_move_views.xml
index 9ff38109..7e3887df 100644
--- a/account_exception/views/account_move_views.xml
+++ b/account_exception/views/account_move_views.xml
@@ -33,8 +33,8 @@
groups="base_exception.group_exception_rule_manager"/>
-
-
+
+
diff --git a/account_exception/wizard/account_move_exception_confirm.py b/account_exception/wizard/account_move_exception_confirm.py
index 3ef20ac2..6733fb06 100644
--- a/account_exception/wizard/account_move_exception_confirm.py
+++ b/account_exception/wizard/account_move_exception_confirm.py
@@ -23,4 +23,5 @@ class AccountMoveExceptionConfirm(models.TransientModel):
def _action_ignore(self):
self.related_model_id.ignore_exception = True
super()._action_ignore()
- return self.related_model_id.action_post()
+ # return self.related_model_id.action_post()
+ return True
\ No newline at end of file
diff --git a/account_exception/wizard/account_move_exception_confirm_views.xml b/account_exception/wizard/account_move_exception_confirm_views.xml
index 57abf88c..0762289f 100644
--- a/account_exception/wizard/account_move_exception_confirm_views.xml
+++ b/account_exception/wizard/account_move_exception_confirm_views.xml
@@ -2,7 +2,7 @@
- Stock Exceptions Rules
+ Journal Entry Exception Rules
account.move.exception.confirm
primary