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

Odoo 17 - Show new field in POS receipt

Subscriure's

Get notified when there's activity on this post

This question has been flagged
recieptpoint_of_salePoint Of Sale17.0
1 Respondre
4185 Vistes
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
Best Answer

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
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
Pos Self Order customization
Point Of Sale 17.0
Avatar
0
de març 25
1409
How to inherit point_of_sale action_pad.xml?
point_of_sale Point Of Sale
Avatar
Avatar
1
de des. 24
2471
Custom filter odoo 17
point_of_sale Point Of Sale
Avatar
0
de des. 24
1694
Looking for a solution to "MODULE ERROR Adjusting the price is not allowed".
point_of_sale Point Of Sale
Avatar
Avatar
1
de gen. 21
3138
How to inherit POS javascript for customization? Solved
point_of_sale Point Of Sale
Avatar
Avatar
Avatar
Avatar
6
de nov. 19
15931
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