diff --git a/account_fiscal_year/__manifest__.py b/account_fiscal_year/__manifest__.py index 1b48526c3..7c89a0e3d 100644 --- a/account_fiscal_year/__manifest__.py +++ b/account_fiscal_year/__manifest__.py @@ -20,5 +20,6 @@ "security/ir.model.access.csv", "security/account_fiscal_year_rule.xml", "views/account_fiscal_year_views.xml", + "views/res_company_views.xml", ], } diff --git a/account_fiscal_year/i18n/account_fiscal_year.pot b/account_fiscal_year/i18n/account_fiscal_year.pot index 139a36190..9e58e58f7 100644 --- a/account_fiscal_year/i18n/account_fiscal_year.pot +++ b/account_fiscal_year/i18n/account_fiscal_year.pot @@ -48,6 +48,11 @@ msgstr "" msgid "End Date" msgstr "" +#. module: account_fiscal_year +#: model:ir.model.fields,field_description:account_fiscal_year.field_res_company__fiscal_year_date_to +msgid "End Date of the Fiscal Year" +msgstr "" + #. 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." @@ -94,20 +99,23 @@ msgstr "" msgid "Start Date" msgstr "" +#. module: account_fiscal_year +#: model:ir.model.fields,field_description:account_fiscal_year.field_res_company__fiscal_year_date_from +msgid "Start Date of the Fiscal Year" +msgstr "" + #. 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 "" #. module: account_fiscal_year -#. odoo-python #: 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 "" #. module: account_fiscal_year -#. odoo-python #: code:addons/account_fiscal_year/models/account_fiscal_year.py:0 #, python-format msgid "" diff --git a/account_fiscal_year/i18n/fr.po b/account_fiscal_year/i18n/fr.po index e87acf87a..e2a359ff4 100644 --- a/account_fiscal_year/i18n/fr.po +++ b/account_fiscal_year/i18n/fr.po @@ -51,6 +51,11 @@ msgstr "Nom affiché" msgid "End Date" msgstr "Date de fin" +#. module: account_fiscal_year +#: model:ir.model.fields,field_description:account_fiscal_year.field_res_company__fiscal_year_date_to +msgid "End Date of the fiscal year" +msgstr "Date de fin d'exercice" + #. 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." @@ -97,26 +102,28 @@ msgstr "Nom" msgid "Start Date" msgstr "Date de début" +#. module: account_fiscal_year +#: model:ir.model.fields,field_description:account_fiscal_year.field_res_company__fiscal_year_date_from +msgid "Start Date of the fiscal year" +msgstr "Date de début d'exercice" + #. 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 "Date de début, incluse dans l'exercice." #. module: account_fiscal_year -#. odoo-python #: 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 date de début doit précéder la date de fin." #. module: account_fiscal_year -#. odoo-python #: 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 "" - -#~ msgid "Last Modified on" -#~ msgstr "Dernière modification le" +"L'exercice '{fy}' chevauche avec '{overlapping_fy}'.\n" +"Veuillez modifier les dates de début et de fin." diff --git a/account_fiscal_year/models/account_fiscal_year.py b/account_fiscal_year/models/account_fiscal_year.py index 9054f79ee..f6e891e77 100644 --- a/account_fiscal_year/models/account_fiscal_year.py +++ b/account_fiscal_year/models/account_fiscal_year.py @@ -107,3 +107,17 @@ class AccountFiscalYear(models.Model): intersection_domain, ] ) + + @api.model + def _get_fiscal_year(self, company, date_from, date_to): + """Return a fiscal year for the given company + that contains the two dates. (or False if no fiscal years) + matches the selection""" + return self.search( + [ + ("company_id", "=", company.id), + ("date_from", "<=", date_from), + ("date_to", ">=", date_to), + ], + limit=1, + ) diff --git a/account_fiscal_year/models/res_company.py b/account_fiscal_year/models/res_company.py index cc5e2ac6c..d87969e57 100644 --- a/account_fiscal_year/models/res_company.py +++ b/account_fiscal_year/models/res_company.py @@ -1,13 +1,32 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from datetime import timedelta -from odoo import models +from odoo import fields, models from odoo.tools import date_utils class ResCompany(models.Model): _inherit = "res.company" + fiscal_year_date_from = fields.Date( + string="Start Date of the Fiscal Year", + compute="_compute_fiscal_year_dates", + compute_sudo=True, + ) + + fiscal_year_date_to = fields.Date( + string="End Date of the Fiscal Year", + compute="_compute_fiscal_year_dates", + compute_sudo=True, + ) + + def _compute_fiscal_year_dates(self): + today = fields.Date.today() + for company in self: + res = company.compute_fiscalyear_dates(today) + company.fiscal_year_date_from = res["date_from"] + company.fiscal_year_date_to = res["date_to"] + def compute_fiscalyear_dates(self, current_date): """Computes the start and end dates of the fiscal year where the given 'date' belongs to. @@ -20,15 +39,13 @@ class ResCompany(models.Model): """ self.ensure_one() + AccountFiscalYear = self.env["account.fiscal.year"] + # Search a fiscal year record containing the date. - fiscalyear = self.env["account.fiscal.year"].search( - [ - ("company_id", "=", self.id), - ("date_from", "<=", current_date), - ("date_to", ">=", current_date), - ], - limit=1, + fiscalyear = AccountFiscalYear._get_fiscal_year( + self, current_date, current_date ) + if fiscalyear: return { "date_from": fiscalyear.date_from, @@ -51,25 +68,13 @@ class ResCompany(models.Model): # => # The period 2017-02-02 - 2017-02-30 is not covered by a fiscal year record. - fiscalyear_from = self.env["account.fiscal.year"].search( - [ - ("company_id", "=", self.id), - ("date_from", "<=", date_from), - ("date_to", ">=", date_from), - ], - limit=1, - ) + fiscalyear_from = AccountFiscalYear._get_fiscal_year(self, date_from, date_from) + if fiscalyear_from: date_from = fiscalyear_from.date_to + timedelta(days=1) - fiscalyear_to = self.env["account.fiscal.year"].search( - [ - ("company_id", "=", self.id), - ("date_from", "<=", date_to), - ("date_to", ">=", date_to), - ], - limit=1, - ) + fiscalyear_to = AccountFiscalYear._get_fiscal_year(self, date_to, date_to) + if fiscalyear_to: date_to = fiscalyear_to.date_from - timedelta(days=1) diff --git a/account_fiscal_year/readme/DESCRIPTION.md b/account_fiscal_year/readme/DESCRIPTION.md index 54e7fdadd..122d32854 100644 --- a/account_fiscal_year/readme/DESCRIPTION.md +++ b/account_fiscal_year/readme/DESCRIPTION.md @@ -1,3 +1,10 @@ This module allows to create and edit fiscal years from the menu: Invoicing \> Configuration \> Accounting \> Fiscal Years + +.. figure:: static/description/account_fiscal_year_form.png + +The start and end dates of the current fiscal years are then available +in the company tree and form views. + +.. figure:: static/description/res_company_tree.png diff --git a/account_fiscal_year/static/description/account_fiscal_year_form.png b/account_fiscal_year/static/description/account_fiscal_year_form.png new file mode 100644 index 000000000..66b73adfc Binary files /dev/null and b/account_fiscal_year/static/description/account_fiscal_year_form.png differ diff --git a/account_fiscal_year/static/description/res_company_tree.png b/account_fiscal_year/static/description/res_company_tree.png new file mode 100644 index 000000000..8ef400db5 Binary files /dev/null and b/account_fiscal_year/static/description/res_company_tree.png differ diff --git a/account_fiscal_year/views/res_company_views.xml b/account_fiscal_year/views/res_company_views.xml new file mode 100644 index 000000000..76fdcb437 --- /dev/null +++ b/account_fiscal_year/views/res_company_views.xml @@ -0,0 +1,31 @@ + + + + + + res.company + + + + + + + + + + + res.company + + + + + + + + + +