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 10, 2024
1 parent 9983efa commit 5febd1f
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 51 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
7 changes: 3 additions & 4 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,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 (
Expand Down

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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
},
Expand All @@ -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,
});
Expand Down Expand Up @@ -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);
Expand All @@ -195,3 +202,5 @@ patch(AnalyticDistribution.prototype, "account_analytic_distribution_manual", {
this.autoFill();
},
});

AnalyticDistribution.components = {...AnalyticDistribution.components, AutoComplete};
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
id="analytic_distribution_inherit"
t-inherit="analytic.AnalyticDistributionPopup"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//span[@t-if='!sortedList.length']" position="before">
<xpath expr="//span[@t-if='!allPlans.length']" position="before">
<div class="pb-4 border-bottom">
<strong>Manual distribution</strong>
<AutoComplete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
invisible="active"
/>
<div class="oe_title">
<label for="name" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="inherit_id" ref="analytic.view_account_analytic_line_tree" />
<field name="arch" type="xml">
<field name="amount" position="after">
<field name="manual_distribution_id" optional="hide" />
<field name="manual_distribution_id" optional="hide" readonly="1" />
</field>
</field>
</record>
Expand All @@ -15,7 +15,7 @@
<field name="inherit_id" ref="analytic.view_account_analytic_line_form" />
<field name="arch" type="xml">
<field name="account_id" position="after">
<field name="manual_distribution_id" />
<field name="manual_distribution_id" readonly="1" />
</field>
</field>
</record>
Expand Down

0 comments on commit 5febd1f

Please sign in to comment.