Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Widget Conversion From Odoo 12 to Odoo 16

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
widgetodoo12odoo16features
2 Replies
4639 Rodiniai
Portretas
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
Portretas
Atmesti
Portretas
shubham shiroya
Best Answer

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
Portretas
Atmesti
Portretas
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

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
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

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

Registracija
Related Posts Replies Rodiniai Veikla
How to use work_permit_upload widget in Odoo16.
widget odoo16features
Portretas
Portretas
1
bal. 24
3311
Converting Odoo 12 timer widget to Odoo16
javascript widget conversion odoo12 odoo16features
Portretas
Portretas
1
rugs. 23
2561
(Odoo 16) widget: many2many_checkboxes need more features
xml widget odoo16features
Portretas
Portretas
1
geg. 24
2805
odoo 16: can i change 'priority widget' default color? Solved
widget color odoo16features
Portretas
Portretas
1
birž. 23
3601
ODOO12: how to pass values of field in javascript Solved
javascript widget odoo12
Portretas
Portretas
Portretas
2
lapkr. 22
7996
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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