Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

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

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
domaindynamiconload
6 Replies
17108 Rodiniai
Portretas
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
Portretas
Atmesti
Zbik
Autorius

Thanks, I will check soon.

Portretas
Zbik
Autorius Best Answer

@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
Portretas
Atmesti
Mathieu Laflamme

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

Zbik
Autorius

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

Portretas
Royal Administrator
Best Answer

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
Portretas
Atmesti
Portretas
Mariusz Mizgier
Best Answer

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
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

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

Registracija
Related Posts Replies Rodiniai Veikla
use dynamic value in domain
domain dynamic
Portretas
Portretas
Portretas
2
geg. 24
8632
dynamic domain in one2many Solved
domain one2many dynamic
Portretas
Portretas
Portretas
2
geg. 24
10091
How to set many2one domain based on many2many field in odoo
domain many2one dynamic
Portretas
Portretas
1
saus. 22
12878
Dynamic Domain in Windows Action Solved
domain purchase_order dynamic
Portretas
Portretas
1
liep. 20
16862
Dynamically Restrict Choices in One2Many Relation Based on Already Selected Values
domain domain_filter dynamic attributes
Portretas
0
kov. 24
1876
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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