Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Update siblings in a tree view

Odebírat

Get notified when there's activity on this post

This question has been flagged
one2manytreesiblingsodoo10
1 Odpovědět
4693 Zobrazení
Avatar
Ruben Valls Blasco

Hi, I have a model which contains a parent and several children.

The parent has a computed field "product_remaining", which is updated from the modification of a different field in any of the children ("lot_qty").

The field "product_remaining" is shown in a tree for all children, using a "related" field in the children's model.

Everything is working fine, except that the tree only updates the "product_remaining" field in the row for which the modification has been done, and it does not update any other line.

Furthermore, if I click to modify a line which has not been updated by a previous change, and leave without modify it, the line gets updated correctly.


Is any way to update/refresh all the affected lines in the tree view, and not only the one where the change has been made?


I am using Odoo v10.

Here is the relevant code:


Python:

class Te2PackLotOperation(models.TransientModel):
    _name = 'te2.pack.lot.operation'
    parent_id = fields.Many2one('te2.pack.product.operation', readonly=True, ondelete='cascade')
    product_id = fields.Many2one('product.product', 'Product', related='parent_id.product_id')
    product_qty = fields.Float('Total', readonly=True, related='parent_id.product_qty')
    product_remaining = fields.Float('Remaining', readonly=True, related='parent_id.product_remaining')
    lot_id = fields.Many2one('stock.production.lot')
    lot_qty = fields.Float('Done')
    packing = fields.Char('Packing')
    @api.onchange('lot_qty')
    def onchange_lot_qty(self):
        rec = self._origin
        rec.write({'lot_qty': self.lot_qty})

class Te2PackProductOperation(models.TransientModel):
    _name = 'te2.pack.product.operation'
    product_id = fields.Many2one('product.product', 'Product', readonly=True)
    product_qty = fields.Float('Total', readonly=True)
    product_remaining = fields.Float('Remaining', readonly=True, compute='_product_remaining_get')
    lot_ids = fields.One2many('te2.pack.lot.operation', 'parent_id')
    @api.one
    @api.depends('lot_ids', 'lot_ids.lot_qty')
    def _product_remaining_get(self):
        already_done = 0
        for lot in self.lot_ids:
            already_done += lot.lot_qty
        self.product_remaining = self.product_qty - already_done


XML:

        <record id="te2_stock_picking_advanced_view_form" model="ir.ui.view">
            <field name="name">te2.pack.operation.form</field>
            <field name="model">te2.pack.product.operation</field>
            <field name="arch" type="xml">
                <form string="Advanced Stock Picking">
                    <field name="lot_ids">
                        <tree editable="bottom" create="false" delete="false"
                              decoration-danger="product_remaining!=0" decoration-success="product_remaining==0"
                              default_order="product_id">
                            <field name="product_id"/>
                            <field name="product_qty"/>
                            <field name="product_remaining"/>
                            <field name="lot_id"
                                   domain="[('product_id','=', product_id)]"
                            />
                            <field name="use_date"/>
                            <field name="lot_qty"/>
                            <field name="packing"/>
                            <button name="add_lot" string="Lot Split" type="object" icon="fa-list"/>
                        </tree>
                    </field>
                    <footer>
                        <button name="save" string="Save" type="object" class="oe_highlight" />
                        <button string="Cancel" class="oe_link" special="cancel"/>
                    </footer>
                </form>
            </field>
        </record>


0
Avatar
Zrušit
Avatar
Ruben Valls Blasco
Autor Nejlepší odpověď

Ok, after some digging, I have managed to solve the issue by extending the JavaScript classes.

If somebody is interested, the code is as follows:


odoo.define('te2_base', function(require) {
"use strict";

var core = require('web.core');

//The ListView. This view is used by the one2many field (see below)
var One2ManyUpdateAllListView = core.one2many_view_registry.get('list').extend({
init: function(viewmanager) {
var result = this._super.apply(this, arguments);
//Register to the save event
this.on("save:after", this, this.reload_all_records);
return result;
},

//Similar to "reload_record" from "list_view.js", but supporting an array of records, and moving the
//100ms delay to the end of the operation, instead of one delay per record.
reload_records: function (records, options={}) {
var self = this;
var fields = this.fields_view.fields;

if (!options || !options.do_not_evict) {
//This is from "form_relational_widgets.js".
// Evict records from cache to ensure it will be reloaded correctly
records.each( function (record) {
self.dataset.evict_record(record.get('id'));
})
}

return this.dataset.read_ids(
records.map(function (record) {return record.get('id')}),
_.pluck(_(this.columns).filter(function (r) {
return r.tag === 'field';
}), 'name'),
{check_access_rule: true}
).then(function (upd_records) {
records.each(function (record) {
var values = upd_records.find(function (upd_r) {return upd_r['id'] == record.get('id')});
if (values == undefined) {
self.records.remove(record);
} else {
// _.each is broken if a field "length" is present
for (var key in values) {
if (fields[key] && fields[key].type === 'many2many')
record.set(key + '__display', false, {silent: true});
record.set(key, values[key], {silent: true});
}
record.trigger('change', record);
}
});

var def = $.Deferred();
setTimeout(function() {
def.resolve();
}, 100);
return def;
});
},
reload_all_records: function () {
return this.reload_records(this.records);
},
});

//The Field. We should override the listview used by the field, so it uses our custom view.
var FieldOne2ManyUpdateAll = core.form_widget_registry.get('one2many').extend({
init: function() {
var result = this._super.apply(this, arguments);
this.x2many_views.list=One2ManyUpdateAllListView;
return result;
}
});

//Register the new field, so we can use it from our XML files
core.form_widget_registry.add('te2_tree_update_all', FieldOne2ManyUpdateAll);

//Make the classes available for other modules.
return {
One2ManyUpdateAllListView: One2ManyUpdateAllListView,
FieldOne2ManyUpdateAll: FieldOne2ManyUpdateAll
};
});


And it can be used just by adding the widget attribute to the field tag (note: it should be added to the "field" tag, not to the "tree" tag):


<field name="lot_op_ids" options='{"always_reload": True}' widget="te2_tree_update_all">


Best regards,

Ruben

0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
One2many field odoo version 10
one2many odoo10
Avatar
Avatar
1
zář 22
2964
One2many fields in tree views Vyřešeno
one2many tree
Avatar
Avatar
Avatar
2
lis 20
19102
"RuntimeError: maximum recursion depth exceeded in cmp" problem
one2many odoo10
Avatar
Avatar
Avatar
Avatar
4
kvě 18
12277
Values has false in one2many field when changing the customer in Sale Order ODOO 10
one2many sale.order.line odoo10
Avatar
0
bře 23
6218
Prevent create and delete on a One2many tree view Vyřešeno
treeview one2many odoo10
Avatar
1
čvc 20
9634
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now