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

Override a javascript function in Odoo 11?

Abonare

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

Această întrebare a fost marcată
javascriptodooodoo11
3 Răspunsuri
9923 Vizualizări
Imagine profil
Kabeer KB

I want to inherit function `add_product` of `models.Order`.

Here is the original function

**/point_of_sale/static/src/js/models.js*  

      add_product: function(product, options){

        if(this._printed){

            this.destroy();

            return this.pos.get_order().add_product(product, options);

        }

        this.assert_editable();

        options = options || {};

        var attr = JSON.parse(JSON.stringify(product));

        attr.pos = this.pos;

        attr.order = this;

        var line = new exports.Orderline({}, {pos: this.pos, order: this, product: product});

        if(options.quantity !== undefined){

            line.set_quantity(options.quantity);

        }

        if(options.price !== undefined){

            line.set_unit_price(options.price);

        }


        //To substract from the unit price the included taxes mapped by the fiscal position

        this.fix_tax_included_price(line);

        if(options.discount !== undefined){

            line.set_discount(options.discount);

        }

        if(options.extras !== undefined){

            for (var prop in options.extras) {

                line[prop] = options.extras[prop];

            }

        }

        var to_merge_orderline;

        for (var i = 0; i < this.orderlines.length; i++) {

            if(this.orderlines.at(i).can_be_merged_with(line) && options.merge !== false){

                to_merge_orderline = this.orderlines.at(i);

            }

        }

        if (to_merge_orderline){

            to_merge_orderline.merge(line);

        } else {

            this.orderlines.add(line);

        }

        this.select_orderline(this.get_last_orderline());

        if(line.has_product_lot){

            this.display_lot_popup();

        }

    },


I need to add one more condidtion like,

       if(options.is_promo !== undefined){

        line.set_promo(options.is_promo);

      }

    },


So in my custom module, I tried this,

      

      var _super_order = models.Order.prototype;

      models.Order = models.Order.extend({

    add_product: function(product, options){

      if(options.is_promo !== undefined){

        line.set_promo(options.is_promo);

      }

       _super_order.add_product.apply(this,arguments);

    },


But it throws an error, `line` is not defined.

And I tried to copy the original code into the custom module and made necessary changes. Then run it, gives me an error. exports is not defined 

How can i do it?

0
Imagine profil
Abandonează
Imagine profil
Pranav P S
Cel mai bun răspuns

var _super_order = models.Order.prototype;

      models.Order = models.Order.extend({

    add_product: function(product, options){

var line = new exports.Orderline({}, {pos: this.pos, order: this, product: product});

if(options.is_promo !== undefined){

        line.set_promo(options.is_promo);

      }

       _super_order.add_product.apply(this,arguments);

    },

1
Imagine profil
Abandonează
Imagine profil
Asha
Cel mai bun răspuns

have you got any solution for this? I'm also facing the same issue on Odoo15

0
Imagine profil
Abandonează
Imagine profil
anggara
Cel mai bun răspuns

i have trouble with pos odoo 12, i wan inherit function add_product ..but every compile in pos ..i always hava trouble  exports is not defined  ...how i can solve this code 

var _super_order_product_add = models.Order.prototype;
models.Order = models.Order.extend({
initialize: function() {
_super_order.initialize.apply(this,arguments);
},

add_product: function(product, options){

this.assert_editable();
options = options || {};
var attr = JSON.parse(JSON.stringify(product));
console.log(attr);
attr.pos = this.pos;
attr.order = this;
var line = new exports.Orderline({}, {pos: this.pos, order: this, product: product});
console.log(line);

if(options.dikirim !== "0"){
line.set_dikirm(options.dikirim);
}

if(options.dikirim == "0"){
line.set_dikirm(options.dikirim);
}

if(options.diambil !== "0"){
line.set_diambil(options.diambil);
}

if(options.diambil == "0"){
line.set_diambil(options.diambil);
}

if(options.price !== undefined){
line.set_unit_price(options.price);
}

},
});
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
Save and get the value of variable from backend
javascript odoo
Imagine profil
0
aug. 23
194
Hide menu for all except specific group Rezolvat
odoo odoo11
Imagine profil
Imagine profil
1
nov. 22
4301
Live tracking in odoo. Rezolvat
odoo odoo11
Imagine profil
Imagine profil
2
aug. 22
8804
Odoo use which javascript framework? Rezolvat
javascript odoo
Imagine profil
Imagine profil
1
feb. 22
3783
How to add URL of current record into an email template odoo Rezolvat
odoo odoo11
Imagine profil
Imagine profil
1
ian. 25
10635
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