Skip to Content
Menu
This question has been flagged
2565 Views

Hello,

I'm looking for a way to pass a value from POS model to model.js to print a custom receipt. 

Inside my PosOrder class i have


class PosOrder(models.Model):

    _inherit = 'pos.order'

    ticket_hacienda_invoice_number = fields.Char(

        'Simplified invoice',

        copy=False,

        oldname='simplified_invoice',

    )

@api.model

    def _order_fields(self, ui_order):

        res = super(PosOrder, self)._order_fields(ui_order)

        res.update({

            'ticket_hacienda_invoice_number': ui_order.get(

                'simplified_invoice', ''),

        })

        return res


@api.model

    def _process_order(self, order):

        simplified_invoice_number = order.get('simplified_invoice', '')

 order.update({

                'ticket_hacienda_invoice_number': clave_factura,

            })


            pos_order.ticket_hacienda_invoice_number = clave_factura


Inside my custom receipt template i have this code

Clave: <t t-esc="widget.pos.ticket_hacienda_invoice_number"/>


And inside my model.js this

var pos_super = models.PosModel.prototype;

    models.PosModel = models.PosModel.extend({

        initialize: function (attributes, options) {

            pos_super.initialize.apply(this, arguments);

            this.pushed_simple_invoices = [];

            return this;

        },


        get_simple_inv_next_number: function () {

            if (this.pushed_simple_invoices.indexOf(this.config.ticket_hacienda_invoice_number) > -1) {

                ++this.config.ticket_hacienda_invoice_number;

            }

            return this.config.ticket_hacienda_invoice_prefix+ this.config.ticket_hacienda_invoice_number;

        },


        push_simple_invoice: function (order) {

            if (this.pushed_simple_invoices.indexOf(order.data.simplified_invoice) === -1) {

                this.pushed_simple_invoices.push(order.data.simplified_invoice);

                ++this.config.ticket_hacienda_invoice_number;

            }

        },

        _flush_orders: function (orders, options) {

            var self = this;

            // Save pushed orders numbers

            _.each(orders, function (order) {

                if (!order.data.to_invoice) {

                    self.push_simple_invoice(order);

                }

            });

            return pos_super._flush_orders.apply(this, arguments);

        }

    });



There is no error, but my receipt is showing a null in the field and i need to print te ticket containing the value.

Note: When listing data in odoo the field ticket_hacienda_invoice_number shows the correct value. Some one could help me?

Thanks

Avatar
Discard