Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

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

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Solved -- Onchange 2 fields in javascript widget

Subscribe

Get notified when there's activity on this post

This question has been flagged
javascriptpythonwidgetodooonchange_event
1 Reply
14645 Views
Avatar
Mostafa Mohamed Abdel Monaem

i need to use onchange fucntion in JavaScript widget

i have 2 fields in a javascript widget 1st(account which refer to contracts) and 2nd(task which refer to customers) and i want to use onchange between them

i want to change account field based on task field ,, that when i choose customer it should load only contracts of that customer only

anyone face that before ? could you give me examples ?


here is my code

openerp.net2do_elkamel = function (instance) {

var module = instance.hr_timesheet_sheet

module.WeeklyTimesheet = module.WeeklyTimesheet.extend({
events: {
"click .oe_timesheet_weekly_account a": "go_to",
"click .oe_timesheet_weekly_task a": "go_to_partner",
},
go_to_partner: function (event) {
var id = JSON.parse($(event.target).data("cus-id"));
this.do_action({
type: 'ir.actions.act_window',
res_model: "res.partner",
res_id: id,
views: [[false, 'form']],
target: 'current'
});
},
initialize_content: function () {
var self = this;
if (self.setting)
return;
// don't render anything until we have date_to and date_from
if (!self.get("date_to") || !self.get("date_from"))
return;
this.destroy_content();

// it's important to use those vars to avoid race conditions
var dates;
var accounts;
var account_names;
var task_names;
var default_get;
return this.render_drop.add(new instance.web.Model("hr.analytic.timesheet").call("default_get", [
['account_id', 'customer', 'general_account_id', 'journal_id', 'date', 'name', 'user_id', 'product_id', 'product_uom_id', 'to_invoice', 'amount', 'unit_amount'],
new instance.web.CompoundContext({'user_id': self.get('user_id')})]).then(function (result) {
default_get = result;
// calculating dates
dates = [];
var start = self.get("date_from");
var end = self.get("date_to");
while (start <= end) {
dates.push(start);
start = start.clone().addDays(1);
}

timesheet_lines = _(self.get("sheets")).chain()
.map(function (el) {
// much simpler to use only the id in all cases
if (typeof(el.account_id) === "object")
el.account_id = el.account_id[0];
if (typeof(el.customer) === "object")
el.customer = el.customer[0];
return el;
}).value();

// group by account
var timesheet_lines_by_account_id = _.groupBy(timesheet_lines, function (el) {
return el.account_id;
});

// group by account and customer
var timesheet_lines_by_account_id_task_id = _.groupBy(timesheet_lines, function (el) {
return [el.account_id, el.customer];
});

var account_ids = _.map(_.keys(timesheet_lines_by_account_id), function (el) {
return el === "false" ? false : Number(el)
});

return new instance.web.Model("hr.analytic.timesheet").call("multi_on_change_account_id", [[], account_ids,
new instance.web.CompoundContext({'user_id': self.get('user_id')})]).then(function (accounts_defaults) {
accounts = _(timesheet_lines_by_account_id_task_id).chain().map(function (lines, account_id_task_id) {
account_defaults = _.extend({}, default_get, (accounts_defaults[lines[0].account_id] || {}).value || {});
// group by days
var index = _.groupBy(lines, "date");
var days = _.map(dates, function (date) {
var day = {day: date, lines: index[instance.web.date_to_str(date)] || []};
// add line where we will insert/remove hours
var to_add = _.find(day.lines, function (line) {
return line.name === self.description_line
});
if (to_add) {
day.lines = _.without(day.lines, to_add);
day.lines.unshift(to_add);
} else {
day.lines.unshift(_.extend(_.clone(account_defaults), {
name: self.description_line,
unit_amount: 0,
date: instance.web.date_to_str(date),
account_id: lines[0].account_id,
customer: lines[0].customer,
}));
}
return day;
});
return {
account_task: account_id_task_id,
account: lines[0].account_id,
task: lines[0].customer,
days: days,
account_defaults: account_defaults
};
}).value();

// we need the name_get of the analytic accounts
return new instance.web.Model("account.analytic.account").call("name_get", [_.pluck(accounts, "account"),
new instance.web.CompoundContext()]).then(function (result) {
account_names = {};
_.each(result, function (el) {
account_names[el[0]] = el[1];
});
// we need the name_get of the customer
return new instance.web.Model("res.partner").call("name_get", [_(accounts).chain().pluck("task").filter(function (el) {
return el;
}).value(),
new instance.web.CompoundContext()]).then(function (result) {
task_names = {};
_.each(result, function (el) {
task_names[el[0]] = el[1];
});
accounts = _.sortBy(accounts, function (el) {
return account_names[el.account];
});
});
});
});
})).then(function (result) {
// we put all the gathered data in self, then we render
self.dates = dates;
self.accounts = accounts;
self.account_names = account_names;
self.task_names = task_names;
self.default_get = default_get;
//real rendering
self.display_data();
});
},
init_add_account: function () {
var self = this;
if (self.dfm)
return;
self.$(".oe_timesheet_weekly_add_row").show();
self.dfm = new instance.web.form.DefaultFieldManager(self);
self.dfm.extend_field_desc({
account: {
relation: "account.analytic.account",
},
task: {
relation: "res.partner",
},
});
self.task_m2o = new instance.web.form.FieldMany2One(self.dfm, {
attrs: {
name: "task",
type: "many2one",
modifiers: '{"required": true}',
},
});


self.account_m2o = new instance.web.form.FieldMany2One(self.dfm, {

attrs: {
name: "account",
type: "many2one",
domain: [
['type', 'in', ['normal', 'contract']],
['use_timesheets', '=', 1],
],
widget:"selection",

context: {
default_use_timesheets: 1,
default_type: "contract",
default_partner_id:self.task_m2o.value,
},
modifiers: '{"required": true}',
},
});


self.task_m2o.prependTo(self.$(".oe_timesheet_weekly_add_row td"));
self.account_m2o.prependTo(self.$(".oe_timesheet_weekly_add_row td"));

self.account_m2o.$input.focusout(function () {
var account_id = self.account_m2o.get_value();
if (account_id === false) {
return;
}
self.task_m2o.init(self.dfm, {
attrs: {
name: "task",
type: "many2one",
context: {
'account_id': account_id,
},
},
});
// reset value previously selected
self.task_m2o.set_value(false);
self.task_m2o.render_value();
});

self.$(".oe_timesheet_weekly_add_row button").click(function () {
var id = self.account_m2o.get_value();
if (id === false) {
self.dfm.set({display_invalid_fields: true});
return;
}
var ops = self.generate_o2m_value();
new instance.web.Model("hr.analytic.timesheet").call("on_change_account_id", [[], id]).then(function (res) {
var def = _.extend({}, self.default_get, res.value, {
name: self.description_line,
unit_amount: 0,
date: instance.web.date_to_str(self.dates[0]),
account_id: id,
customer: self.task_m2o.get_value(),
});
ops.push(def);
self.set({"sheets": ops});
});
});
},

get_box: function (account, day_count) {
return this.$('[data-account-task="' + account.account_task + '"][data-day-count="' + day_count + '"]');
},
get_total: function (account) {
return this.$('[data-account-task-total="' + account.account_task + '"]');
},
});
};



