2
0

[MIG] account_fiscal_year: Migration to 14.0

This commit is contained in:
SimoRubi 2020-11-05 17:10:00 +01:00 committed by Benoit Aimont
parent 97b2da9f45
commit c06c1bb456
17 changed files with 523 additions and 202 deletions

View File

@ -1,90 +0,0 @@
===================
Account Fiscal Year
===================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github
:target: https://github.com/OCA/account-financial-tools/tree/13.0/account_fiscal_year
:alt: OCA/account-financial-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-tools-13-0/account-financial-tools-13-0-account_fiscal_year
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/92/13.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module just adds the menu
Invoicing > Configuration > Accounting > Date ranges > Fiscal Years
This is totally refactored compared to 11 version, because odoo 12 introduced `account.fiscal.year` object.
See https://github.com/OCA/account-financial-tools/pull/706
**Table of contents**
.. contents::
:local:
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_fiscal_year%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Agile Business Group
* Camptocamp SA
Contributors
~~~~~~~~~~~~
* Damien Crier <damien.crier@camptocamp.com>
* Laurent Mignon <laurent.mignon@acsone.eu>
* Lorenzo Battistini <https://github.com/eLBati>
* Andrea Stirpe <a.stirpe@onestein.nl>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
.. |maintainer-eLBati| image:: https://github.com/eLBati.png?size=40px
:target: https://github.com/eLBati
:alt: eLBati
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-eLBati|
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/13.0/account_fiscal_year>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -1 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from . import models

View File

@ -1,19 +1,27 @@
# Copyright 2016 Camptocamp SA # Copyright 2016 Camptocamp SA
# Copyright 2018 Lorenzo Battistini <https://github.com/eLBati> # Copyright 2018 Lorenzo Battistini <https://github.com/eLBati>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). # Copyright 2020 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{ {
"name": "Account Fiscal Year", "name": "Account Fiscal Year",
"summary": "Create a menu for Account Fiscal Year", "summary": "Create Account Fiscal Year",
"version": "13.0.1.0.0", "version": "14.0.1.0.0",
"development_status": "Beta", "development_status": "Beta",
"category": "Accounting", "category": "Accounting",
"website": "https://github.com/OCA/account-financial-tools", "website": "https://github.com/OCA/account-financial-tools"
"14.0/account_fiscal_year",
"author": "Agile Business Group, Camptocamp SA, " "author": "Agile Business Group, Camptocamp SA, "
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"maintainers": ["eLBati"], "maintainers": ["eLBati"],
"license": "LGPL-3", "license": "AGPL-3",
"application": False, "depends": [
"installable": True, "account",
"depends": ["account", "date_range"], "date_range",
"data": ["data/date_range_type.xml", "views/account_views.xml"], ],
"data": [
"security/ir.model.access.csv",
"data/date_range_type.xml",
"views/account_fiscal_year_views.xml",
"views/account_views.xml",
],
} }

View File

@ -1,44 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_fiscal_year
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_type_action_accounting
msgid "Date Range Types"
msgstr ""
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_action_accounting
msgid "Date Ranges"
msgstr ""
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_accounting
msgid "Date ranges"
msgstr ""
#. module: account_fiscal_year
#: model:date.range.type,name:account_fiscal_year.fiscalyear
msgid "Fiscal Year"
msgstr ""
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_actions_account_fiscal_year
msgid "Fiscal Years"
msgstr ""
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_generator_action
msgid "Generate Date Ranges"
msgstr ""

View File

