Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][17.0][IMP] account_fiscal_year add fields on res.company #1924

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions account_fiscal_year/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
}
12 changes: 10 additions & 2 deletions account_fiscal_year/i18n/account_fiscal_year.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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 ""
Expand Down
17 changes: 12 additions & 5 deletions account_fiscal_year/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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."
14 changes: 14 additions & 0 deletions account_fiscal_year/models/account_fiscal_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,17 @@ def _get_overlapping_domain(self):
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,
)
53 changes: 29 additions & 24 deletions account_fiscal_year/models/res_company.py
Original file line number Diff line number Diff line change
@@ -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()

Check warning on line 24 in account_fiscal_year/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

account_fiscal_year/models/res_company.py#L24

Added line #L24 was not covered by tests
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"]

Check warning on line 28 in account_fiscal_year/models/res_company.py

View check run for this annotation

Codecov / codecov/patch

account_fiscal_year/models/res_company.py#L26-L28

Added lines #L26 - L28 were not covered by tests

def compute_fiscalyear_dates(self, current_date):
"""Computes the start and end dates of the fiscal year
where the given 'date' belongs to.
Expand All @@ -20,15 +39,13 @@
"""
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,
Expand All @@ -51,25 +68,13 @@
# =>
# 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)

Expand Down
7 changes: 7 additions & 0 deletions account_fiscal_year/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions account_fiscal_year/views/res_company_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright (C) 2022 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>

<record id="res_company_view_tree" model="ir.ui.view">
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_tree" />
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="fiscal_year_date_from" optional="show" />
<field name="fiscal_year_date_to" optional="show" />
</field>
</field>
</record>

<record id="res_company_view_form" model="ir.ui.view">
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form" />
<field name="arch" type="xml">
<field name="currency_id" position="after">
<field name="fiscal_year_date_from" />
<field name="fiscal_year_date_to" />
</field>
</field>
</record>

</odoo>
Loading