Skip to content

Commit 43c9280

Browse files
committed
[ADD] account_analytic_distribution_model_date: New module account_analytic_distribution_model_date
1 parent e37042c commit 43c9280

16 files changed

+1006
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
========================================
2+
Account Analytic Distribution Model Date
3+
========================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:e87716fa0d73663a1d3824aa9c7d39d8e68d1f842bd88ab5f62b3223b9b18a0e
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github
20+
:target: https://github.com/OCA/account-analytic/tree/17.0/account_analytic_distribution_model_date
21+
:alt: OCA/account-analytic
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/account-analytic-17-0/account-analytic-17-0-account_analytic_distribution_model_date
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-analytic&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module introduces **Start Date** and **End Date** fields for
32+
distribution models.
33+
34+
This functionality enforces stricter management of distributions models,
35+
so only will select the distributions if they are in range of the dates.
36+
37+
**Table of contents**
38+
39+
.. contents::
40+
:local:
41+
42+
Usage
43+
=====
44+
45+
To utilize this module, follow these steps:
46+
47+
1. **Navigate to Analytic Distributions Models**:
48+
49+
- Go to **Invoicing** → **Configuration** → **Analytic Distributions
50+
Models**.
51+
52+
2. **Create or Edit a Distribution Model**:
53+
54+
- Create a new distribution or edit an existing one.
55+
- Set the **Start Date** or **End Date** for the distribution.
56+
- Set the **Partner** and **Prefix**.
57+
58+
3. **Create an Invoice or Vendor Bill**:
59+
60+
- Proceed to create a new **Invoice** or **Vendor Bill**.
61+
- Select the customer and account you put on the Distribution Model.
62+
- Then if the Invoice date is set, it will filter the distribution
63+
by this, if not it will filter them by todays date
64+
65+
Bug Tracker
66+
===========
67+
68+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-analytic/issues>`_.
69+
In case of trouble, please check there if your issue has already been reported.
70+
If you spotted it first, help us to smash it by providing a detailed and welcomed
71+
`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**>`_.
72+
73+
Do not contact contributors directly about support or help with technical issues.
74+
75+
Credits
76+
=======
77+
78+
Authors
79+
-------
80+
81+
* APSL-Nagarro
82+
* Bernat Obrador
83+
84+
Contributors
85+
------------
86+
87+
- APSL - Nagarro <https://apsl.tech>
88+
89+
- Bernat Obrador
90+
91+
Maintainers
92+
-----------
93+
94+
This module is maintained by the OCA.
95+
96+
.. image:: https://odoo-community.org/logo.png
97+
:alt: Odoo Community Association
98+
:target: https://odoo-community.org
99+
100+
OCA, or the Odoo Community Association, is a nonprofit organization whose
101+
mission is to support the collaborative development of Odoo features and
102+
promote its widespread use.
103+
104+
.. |maintainer-BernatObrador| image:: https://github.com/BernatObrador.png?size=40px
105+
:target: https://github.com/BernatObrador
106+
:alt: BernatObrador
107+
108+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
109+
110+
|maintainer-BernatObrador|
111+
112+
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.
113+
114+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 (APSL-Nagarro) - Bernat Obrador
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Account Analytic Distribution Model Date",
6+
"summary": "Account Analytic Distribution Model Date",
7+
"version": "17.0.1.0.0",
8+
"license": "AGPL-3",
9+
"author": "Odoo Community Association (OCA), APSL-Nagarro, Bernat Obrador",
10+
"website": "https://github.com/OCA/account-analytic",
11+
"maintainers": ["BernatObrador"],
12+
"depends": [
13+
"account",
14+
"analytic",
15+
],
16+
"data": [
17+
"views/account_analytic_distribution_model.xml",
18+
],
19+
"installable": True,
20+
"application": False,
21+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * account_analytic_distribution_model_date
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 17.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2024-12-03 10:29+0000\n"
10+
"PO-Revision-Date: 2024-12-03 10:29+0000\n"
11+
"Last-Translator: \n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: account_analytic_distribution_model_date
19+
#: model:ir.model,name:account_analytic_distribution_model_date.model_account_analytic_distribution_model
20+
msgid "Analytic Distribution Model"
21+
msgstr "Model de distribució analítica"
22+
23+
#. module: account_analytic_distribution_model_date
24+
#. odoo-python
25+
#: code:addons/account_analytic_distribution_model_date/models/account_analytic_distribution_model.py:0
26+
#, python-format
27+
msgid "Cannot have overlapping dates for the same partner and account prefix."
28+
msgstr ""
29+
"No es poden tenir dates que es sobreposin per al mateix contacte i prefix de"
30+
" compte."
31+
32+
#. module: account_analytic_distribution_model_date
33+
#: model:ir.model.fields,field_description:account_analytic_distribution_model_date.field_account_analytic_distribution_model__end_date
34+
msgid "End Date"
35+
msgstr "Data de fi"
36+
37+
#. module: account_analytic_distribution_model_date
38+
#: model_terms:ir.ui.view,arch_db:account_analytic_distribution_model_date.inherit_account_analytic_distribution_model_form_view
39+
msgid "Filter Dates"
40+
msgstr "Dates de Filtratge"
41+
42+
#. module: account_analytic_distribution_model_date
43+
#: model:ir.model,name:account_analytic_distribution_model_date.model_account_move_line
44+
msgid "Journal Item"
45+
msgstr "Apunt comptable"
46+
47+
#. module: account_analytic_distribution_model_date
48+
#: model:ir.model.fields,field_description:account_analytic_distribution_model_date.field_account_analytic_distribution_model__start_date
49+
msgid "Start Date"
50+
msgstr "Data d'inici"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * account_analytic_distribution_model_date
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 17.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2024-12-03 10:31+0000\n"
10+
"PO-Revision-Date: 2024-12-03 10:31+0000\n"
11+
"Last-Translator: \n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: account_analytic_distribution_model_date
19+
#: model:ir.model,name:account_analytic_distribution_model_date.model_account_analytic_distribution_model
20+
msgid "Analytic Distribution Model"
21+
msgstr "Modelo de distribución analítica"
22+
23+
#. module: account_analytic_distribution_model_date
24+
#. odoo-python
25+
#: code:addons/account_analytic_distribution_model_date/models/account_analytic_distribution_model.py:0
26+
#, python-format
27+
msgid "Cannot have overlapping dates for the same partner and account prefix."
28+
msgstr ""
29+
"No se pueden tener fechas superpuestas para el mismo contacto y prefijo de "
30+
"cuenta."
31+
32+
#. module: account_analytic_distribution_model_date
33+
#: model:ir.model.fields,field_description:account_analytic_distribution_model_date.field_account_analytic_distribution_model__end_date
34+
msgid "End Date"
35+
msgstr "Fecha de fin"
36+
37+
#. module: account_analytic_distribution_model_date
38+
#: model_terms:ir.ui.view,arch_db:account_analytic_distribution_model_date.inherit_account_analytic_distribution_model_form_view
39+
msgid "Filter Dates"
40+
msgstr "Fechas de Filtrado"
41+
42+
#. module: account_analytic_distribution_model_date
43+
#: model:ir.model,name:account_analytic_distribution_model_date.model_account_move_line
44+
msgid "Journal Item"
45+
msgstr "Apunte contable"
46+
47+
#. module: account_analytic_distribution_model_date
48+
#: model:ir.model.fields,field_description:account_analytic_distribution_model_date.field_account_analytic_distribution_model__start_date
49+
msgid "Start Date"
50+
msgstr "Fecha de inicio"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import account_analytic_distribution_model
2+
from . import account_move_line
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Copyright 2024 (APSL - Nagarro) Bernat Obrador
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import _, api, fields, models
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class AccountAnalyticDistributionModel(models.Model):
9+
_inherit = ["account.analytic.distribution.model"]
10+
11+
start_date = fields.Date()
12+
end_date = fields.Date()
13+
14+
def _create_domain(self, fname, value):
15+
if fname == "date" and value:
16+
return [
17+
"|",
18+
"&",
19+
("start_date", "<=", value),
20+
("end_date", ">=", value),
21+
"|",
22+
"&",
23+
("start_date", "<=", value),
24+
("end_date", "=", False),
25+
"|",
26+
"&",
27+
("start_date", "=", False),
28+
("end_date", ">=", value),
29+
"&",
30+
("start_date", "=", False),
31+
("end_date", "=", False),
32+
]
33+
return super()._create_domain(fname, value)
34+
35+
def _check_score(self, key, value):
36+
self.ensure_one()
37+
if key == "start_date" or key == "end_date":
38+
return 1
39+
40+
return super()._check_score(key, value)
41+
42+
@api.model
43+
def create(self, values):
44+
self._check_duplicate_dates(values)
45+
return super().create(values)
46+
47+
@api.model
48+
def write(self, values):
49+
self._check_duplicate_dates(values)
50+
return super().write(values)
51+
52+
def _check_duplicate_dates(self, values):
53+
"""
54+
Check if there are more than 1 register with overlapping dates
55+
and the same partner.
56+
"""
57+
start_date = values.get("start_date", self.start_date)
58+
end_date = values.get("end_date", self.end_date)
59+
partner_id = values.get("partner_id", self.partner_id.id)
60+
account_prefix = values.get("account_prefix", self.account_prefix)
61+
62+
domain = [
63+
("partner_id", "=", partner_id),
64+
("id", "!=", self.id),
65+
("account_prefix", "=", account_prefix),
66+
]
67+
68+
if start_date:
69+
domain.append("|")
70+
domain.append(("start_date", "<=", start_date))
71+
domain.append(("start_date", "=", False))
72+
73+
if end_date:
74+
domain.append("|")
75+
domain.append(("end_date", ">=", end_date))
76+
domain.append(("end_date", "=", False))
77+
78+
duplicate = self.search(domain)
79+
80+
if duplicate:
81+
raise ValidationError(
82+
_(
83+
"Cannot have overlapping dates for "
84+
+ "the same partner and account prefix."
85+
)
86+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2024 (APSL - Nagarro) Bernat Obrador
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
from odoo.tools import frozendict
6+
7+
8+
class AccountMoveLine(models.Model):
9+
_inherit = ["account.move.line"]
10+
11+
@api.depends("account_id", "partner_id", "product_id")
12+
def _compute_analytic_distribution(self):
13+
cache = {}
14+
for line in self:
15+
if line.display_type == "product" or not line.move_id.is_invoice(
16+
include_receipts=True
17+
):
18+
arguments = frozendict(
19+
{
20+
"product_id": line.product_id.id,
21+
"product_categ_id": line.product_id.categ_id.id,
22+
"partner_id": line.partner_id.id,
23+
"partner_category_id": line.partner_id.category_id.ids,
24+
"account_prefix": line.account_id.code,
25+
"company_id": line.company_id.id,
26+
"date": self._get_date(line).strftime("%Y-%m-%d"),
27+
}
28+
)
29+
if arguments not in cache:
30+
cache[arguments] = self.env[
31+
"account.analytic.distribution.model"
32+
]._get_distribution(arguments)
33+
line.analytic_distribution = (
34+
cache[arguments] or line.analytic_distribution
35+
)
36+
37+
def _get_date(self, line):
38+
return line.invoice_date or fields.Date.today()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- APSL - Nagarro \<<https://apsl.tech>\>
2+
- Bernat Obrador

0 commit comments

Comments
 (0)