Merge PR #1924 into 17.0

Signed-off-by rafaelbn
This commit is contained in:
OCA-git-bot
2024-08-20 18:09:44 +00:00
9 changed files with 104 additions and 31 deletions

View File

@@ -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",
],
}

View File

@@ -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 ""

View File

@@ -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."

View File

@@ -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,
)

View File

@@ -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)

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -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>