Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

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

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
javascriptinheritancepoint_of_saleodooodoo11
1 Responder
16872 Vistas
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
Mejor respuesta

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;

},

¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
How add field in current pos order from JavaScript Odoo 11 Resuelto
javascript order point_of_sale odoo odoo11
Avatar
Avatar
Avatar
2
may 21
8611
Override a javascript function in Odoo 11? Resuelto
javascript odoo odoo11
Avatar
Avatar
Avatar
Avatar
3
may 22
9855
Inherit the RewardButton class Js point of sale
javascript point_of_sale odoo owl
Avatar
Avatar
1
dic 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 Resuelto
javascript inheritance point_of_sale odoo10.0
Avatar
Avatar
1
abr 18
11430
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

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