@ -4,17 +4,41 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n" "Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2018-12-24 16:58+0000\n" "POT-Creation-Date: 2020-11-06 09:43+0000\n"
"Last-Translator: Sergio Zanchetta <primes2h@gmail.com>\n" "PO-Revision-Date: 2020-11-06 09:43+0000\n"
"Language-Team: none\n" "Last-Translator: \n"
"Language: it\n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n" "Plural-Forms: \n"
"X-Generator: Weblate 3.3\n"
#. module: account_fiscal_year
#: model_terms:ir.actions.act_window,help:account_fiscal_year.actions_account_fiscal_year
msgid "Click here to create a new fiscal year."
msgstr "Clicca qui per creare un nuovo anno fiscale."
#. module: account_fiscal_year
#: model:ir.model,name:account_fiscal_year.model_res_company
msgid "Companies"
msgstr "Aziende"
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__company_id
msgid "Company"
msgstr "Azienda"
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__create_uid
msgid "Created by"
msgstr ""
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__create_date
msgid "Created on"
msgstr ""
#. module: account_fiscal_year #. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_type_action_accounting #: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_type_action_accounting
@ -31,13 +55,35 @@ msgstr "Intervalli data"
msgid "Date ranges" msgid "Date ranges"
msgstr "Intervalli data" msgstr "Intervalli data"
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__display_name
#: model:ir.model.fields,field_description:account_fiscal_year.field_res_company__display_name
msgid "Display Name"
msgstr "Nome visualizzato"
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__date_to
msgid "End Date"
msgstr "Data fine"
#. module: account_fiscal_year
#: model:ir.model.fields,help:account_fiscal_year.field_account_fiscal_year__date_to
msgid "Ending Date, included in the fiscal year."
msgstr "Data di chiusura, inclusa nell'anno fiscale."
#. module: account_fiscal_year #. module: account_fiscal_year
#: model:date.range.type,name:account_fiscal_year.fiscalyear #: model:date.range.type,name:account_fiscal_year.fiscalyear
#, fuzzy #: model:ir.model,name:account_fiscal_year.model_account_fiscal_year
msgid "Fiscal Year" msgid "Fiscal Year"
msgstr "Anni fiscali" msgstr "Anni fiscali"
#. module: account_fiscal_year #. module: account_fiscal_year
#: model_terms:ir.ui.view,arch_db:account_fiscal_year.account_fiscal_year_form_view
msgid "Fiscal Year 2020"
msgstr "Anno fiscale 2020"
#. module: account_fiscal_year
#: model:ir.actions.act_window,name:account_fiscal_year.actions_account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_actions_account_fiscal_year #: model:ir.ui.menu,name:account_fiscal_year.menu_actions_account_fiscal_year
msgid "Fiscal Years" msgid "Fiscal Years"
msgstr "Anni fiscali" msgstr "Anni fiscali"
@ -46,3 +92,56 @@ msgstr "Anni fiscali"
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_generator_action #: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_generator_action
msgid "Generate Date Ranges" msgid "Generate Date Ranges"
msgstr "Generazione intervalli data" msgstr "Generazione intervalli data"
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__id
#: model:ir.model.fields,field_description:account_fiscal_year.field_res_company__id
msgid "ID"
msgstr ""
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year____last_update
#: model:ir.model.fields,field_description:account_fiscal_year.field_res_company____last_update
msgid "Last Modified on"
msgstr "Ultima modifica il"
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__write_uid
msgid "Last Updated by"
msgstr ""
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__write_date
msgid "Last Updated on"
msgstr ""
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__name
msgid "Name"
msgstr "Nome"
#. module: account_fiscal_year
#: model:ir.model.fields,field_description:account_fiscal_year.field_account_fiscal_year__date_from
msgid "Start Date"
msgstr "Data inizio"
#. module: account_fiscal_year
#: model:ir.model.fields,help:account_fiscal_year.field_account_fiscal_year__date_from
msgid "Start Date, included in the fiscal year."
msgstr "Data inizio, inclusa nell'anno fiscale."
#. module: account_fiscal_year
#: code:addons/account_fiscal_year/models/account_fiscal_year.py:0
#, python-format
msgid "The ending date must not be prior to the starting date."
msgstr "La data di fine non deve essere antecedente a quella di inizio."
#. module: account_fiscal_year
#: code:addons/account_fiscal_year/models/account_fiscal_year.py:0
#, python-format
msgid ""
"This fiscal year '{fy}' overlaps with '{overlapping_fy}'.\n"
"Please correct the start and/or end dates of your fiscal years."
msgstr ""
"Questo anno fiscale '{fy}' si sovrappone a '{overlapping_fy}'.\n"
"Correggere le relative date di inizio e/o di fine."

View File

