From 379c04343b63771ad2236e2ea8435d3267ca29ef Mon Sep 17 00:00:00 2001 From: bobrador Date: Thu, 10 Oct 2024 14:03:42 +0200 Subject: [PATCH] [MIG] account_analytic_distribution_manual: Migration to 17.0 --- .../README.rst | 4 + .../__manifest__.py | 2 +- account_analytic_distribution_manual/hooks.py | 56 ++--- .../i18n/ca.po | 196 ++++++++++++++++++ .../migrations/16.0.2.3.0/post-migration.py | 19 -- .../models/base.py | 6 +- .../readme/CONTRIBUTORS.md | 2 + .../reports/invoice_report.py | 4 +- .../static/description/index.html | 4 + .../analytic_distribution.esm.js | 103 +++++---- .../analytic_distribution.xml | 3 +- ...ccount_analytic_distribution_manual.esm.js | 26 ++- .../test_analytic_distribution_manual.py | 14 +- ...unt_analytic_distribution_manual_views.xml | 2 +- .../views/account_analytic_line_views.xml | 4 +- 15 files changed, 334 insertions(+), 111 deletions(-) create mode 100644 account_analytic_distribution_manual/i18n/ca.po delete mode 100644 account_analytic_distribution_manual/migrations/16.0.2.3.0/post-migration.py diff --git a/account_analytic_distribution_manual/README.rst b/account_analytic_distribution_manual/README.rst index 97d42c443a..823882e898 100644 --- a/account_analytic_distribution_manual/README.rst +++ b/account_analytic_distribution_manual/README.rst @@ -84,6 +84,10 @@ Contributors - Carlos Lopez +- APSL - Nagarro + + - Bernat Obrador + Maintainers ----------- diff --git a/account_analytic_distribution_manual/__manifest__.py b/account_analytic_distribution_manual/__manifest__.py index 7f6a1daa62..592974338a 100644 --- a/account_analytic_distribution_manual/__manifest__.py +++ b/account_analytic_distribution_manual/__manifest__.py @@ -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)", diff --git a/account_analytic_distribution_manual/hooks.py b/account_analytic_distribution_manual/hooks.py index 2b355c8d9d..16b3431a21 100644 --- a/account_analytic_distribution_manual/hooks.py +++ b/account_analytic_distribution_manual/hooks.py @@ -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 @@ -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 = {} @@ -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} diff --git a/account_analytic_distribution_manual/i18n/ca.po b/account_analytic_distribution_manual/i18n/ca.po new file mode 100644 index 0000000000..6347c0867b --- /dev/null +++ b/account_analytic_distribution_manual/i18n/ca.po @@ -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" diff --git a/account_analytic_distribution_manual/migrations/16.0.2.3.0/post-migration.py b/account_analytic_distribution_manual/migrations/16.0.2.3.0/post-migration.py deleted file mode 100644 index c564a8b3d7..0000000000 --- a/account_analytic_distribution_manual/migrations/16.0.2.3.0/post-migration.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2024 Tecnativa - Víctor Martínez -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - openupgrade.logged_query( - env.cr, - """ - UPDATE account_analytic_line AS aal - SET manual_distribution_id = aml.manual_distribution_id - FROM account_move_line AS aml - WHERE aal.move_line_id = aml.id - AND aml.manual_distribution_id IS NOT NULL - AND aal.manual_distribution_id IS NULL - """, - ) diff --git a/account_analytic_distribution_manual/models/base.py b/account_analytic_distribution_manual/models/base.py index f03a5396da..a391aa52fa 100644 --- a/account_analytic_distribution_manual/models/base.py +++ b/account_analytic_distribution_manual/models/base.py @@ -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 @@ -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 diff --git a/account_analytic_distribution_manual/readme/CONTRIBUTORS.md b/account_analytic_distribution_manual/readme/CONTRIBUTORS.md index cdd4ae91a8..2e48dbfee8 100644 --- a/account_analytic_distribution_manual/readme/CONTRIBUTORS.md +++ b/account_analytic_distribution_manual/readme/CONTRIBUTORS.md @@ -1,2 +1,4 @@ - Tecnativa (): - Carlos Lopez +- APSL - Nagarro \<\> + - Bernat Obrador diff --git a/account_analytic_distribution_manual/reports/invoice_report.py b/account_analytic_distribution_manual/reports/invoice_report.py index c58835e95e..fdfc8840ac 100644 --- a/account_analytic_distribution_manual/reports/invoice_report.py +++ b/account_analytic_distribution_manual/reports/invoice_report.py @@ -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" diff --git a/account_analytic_distribution_manual/static/description/index.html b/account_analytic_distribution_manual/static/description/index.html index fdf96eb14d..a46d0786d9 100644 --- a/account_analytic_distribution_manual/static/description/index.html +++ b/account_analytic_distribution_manual/static/description/index.html @@ -434,6 +434,10 @@

