Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] account_move_tier_validation: Pass context to allow confirming moves with tier validation #1703

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions account_move_tier_validation/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ def _get_to_validate_message_name(self):
elif self.move_type == "out_refund":
name = _("Credit Note")
return name

def action_post(self):
return super(
AccountMove, self.with_context(skip_validation_check=True)
).action_post()
55 changes: 55 additions & 0 deletions account_move_tier_validation/tests/test_tier_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2018 ForgeFlow S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from odoo import _, fields
from odoo.exceptions import ValidationError
from odoo.tests import common
from odoo.tests.common import tagged

Expand All @@ -26,3 +28,56 @@ def test_02_form(self):
) as form:
form.save()
self.assertTrue(form.hide_post_button)

def test_03_move_post(self):
group_ids = [
self.env.ref("base.group_system").id,
self.env.ref("account.group_account_manager").id,
]
self.test_user_1 = self.env["res.users"].create(
{
"name": "John",
"login": "test1",
"email": "[email protected]",
"groups_id": [(6, 0, group_ids)],
}
)
self.test_user_2 = self.env["res.users"].create(
{
"name": "Mike",
"login": "test2",
"email": "[email protected]",
"groups_id": [(6, 0, group_ids)],
}
)
self.env["tier.definition"].create(
{
"model_id": self.env["ir.model"]
.search([("model", "=", "account.move")])
.id,
"definition_domain": "[('move_type', '=', 'out_invoice')]",
"reviewer_id": self.test_user_1.id,
}
)
partner = self.env["res.partner"].create({"name": "Test Partner"})
product = self.env["product.product"].create({"name": "Test product"})
invoice = self.env["account.move"].create(
{
"move_type": "out_invoice",
"partner_id": partner.id,
"invoice_date_due": fields.Date.from_string("2024-01-01"),
"invoice_line_ids": [
(0, 0, {"product_id": product.id, "quantity": 1, "price_unit": 30})
],
}
)
invoice.with_user(self.test_user_2.id).request_validation()
invoice = invoice.with_user(self.test_user_1.id)
invoice.invalidate_model()
invoice.validate_tier()
with self.assertRaisesRegex(
ValidationError, _("You are not allowed to write those fields")
):
invoice._post()
# Calls _post method by passing context skip_validation_check set to True
invoice.action_post()
Loading