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,7 +2,7 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
import logging
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -13,27 +13,40 @@ class AccountJournal(models.Model):
|
||||
entry_number_sequence_id = fields.Many2one(
|
||||
comodel_name="ir.sequence",
|
||||
string="Account entry number sequence",
|
||||
default=lambda self: self._default_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")
|
||||
|
||||
def _default_entry_number_sequence(self):
|
||||
@api.depends("company_id")
|
||||
def _compute_entry_number_sequence(self):
|
||||
"""Get the default sequence for all journals."""
|
||||
result = self.env["ir.sequence"].search(
|
||||
[("code", "=", "account_journal_general_sequence.default")]
|
||||
)
|
||||
if result:
|
||||
return result
|
||||
_logger.info("Creating default sequence for account move numbers")
|
||||
result = self.env["ir.sequence"].create(
|
||||
{
|
||||
"name": _("Account entry default numbering"),
|
||||
"code": "account_journal_general_sequence.default",
|
||||
"implementation": "no_gap",
|
||||
"prefix": "%(range_year)s/",
|
||||
"padding": 10,
|
||||
"use_date_range": True,
|
||||
}
|
||||
)
|
||||
return result
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user