Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

get the model in js

Odoberať

Get notified when there's activity on this post

This question has been flagged
javascriptmodelnameodoo16features
3 Replies
4760 Zobrazenia
Avatar
Denis Lutsak

Hello, can anyone help me with getting the model I'm working in now? I have a button that should be clicked to execute a webhook, but I can't get the model in which the button is clicked. i'm new to js, so it's very difficult to understand


0
Avatar
Zrušiť
Avatar
Aravind S
Best Answer

usually model is inside this keyword. That depends on where you call it. If nothing works the last option is get the url of the current page and get the model from it.

var url = window.location.href;
2
Avatar
Zrušiť
Avatar
Dương Nguyễn
Best Answer

This is how odoo field get the current  model

https://github.com/odoo/odoo/blob/849ece86a6cf49c0a9249ed910aa52add197f431/addons/web/static/src/views/fields/binary/binary_field.js#L43

It seem that you trying to create a new field extend from some field right, i don't think what you are coding seem fit to odoo in general, window.makeCall is not the way to define some method in Odoo OWL or Legacy

0
Avatar
Zrušiť
Avatar
Denis Lutsak
Autor Best Answer
window.makeCall = function(event) {
event.preventDefault();

var $button = $(event.currentTarget);
var modelName = this.dataset.model;
var recordId = $button.attr('data-record-id');
var phone = $button.prev('input.o_input').val();

console.log('Model Name:', modelName);
// Determine context and set data accordingly
var data = {
phone: phone,
contact_id: modelName === 'res.partner' ? recordId : undefined,
lead_id: modelName === 'crm.lead' ? recordId : undefined,
};

// Example of fetching additional data if needed
if (modelName === 'crm.lead') {
odoo.define('model.func', function(require) {
var rpc = require('web.rpc');
rpc.query({
model: modelName,
method: 'read',
args: [[recordId], ['partner_id']],
}).then(function(records) {
var record = records[0];
if (record.partner_id) {
data.contact_id = record.partner_id[0];
}

// Now, make the AJAX call with the complete data object
$.ajax({
url: url,
type: "POST",
contentType: "application/json",
data: JSON.stringify(data),
success: function(response) {
console.log("Call initiated successfully", response);
},
error: function(error) {
console.error("Error initiating call", error);
}
});
});
});
} else {
// If not crm.lead or additional data not needed, make the call directly
$.ajax({
url: url,
type: "POST",
contentType: "application/json",
data: JSON.stringify(data),
success: function(response) {
console.log("Call initiated successfully", response);
},
error: function(error) {
console.error("Error initiating call", error);
}
});
}
};


0
Avatar
Zrušiť
Denis Lutsak
Autor

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="web.PhoneField" owl="1">
<div class="o_phone_content d-inline-flex w-100">
<t t-if="props.readonly">
<a t-if="props.value" class="o_form_uri" t-att-href="phoneHref" t-esc="props.value"/>
</t>
<t t-else="">
<input
class="o_input"
t-att-id="props.id"
type="tel"
autocomplete="off"
t-att-placeholder="props.placeholder"
t-ref="input"
/>
</t>
</div>
</t>

<t t-name="web.FormPhoneField" t-inherit="web.PhoneField" t-inherit-mode="primary">
<xpath expr="//input" position="after">
<a
t-if="props.value"
href="#"
onclick="makeCall(event)"
class="o_phone_form_link ms-3 d-inline-flex align-items-center"
t-att-data-model-name="props.modelName"
t-att-data-record-id="props.recordId"
>
<i class="fa fa-phone"></i><small class="fw-bold ms-1">Call</small>
</a>
</xpath>
</t>
</templates>

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

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
Can't log the console inside the include javascript Odoo v16 Solved
javascript odoo16features
Avatar
Avatar
1
apr 24
3092
Odoo 16.0 CE - Missing widget: radio_reduce_selection for field of type selection
javascript odoo16features
Avatar
0
jan 24
2604
What is the Best Practice for Integrating JavaScript in Odoo 16?
javascript odoo16features
Avatar
Avatar
1
sep 23
4217
Odoo 16 JavaScript: TypeError: utils.getComponent(...).IsCustomButton is not a function
javascript odoo16features
Avatar
Avatar
2
apr 23
6399
How to call javascript on button click Solved
javascript odoo16features
Avatar
Avatar
2
jan 23
8896
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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