forked from Vauxoo/account-financial-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] ir_sequence: Fix creating date_range_seq with range_month and r…
…ange_day More info about: - odoo/odoo#91019 TODO: Revert this commit after it is merged
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |