Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

How get my field value in custom widget.

Subscriure's

Get notified when there's activity on this post

This question has been flagged
fieldsfieldqwebjsOdoo13.0
8158 Vistes
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
Descartar
Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Related Posts Respostes Vistes Activitat
How to overwrite field string name?
field qweb js
Avatar
Avatar
1
de set. 19
6812
Creating a custom field widget on Odoo ERP system Solved
fields widget js Odoo13.0
Avatar
Avatar
1
de gen. 20
7795
How to overwrite field name?
field qweb js backbone.js
Avatar
0
de set. 19
7
How to use fieldsToFetch, for set values from my field.
widget qweb js table Odoo13.0
Avatar
0
de març 21
5978
Concatenate two fields in a third one Solved
fields field
Avatar
Avatar
Avatar
2
d’ag. 24
3247
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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