@ -1,47 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_fiscal_year
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2019-08-21 12:44+0000\n"
"Last-Translator: Yung-Wa <yw.ng@onestein.nl>\n"
"Language-Team: none\n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 3.7.1\n"
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_type_action_accounting
msgid "Date Range Types"
msgstr "Datumreek types"
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_action_accounting
msgid "Date Ranges"
msgstr "Datumreeksen"
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_accounting
msgid "Date ranges"
msgstr "Datumreeksen"
#. module: account_fiscal_year
#: model:date.range.type,name:account_fiscal_year.fiscalyear
msgid "Fiscal Year"
msgstr "Fiscaal jaar"
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_actions_account_fiscal_year
msgid "Fiscal Years"
msgstr "Fiscale jaren"
#. module: account_fiscal_year
#: model:ir.ui.menu,name:account_fiscal_year.menu_date_range_generator_action
msgid "Generate Date Ranges"
msgstr "Genereer datumreeksen"

View File

@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import account_fiscal_year
from . import res_company

View File

@ -0,0 +1,111 @@
# Copyright 2020 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.osv import expression
class AccountFiscalYear(models.Model):
_name = "account.fiscal.year"
_description = "Fiscal Year"
_rec_name = "name"
name = fields.Char(
string="Name",
required=True,
)
date_from = fields.Date(
string="Start Date",
required=True,
help="Start Date, included in the fiscal year.",
)
date_to = fields.Date(
string="End Date",
required=True,
help="Ending Date, included in the fiscal year.",
)
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
required=True,
default=lambda self: self.env.company,
)
@api.constrains("date_from", "date_to", "company_id")
def _check_dates(self):
"""Check intersection with existing fiscal years."""
for fy in self:
# Starting date must be prior to the ending date
date_from = fy.date_from
date_to = fy.date_to
if date_to < date_from:
raise ValidationError(
_("The ending date must not be prior to the starting date.")
)
domain = fy._get_overlapping_domain()
overlapping_fy = self.search(domain, limit=1)
if overlapping_fy:
raise ValidationError(
_(
"This fiscal year '{fy}' "
"overlaps with '{overlapping_fy}'.\n"
"Please correct the start and/or end dates "
"of your fiscal years."
).format(
fy=fy.display_name,
overlapping_fy=overlapping_fy.display_name,
)
)
def _get_overlapping_domain(self):
"""Get domain for finding fiscal years overlapping with self.
The domain will search only among fiscal years of this company.
"""
self.ensure_one()
# Compare with other fiscal years defined for this company
company_domain = [
("id", "!=", self.id),
("company_id", "=", self.company_id.id),
]
date_from = self.date_from
date_to = self.date_to
# Search fiscal years intersecting with current fiscal year.
# This fiscal year's `from` is contained in another fiscal year
# other.from <= fy.from <= other.to
intersection_domain_from = [
"&",
("date_from", "<=", date_from),
("date_to", ">=", date_from),
]
# This fiscal year's `to` is contained in another fiscal year
# other.from <= fy.to <= other.to
intersection_domain_to = [
"&",
("date_from", "<=", date_to),
("date_to", ">=", date_to),
]
# This fiscal year completely contains another fiscal year
# fy.from <= other.from (or other.to) <= fy.to
intersection_domain_contain = [
"&",
("date_from", ">=", date_from),
("date_from", "<=", date_to),
]
intersection_domain = expression.OR(
[
intersection_domain_from,
intersection_domain_to,
intersection_domain_contain,
]
)
return expression.AND(
[
company_domain,
intersection_domain,
]
)

View File

