Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Widget Conversion From Odoo 12 to Odoo 16

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
widgetodoo12odoo16features
2 Răspunsuri
4698 Vizualizări
Imagine profil
Denis Craciun

I have this custom widget that is used in an Odoo 12 project. I am new to Odoo still, and I need to convert it to Odoo 16. I am familiar with Odoo 12 because that's the version I followed a course from, but not with 16, so I can't really understand where the problem could be, but I am pretty sure it's in the widget.js file, and maybe it's something related to the libraries that are required in the code (maybe they are outdated)? The manifest file should be correct (unless there are some major changes that you are aware), and the view is a very simple xml file that shouldn't have any problems.

What this widget does btw, it takes a pdf file and it creates an url for it so you can preview it.

Thanks in advance, let me know if there's something I've been missing, but here's the js file:

odoo.define("pdf_preview_widget", function (require) {

  "use strict";


  var core = require('web.core');

  var fieldRegistry = require("web.field_registry");

  var basicFields = require("web.basic_fields");


  var PdfPreviewWidget = basicFields.FieldBinaryFile.extend({

    template: "PdfPreviewWidget",

    

    _renderModal: function (data) {

      const self = this;


      if($('.pdf-preview-modal').length) return;


      let modalTemplate = core.qweb.render('PdfPreviewModal', {

        iframe_data: data

      });


      $('body').append(modalTemplate);

      $('.modal-window').addClass('visible');

      $(".modal-close").on('click', function(ev) {

        ev.preventDefault();


        $(this).parent().parent().parent().remove();

      });

    },


    _b64toBlob: function(b64Data, contentType='', sliceSize=512) {

      const byteCharacters = atob(b64Data);

      const byteArrays = [];

    

      for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {

        const slice = byteCharacters.slice(offset, offset + sliceSize);

    

        const byteNumbers = new Array(slice.length);

        for (let i = 0; i < slice.length; i++) {

          byteNumbers[i] = slice.charCodeAt(i);

        }

    

        const byteArray = new Uint8Array(byteNumbers);

        byteArrays.push(byteArray);

      }

    

      const blob = new Blob(byteArrays, {type: contentType, title: 'Download.pdf'});

      return blob;

    },


    _render: function () {

      const self = this;


      this.$(".oe_field_pdf_preview").on('click', function(ev) {

        ev.preventDefault();


        const resBlob = self._b64toBlob(self.value, 'application/pdf');

        const resFile = new File([resBlob], 'Download.pdf', {type: 'application/pdf'});

        const resUrl = URL.createObjectURL(resFile, {type: 'application/pdf'});


        self._renderModal(resUrl);

      });

    }

  });


  fieldRegistry.add("pdf_preview", PdfPreviewWidget);

});
0
Imagine profil
Abandonează
Imagine profil
shubham shiroya
Cel mai bun răspuns

try this way:
odoo.define("pdf_preview_widget", function (require) {
"use strict";

var core = require("web.core");
var BasicFields = require("web.basic_fields");

var PdfPreviewWidget = BasicFields.FieldBinaryFile.extend({
template: "PdfPreviewWidget",

_render: function () {
var self = this;

this.$(".oe_field_pdf_preview").on("click", function (ev) {
ev.preventDefault();

var resBlob = self._b64toBlob(self.value, "application/pdf");
var resUrl = URL.createObjectURL(resBlob);

self._renderModal(resUrl);
});
},

_renderModal: function (data) {
if ($(".pdf-preview-modal").length) return;

var modalTemplate = core.qweb.render("PdfPreviewModal", {
iframe_data: data,
});

$("body").append(modalTemplate);
$(".modal-window").addClass("visible");

$(".modal-close").on("click", function (ev) {
ev.preventDefault();
$(this).parent().parent().parent().remove();
});
},

_b64toBlob: function (b64Data, contentType = "", sliceSize = 512) {
var byteCharacters = atob(b64Data);
var byteArrays = [];

for (
var offset = 0;
offset < byteCharacters.length;
offset += sliceSize
) {
var slice = byteCharacters.slice(offset, offset + sliceSize);

var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}

var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}

var blob = new Blob(byteArrays, { type: contentType, title: "Download.pdf" });
return blob;
},
});

return {
PdfPreviewWidget: PdfPreviewWidget,
};
});

0
Imagine profil
Abandonează
Imagine profil
Cybrosys Techno Solutions Pvt.Ltd
Cel mai bun răspuns

Hi,
There is a lot of change that comes when Odoo was upgraded from version 12 to 16. Currently, in the case of the backend, we are using OWL (Odoo Web Library)
To create a field widget in Odoo 16, you can follow the instructions provided in this blog: "How to Create a Field Widget in Odoo 16".
https://www.cybrosys.com/blog/how-to-create-a-field-widget-in-the-odoo-16
The blog should provide you with detailed steps and guidance on creating a custom field widget in Odoo 16.

Hope it helps

0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to use work_permit_upload widget in Odoo16.
widget odoo16features
Imagine profil
Imagine profil
1
apr. 24
3338
Converting Odoo 12 timer widget to Odoo16
javascript widget conversion odoo12 odoo16features
Imagine profil
Imagine profil
1
sept. 23
2606
(Odoo 16) widget: many2many_checkboxes need more features
xml widget odoo16features
Imagine profil
Imagine profil
1
mai 24
2871
odoo 16: can i change 'priority widget' default color? Rezolvat
widget color odoo16features
Imagine profil
Imagine profil
1
iun. 23
3645
ODOO12: how to pass values of field in javascript Rezolvat
javascript widget odoo12
Imagine profil
Imagine profil
Imagine profil
2
nov. 22
8069
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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