2021-09-07 00:42:41 +02:00
|
|
|
# Copyright 2021 Akretion France (http://www.akretion.com/)
|
|
|
|
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
2021-09-08 14:21:43 +02:00
|
|
|
from odoo import api, fields, models
|
2021-09-07 00:42:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AccountMove(models.Model):
|
|
|
|
_inherit = "account.move"
|
|
|
|
|
2021-09-08 14:21:43 +02:00
|
|
|
name = fields.Char(compute="_compute_name_by_sequence")
|
|
|
|
# highest_name, sequence_prefix and sequence_number are not needed any more
|
|
|
|
# -> compute=False to improve perf
|
|
|
|
highest_name = fields.Char(compute=False)
|
|
|
|
sequence_prefix = fields.Char(compute=False)
|
|
|
|
sequence_number = fields.Integer(compute=False)
|
|
|
|
|
|
|
|
@api.depends("state", "journal_id", "date")
|
|
|
|
def _compute_name_by_sequence(self):
|
|
|
|
for move in self:
|
|
|
|
name = move.name or "/"
|
|
|
|
# I can't use posted_before in this IF because
|
|
|
|
# posted_before is set to True in _post() at the same
|
|
|
|
# time as state is set to "posted"
|
2021-09-07 00:42:41 +02:00
|
|
|
if (
|
2021-09-08 14:21:43 +02:00
|
|
|
move.state == "posted"
|
|
|
|
and (not move.name or move.name == "/")
|
|
|
|
and move.journal_id
|
|
|
|
and move.journal_id.sequence_id
|
2021-09-07 00:42:41 +02:00
|
|
|
):
|
2021-09-08 14:21:43 +02:00
|
|
|
if (
|
|
|
|
move.move_type in ("out_refund", "in_refund")
|
|
|
|
and move.journal_id.type in ("sale", "purchase")
|
|
|
|
and move.journal_id.refund_sequence
|
|
|
|
and move.journal_id.refund_sequence_id
|
|
|
|
):
|
|
|
|
seq = move.journal_id.refund_sequence_id
|
|
|
|
else:
|
|
|
|
seq = move.journal_id.sequence_id
|
|
|
|
name = seq.next_by_id(sequence_date=move.date)
|
|
|
|
move.name = name
|
|
|
|
|
|
|
|
# We must by-pass this constraint of sequence.mixin
|
|
|
|
def _constrains_date_sequence(self):
|
|
|
|
return True
|