@ -0,0 +1,82 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import timedelta
from odoo import models
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, date_utils
class ResCompany(models.Model):
_inherit = "res.company"
def compute_fiscalyear_dates(self, current_date):
"""Computes the start and end dates of the fiscal year
where the given 'date' belongs to.
:param current_date: A datetime.date/datetime.datetime object.
:return: A dictionary containing:
* date_from
* date_to
* [Optionally] record: The fiscal year record.
"""
self.ensure_one()
date_str = current_date.strftime(DEFAULT_SERVER_DATE_FORMAT)
# Search a fiscal year record containing the date.
fiscalyear = self.env["account.fiscal.year"].search(
[
("company_id", "=", self.id),
("date_from", "<=", date_str),
("date_to", ">=", date_str),
],
limit=1,
)
if fiscalyear:
return {
"date_from": fiscalyear.date_from,
"date_to": fiscalyear.date_to,
"record": fiscalyear,
}
date_from, date_to = date_utils.get_fiscal_year(
current_date,
day=self.fiscalyear_last_day,
month=int(self.fiscalyear_last_month),
)
# Search for fiscal year records reducing
# the delta between the date_from/date_to.
# This case could happen if there is a gap
# between two fiscal year records.
# E.g. two fiscal year records:
# 2017-01-01 -> 2017-02-01 and 2017-03-01 -> 2017-12-31.
# =>
# The period 2017-02-02 - 2017-02-30 is not covered by a fiscal year record.
date_from_str = date_from.strftime(DEFAULT_SERVER_DATE_FORMAT)
fiscalyear_from = self.env["account.fiscal.year"].search(
[
("company_id", "=", self.id),
("date_from", "<=", date_from_str),
("date_to", ">=", date_from_str),
],
limit=1,
)
if fiscalyear_from:
date_from = fiscalyear_from.date_to + timedelta(days=1)
date_to_str = date_to.strftime(DEFAULT_SERVER_DATE_FORMAT)
fiscalyear_to = self.env["account.fiscal.year"].search(
[
("company_id", "=", self.id),
("date_from", "<=", date_to_str),
("date_to", ">=", date_to_str),
],
limit=1,
)
if fiscalyear_to:
date_to = fiscalyear_to.date_from - timedelta(days=1)
return {
"date_from": date_from,
"date_to": date_to,
}

View File

@ -2,3 +2,4 @@
* Laurent Mignon <laurent.mignon@acsone.eu> * Laurent Mignon <laurent.mignon@acsone.eu>
* Lorenzo Battistini <https://github.com/eLBati> * Lorenzo Battistini <https://github.com/eLBati>
* Andrea Stirpe <a.stirpe@onestein.nl> * Andrea Stirpe <a.stirpe@onestein.nl>
* Simone Rubino <simone.rubino@agilebg.com>

View File

@ -1,6 +1,5 @@
This module just adds the menu This module allows to create and edit fiscal years from the menu:
Invoicing > Configuration > Accounting > Date ranges > Fiscal Years Invoicing > Configuration > Accounting > Date ranges > Fiscal Years
This is totally refactored compared to 11 version, because odoo 12 introduced `account.fiscal.year` object. A new type of date range 'Fiscal year' is also included.
See https://github.com/OCA/account-financial-tools/pull/706

View File

@ -0,0 +1 @@
The account.fiscal.year model definition and views come from the core of Odoo v13 community because in v14, account.fiscal.year has been moved to Odoo enterprise.

View File

@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_account_fiscal_year_user,account.fiscal.year.user,model_account_fiscal_year,account.group_account_user,1,0,0,0
access_account_fiscal_year_manager,account.fiscal.year.manager,model_account_fiscal_year,account.group_account_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_account_fiscal_year_user account.fiscal.year.user model_account_fiscal_year account.group_account_user 1 0 0 0
3 access_account_fiscal_year_manager account.fiscal.year.manager model_account_fiscal_year account.group_account_manager 1 1 1 1

View File

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_account_fiscal_year

View File