Contributors

  • Carlos Lopez
  • +
  • APSL - Nagarro <https://apsl.tech>
      +
    • Bernat Obrador
    • +
    +
  • diff --git a/account_analytic_distribution_manual/static/src/components/analytic_distribution/analytic_distribution.esm.js b/account_analytic_distribution_manual/static/src/components/analytic_distribution/analytic_distribution.esm.js index 571585958b..b87d5c4fc2 100644 --- a/account_analytic_distribution_manual/static/src/components/analytic_distribution/analytic_distribution.esm.js +++ b/account_analytic_distribution_manual/static/src/components/analytic_distribution/analytic_distribution.esm.js @@ -1,12 +1,14 @@ /** @odoo-module **/ import {AnalyticDistribution} from "@analytic/components/analytic_distribution/analytic_distribution"; +import {AutoComplete} from "@web/core/autocomplete/autocomplete"; +import {_t} from "@web/core/l10n/translation"; import {patch} from "@web/core/utils/patch"; const {useState} = owl; -patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { +patch(AnalyticDistribution.prototype, { setup() { - this._super(); + super.setup(...arguments); this.manual_distribution_by_id = {}; this.state_manual_distribution = useState({ id: this.props.record.data.manual_distribution_id @@ -17,13 +19,13 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { }); }, async willStart() { - await this._super(); + await super.willStart(...arguments); if (this.state_manual_distribution.id) { this.refreshManualDistribution(this.state_manual_distribution.id); } }, async willUpdate(nextProps) { - await this._super(nextProps); + await super.willUpdate(nextProps); const record_id = this.props.record.data.id || 0; const current_manual_distribution_id = this.state_manual_distribution.id; const new_manual_distribution_id = nextProps.record.data.manual_distribution_id @@ -42,13 +44,15 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { } }, async save() { - await this._super(); - await this.props.record.update({ - manual_distribution_id: [ - this.state_manual_distribution.id, - this.state_manual_distribution.label, - ], - }); + await super.save(); + if (this.state_manual_distribution.id) { + await this.props.record.update({ + manual_distribution_id: [ + this.state_manual_distribution.id, + this.state_manual_distribution.label, + ], + }); + } }, async refreshManualDistribution(manual_distribution_id) { if (manual_distribution_id === 0) { @@ -77,7 +81,7 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { } }, get tags() { - let res = this._super(); + let res = super.tags(...arguments); if (this.state_manual_distribution.id) { // Remove the delete button from tags // it will be added only to the manual distribution tag @@ -98,16 +102,13 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { analytic_distribution: [], }; // Clear all distribution - for (const group_id in this.list) { - this.list[group_id].distribution = []; - } - this.autoFill(); + this.state.formattedData = []; }, // Autocomplete sourcesAnalyticDistributionManual() { return [ { - placeholder: this.env._t("Loading..."), + placeholder: _t("Loading..."), options: (searchTerm) => this.loadOptionsSourceDistributionManual(searchTerm), }, @@ -130,7 +131,7 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { } if (!options.length) { options.push({ - label: this.env._t("No Analytic Distribution Manual found"), + label: _t("No Analytic Distribution Manual found"), classList: "o_m2o_no_result", unselectable: true, }); @@ -165,6 +166,49 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { this.deleteManualTag(); } }, + async processSelectedOption(selected_option) { + for (const idsString in selected_option.analytic_distribution) { + const percentage = selected_option.analytic_distribution[idsString]; + + // Parse the IDs of selected_options, converting the key (e.g., "1,3") into an array of IDs [1, 3]. + const idsArray = idsString.split(",").map((id) => parseInt(id, 10)); + const lineToAdd = { + id: this.nextId++, + analyticAccounts: this.plansToArray(), + percentage: percentage / 100, + }; + + for (let i = 0; i < idsArray.length; i++) { + const accountId = idsArray[i]; + const accountData = await this.getAccountDetails(accountId); + if (accountData) { + lineToAdd.analyticAccounts.push({ + accountId: accountData.id, + accountDisplayName: accountData.display_name, + planColor: accountData.color, + accountRootPlanId: accountData.root_plan_id[0], + planId: accountData.root_plan_id[0], + planName: accountData.root_plan_id[1], + }); + } + } + this.state.formattedData.push(lineToAdd); + } + }, + async getAccountDetails(accountId) { + const record = await this.orm.read( + "account.analytic.account", + [accountId], + ["name", "color", "root_plan_id"] + ); + const accountDetails = { + id: accountId, + display_name: record[0].name, + color: record[0].color, + root_plan_id: record[0].root_plan_id, + }; + return accountDetails; + }, async onSelectDistributionManual(option) { const selected_option = Object.getPrototypeOf(option); this.state_manual_distribution = { @@ -172,26 +216,11 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { label: selected_option.label, analytic_distribution: selected_option.analytic_distribution, }; - const account_ids = Object.keys(selected_option.analytic_distribution).map( - (id) => parseInt(id, 10) - ); - const analytic_accounts = await this.fetchAnalyticAccounts([ - ["id", "in", account_ids], - ]); // Clear all distribution - for (const group_id in this.list) { - this.list[group_id].distribution = []; - } - for (const account of analytic_accounts) { - // Add new tags - const planId = account.root_plan_id[0]; - const tag = this.newTag(planId); - tag.analytic_account_id = account.id; - tag.analytic_account_name = account.display_name; - tag.percentage = selected_option.analytic_distribution[account.id]; - this.list[planId].distribution.push(tag); - } + this.state.formattedData = []; - this.autoFill(); + await this.processSelectedOption(selected_option); }, }); + +AnalyticDistribution.components = {...AnalyticDistribution.components, AutoComplete}; diff --git a/account_analytic_distribution_manual/static/src/components/analytic_distribution/analytic_distribution.xml b/account_analytic_distribution_manual/static/src/components/analytic_distribution/analytic_distribution.xml index ed720811ea..df8f19e01f 100644 --- a/account_analytic_distribution_manual/static/src/components/analytic_distribution/analytic_distribution.xml +++ b/account_analytic_distribution_manual/static/src/components/analytic_distribution/analytic_distribution.xml @@ -4,9 +4,8 @@ id="analytic_distribution_inherit" t-inherit="analytic.AnalyticDistributionPopup" t-inherit-mode="extension" - owl="1" > - +
    Manual distribution [ + stepUtils.showAppsMenuItem(), { id: "account_menu_click", content: "Go to Invoicing", @@ -24,9 +22,9 @@ tour.register( trigger: 'a:contains("Invoices")', }, { - extra_trigger: '.breadcrumb:contains("Invoices")', + extra_trigger: '.breadcrumb a:contains("Invoices")', content: "Create new invoice", - trigger: ".o_list_button_add", + trigger: 'button:contains("New")', }, { content: "Add Customer", @@ -99,6 +97,6 @@ tour.register( run: "click", }, // Save account.move - ...tour.stepUtils.saveForm(), - ] -); + ...stepUtils.saveForm(), + ], +}); diff --git a/account_analytic_distribution_manual/tests/test_analytic_distribution_manual.py b/account_analytic_distribution_manual/tests/test_analytic_distribution_manual.py index d222685855..d8387c3775 100644 --- a/account_analytic_distribution_manual/tests/test_analytic_distribution_manual.py +++ b/account_analytic_distribution_manual/tests/test_analytic_distribution_manual.py @@ -72,9 +72,17 @@ def test_manual_distribution_analytic_distribution_process_02(self): invoice_line.analytic_line_ids.mapped("manual_distribution_id"), self.distribution_1, ) - accounts = invoice_line.analytic_line_ids.mapped("account_id") - self.assertIn(aa_1, accounts) - self.assertIn(aa_2, accounts) + # In this case, the analytic account ID is stored in + # the field x_plan{self.plan_a.id}_id, + # not in the account_id field. The account_id field + # only contains the ID of the analytic + # account from the first plan (Projects), + # or the plan with ID = 1. + account_by_plan = invoice_line.analytic_line_ids.mapped( + f"x_plan{self.plan_a.id}_id" + ) + self.assertIn(aa_1, account_by_plan) + self.assertIn(aa_2, account_by_plan) def test_manual_distribution_analytic_distribution_text(self): self.analytic_account_a1.name = "test-1" diff --git a/account_analytic_distribution_manual/views/account_analytic_distribution_manual_views.xml b/account_analytic_distribution_manual/views/account_analytic_distribution_manual_views.xml index 990ecb0212..66203a9585 100644 --- a/account_analytic_distribution_manual/views/account_analytic_distribution_manual_views.xml +++ b/account_analytic_distribution_manual/views/account_analytic_distribution_manual_views.xml @@ -27,7 +27,7 @@ name="web_ribbon" title="Archived" bg_color="bg-danger" - attrs="{'invisible': [('active', '=', True)]}" + invisible="active" />