Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar 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
  • Proyecto
  • 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

Odoo 17 - Show new field in POS receipt

Suscribirse

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

Se marcó esta pregunta
recieptpoint_of_salePoint Of Sale17.0
1 Responder
4187 Vistas
Avatar
Kareem Magdy

I'm using Odoo 17 pos I've added new field called is_void, I want to access this field from the receipt, It comes with undefined (empty), but It sent to the DB Correctly here is my code below:

Python:

from odoo import models, fields


class PosOrderLine(models.Model):
    _inherit = "pos.order.line"

    is_void = fields.Boolean(
        string="Is Void",
        default=False,
        help="Indicates whether this line is voided or not.",
    )

    def _order_line_fields(self, line, session_id=None):
        result = super(PosOrderLine, self)._order_line_fields(line, session_id)
        result["is_void"] = line.get("is_void", False)
        return result

    def _export_for_ui(self, orderline):
        result = super()._export_for_ui(orderline)
        result.update(
            {
                "is_void": orderline.is_void,
            }
        )
        return result

Javascript:

patch(Orderline.prototype, {
  constructor() {
    this.is_void = this.is_void || false;
  },

  // // Toggle the is_void flag
  toggleVoid() {
    this.is_void = !this.is_void;
  },

  // Include is_void in export_as_JSON
  export_as_JSON() {
    const result = super.export_as_JSON(...arguments);
    result["is_void"] = this.is_void;
    return result;
  },

  init_from_JSON(json) {
    super.init_from_JSON(...arguments);
    this.is_void = json.is_void || false;
  },

  export_for_printing() {
    const json = this._super(...arguments);
    json.is_void = this.is_void;
    return json;
  },
});
Getting the below error

point_of_sale.assets_prod.min.js:9701 Failed to send orders: [{…}]
_save_to_server @ point_of_sale.assets_prod.min.js:9701
RPC_ERROR://localhost:8069/web/assets/7b7dc0e/point_of_sale.assets_prod.min.js:6586:163)
    at XMLHttpRequest. (http://localhost:8069/web/assets/7b7dc0e/point_of_sale.assets_prod.min.js:6590:13)

Also I tried to load_params but this solution works only if the custom field is predefined not defined or set its value during making the order itself.


0
Avatar
Descartar
Avatar
S.A. Methsiri Madusanka Sooriyaarachchi
Mejor respuesta

The error you're encountering while attempting to include the is_void field in the Odoo POS receipt seems to be related to how the field data is being passed and processed between the client-side JavaScript code and the server-side Python code. Here's a breakdown of how to address this issue:

1. Ensure the Field is Properly Initialized

The is_void field needs to be correctly initialized in both the server-side and client-side code. You appear to be doing this in the export_as_JSON and init_from_JSON methods in JavaScript, and in the _order_line_fields and _export_for_ui methods in Python. These are the right places, but let’s ensure that everything is correctly linked.

2. Review the JavaScript Logic

You need to make sure that is_void is being handled correctly when the order is being exported and imported. Since the error happens during order saving, let’s focus on the methods dealing with data persistence:

javascriptCopy code// Extend Orderline with new logic for is_void field
patch(Orderline.prototype, {
  // Constructor logic to initialize is_void
  constructor() {
    this.is_void = this.is_void || false;
  },

  // Toggle is_void field
  toggleVoid() {
    this.is_void = !this.is_void;
  },

  // Export data as JSON for backend
  export_as_JSON() {
    const result = super.export_as_JSON(...arguments);
    result["is_void"] = this.is_void;
    return result;
  },

  // Initialize from JSON data received from the backend
  init_from_JSON(json) {
    super.init_from_JSON(...arguments);
    this.is_void = json.is_void || false;
  },

  // Export data for printing (receipt)
  export_for_printing() {
    const json = this._super(...arguments);
    json.is_void = this.is_void;
    return json;
  },
});

3. Review the Python Code for Compatibility

Make sure that the Python methods handling the order lines are correctly updating and retrieving the is_void field:

pythonCopy codefrom odoo import models, fields

class PosOrderLine(models.Model):
    _inherit = "pos.order.line"

    is_void = fields.Boolean(
        string="Is Void",
        default=False,
        help="Indicates whether this line is voided or not.",
    )

    def _order_line_fields(self, line, session_id=None):
        result = super(PosOrderLine, self)._order_line_fields(line, session_id)
        result["is_void"] = line.get("is_void", False)
        return result

    def _export_for_ui(self, orderline):
        result = super()._export_for_ui(orderline)
        result.update({
            "is_void": orderline.is_void,
        })
        return result

4. Check the Field Mapping in the POS Frontend

Ensure that your custom is_void field is correctly referenced in all parts of the code that manage the order data, particularly in the load_params and save_to_server processes.

5. Investigate the Error Message

The error Failed to send orders suggests that there might be an issue with how the order data, including your custom field, is being transmitted to the server. Here’s what to look for:

  • Check the Network Tab: In your browser's developer tools, check the network tab to see the payload of the request being sent to the server. Ensure that is_void is correctly included in the JSON data.
  • Check the Logs: Look at the Odoo server logs for any more detailed error messages that might give you clues.

6. Debug the Save Process

You might need to add some debug logging in the JavaScript and Python methods that handle order saving to identify where the process is failing. For example, log the content of export_as_JSON in the JavaScript to ensure the data is being exported correctly.

7. Odoo Field Initialization Timing

If the field is only set during the order process, make sure that any logic depending on is_void doesn't run before the field is initialized (e.g., during the first render or before the order is saved).

8. Possible Fix for load_params Issue

The load_params issue you mentioned typically arises if the field isn’t recognized during the order’s initial loading. Ensure that the field is part of the pos.order.line model and that any dependencies in load_params correctly refer to it.

Final Step: Testing

After applying these changes, test the functionality again by:

  • Adding a line with is_void set to True or False.
  • Saving the order and ensuring it is correctly stored in the database.
  • Checking the receipt to see if is_void is correctly reflected.

This process should help resolve the issue with your is_void field being undefined during the receipt printing process while ensuring it is correctly stored and retrieved in Odoo POS.

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

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

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
Pos Self Order customization
Point Of Sale 17.0
Avatar
0
mar 25
1409
How to inherit point_of_sale action_pad.xml?
point_of_sale Point Of Sale
Avatar
Avatar
1
dic 24
2473
Custom filter odoo 17
point_of_sale Point Of Sale
Avatar
0
dic 24
1698
Looking for a solution to "MODULE ERROR Adjusting the price is not allowed".
point_of_sale Point Of Sale
Avatar
Avatar
1
ene 21
3139
How to inherit POS javascript for customization? Resuelto
point_of_sale Point Of Sale
Avatar
Avatar
Avatar
Avatar
6
nov 19
15934
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información 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 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