2
0
account-financial-tools/account_journal_general_sequence/models/account_journal.py
Jairo Llopis ddb5d15f53
[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>
2023-06-28 11:28:23 +01:00

53 lines
1.9 KiB
Python

# Copyright 2022 Moduon
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
import logging
from odoo import _, api, fields, models
_logger = logging.getLogger(__name__)
class AccountJournal(models.Model):
_inherit = "account.journal"
entry_number_sequence_id = fields.Many2one(
comodel_name="ir.sequence",
string="Account entry number sequence",
compute="_compute_entry_number_sequence",
domain="[('company_id', '=', company_id)]",
check_company=True,
readonly=False,
store=True,
copy=False,
help="Sequence used for account entry numbering.",
)
entry_number_sequence_id_name = fields.Char(related="entry_number_sequence_id.code")
@api.depends("company_id")
def _compute_entry_number_sequence(self):
"""Get the default sequence for all journals."""
for one in self:
sequence = self.env["ir.sequence"].search(
[
("code", "=", "account_journal_general_sequence.default"),
("company_id", "=", one.company_id.id),
]
)
if not sequence:
_logger.info("Creating default sequence for account move numbers")
sequence = self.env["ir.sequence"].create(
{
"name": _(
"Account entry default numbering (%s)",
one.company_id.name,
),
"code": "account_journal_general_sequence.default",
"company_id": one.company_id.id,
"implementation": "no_gap",
"prefix": "%(range_year)s/",
"padding": 8,
"use_date_range": True,
}
)
one.entry_number_sequence_id = sequence