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

[15.0][mig] analytic_tag_dimension_enhanced #498

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a7d2698
[12.0][ADD] account_tag_dimension_enhanced
kittiu Sep 22, 2019
474d656
[UPD] Update analytic_tag_dimension_enhanced.pot
oca-travis Jun 23, 2020
abe92ce
[UPD] README.rst
OCA-git-bot Jun 23, 2020
b9e2008
[FIX+IMP] analytic_tag_dimension_enhanced: Adapt tests
pedrobaeza Oct 28, 2020
5131352
[IMP] analytic_tag_dimension_enhanced: black, isort, prettier
Saran440 Nov 3, 2020
c9ee18a
[13.0][MIG] analytic_tag_dimension_enhanced
Saran440 Nov 3, 2020
fd9c5cb
[MIG][FIX] analytic_tag_dimension_enhanced, fix required check
kittiu Nov 26, 2020
9b17520
[FIX] domain filtered
Saran440 Nov 26, 2020
3d302e2
[FIX] Split files analytic.py
Saran440 Nov 26, 2020
8c96c25
[IMP] analytic_tag_dimension_enhanced: black, isort, prettier
kittiu May 5, 2021
5dd1c45
[14.0][MIG] analytic_tag_dimension_enhanced
kittiu May 5, 2021
7622b50
[UPD] Update analytic_tag_dimension_enhanced.pot
oca-travis Jun 10, 2021
1683da6
[UPD] README.rst
OCA-git-bot Jun 10, 2021
e80d8d9
[FIX] update name tag from create tag dimension
Saran440 Jun 11, 2021
440cb5e
analytic_tag_dimension_enhanced 14.0.1.1.0
OCA-git-bot Nov 29, 2021
4bd10cb
[FIX] domain_tag follow line_ids (journal items)
Saran440 Jan 5, 2022
705742d
[IMP] update dotfiles [ci skip]
OCA-git-bot Mar 30, 2022
f217646
[FIX] analytic_tag_dimension_enhanced: not check required dimension i…
ps-tubtim Jun 15, 2021
7614137
analytic_tag_dimension_enhanced 14.0.1.1.1
OCA-git-bot May 30, 2022
17a6b5f
analytic_tag_dimension_enhanced 14.0.1.1.2
OCA-git-bot Aug 30, 2022
7215348
[IMP] analytic_tag_dimension_enhanced: black, isort, prettier
Saran440 Mar 3, 2023
ca3e702
[MIG] analytic_tag_dimension_enhanced: Migration to 15.0
Saran440 Mar 3, 2023
d7c2bf3
[ENH] analytic_tag_dimension_enhanced: add exclude required module
Saran440 May 12, 2023
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
93 changes: 93 additions & 0 deletions analytic_tag_dimension_enhanced/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
=====================================
Analytic Accounts Dimensions Enhanced
=====================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/14.0/analytic_tag_dimension_enhanced
: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-14-0/account-analytic-14-0-analytic_tag_dimension_enhanced
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/87/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

Analytic Tags Dimension (analytic_tag_dimension) ensure that one tag can be selected for each dimension.

This module add even more configurable usability to analytic tag field.

1. Set required tag dimension
2. Select tags by dimension sequence
3. Mass create tags based on model data
4. Filter subsequence tag selections based on previous selected tag's dimension

**Table of contents**

.. contents::
:local:

Configuration
=============

Go to menu Invoicing > Configuration > Analytic Accounting > Analytic Accounts Dimensions

Configurations:

* Required: if checked, user must select the dimension, otherwise, cannot save.
* By Sequence: if selected, this tag dimension is selectable only when previous sequences has been selected.
* Ref Model: to refer this analytic tags into a model, and also allow to create analytic tags by data in model.
* Filtered by fields: if ref model is set, you can also filter (domain) selections by its field(s).

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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-analytic/issues/new?body=module:%20analytic_tag_dimension_enhanced%0Aversion:%2014.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
~~~~~~~

* Ecosoft

Contributors
~~~~~~~~~~~~

* Kitti Upariphutthiphong <[email protected]>
* Saran Lim. <[email protected]>

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.

