Files
Odoo-18.0-20251222/account_sequence_option/models/account_move.py
tocmo0nlord adbe430761
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled
Initial commit: Odoo 18.0-20251222 extra-addons
2026-03-13 20:43:25 +00:00

72 lines
2.6 KiB
Python
Executable File

# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
class AccountMove(models.Model):
_inherit = "account.move"
sequence_option = fields.Boolean(
compute="_compute_sequence_option",
default=False,
copy=False,
store=True,
index=True,
)
@api.depends("posted_before", "state", "journal_id", "date")
def _compute_sequence_option(self):
if hasattr(self.env["account.journal"], "sequence_id"):
return
return self._compute_name()
@api.depends("posted_before", "state", "journal_id", "date")
def _compute_name(self):
options = self.env["ir.sequence.option.line"].get_model_options(self._name)
# On post, get the sequence option
if options:
for rec in self.filtered(
lambda x: x.name in (False, "/") and x.state == "posted"
):
sequence = self.env["ir.sequence.option.line"].get_sequence(
rec, options=options
)
if sequence:
rec.name = sequence.next_by_id(sequence_date=rec.date)
rec.sequence_option = True
# Call super()
res = super()._compute_name()
if options:
for rec in self:
# On create new, odoo may suggest the 1st new number, remove it.
if (
not rec.create_date
and rec.state == "draft"
and rec.name not in (False, "/")
):
rec.name = "/"
# On cancel/draft w/o number assigned yet,
# ensure no odoo number assigned.
if (
rec.create_date
and rec.state in ("draft", "cancel")
and rec.name not in (False, "/")
and not rec.sequence_option
):
rec.name = "/"
return res
# Bypass constrains if sequence is defined
def _constrains_date_sequence(self):
records = self.filtered(
lambda x: self.env["ir.sequence.option.line"].get_sequence(x)
)
return super(AccountMove, self - records)._constrains_date_sequence()
def _get_last_sequence_domain(self, relaxed=False):
(where_string, param) = super()._get_last_sequence_domain(relaxed=relaxed)
where_string += " AND coalesce(sequence_option, false) = false "
return where_string, param