Skip to content

Commit

Permalink
[MIG] account_analytic_distribution_manual: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BernatObrador committed Oct 15, 2024
1 parent 9983efa commit 5144581
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 94 deletions.
4 changes: 4 additions & 0 deletions account_analytic_distribution_manual/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ Contributors

- Carlos Lopez

- APSL - Nagarro <https://apsl.tech>

- Bernat Obrador

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion account_analytic_distribution_manual/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Account analytic distribution manual",
"summary": "Account analytic distribution manual",
"version": "16.0.2.4.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"website": "https://github.com/OCA/account-analytic",
"author": "Tecnativa, Odoo Community Association (OCA)",
Expand Down
56 changes: 30 additions & 26 deletions account_analytic_distribution_manual/hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2024 Tecnativa - Carlos Lopez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import SUPERUSER_ID, api, tools
from odoo import tools

# metadata for all models related to account_analytic_tag(m2m)
# add more models if needed
Expand Down Expand Up @@ -105,37 +105,40 @@
}


def post_init_hook(cr, registry):
if tools.table_exists(cr, "account_analytic_tag"):
env = api.Environment(cr, SUPERUSER_ID, {})
def post_init_hook(env):
if tools.table_exists(env.cr, "account_analytic_tag"):
DistributionManual = env["account.analytic.distribution.manual"]
sql = """
WITH counted_tags AS (
WITH counted_tags AS (
SELECT
tag.id,
tag.name,
tag.active,
tag.company_id,
ROW_NUMBER() OVER (PARTITION BY tag.name ORDER BY tag.id)
AS row_count
FROM account_analytic_tag tag
)
SELECT
CASE
WHEN row_count = 1 THEN tag.name
ELSE CONCAT(tag.name, ' (', tag.id, ')')
END AS name,
tag.id,
tag.name,
tag.active,
tag.company_id,
ROW_NUMBER() OVER (PARTITION BY tag.name ORDER BY tag.id) AS row_count
FROM account_analytic_tag tag
WHERE tag.active_analytic_distribution = true
)
SELECT
CASE
WHEN row_count = 1 THEN tag.name
ELSE CONCAT(tag.name, ' (', tag.id, ')')
END AS name,
tag.id,
tag.active,
tag.company_id,
distribution.account_id,
distribution.percentage
FROM
counted_tags tag
INNER JOIN
account_analytic_distribution distribution
ON tag.id = distribution.tag_id;
distribution.account_id,
distribution.percentage
FROM
counted_tags tag
INNER JOIN account_analytic_tag_account_move_line_rel rel ON
rel.account_analytic_tag_id = tag.id
INNER JOIN account_move_line line ON
line.id = rel.account_move_line_id
CROSS JOIN LATERAL jsonb_each(line.analytic_distribution)
AS distribution(account_id, percentage)
;
"""
env.cr.execute(sql)
distribution_by_tag = {}
Expand Down Expand Up @@ -167,6 +170,7 @@ def post_init_hook(cr, registry):
if (
res_model_name in env
and "manual_distribution_id" in env[res_model_name]._fields
and tools.table_exists(env.cr, table_m2m)
):
sql = f"""
SELECT {column1}, {column2}
Expand Down
196 changes: 196 additions & 0 deletions account_analytic_distribution_manual/i18n/ca_ES.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_analytic_distribution_manual
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-15 12:54+0000\n"
"PO-Revision-Date: 2024-10-15 12:54+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_manual
#: model:ir.model,name:account_analytic_distribution_manual.model_account_analytic_distribution_manual
msgid "Account analytic distribution manual"
msgstr "Distribució Analítica Manual"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__active
msgid "Active"
msgstr "Actiu"

#. module: account_analytic_distribution_manual
#: model_terms:ir.actions.act_window,help:account_analytic_distribution_manual.action_account_analytic_distribution_manual
msgid "Add a new Manual Analytic Distributions"
msgstr "Afegir una nova Distribució Analítica Manual"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__analytic_distribution
msgid "Analytic Distribution"
msgstr "Distribució Analítica"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__analytic_distribution_search
msgid "Analytic Distribution Search"
msgstr "Cerca de Distribució Analítica"

#. module: account_analytic_distribution_manual
#: model:ir.model,name:account_analytic_distribution_manual.model_account_analytic_line
msgid "Analytic Line"
msgstr "Línia Analítica"

#. module: account_analytic_distribution_manual
#: model:ir.model,name:account_analytic_distribution_manual.model_analytic_mixin
msgid "Analytic Mixin"
msgstr "Combinació Analítica"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__analytic_precision
msgid "Analytic Precision"
msgstr "Precisión Analítica"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_model__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_asset__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_asset_profile__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_move_line__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_move_template_line__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_move_template_line_run__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_reconcile_model_line__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_spread__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_spread_template__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_spread_template_auto__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_analytic_mixin__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_mrp_bom__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_mrp_production__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_mrp_workcenter__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_purchase_order_line__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_sale_order_line__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_stock_move__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_stock_move_line__analytic_distribution_import
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_stock_scrap__analytic_distribution_import
msgid "Analytic distribution (importable)"
msgstr "Distribució analítica (importable)"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_line__manual_distribution_id
msgid "Analytic distribution manual"
msgstr "Distribució analítica manual"

#. module: account_analytic_distribution_manual
#: model_terms:ir.ui.view,arch_db:account_analytic_distribution_manual.view_account_analytic_distribution_manual_form
#: model_terms:ir.ui.view,arch_db:account_analytic_distribution_manual.view_account_analytic_distribution_manual_search
msgid "Archived"
msgstr "Arxivat"

#. module: account_analytic_distribution_manual
#: model:ir.model,name:account_analytic_distribution_manual.model_base
msgid "Base"
msgstr "Base"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__company_id
msgid "Company"
msgstr "Companyia"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__create_uid
msgid "Created by"
msgstr "Creat per"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__create_date
msgid "Created on"
msgstr "Creat el"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_analytic_distribution_manual__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_analytic_distribution_model__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_asset__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_asset_profile__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_move_line__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_move_template_line__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_move_template_line_run__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_reconcile_model_line__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_spread__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_spread_template__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_account_spread_template_auto__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_analytic_mixin__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_mrp_bom__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_mrp_production__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_mrp_workcenter__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_purchase_order_line__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_sale_order_line__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_stock_move__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_stock_move_line__analytic_distribution_import
#: model:ir.model.fields,help:account_analytic_distribution_manual.field_stock_scrap__analytic_distribution_import
msgid ""
"Defining this field, it will set the analytical distribution in JSON format,"
" but using the analytic accounts names as keys of the dictionary, so it "
"eases the human input."
msgstr ""
"Definint aquest camp, es definirà la distribució analítica en format JSON,"
" utilitzant els noms dels comptes analítics com a claus del diccionari, així "
"facilitant l'entrada per part de l'usuari."

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__id
msgid "ID"
msgstr "ID"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__name
msgid "Name"
msgstr "Nom"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__type"
msgid "Type"
msgstr "Tipus"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__sequence"
msgid "Sequence"
msgstr "Seqüència"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__display_name
msgid "Display Name"
msgstr "Nom a mostrar"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__price"
msgid "Price"
msgstr "Preu"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__total_amount"
msgid "Total Amount"
msgstr "Import Total"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__analytic_account_id"
msgid "Analytic Account"
msgstr "Compte Analític"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__amount"
msgid "Amount"
msgstr "Import"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__write_uid"
msgid "Last Updated by"
msgstr "Última actualització per"

#. module: account_analytic_distribution_manual
#: model:ir.model.fields,field_description:account_analytic_distribution_manual.field_account_analytic_distribution_manual__write_date"
msgid "Last Updated on"
msgstr "Última actualització el"

This file was deleted.

6 changes: 3 additions & 3 deletions account_analytic_distribution_manual/models/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright 2024 Tecnativa - Carlos Lopez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import json

from lxml import etree

Expand Down Expand Up @@ -35,12 +34,13 @@ def get_view(self, view_id=None, view_type="form", **options):

def add_field(node, view_type, res_model):
attribute = "column_invisible" if view_type == "tree" else "invisible"
modifiers = json.dumps({attribute: True})
field_options = {
"name": manual_distribution_field_name,
"modifiers": modifiers,
}
field_element = etree.SubElement(node, "field", field_options)
# Now, attributes need to be set directly on the 'field_element'.
# If they are passed through 'field_options', it won't work correctly.
field_element.set(attribute, "1")
new_arch, new_models = View.postprocess_and_fields(field_element, res_model)
_merge_view_fields(all_models, new_models)
return field_element
Expand Down
2 changes: 2 additions & 0 deletions account_analytic_distribution_manual/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- Tecnativa (<https://www.tecnativa.com>):
- Carlos Lopez
- APSL - Nagarro \<<https://apsl.tech>\>
- Bernat Obrador
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
class AccountInvoiceReport(models.Model):
_inherit = "account.invoice.report"

manual_distribution_id = fields.Many2one(
"account.analytic.distribution.manual", readonly=True
)
manual_distribution_id = fields.Many2one("account.analytic.distribution.manual")

def _select(self):
return super()._select() + ", line.manual_distribution_id"
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<li>Carlos Lopez</li>
</ul>
</li>
<li>APSL - Nagarro &lt;<a class="reference external" href="https://apsl.tech">https://apsl.tech</a>&gt;<ul>
<li>Bernat Obrador</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Loading

0 comments on commit 5144581

Please sign in to comment.