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..30594ba3d7 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,9 +105,8 @@ } -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 ( 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..85ae589980 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", { - setup() { - this._super(); +patch(AnalyticDistribution.prototype, { + async setup() { + 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 @@ -107,7 +111,7 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { sourcesAnalyticDistributionManual() { return [ { - placeholder: this.env._t("Loading..."), + placeholder: _t("Loading..."), options: (searchTerm) => this.loadOptionsSourceDistributionManual(searchTerm), }, @@ -130,7 +134,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, }); @@ -178,11 +182,14 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { const analytic_accounts = await this.fetchAnalyticAccounts([ ["id", "in", account_ids], ]); + const accountsArray = Array.isArray(analytic_accounts) + ? analytic_accounts + : Object.values(analytic_accounts); // Clear all distribution for (const group_id in this.list) { this.list[group_id].distribution = []; } - for (const account of analytic_accounts) { + for (const account of accountsArray) { // Add new tags const planId = account.root_plan_id[0]; const tag = this.newTag(planId); @@ -195,3 +202,5 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", { this.autoFill(); }, }); + +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