Newer
Older
##############################################################################
# Copyright © 2018, 2021 XCG Consulting <https://odoo.consulting/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
class AccountPeriod(models.Model):
"""Account period defined an accounting period.
This module aims to recreate the same behaviour as the account.period model from
previous versions of Odoo.
_name = "account.period"
_description = "Accounting period"
date_range_id = fields.Many2one(
string="Date Range",
comodel_name="date.range",
delegate=True,
ondelete="cascade",
index=True,
required=True,
)
date_cutoff = fields.Date(
"Optional cut-off date which helps force transaction dates and "
"this period for a few days after the end of this period."
def _get_date_effective_cutoff(self):
for period in self:
period.date_effective_cutoff = period.date_cutoff or period.date_end
date_effective_cutoff = fields.Date(
compute=_get_date_effective_cutoff,
string="Effective cut-off date",
help="The cut-off date when defined; the ending date otherwise.",
readonly=True,
store=True,
)
fiscal_year_id = fields.Many2one(
comodel_name="account.fiscal.year",
string="Fiscal year",
help="The fiscal year this period is in.",
ondelete="cascade",
required=True,
)
state = fields.Selection(
selection=[("draft", "Open"), ("done", "Closed")],
string="State",
default="draft",
def reopen_period(self):
"""Called by a button to re-open a closed period."""
self.ensure_one()
self.state = "draft"