2017-07-06 09:41:05 +02:00
|
|
|
# Copyright 2017 ACSONE SA/NV
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
from odoo import api, fields, models
|
|
|
|
from odoo.osv import expression
|
|
|
|
|
|
|
|
|
|
|
|
class AccountMove(models.Model):
|
|
|
|
|
2020-11-17 02:38:56 +01:00
|
|
|
_inherit = "account.move"
|
2017-07-06 09:41:05 +02:00
|
|
|
|
|
|
|
date_range_fm_id = fields.Many2one(
|
2020-11-17 02:38:56 +01:00
|
|
|
comodel_name="date.range",
|
|
|
|
string="Fiscal month",
|
|
|
|
compute="_compute_date_range_fm",
|
|
|
|
search="_search_date_range_fm",
|
2018-03-17 16:43:55 +01:00
|
|
|
)
|
2017-07-06 09:41:05 +02:00
|
|
|
|
2020-11-17 02:38:56 +01:00
|
|
|
@api.depends("date", "company_id")
|
2017-07-06 09:41:05 +02:00
|
|
|
def _compute_date_range_fm(self):
|
|
|
|
for rec in self:
|
|
|
|
date = rec.date
|
|
|
|
company = rec.company_id
|
2020-11-17 02:38:56 +01:00
|
|
|
rec.date_range_fm_id = company and company.find_daterange_fm(date) or False
|
2017-07-06 09:41:05 +02:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _search_date_range_fm(self, operator, value):
|
2020-11-17 02:38:56 +01:00
|
|
|
if operator in ("=", "!=", "in", "not in"):
|
|
|
|
date_range_domain = [("id", operator, value)]
|
2017-07-06 09:41:05 +02:00
|
|
|
else:
|
2020-11-17 02:38:56 +01:00
|
|
|
date_range_domain = [("name", operator, value)]
|
2017-07-06 09:41:05 +02:00
|
|
|
|
2020-11-17 02:38:56 +01:00
|
|
|
date_ranges = self.env["date.range"].search(date_range_domain)
|
2017-07-06 09:41:05 +02:00
|
|
|
domain = []
|
|
|
|
for date_range in date_ranges:
|
2020-11-17 02:38:56 +01:00
|
|
|
domain = expression.OR(
|
|
|
|
[
|
|
|
|
domain,
|
|
|
|
[
|
|
|
|
"&",
|
|
|
|
"&",
|
|
|
|
("date", ">=", date_range.date_start),
|
|
|
|
("date", "<=", date_range.date_end),
|
|
|
|
"|",
|
|
|
|
("company_id", "=", False),
|
|
|
|
("company_id", "=", date_range.company_id.id),
|
|
|
|
],
|
|
|
|
]
|
|
|
|
)
|
2017-07-06 09:41:05 +02:00
|
|
|
return domain
|