-
-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] account_analytic_distribution_model_date: New module account_an…
…alytic_distribution_model_date
- Loading branch information
1 parent
e37042c
commit 6fd7767
Showing
16 changed files
with
1,044 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
======================================== | ||
Account Analytic Distribution Model Date | ||
======================================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:e87716fa0d73663a1d3824aa9c7d39d8e68d1f842bd88ab5f62b3223b9b18a0e | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account-analytic/tree/17.0/account_analytic_distribution_model_date | ||
:alt: OCA/account-analytic | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/account-analytic-17-0/account-analytic-17-0-account_analytic_distribution_model_date | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-analytic&target_branch=17.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module introduces **Start Date** and **End Date** fields for | ||
distribution models. | ||
|
||
This functionality enforces stricter management of distributions models, | ||
so only will select the distributions if they are in range of the dates. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To utilize this module, follow these steps: | ||
|
||
1. **Navigate to Analytic Distributions Models**: | ||
|
||
- Go to **Invoicing** → **Configuration** → **Analytic Distributions | ||
Models**. | ||
|
||
2. **Create or Edit a Distribution Model**: | ||
|
||
- Create a new distribution or edit an existing one. | ||
- Set the **Start Date** or **End Date** for the distribution. | ||
- Set the **Partner** and **Prefix**. | ||
|
||
3. **Create an Invoice or Vendor Bill**: | ||
|
||
- Proceed to create a new **Invoice** or **Vendor Bill**. | ||
- Select the customer and account you put on the Distribution Model. | ||
- Then if the Invoice date is set, it will filter the distribution | ||
by this, if not it will filter them by todays date | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-analytic/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/account-analytic/issues/new?body=module:%20account_analytic_distribution_model_date%0Aversion:%2017.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 | ||
------- | ||
|
||
* APSL-Nagarro | ||
* Bernat Obrador | ||
|
||
Contributors | ||
------------ | ||
|
||
- APSL - Nagarro <https://apsl.tech> | ||
|
||
- Bernat Obrador | ||
|
||
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-BernatObrador| image:: https://github.com/BernatObrador.png?size=40px | ||
:target: https://github.com/BernatObrador | ||
:alt: BernatObrador | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-BernatObrador| | ||
|
||
This module is part of the `OCA/account-analytic <https://github.com/OCA/account-analytic/tree/17.0/account_analytic_distribution_model_date>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2024 (APSL-Nagarro) - Bernat Obrador | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Account Analytic Distribution Model Date", | ||
"summary": "Account Analytic Distribution Model Date", | ||
"version": "17.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "Odoo Community Association (OCA), APSL-Nagarro, Bernat Obrador", | ||
"website": "https://github.com/OCA/account-analytic", | ||
"maintainers": ["BernatObrador"], | ||
"depends": [ | ||
"account", | ||
"analytic", | ||
], | ||
"data": [ | ||
"views/account_analytic_distribution_model.xml", | ||
], | ||
"installable": True, | ||
"application": False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * account_analytic_distribution_model_date | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 17.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-12-03 10:29+0000\n" | ||
"PO-Revision-Date: 2024-12-03 10:29+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_analytic_distribution_model_date | ||
#: model:ir.model,name:account_analytic_distribution_model_date.model_account_analytic_distribution_model | ||
msgid "Analytic Distribution Model" | ||
msgstr "Model de distribució analítica" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#. odoo-python | ||
#: code:addons/account_analytic_distribution_model_date/models/account_analytic_distribution_model.py:0 | ||
#, python-format | ||
msgid "Cannot have overlapping dates for the same partner and account prefix." | ||
msgstr "" | ||
"No es poden tenir dates que es sobreposin per al mateix contacte i prefix de" | ||
" compte." | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#: model:ir.model.fields,field_description:account_analytic_distribution_model_date.field_account_analytic_distribution_model__end_date | ||
msgid "End Date" | ||
msgstr "Data de fi" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#: model_terms:ir.ui.view,arch_db:account_analytic_distribution_model_date.inherit_account_analytic_distribution_model_form_view | ||
msgid "Filter Dates" | ||
msgstr "Dates de Filtratge" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#: model:ir.model,name:account_analytic_distribution_model_date.model_account_move_line | ||
msgid "Journal Item" | ||
msgstr "Apunt comptable" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#: model:ir.model.fields,field_description:account_analytic_distribution_model_date.field_account_analytic_distribution_model__start_date | ||
msgid "Start Date" | ||
msgstr "Data d'inici" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#. odoo-python | ||
#: code:addons/account_analytic_distribution_model_date/models/account_analytic_distribution_model.py:0 | ||
#, python-format | ||
msgid "The start date cannot be later than the end date." | ||
msgstr "La data d'inici no pot ser posterior a la data de finalització." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * account_analytic_distribution_model_date | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 17.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-12-03 10:31+0000\n" | ||
"PO-Revision-Date: 2024-12-03 10:31+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_analytic_distribution_model_date | ||
#: model:ir.model,name:account_analytic_distribution_model_date.model_account_analytic_distribution_model | ||
msgid "Analytic Distribution Model" | ||
msgstr "Modelo de distribución analítica" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#. odoo-python | ||
#: code:addons/account_analytic_distribution_model_date/models/account_analytic_distribution_model.py:0 | ||
#, python-format | ||
msgid "Cannot have overlapping dates for the same partner and account prefix." | ||
msgstr "" | ||
"No se pueden tener fechas superpuestas para el mismo contacto y prefijo de " | ||
"cuenta." | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#: model:ir.model.fields,field_description:account_analytic_distribution_model_date.field_account_analytic_distribution_model__end_date | ||
msgid "End Date" | ||
msgstr "Fecha de fin" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#: model_terms:ir.ui.view,arch_db:account_analytic_distribution_model_date.inherit_account_analytic_distribution_model_form_view | ||
msgid "Filter Dates" | ||
msgstr "Fechas de Filtrado" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#: model:ir.model,name:account_analytic_distribution_model_date.model_account_move_line | ||
msgid "Journal Item" | ||
msgstr "Apunte contable" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#: model:ir.model.fields,field_description:account_analytic_distribution_model_date.field_account_analytic_distribution_model__start_date | ||
msgid "Start Date" | ||
msgstr "Fecha de inicio" | ||
|
||
#. module: account_analytic_distribution_model_date | ||
#. odoo-python | ||
#: code:addons/account_analytic_distribution_model_date/models/account_analytic_distribution_model.py:0 | ||
#, python-format | ||
msgid "The start date cannot be later than the end date." | ||
msgstr "La fecha de inicio no puede ser posterior a la fecha de finalización." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import account_analytic_distribution_model | ||
from . import account_move_line |
100 changes: 100 additions & 0 deletions
100
account_analytic_distribution_model_date/models/account_analytic_distribution_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Copyright 2024 (APSL - Nagarro) Bernat Obrador | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class AccountAnalyticDistributionModel(models.Model): | ||
_inherit = ["account.analytic.distribution.model"] | ||
|
||
start_date = fields.Date() | ||
end_date = fields.Date() | ||
|
||
@api.constrains("start_date", "end_date") | ||
def _check_start_date_before_end_date(self): | ||
for record in self: | ||
if ( | ||
record.start_date | ||
and record.end_date | ||
and record.start_date > record.end_date | ||
): | ||
raise ValidationError( | ||
Check warning on line 22 in account_analytic_distribution_model_date/models/account_analytic_distribution_model.py Codecov / codecov/patchaccount_analytic_distribution_model_date/models/account_analytic_distribution_model.py#L22
|
||
_("The start date cannot be later than the end date.") | ||
) | ||
|
||
def _create_domain(self, fname, value): | ||
if fname == "date" and value: | ||
return [ | ||
"|", | ||
"&", | ||
("start_date", "<=", value), | ||
("end_date", ">=", value), | ||
"|", | ||
"&", | ||
("start_date", "<=", value), | ||
("end_date", "=", False), | ||
"|", | ||
"&", | ||
("start_date", "=", False), | ||
("end_date", ">=", value), | ||
"&", | ||
("start_date", "=", False), | ||
("end_date", "=", False), | ||
] | ||
return super()._create_domain(fname, value) | ||
|
||
def _check_score(self, key, value): | ||
self.ensure_one() | ||
if key == "start_date" or key == "end_date": | ||
return 1 | ||
|
||
return super()._check_score(key, value) | ||
|
||
@api.model | ||
def create(self, values): | ||
self._check_duplicate_dates(values) | ||
return super().create(values) | ||
|
||
@api.model | ||
def write(self, values): | ||
self._check_duplicate_dates(values) | ||
return super().write(values) | ||
Check warning on line 62 in account_analytic_distribution_model_date/models/account_analytic_distribution_model.py Codecov / codecov/patchaccount_analytic_distribution_model_date/models/account_analytic_distribution_model.py#L62
|
||
|
||
def _check_duplicate_dates(self, values): | ||
""" | ||
Check if there are more than 1 register with overlapping dates | ||
for the same partner and prefix. | ||
""" | ||
start_date = values.get("start_date", self.start_date) | ||
end_date = values.get("end_date", self.end_date) | ||
partner_id = values.get("partner_id", self.partner_id.id) | ||
account_prefix = values.get("account_prefix", self.account_prefix) | ||
|
||
domain = [ | ||
("partner_id", "=", partner_id), | ||
("id", "!=", self.id), | ||
("account_prefix", "=", account_prefix), | ||
] | ||
|
||
domain_without_dates = domain + [ | ||
("start_date", "=", False), | ||
("end_date", "=", False), | ||
] | ||
duplicate_without_dates = self.search(domain_without_dates) | ||
|
||
if start_date: | ||
domain.append(("start_date", "<=", end_date)) | ||
|
||
if end_date: | ||
domain.append(("end_date", ">=", start_date)) | ||
|
||
duplicate = self.search(domain) | ||
|
||
if duplicate or duplicate_without_dates: | ||
raise ValidationError( | ||
_( | ||
"Cannot have overlapping dates for " | ||
+ "the same partner and account prefix." | ||
) | ||
) |
38 changes: 38 additions & 0 deletions
38
account_analytic_distribution_model_date/models/account_move_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2024 (APSL - Nagarro) Bernat Obrador | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
from odoo.tools import frozendict | ||
|
||
|
||
class AccountMoveLine(models.Model): | ||
_inherit = ["account.move.line"] | ||
|
||
@api.depends("account_id", "partner_id", "product_id") | ||
def _compute_analytic_distribution(self): | ||
cache = {} | ||
for line in self: | ||
if line.display_type == "product" or not line.move_id.is_invoice( | ||
include_receipts=True | ||
): | ||
arguments = frozendict( | ||
{ | ||
"product_id": line.product_id.id, | ||
"product_categ_id": line.product_id.categ_id.id, | ||
"partner_id": line.partner_id.id, | ||
"partner_category_id": line.partner_id.category_id.ids, | ||
"account_prefix": line.account_id.code, | ||
"company_id": line.company_id.id, | ||
"date": self._get_date(line).strftime("%Y-%m-%d"), | ||
} | ||
) | ||
if arguments not in cache: | ||
cache[arguments] = self.env[ | ||
"account.analytic.distribution.model" | ||
]._get_distribution(arguments) | ||
line.analytic_distribution = ( | ||
cache[arguments] or line.analytic_distribution | ||
) | ||
|
||
def _get_date(self, line): | ||
return line.invoice_date or fields.Date.today() |
Oops, something went wrong.