This module is part of the `OCA/account-analytic <https://github.com/OCA/account-analytic/tree/14.0/analytic_tag_dimension_enhanced>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions analytic_tag_dimension_enhanced/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import models
17 changes: 17 additions & 0 deletions analytic_tag_dimension_enhanced/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

{
"name": "Analytic Accounts Dimensions Enhanced",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["analytic_tag_dimension"],
"data": [
"security/ir.model.access.csv",
"views/analytic_view.xml",
"views/account_move_view.xml",
],
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * analytic_tag_dimension_enhanced
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \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: analytic_tag_dimension_enhanced
#: model_terms:ir.ui.view,arch_db:analytic_tag_dimension_enhanced.view_AccountAnalyticDimension_form
msgid "=> Create Tags"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model,name:analytic_tag_dimension_enhanced.model_account_analytic_dimension
msgid "Account Analytic Dimension"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model,name:analytic_tag_dimension_enhanced.model_analytic_dimension_line
msgid "Analytic Dimension Line"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model,name:analytic_tag_dimension_enhanced.model_account_analytic_tag
msgid "Analytic Tags"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_dimension__by_sequence
msgid "By Sequence"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_dimension__display_name
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_tag__display_name
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_analytic_dimension_line__display_name
msgid "Display Name"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_line__domain_tag_ids
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_move_line__domain_tag_ids
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_analytic_dimension_line__domain_tag_ids
msgid "Domain Tag"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: code:addons/analytic_tag_dimension_enhanced/models/account_analytic_dimension.py:0
#, python-format
msgid "Duplicated dimension sequences"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_dimension__filtered_field_ids
msgid "Filtered by fields"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,help:analytic_tag_dimension_enhanced.field_account_analytic_dimension__filtered_field_ids
msgid ""
"Filtered listing tags by fields of this model, based on value of selected "
"analytic tags in working document"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: code:addons/analytic_tag_dimension_enhanced/models/account_analytic_tag.py:0
#, python-format
msgid "Following dimension(s) not selected: %s"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,help:analytic_tag_dimension_enhanced.field_account_analytic_line__domain_tag_ids
#: model:ir.model.fields,help:analytic_tag_dimension_enhanced.field_account_move_line__domain_tag_ids
#: model:ir.model.fields,help:analytic_tag_dimension_enhanced.field_analytic_dimension_line__domain_tag_ids
msgid "Helper field, the filtered tags_ids when record is saved"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_dimension__id
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_tag__id
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_analytic_dimension_line__id
msgid "ID"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,help:analytic_tag_dimension_enhanced.field_account_analytic_dimension__by_sequence
msgid ""
"If checked, this dimemsion's tags will be available only when previous "
"dimension's tags is selected"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,help:analytic_tag_dimension_enhanced.field_account_analytic_dimension__required
msgid "If required, this dimension needed to be selected in working document"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_dimension____last_update
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_tag____last_update
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_analytic_dimension_line____last_update
msgid "Last Modified on"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_tag__resource_ref
msgid "Record"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_dimension__ref_model_id
msgid "Ref Model"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_dimension__required
msgid "Required"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,help:analytic_tag_dimension_enhanced.field_account_analytic_dimension__ref_model_id
msgid ""
"Select model if you want to use it to create analytic tags, each tag will have reference to the data record in that model.\n"
"For example, if you select Department (hr.department) then click Create Tags button, tags will be created from each department and also has resource_ref to the department record"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,field_description:analytic_tag_dimension_enhanced.field_account_analytic_dimension__sequence
msgid "Sequence"
msgstr ""

#. module: analytic_tag_dimension_enhanced
#: model:ir.model.fields,help:analytic_tag_dimension_enhanced.field_account_analytic_dimension__sequence
msgid "This field works with By Sequence"
msgstr ""
5 changes: 5 additions & 0 deletions analytic_tag_dimension_enhanced/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import analytic_dimension_line
from . import account_analytic_dimension
from . import account_analytic_tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class AccountAnalyticDimension(models.Model):
_inherit = "account.analytic.dimension"

ref_model_id = fields.Many2one(
comodel_name="ir.model",
string="Ref Model",
help="Select model if you want to use it to create analytic tags, "
"each tag will have reference to the data record in that model.\n"
"For example, if you select Department (hr.department) then click "
"Create Tags button, tags will be created from each department "
" and also has resource_ref to the department record",
)
filtered_field_ids = fields.Many2many(
comodel_name="ir.model.fields",
string="Filtered by fields",
domain="[('model_id', '=', ref_model_id), ('ttype', '=', 'many2one')]",
help="Filtered listing tags by fields of this model, based on value "
"of selected analytic tags in working document",
)
required = fields.Boolean(
default=False,
help="If required, this dimension needed to be selected in working document",
)
exclude_required = fields.Many2many(
comodel_name="ir.model",
string="Exclude Module Required",
)
by_sequence = fields.Boolean(
default=False,
help="If checked, this dimemsion's tags will be available "
"only when previous dimension's tags is selected",
)
sequence = fields.Integer(
help="This field works with By Sequence",
)

@api.constrains("by_sequence", "sequence")
def _check_sequence(self):
seq_list = self.search([("by_sequence", "=", True)]).mapped("sequence")
if len(seq_list) != len(set(seq_list)):
raise ValidationError(_("Duplicated dimension sequences"))

def create_analytic_tags(self):
"""Helper function to create tags based on ref_model_id"""
self.ensure_one()
if not self.ref_model_id:
return
Tag = self.env["account.analytic.tag"]
model = self.ref_model_id.model
TagModel = self.env[model]
# Delete orphan tags
self.analytic_tag_ids.filtered(
lambda l: not l.resource_ref or l.resource_ref._name != model
).unlink()
# Update name analytic tag from Ref model.
tags = self.analytic_tag_ids.filtered(
lambda l: l.display_name != l.resource_ref.display_name
)
for tag in tags:
tag.name = tag.resource_ref.display_name

Check warning on line 67 in analytic_tag_dimension_enhanced/models/account_analytic_dimension.py

View check run for this annotation

Codecov / codecov/patch

analytic_tag_dimension_enhanced/models/account_analytic_dimension.py#L67

Added line #L67 was not covered by tests
tag_res_ids = [x.resource_ref.id for x in self.analytic_tag_ids]
recs = TagModel.search([("id", "not in", tag_res_ids)])
vals_dict = [
{
"name": rec.display_name,
"analytic_dimension_id": self.id,
"resource_ref": "{},{}".format(model, rec.id),
}
for rec in recs
]
Tag.create(vals_dict)
51 changes: 51 additions & 0 deletions analytic_tag_dimension_enhanced/models/account_analytic_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import _, fields, models
from odoo.exceptions import ValidationError


class AccountAnalyticTag(models.Model):
_inherit = "account.analytic.tag"

resource_ref = fields.Reference(
selection=lambda self: [
(model.model, model.name) for model in self.env["ir.model"].search([])
],
string="Record",
)

def _check_required_dimension(self, record):
"""Test all required dimension is selected (exclude non-invoice)"""
record.ensure_one()
if (
record._name == "account.payment.register"
or (
"exclude_from_invoice_tab" in record and record.exclude_from_invoice_tab
)
or (
"move_id" in record
and "move_type" in record.move_id
and record.move_id.move_type == "entry"
)
or ("display_type" in record and record.display_type)
or self._context.get("bypass_required_dimension")
):
return
Dimension = self.env["account.analytic.dimension"]
req_dimensions = Dimension.search([("required", "=", True)])
tags_dimension = self.filtered("analytic_dimension_id.required")
dimensions = tags_dimension.mapped("analytic_dimension_id")
missing = req_dimensions - dimensions
# Check record in exclude required, it will skip it
if (
req_dimensions
and req_dimensions.exclude_required
and record._name in req_dimensions.exclude_required.mapped("model")
):
missing = False
if missing:
raise ValidationError(
_("Following analytic tag dimension(s) not selected: %s")
% ", ".join(missing.mapped("name"))
)
Loading
Loading