mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] account_exception: back to detedt error on post
H11044
This commit is contained in:
@@ -10,13 +10,4 @@
|
||||
<field name="active" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record id="except_no_phone_on_post" model="exception.rule">
|
||||
<field name="name">No phone when posting</field>
|
||||
<field name="description">No phone when posting</field>
|
||||
<field name="sequence">50</field>
|
||||
<field name="model">account.move</field>
|
||||
<field name="code">failed = journal_entry._context.get('newState') == 'posted' and journal_entry.move_type == 'out_invoice' and not journal_entry.partner_id.phone</field>
|
||||
<field name="active" eval="True"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -18,6 +18,7 @@ class ExceptionRule(models.Model):
|
||||
'account.move',
|
||||
string="Journal Entries")
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = ['account.move', 'base.exception']
|
||||
_name = "account.move"
|
||||
@@ -37,19 +38,8 @@ class AccountMove(models.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
|
||||
def action_post(self):
|
||||
self.ensure_one()
|
||||
if self.detect_exceptions():
|
||||
return self._popup_exceptions()
|
||||
return super().action_post()
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
# 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_write(self):
|
||||
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.excep_no_phone').sudo()
|
||||
exception = self.env.ref('account_exception.except_no_phone').sudo()
|
||||
exception.active = True
|
||||
invoice = self.init_invoice('out_invoice', products=self.product_a)
|
||||
|
||||
@@ -20,5 +21,4 @@ class TestAccountMoveException(AccountTestInvoicingCommon):
|
||||
# no exceptions when phone and posting
|
||||
invoice.partner_id.phone = '123'
|
||||
invoice.action_post()
|
||||
self.assertTrue(invoice.exception_ids)
|
||||
self.assertTrue(invoice.state='posted')
|
||||
self.assertFalse(invoice.exception_ids)
|
||||
|
||||
@@ -23,5 +23,4 @@ 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 True
|
||||
return self.related_model_id.action_post()
|
||||
|
||||
Reference in New Issue
Block a user