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

[ADD] account_analytic_distribution_model_date: New module account_analytic_distribution_model_date #720

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
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
114 changes: 114 additions & 0 deletions account_analytic_distribution_model_date/README.rst
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.
1 change: 1 addition & 0 deletions account_analytic_distribution_model_date/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions account_analytic_distribution_model_date/__manifest__.py
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,
}
57 changes: 57 additions & 0 deletions account_analytic_distribution_model_date/i18n/ca.po
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ó."
57 changes: 57 additions & 0 deletions account_analytic_distribution_model_date/i18n/es.po
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."
2 changes: 2 additions & 0 deletions account_analytic_distribution_model_date/models/__init__.py
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# 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

View check run for this annotation

Codecov / codecov/patch

account_analytic_distribution_model_date/models/account_analytic_distribution_model.py#L22

Added line #L22 was not covered by tests
_("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.onchange("start_date", "end_date", "partner_id", "account_prefix")
def _check_duplicate_dates(self):
"""
Check if there are more than 1 register with overlapping dates
for the same partner and prefix.
"""
start_date = self.start_date if self.start_date else False
end_date = self.end_date if self.end_date else False
partner_id = self.partner_id.id if self.partner_id.id else False
account_prefix = self.account_prefix[0] if self.account_prefix else False

domain = [
("partner_id", "=", partner_id),
("company_id", "=", self.company_id.id),
]

if self.ids:
domain.append(("id", "!=", self.ids[0]))

if account_prefix:
domain.append(("account_prefix", "=ilike", f"{account_prefix}%"))

Check warning on line 74 in account_analytic_distribution_model_date/models/account_analytic_distribution_model.py

View check run for this annotation

Codecov / codecov/patch

account_analytic_distribution_model_date/models/account_analytic_distribution_model.py#L74

Added line #L74 was not covered by tests
else:
domain.append(("account_prefix", "=", False))

domain_without_dates = domain + [
("start_date", "=", False),
("end_date", "=", False),
]
duplicate_without_dates = self.search(domain_without_dates)

if start_date and not end_date:
domain.append(("end_date", ">=", start_date))
elif start_date and end_date:
domain.append("|")
domain.append(("start_date", "<=", end_date))
domain.append(("start_date", "=", False))

if end_date and not start_date:
domain.append(("start_date", "<=", end_date))
elif end_date and start_date:
domain.append("|")
domain.append(("end_date", ">=", start_date))
domain.append(("end_date", "=", False))

duplicate = self.search(domain)

if duplicate or duplicate_without_dates:
raise ValidationError(
_(
"Cannot have overlapping dates for "
+ "the same partner and account prefix."
)
)
Loading
Loading