@ -0,0 +1,132 @@
from odoo import fields
from odoo.tests import SavepointCase
class TestFiscalPosition(SavepointCase):
def check_compute_fiscal_year(
self, company, date, expected_date_from, expected_date_to
):
"""Compute the fiscal year at a certain date for the company
passed as parameter.
Then, check if the result matches the
'expected_date_from'/'expected_date_to' dates.
:param company: The company.
:param date: The date belonging to the fiscal year.
:param expected_date_from: The expected date_from after computation.
:param expected_date_to: The expected date_to after computation.
"""
current_date = fields.Date.from_string(date)
res = company.compute_fiscalyear_dates(current_date)
self.assertEqual(res["date_from"], fields.Date.from_string(expected_date_from))
self.assertEqual(res["date_to"], fields.Date.from_string(expected_date_to))
def test_default_fiscal_year(self):
"""Basic case with a fiscal year xxxx-01-01 - xxxx-12-31."""
company = self.env.ref("base.main_company")
company.fiscalyear_last_day = 31
company.fiscalyear_last_month = "12"
self.check_compute_fiscal_year(
company,
"2017-12-31",
"2017-01-01",
"2017-12-31",
)
self.check_compute_fiscal_year(
company,
"2017-01-01",
"2017-01-01",
"2017-12-31",
)
def test_leap_fiscal_year_1(self):
"""Case with a leap year ending the 29 February."""
company = self.env.ref("base.main_company")
company.fiscalyear_last_day = 29
company.fiscalyear_last_month = "2"
self.check_compute_fiscal_year(
company,
"2016-02-29",
"2015-03-01",
"2016-02-29",
)
self.check_compute_fiscal_year(
company,
"2015-03-01",
"2015-03-01",
"2016-02-29",
)
def test_leap_fiscal_year_2(self):
"""Case with a leap year ending the 28 February."""
company = self.env.ref("base.main_company")
company.fiscalyear_last_day = 28
company.fiscalyear_last_month = "2"
self.check_compute_fiscal_year(
company,
"2016-02-29",
"2015-03-01",
"2016-02-29",
)
self.check_compute_fiscal_year(
company,
"2016-03-01",
"2016-03-01",
"2017-02-28",
)
def test_custom_fiscal_year(self):
"""Case with custom fiscal years."""
company = self.env.ref("base.main_company")
company.fiscalyear_last_day = 31
company.fiscalyear_last_month = "12"
# Create custom fiscal year covering the 6 first months of 2017.
self.env["account.fiscal.year"].create(
{
"name": "6 month 2017",
"date_from": "2017-01-01",
"date_to": "2017-05-31",
"company_id": company.id,
}
)
# Check before the custom fiscal year).
self.check_compute_fiscal_year(
company,
"2017-02-01",
"2017-01-01",
"2017-05-31",
)
# Check after the custom fiscal year.
self.check_compute_fiscal_year(
company,
"2017-11-01",
"2017-06-01",
"2017-12-31",
)
# Create custom fiscal year covering the 3 last months of 2017.
self.env["account.fiscal.year"].create(
{
"name": "last 3 month 2017",
"date_from": "2017-10-01",
"date_to": "2017-12-31",
"company_id": company.id,
}
)
# Check inside the custom fiscal years.
self.check_compute_fiscal_year(
company,
"2017-07-01",
"2017-06-01",
"2017-09-30",
)

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
~ Copyright 2020 Simone Rubino - Agile Business Group
~ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="account_fiscal_year_form_view" model="ir.ui.view">
<field name="name">Form view for account.fiscal.year</field>
<field name="model">account.fiscal.year</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name" placeholder="Fiscal Year 2020" />
<field name="date_from" />
<field name="date_to" />
<field name="company_id" groups="base.group_multi_company" />
</group>
</sheet>
</form>
</field>
</record>
<record id="account_fiscal_year_search_view" model="ir.ui.view">
<field name="name">Search view for account.fiscal.year</field>
<field name="model">account.fiscal.year</field>
<field name="arch" type="xml">
<search>
<field name="name" />
</search>
</field>
</record>
<record id="account_fiscal_year_tree_view" model="ir.ui.view">
<field name="name">Tree view for account.fiscal.year</field>
<field name="model">account.fiscal.year</field>
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="date_from" />
<field name="date_to" />
<field name="company_id" groups="base.group_multi_company" />
</tree>
</field>
</record>
<record id="actions_account_fiscal_year" model="ir.actions.act_window">
<field name="name">Fiscal Years</field>
<field name="res_model">account.fiscal.year</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click here to create a new fiscal year.
</p>
</field>
</record>
</odoo>

View File

@ -8,7 +8,7 @@
/> />
<menuitem <menuitem
id="menu_actions_account_fiscal_year" id="menu_actions_account_fiscal_year"
action="account.actions_account_fiscal_year" action="actions_account_fiscal_year"
parent="menu_date_range_accounting" parent="menu_date_range_accounting"
/> />
<menuitem <menuitem