2019-06-28 22:05:16 +02:00
|
|
|
# Copyright 2009-2017 Noviat
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
from datetime import datetime
|
2020-01-29 18:34:31 +01:00
|
|
|
|
2019-06-28 22:05:16 +02:00
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
|
|
from odoo import api, models
|
|
|
|
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class AccountFiscalYear(models.Model):
|
2020-01-29 18:34:31 +01:00
|
|
|
_inherit = "account.fiscal.year"
|
2019-06-28 22:05:16 +02:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def create(self, vals):
|
2020-01-29 18:34:31 +01:00
|
|
|
date_from = datetime.strptime(vals.get("date_from"), "%Y-%m-%d")
|
|
|
|
date_to = datetime.strptime(vals.get("date_to"), "%Y-%m-%d")
|
2019-06-28 22:05:16 +02:00
|
|
|
if not date_to == date_from + relativedelta(years=1, days=-1):
|
|
|
|
recompute_vals = {
|
2020-01-29 18:34:31 +01:00
|
|
|
"reason": "creation of fiscalyear %s" % vals.get("name"),
|
|
|
|
"company_id": vals.get("company_id") or self.env.user.company_id.id,
|
|
|
|
"date_trigger": time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
|
|
|
"state": "open",
|
2019-06-28 22:05:16 +02:00
|
|
|
}
|
2020-01-29 18:34:31 +01:00
|
|
|
self.env["account.asset.recompute.trigger"].sudo().create(recompute_vals)
|
2019-06-28 22:05:16 +02:00
|
|
|
return super().create(vals)
|
|
|
|
|
|
|
|
def write(self, vals):
|
2020-01-29 18:34:31 +01:00
|
|
|
if vals.get("date_from") or vals.get("date_to"):
|
2019-06-28 22:05:16 +02:00
|
|
|
for fy in self:
|
|
|
|
recompute_vals = {
|
2020-01-29 18:34:31 +01:00
|
|
|
"reason": "duration change of fiscalyear %s" % fy.name,
|
|
|
|
"company_id": fy.company_id.id,
|
|
|
|
"date_trigger": time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
|
|
|
"state": "open",
|
2019-06-28 22:05:16 +02:00
|
|
|
}
|
2020-01-29 18:34:31 +01:00
|
|
|
self.env["account.asset.recompute.trigger"].sudo().create(
|
|
|
|
recompute_vals
|
|
|
|
)
|
2019-06-28 22:05:16 +02:00
|
|
|
return super().write(vals)
|