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

[14.0][MIG] account_fiscal_year #1081

Merged
merged 26 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
705ea3a
[ADD] add module "account_fiscal_year"
damdam-s Apr 27, 2016
09b9db8
[FIX] Tests
lmignon Apr 28, 2016
9c7b415
[FIX*IMP] account_fiscal_year
damdam-s Apr 28, 2016
76de755
OCA Transbot updated translations from Transifex
oca-transbot May 14, 2016
4814c92
[10.0][MIGRATION] Migrated module 'account_fiscal_year' to V10 (#407)
espo-tony Oct 11, 2016
bb671c8
OCA Transbot updated translations from Transifex
oca-transbot Nov 24, 2016
01acd35
[MIG] account_fiscal_year: Migration to 11.
TDu Nov 13, 2017
5421dcc
OCA Transbot updated translations from Transifex
oca-transbot Dec 22, 2017
cb95046
Added translation using Weblate (Arabic)
osoul Jun 29, 2018
cea7901
OCA Transbot updated translations from Transifex
oca-transbot Dec 1, 2017
5da91c4
Added translation using Weblate (Danish)
hhgabelgaard Sep 5, 2018
016cdd5
[UPD] Update account_fiscal_year.pot
oca-travis Nov 21, 2018
337b98b
[ADD] icon.png
OCA-git-bot Apr 3, 2019
bca798b
ADD refactored account_fiscal_year
eLBati Nov 9, 2018
745eb5f
[ADD] fiscalyear date.range.type data
MiquelRForgeFlow Jul 19, 2019
3c56933
[UPD] Update account_fiscal_year.pot
oca-travis Jul 23, 2019
caa2639
Update translation files
oca-transbot Jul 27, 2019
2608a33
[UPD] README.rst
OCA-git-bot Jul 29, 2019
5be667d
Added translation using Weblate (Dutch)
Aug 21, 2019
ba61054
[13.0][MIG] account_fiscal_year
astirpe Oct 16, 2019
6222e54
[UPD] Update account_fiscal_year.pot
oca-travis Mar 10, 2020
3971182
[UPD] README.rst
OCA-git-bot Mar 10, 2020
b7d3624
pre-commit update
OCA-git-bot Mar 14, 2020
0f3b16c
Update translation files
oca-transbot Aug 16, 2020
93ec1fb
[MIG] account_fiscal_year: Migration to 14.0
SimoRubi Nov 5, 2020
5812d6f
account_fiscal_year: Date range dependency no more needed
SimoRubi Nov 9, 2020
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
3 changes: 3 additions & 0 deletions account_fiscal_year/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from . import models
24 changes: 24 additions & 0 deletions account_fiscal_year/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2016 Camptocamp SA
# Copyright 2018 Lorenzo Battistini <https://github.com/eLBati>
# Copyright 2020 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Account Fiscal Year",
"summary": "Create Account Fiscal Year",
"version": "14.0.1.0.0",
"development_status": "Beta",
"category": "Accounting",
"website": "https://github.com/OCA/account-financial-tools"
"14.0/account_fiscal_year",
"author": "Agile Business Group, Camptocamp SA, "
"Odoo Community Association (OCA)",
"maintainers": ["eLBati"],
"license": "AGPL-3",
SimoRubi marked this conversation as resolved.
Show resolved Hide resolved
"depends": [
"account",
],
"data": [
"security/ir.model.access.csv",
"views/account_fiscal_year_views.xml",
],
}
126 changes: 126 additions & 0 deletions account_fiscal_year/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_fiscal_year
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-11-09 08:15+0000\n"
"PO-Revision-Date: 2020-11-09 08:15+0000\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_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
#: 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
#: model:ir.model,name:account_fiscal_year.model_account_fiscal_year
msgid "Fiscal Year"
msgstr "Anni fiscali"

#. 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
msgid "Fiscal Years"
msgstr "Anni fiscali"

#. 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."
4 changes: 4 additions & 0 deletions account_fiscal_year/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
111 changes: 111 additions & 0 deletions account_fiscal_year/models/account_fiscal_year.py
Original file line number Diff line number Diff line change
@@ -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,
]
)
82 changes: 82 additions & 0 deletions account_fiscal_year/models/res_company.py
Original file line number Diff line number Diff line change
@@ -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):
tafaRU marked this conversation as resolved.
Show resolved Hide resolved
"""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,
}
5 changes: 5 additions & 0 deletions account_fiscal_year/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Damien Crier <[email protected]>
* Laurent Mignon <[email protected]>
* Lorenzo Battistini <https://github.com/eLBati>
* Andrea Stirpe <[email protected]>
* Simone Rubino <[email protected]>
3 changes: 3 additions & 0 deletions account_fiscal_year/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module allows to create and edit fiscal years from the menu:

Invoicing > Configuration > Accounting > Fiscal Years
1 change: 1 addition & 0 deletions account_fiscal_year/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions account_fiscal_year/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
Binary file added account_fiscal_year/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading