Skip to content

Commit

Permalink
[FIX] account_move_tier_validation: Pass context to allow confirming …
Browse files Browse the repository at this point in the history
…moves with tier validation

Added tests for changes

Updated error to be checked in tests

Updated error to be checked in tests
  • Loading branch information
ByteMeAsap committed Aug 22, 2024
1 parent b195bf4 commit cf44d37
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
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()

0 comments on commit cf44d37

Please sign in to comment.