2
0

[FIX] account_journal_general_sequence: let non-admin accounting managers renumber moves

Before this patch, if users were accounting managers but not system administrators, they couldn't execute the account move renumbering.

Now that's fixed and tested.

@moduon MT-1728
This commit is contained in:
Jairo Llopis 2022-12-15 10:01:15 +00:00
parent 731c687a01
commit 9cf19e12a4
No known key found for this signature in database
GPG Key ID: E47E3BE44B940490
2 changed files with 14 additions and 4 deletions

View File

@ -2,7 +2,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from freezegun import freeze_time from freezegun import freeze_time
from odoo.tests.common import Form, tagged from odoo.tests.common import Form, new_test_user, tagged, users
from odoo.tools import mute_logger from odoo.tools import mute_logger
from odoo.addons.account.tests.common import TestAccountReconciliationCommon from odoo.addons.account.tests.common import TestAccountReconciliationCommon
@ -14,7 +14,14 @@ class RenumberCase(TestAccountReconciliationCommon):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
cls.invoicer = new_test_user(
cls.env, "test_invoicer", "account.group_account_invoice"
)
cls.manager = new_test_user(
cls.env, "test_manager", "account.group_account_manager"
)
@users("test_invoicer")
def test_invoice_gets_entry_number(self): def test_invoice_gets_entry_number(self):
# Draft invoice without entry number # Draft invoice without entry number
invoice = self._create_invoice() invoice = self._create_invoice()
@ -29,6 +36,7 @@ class RenumberCase(TestAccountReconciliationCommon):
invoice.button_cancel() invoice.button_cancel()
self.assertFalse(invoice.entry_number) self.assertFalse(invoice.entry_number)
@users("test_manager")
def test_renumber(self): def test_renumber(self):
# Post invoices in wrong order # Post invoices in wrong order
new_invoice = self._create_invoice( new_invoice = self._create_invoice(
@ -56,13 +64,14 @@ class RenumberCase(TestAccountReconciliationCommon):
wiz.action_renumber() wiz.action_renumber()
self.assertEqual(opening_invoice.entry_number, "2022/0000000000") self.assertEqual(opening_invoice.entry_number, "2022/0000000000")
@users("test_invoicer")
def test_install_no_entry_number(self): def test_install_no_entry_number(self):
"""No entry numbers assigned on module installation.""" """No entry numbers assigned on module installation."""
# Imitate installation environment # Imitate installation environment
self.env = self.env( self.env = self.env(
context=dict(self.env.context, module="account_journal_general_sequence") context=dict(self.env.context, module="account_journal_general_sequence")
) )
self.env["ir.module.module"].search( self.env["ir.module.module"].sudo().search(
[("name", "=", "account_journal_general_sequence")] [("name", "=", "account_journal_general_sequence")]
).state = "to install" ).state = "to install"
# Do some action that would make the move get an entry number # Do some action that would make the move get an entry number

View File

@ -74,8 +74,9 @@ class AccountMoveRenumberWizard(models.TransientModel):
) )
future_ranges.unlink() future_ranges.unlink()
current_range = self.sequence_id._get_current_sequence(self.starting_date) current_range = self.sequence_id._get_current_sequence(self.starting_date)
current_range.number_next = self.starting_number # Safe `sudo`; wizard only available for accounting managers
self.sequence_id.number_next = self.starting_number current_range.sudo().number_next = self.starting_number
self.sequence_id.sudo().number_next = self.starting_number
# Renumber the moves # Renumber the moves
moves.entry_number = False moves.entry_number = False
moves.flush(["entry_number"]) moves.flush(["entry_number"])