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

Add a field and update the value in odoo pos orderline Odoo 11

Subscriure's

Get notified when there's activity on this post

This question has been flagged
javascriptinheritancepoint_of_saleodooodoo11
1 Respondre
16905 Vistes
Avatar
Kabeer KB

I am trying to add a new field in pos order line and update the value in button click.


**pos.oerder.line.py**


    

    class pos_order_line(models.Model):

        _inherit = 'pos.order.line'

        is_promo = fields.Boolean(string='Promo',default=False)


***.js**


    models.Orderline = models.Orderline.extend({


    initialize: function() {

      _super_orderline.initialize.apply(this,arguments);

      this.is_promo = false;

    },


    // Help me to understand this function

    export_as_JSON: function(){ 

        var json = _super_orderline.export_as_JSON.apply(this,arguments);

        json.is_promo = this.is_promo;

        return json;

    },


    // Help me to understand this function

    init_from_JSON: function(json){

        _super_orderline.init_from_JSON.apply(this,arguments);

        this.is_promo = json.is_promo;

    },

  

    });


    var OfferButton = screens.ActionButtonWidget.extend({

    'template': 'PromotioanlButton',

    button_click: function(){

        var self = this;

        self.get_promo_config();

    },



    get_promo_config: function () {

      var self = this;

      var order    = this.pos.get_order();

      var orderline = order.get_orderlines();

      var order_product_ids = []

      _.each(orderline,function(line){

        order_product_ids.push({'product_id':line.product.id,'qty':line.quantity});

      });


      rpc.query({

        model:'promo.config',

        method:'check_promo_offer',

        args :[order_product_ids],

      }).then(function(product_ids){


        _.each(product_ids, function(pid){

          var product  = self.pos.db.get_product_by_id(pid.product_id);



     **// I added new item into cart using below code and its working fine. 

     //It add all the fields below mention except `is_promo`, i mean it still false. 

      //how can i make it true.**

          order.add_product(product, { price:0.0 ,quantity:pid.product_uom_qty,discount:25,is_promo:true,merge:false});

      });

      });

    },

    });




Please suggest any solution.


0
Avatar
Descartar
shalin wilson

<?xml version="1.0" encoding="UTF-8"?>

<templates id="template" xml:space="preserve">

<t t-extend="Orderline">

<t t-jquery="ul[class*='info-list']" t-operation="append">

<li class="info orderline-note">

<i class="fa fa-caret-right"/>Note

</li>

</t>

</t>

</templates>

Avatar
Pranav P S
Best Answer

In button click make is_promo true:


    button_click: function(){

        this.is_promo = true;

    }


And in product selection or change, update the lines:


var models = require('point_of_sale.models');
var _super_Order = models.Order.prototype;
models.Order = models.Order.extend({
export_as_JSON: function () {
var json = _super_Order.export_as_JSON.apply(this, arguments);
    if (json.lines){
        ......
        your logic
        ......
        json.lines[j][2].is_promo = this.is_promo;
    }
}

* No need of init_from_JSON

*Export as json will regenerate the order lines(JSON) on product selection/removal/updation etc

1
Avatar
Descartar
Kabeer KB
Autor

@Pranav, what is `j` in this line, `json.lines[j][2].is_promo = this.is_promo;`

And i think it will update `is_promo` for all orderlines, right?

Pranav P S

'j' i meant for line number, you can replace 'j' with actual line number.

Kabeer KB
Autor

I changed to this `var len = json.lines.length

json.lines[len-1][2].is_promo = true;`

But in the view it didnt change the value.

Pranav P S

No it will not change the view, this json is to pass value to odoo backend.

Kabeer KB
Autor

But i want it to change it in the view too.

Pranav P S

How and where you have to display in view?

Kabeer KB
Autor

I updated my question with a screen shot.

Pranav P S

Please refer <t t-name="Orderline"> in pos.xml.

Extend view and add your method to return this.is_promo value in models.js same as below.

Eg:

pos.xml

<t t-esc="line.get_quantity_str()" />

models.js:

get_quantity_str: function(){

return this.quantityStr;

},

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 add field in current pos order from JavaScript Odoo 11 Solved
javascript order point_of_sale odoo odoo11
Avatar
Avatar
Avatar
2
de maig 21
8626
Override a javascript function in Odoo 11? Solved
javascript odoo odoo11
Avatar
Avatar
Avatar
Avatar
3
de maig 22
9858
Inherit the RewardButton class Js point of sale
javascript point_of_sale odoo owl
Avatar
Avatar
1
de des. 23
2436
Point of sale image src call javaScript variable
javascript pos point_of_sale odoo11
Avatar
0
de març 19
4068
Inherit POS Javascript function in Odoo 10 Solved
javascript inheritance point_of_sale odoo10.0
Avatar
Avatar
1
d’abr. 18
11447
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