Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
javascriptinheritancepoint_of_saleodooodoo11
1 Odgovori
16875 Prikazi
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
Opusti
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
Opusti
Kabeer KB
Avtor

@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
Avtor

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
Avtor

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
Avtor

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!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
How add field in current pos order from JavaScript Odoo 11 Solved
javascript order point_of_sale odoo odoo11
Avatar
Avatar
Avatar
2
maj 21
8611
Override a javascript function in Odoo 11? Solved
javascript odoo odoo11
Avatar
Avatar
Avatar
Avatar
3
maj 22
9855
Inherit the RewardButton class Js point of sale
javascript point_of_sale odoo owl
Avatar
Avatar
1
dec. 23
2427
Point of sale image src call javaScript variable
javascript pos point_of_sale odoo11
Avatar
0
mar. 19
4067
Inherit POS Javascript function in Odoo 10 Solved
javascript inheritance point_of_sale odoo10.0
Avatar
Avatar
1
apr. 18
11430
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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