0
Avatar
Discard
Avatar
Mostafa Mohamed Abdel Monaem
Author Best Answer


Here is what i add but didn't work i don't know why!


self.task_m2o.change(function () {
alert("Here is the change")
var task_id = self.task_m2o.get_value();
if (task_id === false) {
return;
}
self.account_m2o.init(self.dfm, {
attrs: {
name: "account",
type: "many2one",
domain: [
['type', 'in', ['normal', 'contract']],
['use_timesheets', '=', 1],
['partner_id', '=', task_id]
],
context: {
default_use_timesheets: 1,
default_type: "contract",
default_partner_id: self.task_m2o.value,
},
modifiers: '{"required": true}',
},
});
// reset value previously selected
self.account_m2o.set_value(false);
self.account_m2o.render_value();
});



0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Call wizard view in js function
javascript python odoo
Avatar
Avatar
1
दिस॰ 22
4379
TypeError: Cannot read property 'taxes_by_id' of undefined at DiscountButton.apply_discount
javascript python odoo
Avatar
0
दिस॰ 20
50
How to call JavaScript from python function?
javascript python odoo
Avatar
0
दिस॰ 15
14334
Display header only on the first page and footer on the last page Qweb Odoo 14
javascript python xml odoo
Avatar
Avatar
Avatar
2
अग॰ 24
7745
ODOO9: How to call save function in javascript?
javascript widget save odoo
Avatar
Avatar
1
जन॰ 23
5566
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة 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, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

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