Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Resize client upload web/static/src /js/fields/relational_fields.js (Odoo 11)

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
3554 Vistas
Avatar
Edwin valdez

Hi, modifying the web base file web/static/src /js/fields/relational_fields.js
I am resizing the images on the client side using the many2many_binary widget managed to modify it but it has problems since when it selected 10 images for example it only shows me 8 images that were uploaded to the analysis in the console it shows me that 10 images were loaded but it shows less I think it is not possible to climb due to lack of time I hope you can help me thanks.

_onFileChanged: function (ev) {
var self = this;
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;

var dataurl=null;
var filesnew=[];
var filesname=[];
var finaliza=false;
var conteo=0;
_.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],
});
}
}
if (file.type.match('image.*')) {
var MAX_WIDTH = 800;
var MAX_HEIGHT = 600;
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(e) {
var img = new Image();

img.src = e.target.result;
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
img.onload = function(){
var height = img.height;
var width = img.width;
ctx.drawImage(img, 0, 0);

if (width > MAX_WIDTH || height> MAX_HEIGHT ) {
if (width > MAX_WIDTH) {
var scaleFactor = MAX_WIDTH / width;
width = MAX_WIDTH;
height = height * scaleFactor;

} else if (height > MAX_HEIGHT) {
var scaleFactor = MAX_HEIGHT / height;
height = MAX_HEIGHT;
width = width * scaleFactor;

}
canvas.width = width;
canvas.height = height;
ctx.drawImage(img, 0, 0, width, height);


}
dataurl = canvas.toDataURL(file.type);
console.log("cantidad archivos");
console.log(files.length);
file.src = dataurl;
filesnew.push(dataurl);
filesname.push(file.name);

conteo++;

if(files.length == conteo){
finaliza=true;

}


};//fin onload image
};//fin onload reader
} else { //onload image type
conteo++;
}
self.uploadingFiles.push(file);
});
this._setValue({
operation: 'REPLACE_WITH',
ids: attachment_ids,
});


var thiss=this;
var interv = setInterval(function(){
console.log(finaliza);
console.log("SET INTERVAL");
if(finaliza){
console.log(files.length);
for(var i=0;i<filesnew.length;i++){
console.log(filesnew.src);
console.log("llama a upload");
uploadFile(filesnew[i],thiss.fileupload_id,thiss.model,filesname[i]);
}
finaliza=false;
console.log("FINALIZA");
thiss.$('.oe_fileupload').hide();
ev.target.value = "";
clearInterval(interv);
}
},3000);

function uploadFile (imagen,fileupload_id,model,name) {
console.log("ENTRA A UPLOAD");
var nombreIframe=fileupload_id;
fetch(imagen).then(res => res.blob()).then(blob => {

var xhr = new XMLHttpRequest();
xhr.open('POST', '/web/binary/upload_attachment', true);

// define new form
var formData = new FormData();
formData.append('ufile', blob,name);
formData.append('csrf_token', core.csrf_token);
formData.append('callback',nombreIframe);
formData.append('model',model);
formData.append('id','0');
// action after uploading happens
xhr.onload = function(e) {
console.log("File uploading completed! ");

var regex = new RegExp("\"", "g");
var textojavascript=(xhr.responseText.toString().replace(regex,"'").replace("<script language='javascript' type='text/javascript'>",'').replace('</script>',''));
var html = '<html><head></head><body></body></html>';


var eScript = document.createElement("script");
var script = document.createTextNode(textojavascript);
eScript.appendChild(script);

var eHead = document.createElement("head");
eHead.appendChild(eScript);


var iframe=document.getElementById(nombreIframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
//document.body.appendChild(iframe);

//document.getElementById("oe_fileupload_temp43").contentWindow.document.write(eHead);
var doc = iframe.contentWindow.document.head;
doc.append(eHead);
//document.getElementById("oe_fileupload_temp43")=eIframe;
};
// do the uploading
xhr.send(formData);
xhr.onreadystatechange = (e) => {

}
});
}



0
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Sitio web hecho con

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