Skip to content

Commit

Permalink
[FIX] ir_sequence: Fix creating date_range_seq with range_month and r…
Browse files Browse the repository at this point in the history
…ange_day

More info about:
 - odoo/odoo#91019

TODO: Revert this commit after it is merged
  • Loading branch information
moylop260 authored and frahikLV committed May 26, 2022
1 parent c23129b commit b5cbca9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions account_move_name_sequence/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import account_journal
from . import account_move
from . import ir_sequence
58 changes: 58 additions & 0 deletions account_move_name_sequence/models/ir_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from dateutil.relativedelta import relativedelta

from odoo import fields, models


class IrSequence(models.Model):
_inherit = "ir.sequence"

def _create_date_range_seq(self, date):
# Fix issue creating new date range for future dates
# It assigns more than one month
# TODO: Remove if odoo merge the following PR:
# https://github.com/odoo/odoo/pull/91019
date_obj = fields.Date.from_string(date)
prefix_suffix = "%s %s" % (self.prefix, self.suffix)
if "%(range_day)s" in prefix_suffix:
date_from = date_obj
date_to = date_obj
elif "%(range_month)s" in prefix_suffix:
date_from = date_obj + relativedelta(day=1)
date_to = date_obj + relativedelta(day=31)
else:
date_from = date_obj + relativedelta(day=1, month=1)
date_to = date_obj + relativedelta(day=31, month=12)
date_range = self.env["ir.sequence.date_range"].search(
[
("sequence_id", "=", self.id),
("date_from", ">=", date),
("date_from", "<=", date_to),
],
order="date_from desc",
limit=1,
)
if date_range:
date_to = date_range.date_from + relativedelta(days=-1)
date_range = self.env["ir.sequence.date_range"].search(
[
("sequence_id", "=", self.id),
("date_to", ">=", date_from),
("date_to", "<=", date),
],
order="date_to desc",
limit=1,
)
if date_range:
date_from = date_range.date_to + relativedelta(days=1)
seq_date_range = (
self.env["ir.sequence.date_range"]
.sudo()
.create(
{
"date_from": date_from,
"date_to": date_to,
"sequence_id": self.id,
}
)
)
return seq_date_range

0 comments on commit b5cbca9

Please sign in to comment.