Skip to content

Commit cf44d37

Browse files
committed
[FIX] account_move_tier_validation: Pass context to allow confirming moves with tier validation
Added tests for changes Updated error to be checked in tests Updated error to be checked in tests
1 parent b195bf4 commit cf44d37

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

account_move_tier_validation/models/account_move.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ def _get_to_validate_message_name(self):
3333
elif self.move_type == "out_refund":
3434
name = _("Credit Note")
3535
return name
36+
37+
def action_post(self):
38+
return super(
39+
AccountMove, self.with_context(skip_validation_check=True)
40+
).action_post()

account_move_tier_validation/tests/test_tier_validation.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright 2018 ForgeFlow S.L.
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
33

4+
from odoo import _, fields
5+
from odoo.exceptions import ValidationError
46
from odoo.tests import common
57
from odoo.tests.common import tagged
68

@@ -26,3 +28,56 @@ def test_02_form(self):
2628
) as form:
2729
form.save()
2830
self.assertTrue(form.hide_post_button)
31+
32+
def test_03_move_post(self):
33+
group_ids = [
34+
self.env.ref("base.group_system").id,
35+
self.env.ref("account.group_account_manager").id,
36+
]
37+
self.test_user_1 = self.env["res.users"].create(
38+
{
39+
"name": "John",
40+
"login": "test1",
41+
"email": "[email protected]",
42+
"groups_id": [(6, 0, group_ids)],
43+
}
44+
)
45+
self.test_user_2 = self.env["res.users"].create(
46+
{
47+
"name": "Mike",
48+
"login": "test2",
49+
"email": "[email protected]",
50+
"groups_id": [(6, 0, group_ids)],
51+
}
52+
)
53+
self.env["tier.definition"].create(
54+
{
55+
"model_id": self.env["ir.model"]
56+
.search([("model", "=", "account.move")])
57+
.id,
58+
"definition_domain": "[('move_type', '=', 'out_invoice')]",
59+
"reviewer_id": self.test_user_1.id,
60+
}
61+
)
62+
partner = self.env["res.partner"].create({"name": "Test Partner"})
63+
product = self.env["product.product"].create({"name": "Test product"})
64+
invoice = self.env["account.move"].create(
65+
{
66+
"move_type": "out_invoice",
67+
"partner_id": partner.id,
68+
"invoice_date_due": fields.Date.from_string("2024-01-01"),
69+
"invoice_line_ids": [
70+
(0, 0, {"product_id": product.id, "quantity": 1, "price_unit": 30})
71+
],
72+
}
73+
)
74+
invoice.with_user(self.test_user_2.id).request_validation()
75+
invoice = invoice.with_user(self.test_user_1.id)
76+
invoice.invalidate_model()
77+
invoice.validate_tier()
78+
with self.assertRaisesRegex(
79+
ValidationError, _("You are not allowed to write those fields")
80+
):
81+
invoice._post()
82+
# Calls _post method by passing context skip_validation_check set to True
83+
invoice.action_post()

0 commit comments

Comments
 (0)