[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:
Jairo Llopis
2023-06-28 11:28:23 +01:00
parent 69d5ffe23f
commit ddb5d15f53
6 changed files with 133 additions and 34 deletions

View File

@@ -0,0 +1,44 @@
# Copyright 2023 Moduon Team S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
from odoo import SUPERUSER_ID, api, fields
def migrate(cr, version):
"""One journal sequence per company."""
env = api.Environment(cr, SUPERUSER_ID, {})
journals = env["account.journal"].search(
[
(
"entry_number_sequence_id.code",
"=",
"account_journal_general_sequence.default",
)
]
)
for journal in journals:
if journal.company_id != journal.entry_number_sequence_id.company_id:
new_sequence = env["ir.sequence"].search(
[
("code", "=", "account_journal_general_sequence.default"),
("company_id", "=", journal.company_id.id),
]
) or journal.entry_number_sequence_id.copy(
{
"company_id": journal.company_id.id,
"name": "{} ({})".format(
journal.entry_number_sequence_id.name, journal.company_id.name
),
"number_next_actual": journal.entry_number_sequence_id.number_next_actual,
"date_range_ids": [
fields.Command.create(
{
"date_from": rng.date_from,
"date_to": rng.date_to,
"number_next_actual": rng.number_next_actual,
}
)
for rng in journal.entry_number_sequence_id.date_range_ids
],
}
)
journal.entry_number_sequence_id = new_sequence