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
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • 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
    Browse all Industries
  • 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
    • Services for Partners
    • 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

How get my field value in custom widget.

Odebírat

Get notified when there's activity on this post

This question has been flagged
fieldsfieldqwebjsOdoo13.0
8130 Zobrazení
Avatar
Pavel

How to get the value of my field in my custom widget(contact.DragWidget), for set in my template.
Code samples.

My field:

<field name="attachment_ids" widget="contact.DragWidget"/>

My widget code:

console.log('Hi im work')
odoo.define('sale.ch15_r01_drag', function (require) {
'use strict';
var core = require('web.core');
var QWeb = core.qweb;
var relational_fields = require('web.relational_fields');
var registry = require('web.field_registry');
var rpc = require('web.rpc');
// var model = new instance.web.Model("oepetstore.message_of_the_day");
var ContactDragWidget = relational_fields.FieldMany2Many.extend({
template: "Field.Drag.template",
events: {
'click .o_attach': '_onAttach',
'click .o_attachment_delete': '_onDelete',
'change .o_input_file': '_onFileChanged',
},

willStart: function() {
console.log(this)
return Promise.all([
this._super.apply(this, arguments),
this._getHtml()
]);
},

init: function(parent, name, record, options) {
this._super.apply(this, arguments);
console.log(parent, name, record, options)
},

_getHtml() {
var self = this;
let domain = [];
let field = [];
self.categories = [];
return rpc.query({
model: 'categories',
method: 'search_read',
args: [domain, field],
}).then(function (data) {
for (var key in data) {
self.categories.push(data[key].category_name)
}
self.test = '15'
}).catch(function (error){
console.error(`You have this error:${error}`);
});;
},

start: function () {
this._super.apply(this, arguments);
console.log(this)
},


_onAttach: function () {
this.$('.o_input_file').click();
},


_onDelete: function (ev) {
ev.preventDefault();
ev.stopPropagation();

var fileID = $(ev.currentTarget).data('id');
var record = _.findWhere(this.value.data, {res_id: fileID});
if (record) {
this._setValue({
operation: 'FORGET',
ids: [record.id],
});
var metadata = this.metadata[record.id];
if (!metadata || metadata.allowUnlink) {
this._rpc({
model: 'ir.attachment',
method: 'unlink',
args: [record.res_id],
});
}
}
},

_onFileChanged: function (ev) {
var self = this;
ev.stopPropagation();

var files = ev.target.files;
var attachment_ids = this.value.res_ids;

// Don't create an attachment if the upload window is cancelled.
if(files.length === 0)
return;

_.each(files, function (file) {
var record = _.find(self.value.data, function (attachment) {
return attachment.data.name === file.name;
});
if (record) {
var metadata = self.metadata[record.id];
if (!metadata || metadata.allowUnlink) {
// there is a existing attachment with the same name so we
// replace it
attachment_ids = _.without(attachment_ids, record.res_id);
self._rpc({
model: 'ir.attachment',
method: 'unlink',
args: [record.res_id],
});
}
}
self.uploadingFiles.push(file);
});

this._setValue({
operation: 'REPLACE_WITH',
ids: attachment_ids,
});

// this.$('form.o_form_binary_form').submit();
this.$('.oe_fileupload').hide();
ev.target.value = "";
},


});

registry.add('contact.DragWidget', ContactDragWidget)
});

My tamplate:

 <t t-name="Field.Drag.template">
<t t-if="data" t-set="file" t-value="file.data"/>
<t t-set="editable" t-value="widget.mode === 'edit'"/>
<t t-if="mimetype" t-set="mimetype" t-value="mimetype"/>
<div class="d-flex flex-wrap justify-content-around" >
<!-- <span><t t-esc="attachments.name"/>Hello world</span>-->
<t t-foreach="widget.categories" t-as="i">
<article class="article-category">
<div class="article-category_header d-flex justify-content-between align-items-baseline"><h4><t t-esc="i"/></h4><button t-if="widget.mode !== 'readonly'" class="btn btn-secondary o_attach" title="Attach"><span class="fa fa-paperclip" aria-label="Attach"/>Add</button></div>
<!-- <div class="article-category_content">-->
<!-- <div t-if="file.category_id === i" class="attachment-item">-->

<!-- </div>-->
<!-- </div>-->
<div class="oe_placeholder_files"/>
<div t-if="widget.mode !== 'readonly'" class="oe_add">
<t t-call="HiddenInputFile">
<t t-set="fileupload_id" />
<t t-set="fileupload_action" t-translation="off">/web/binary/upload_attachment</t>
<t t-set="multi_upload" t-value="true"/>
<input type="hidden" name="model" t-att-value="widget.model"/>
<input type="hidden" name="id" value="0"/>
</t>
</div>
</article>
</t>
</div>
</t>
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
How to overwrite field string name?
field qweb js
Avatar
Avatar
1
zář 19
6788
Creating a custom field widget on Odoo ERP system Vyřešeno
fields widget js Odoo13.0
Avatar
Avatar
1
led 20
7771
How to overwrite field name?
field qweb js backbone.js
Avatar
0
zář 19
7
How to use fieldsToFetch, for set values from my field.
widget qweb js table Odoo13.0
Avatar
0
bře 21
5972
Concatenate two fields in a third one Vyřešeno
fields field
Avatar
Avatar
Avatar
2
srp 24
3228
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