Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Equivalent javascript onLoad() - it is possible when form is loaded?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
domaindynamiconload
6 Odpowiedzi
17107 Widoki
Awatar
Zbik

This question is related to my previous question: conditional, dynamic field domain.

Example:

<field name="xxx"/>
<field name="yyy_ids" widget="many2many" domain="....DOMAIN......">

I know how to change the domain for yyy_ids when signal change is generated 

@api.onchange('xxx')
def do_xxx(self):

.... here code to change DOMAIN...

return {'domain': {'yyy_ids': ....DOMAIN_VALUE....}}

but how generate onchange signal, at the start, when form will be loaded?

0
Awatar
Odrzuć
Zbik
Autor

Thanks, I will check soon.

Awatar
Zbik
Autor Najlepsza odpowiedź

@Mariusz, PARTLY SOLVED :(. Yes, we now have a new system behavior. Method onchage is fired when a record is created, but if record already exist onchange is not fired, regardless of the default and the new contents of the field xxx.

1
Awatar
Odrzuć
Mathieu Laflamme

Any workaround on that? I have the same challenge and I don't know what to do yet :(

Zbik
Autor

I have no new messages. See: https://github.com/odoo/odoo/issues/5199

Awatar
Royal Administrator
Najlepsza odpowiedź

Here is a way to cause the As Of date to immediately be modified when edit mode is entered:

  - a new FieldAutoJS widget that runs javascript from the xml when it becomes editable
  - declare a new writable field with create and write hooks that clear any attempted writes
  - include the field invisibly on the form and use the autojs widget to set any value
  - in onchange for the new field, if the field is not set, do whatever actions desired to initialize the form, e.g. set date

Javascript:

// 13.0.6.13.2-t8 jimays
// code--1299-edc6-4d86f0db-acb0-f9ee6cefae13--13.0.6.13.2-t8--7.55.20--5.22--XYqqm7*iTnaBOodPqhvqh1
//---------------------------------------------------------------------------------------------

odoo.define('carlisleofficesuites.thermostats', function (require){
'use strict';
var form_widget = require('web.form_widgets');
var core = require('web.core');

// gratitude https://www.odoo.com/forum/help-1/question/equivalent-javascript-onload-it-is-possible-when-form-is-loaded-75863
// gratitude https://www.odoo.com/forum/aide-1/question/how-to-customize-the-onclick-javascript-action-of-an-edit-button-odoo-10-125253
// gratitude https://www.odoo.com/fr_FR/forum/aide-1/question/onchange-method-works-before-something-change-on-field-odoo11-133024
// gratitude https://stackoverflow.com/questions/7650071/is-there-a-way-to-create-a-function-from-a-string-with-javascript
// gratitude https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
// which precisely asks the question, and also
// gratitude https://stackoverflow.com/questions/31187456/which-method-is-called-when-user-click-on-edit-button
// gratitude https://stackoverflow.com/questions/11970035/change-field-value-and-trigger-onchange-event-on-button-press
// gratitude https://www.odoo.com/forum/aide-1/question/how-to-trigger-an-action-onload-of-a-form-view-23593
// gratitude https://www.odoo.com/forum/help-1/question/override-a-field-s-value-on-form-load-108986
// gratitude https://www.odoo.com/forum/aide-1/question/default-method-trigger-my-api-onchange-method-why-151042
// "Since a default value is being loaded..., there is a change in value which will trigger the onchange method.
// So whenever the value in that field changes, even when the default value is loaded, it will trigger the onchange method."
// "Try creating a new invisible field without any value. In your onchange check whether this field is empty or not.
// If it is empty, write some value to this field and exit. If it is not empty continue with your onchange.
// I mentioned this because this is easy to understand. There may be better ways to accomplish the same thing."
// gratitude https://www.odoo.com/forum/aide-1/question/onchange-method-works-before-something-change-on-field-odoo11-133024
// "... when form is load, onchange method is automatically called."
// gratitude http://elico-corp.com.sg/2015/10/01/how-to-tech-dynamically-modify-your-view/
// gratitude https://stackoverflow.com/questions/39424027/adding-a-button-in-tree-view-odoo-8
// gratitude addons/web/static/src/js/views/form_view.js
// gratitude addons/web/static/src/js/views/form_widgets.js
// gratitude FieldsBoolean and FieldsPriority and FieldBinaryFile
//
// Pair with:
//
// <field name="auto" widget="autojs" autojs="your_function();"/?
//
// To force an onchange when Edit is clicked, field can add invisible="1" to the xml
// Couple this code with create and write hooks that always clear the field from the write vals.
//
// <field name="auto" widget="autojs" autojs="return 'auto';" invisible="1"/>
//
// as_of = fields.Datetime('As Of', required=True)
// auto = fields.Char('Auto')
//
// @api.onchange('auto')
// def onchange_auto(self):
// if not self.auto:
// # the as_of is visibly adjusted when Edit is clicked
// self.as_of = fields.datetime.now()
//
// @api.model
// def update_write_vals(self, vals):
// vals['as_of'] = fields.Datetime.now()
// if 'auto' in vals:
// del vals['auto']
//
// @api.model
// @api.returns('self', lambda value: value.id)
// def create(self, vals):
// self.update_write_vals(vals)
// return super(ThisModel, self).create(vals)
//
// @api.multi
// def write(self, vals):
// self.update_write_vals(vals)
// super(ThisModel, self).write(vals)

var FieldAutoJS = form_widget.FieldChar.extend({
start: function(){
true && console.log('FieldAuto.start: this.field: ' + JSON.stringify(this.field));
true && console.log('FieldAuto.start: this.options.model_field: ' + JSON.stringify(this.options.model_field));
var self = this;
var change_effective_readonly = function(){
if(!self.get("effective_readonly")){
true && console.log('FieldAuto: Auto field has become editable.');
if('autojs' in self.node.attrs){
true && console.log('FieldAuto: Setting value with javascript: ' + self.node.attrs.autojs);
var autojs_function = new Function(self.node.attrs.autojs);
var newValue = autojs_function(self);
var oldValue = self.get_value();
true && console.log('FieldAuto: Triggering change:value, oldValue: ' + oldValue + ', newValue: ' + newValue);
self.trigger("change:value", self, { oldValue: oldValue, newValue: newValue });
self.render_value();
}
}
};
this.on("change:effective_readonly", this, change_effective_readonly);
change_effective_readonly.call(this);
this._super.apply(this, arguments);
},
});

core.form_widget_registry.add('autojs', FieldAutoJS);
});

Python

class CarlisleOfficeSuites_Thermostat(models.Model):
_name = 'carlisleofficesuites.thermostat'
_rec_name = 'zone'

zone = fields.Char('Zone', required=True)

# 13.0.6.13.2-t8 The auto field is always blank in the database and always auto-set by the javascript upon entering form view edit mode.
# This trick makes the form have a changed value as soon as it opens for edit, which visibly pre-adjusts the As Of, which is cute,
# and more importantly marks the form as changed so a save actually calls the write hook, and the latest draft settings become active.

as_of = fields.Datetime('As Of', required=True)
auto = fields.Char('Auto')

@api.onchange('auto')
def onchange_auto(self):
_logger.debug('onchange_auto, self.auto: ' + unicode(self.auto))
if not self.auto:
​ # the as_of is visibly adjusted when Edit is clicked
            self.as_of = fields.datetime.now()
    @api.model
def update_write_vals(self, vals):
vals['as_of'] = fields.Datetime.now()
if 'auto' in vals:
del vals['auto']
    @api.model
@api.returns('self', lambda value: value.id)
def create(self, vals):
self.update_write_vals(vals)
return super(CarlisleOfficeSuites_Thermostat, self).create(vals)

@api.multi
def write(self, vals):
self.update_write_vals(vals)
super(CarlisleOfficeSuites_Thermostat, self).write(vals)
return True
0
Awatar
Odrzuć
Awatar
Mariusz Mizgier
Najlepsza odpowiedź

Did you try: 1. apply this patch - https://github.com/odoo/odoo/commit/2067a206ecba9a8dbf7f76a55926be964e580e7e 2. move your xxx before yyy_ids in form view 3. set _defaults for xxx to False Didn't check that, but that should work - if not, maybe change in logic (defaults = True) so that this field does change it's value.

0
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
use dynamic value in domain
domain dynamic
Awatar
Awatar
Awatar
2
maj 24
8628
dynamic domain in one2many Rozwiązane
domain one2many dynamic
Awatar
Awatar
Awatar
2
maj 24
10091
How to set many2one domain based on many2many field in odoo
domain many2one dynamic
Awatar
Awatar
1
sty 22
12872
Dynamic Domain in Windows Action Rozwiązane
domain purchase_order dynamic
Awatar
Awatar
1
lip 20
16859
Dynamically Restrict Choices in One2Many Relation Based on Already Selected Values
domain domain_filter dynamic attributes
Awatar
0
mar 24
1872
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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