mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[FIX] account_journal_general_sequence: fix multicompany
Instead of defining the new sequence as a field default, it is now a compute. This is because the sequence depends on the company, but we don't have the `company_id` field until the record is created. Reduced the default number of padded zeroes to 8. This is a product decision. The original implementation didn't make much sense because it allowed the user to set a different sequence per journal, but Odoo already has that kind of sequence. The only purpose of this module is to have a sequence *per company*. To avoid breaking too much, for now, when the journal sequence is the default one, we set it as readonly. Limit the available sequences in the renumbering wizard. Display only those that you have access by your selected context companies. For some reason, Odoo doesn't filter sequences by company automatically. @moduon MT-3076 Co-authored-by: Andrea Cattalani <22261939+anddago78@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
from freezegun import freeze_time
|
||||
|
||||
from odoo.fields import Command
|
||||
from odoo.tests.common import Form, new_test_user, tagged, users
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
@@ -14,11 +15,18 @@ class RenumberCase(TestAccountReconciliationCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
companies = cls.company_data["company"] | cls.company_data_2["company"]
|
||||
cls.invoicer = new_test_user(
|
||||
cls.env, "test_invoicer", "account.group_account_invoice"
|
||||
cls.env,
|
||||
"test_invoicer",
|
||||
"account.group_account_invoice",
|
||||
company_ids=[Command.set(companies.ids)],
|
||||
)
|
||||
cls.manager = new_test_user(
|
||||
cls.env, "test_manager", "account.group_account_manager"
|
||||
cls.env,
|
||||
"test_manager",
|
||||
"account.group_account_manager",
|
||||
company_ids=[Command.set(companies.ids)],
|
||||
)
|
||||
|
||||
@users("test_invoicer")
|
||||
@@ -42,18 +50,22 @@ class RenumberCase(TestAccountReconciliationCommon):
|
||||
next_year_invoice = self._create_invoice(
|
||||
date_invoice="2023-12-31", auto_validate=True
|
||||
)
|
||||
next_year_invoice.flush(["entry_number"], next_year_invoice)
|
||||
next_year_invoice.flush_recordset(["entry_number"])
|
||||
new_invoice = self._create_invoice(
|
||||
date_invoice="2022-05-10", auto_validate=True
|
||||
)
|
||||
new_invoice.flush(["entry_number"], new_invoice)
|
||||
new_invoice.flush_recordset(["entry_number"])
|
||||
old_invoice = self._create_invoice(
|
||||
date_invoice="2022-04-30", auto_validate=True
|
||||
)
|
||||
old_invoice.flush(["entry_number"], old_invoice)
|
||||
old_invoice.flush_recordset(["entry_number"])
|
||||
self.assertLess(new_invoice.entry_number, old_invoice.entry_number)
|
||||
# Fix entry number order with wizard; default values are OK
|
||||
wiz_f = Form(self.env["account.move.renumber.wizard"])
|
||||
wiz_f = Form(
|
||||
self.env["account.move.renumber.wizard"].with_company(
|
||||
self.company_data["company"]
|
||||
)
|
||||
)
|
||||
self.assertEqual(len(wiz_f.available_sequence_ids), 1)
|
||||
wiz = wiz_f.save()
|
||||
wiz.action_renumber()
|
||||
@@ -67,10 +79,10 @@ class RenumberCase(TestAccountReconciliationCommon):
|
||||
wiz_f = Form(self.env["account.move.renumber.wizard"])
|
||||
wiz = wiz_f.save()
|
||||
wiz.action_renumber()
|
||||
self.assertEqual(opening_invoice.entry_number, "2022/0000000001")
|
||||
self.assertEqual(old_invoice.entry_number, "2022/0000000002")
|
||||
self.assertEqual(new_invoice.entry_number, "2022/0000000003")
|
||||
self.assertEqual(next_year_invoice.entry_number, "2023/0000000001")
|
||||
self.assertEqual(opening_invoice.entry_number, "2022/00000001")
|
||||
self.assertEqual(old_invoice.entry_number, "2022/00000002")
|
||||
self.assertEqual(new_invoice.entry_number, "2022/00000003")
|
||||
self.assertEqual(next_year_invoice.entry_number, "2023/00000001")
|
||||
|
||||
@users("test_invoicer")
|
||||
def test_install_no_entry_number(self):
|
||||
@@ -88,3 +100,21 @@ class RenumberCase(TestAccountReconciliationCommon):
|
||||
invoice.action_post()
|
||||
# Ensure there's no entry number
|
||||
self.assertFalse(invoice.entry_number)
|
||||
|
||||
@users("test_invoicer")
|
||||
def test_new_company_journal(self):
|
||||
# Create new companies
|
||||
cmp1 = self.company_data["company"]
|
||||
cmp2 = self.company_data_2["company"]
|
||||
# Create a new invoice for each company
|
||||
self.env = self.env(
|
||||
context=dict(self.env.context, allowed_company_ids=cmp1.ids)
|
||||
)
|
||||
invoice1 = self.create_invoice()
|
||||
self.env = self.env(
|
||||
context=dict(self.env.context, allowed_company_ids=cmp2.ids)
|
||||
)
|
||||
invoice2 = self.create_invoice()
|
||||
# Each company has a different sequence, so the entry number should be the same
|
||||
self.assertEqual(invoice1.entry_number, "2022/00000001")
|
||||
self.assertEqual(invoice2.entry_number, "2022/00000001")
|
||||
|
||||
Reference in New Issue
Block a user