İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
1459 Görünümler

Hello community, I have been trying for several days to update the ticket generated from the POS at the end of the purchase so that it is printed on the thermal ticket machine, I need to add the invoice number, the code that I am implementing so far is the following:


# models/custom_pos.py #
from odoo import models, fields
class PosOrder(models.Model):    _inherit = 'pos.order'
     invoice_id = fields.Many2one('account.move', string='Factura')


/* static/src/js/receipt_order.js */
odoo.define('custom_receipts_for_pos.receipt_order', function (require) 
"use strict";
var models = require('point_of_sale.models');   
var OrderSuper = models.Order.prototype;
models.Order = models.Order.extend({
        initialize: function (attributes, options) {
            OrderSuper.initialize.apply(this, arguments);
            this.invoice_id = this.invoice_id || false;
        },
        export_for_printing: function () {
            var result = OrderSuper.export_for_printing.apply(this, arguments);
            result.invoice_id = this.invoice_id;
            return result;
        },
    });
});


Since I have not been able to load the invoice_id in the JavaScript, I am not doing the xml view, but it should be something similar to this:


< !-- views/post_custom.xml-- >
< odoo>
    < template id="pos_ticket_custom" inherit_id="point_of_sale.receipt">
        < xpath expr="//div[@class='pos-receipt']" position="inside">
            < t t-if="order.invoice_id">
                < div>
                    < strong>Número de Factura:< /strong> < span t-esc="order.invoice_id.name"/>
                < /div>
            < /t>
        < /xpath>
    < /template>
< /odoo>


In case you didn't read the subject, the version is Odoo 17 and I'm testing in the Community and Enterprise version and it doesn't work


HELP!

Avatar
Vazgeç
En İyi Yanıt

Hello Edgar Vasquez Vergara,


To print the invoice number on a POS receipt in Odoo v17, you can simply try this approach.


Js file :


//Code 1 in Comment//


Python file:-


//Code 2 in Comment//


xml file:-


//Code 3 in comment//



Hope this Helps,

If you need any help in customization feel free to contact us.


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

Avatar
Vazgeç

Code 1 :
/ @odoo-module /

import { useState } from "@odoo/owl";
import { ReceiptHeader } from "@point_of_sale/app/screens/receipt_screen/receipt/receipt_header/receipt_header";
import { usePos } from "@point_of_sale/app/store/pos_hook";
import { useService } from "@web/core/utils/hooks";
import { patch } from "@web/core/utils/patch";

patch(ReceiptHeader.prototype, {
/**
* Extends the setup method of the ReceiptHeader component to include invoice number handling.
*
* This patched setup method initializes the component state with an `invoiceNumber` field set to `0`,
* retrieves the POS orders from the `pos` service, and if an order is eligible for invoicing (i.e.,
* `to_invoice` is true and `server_id` is present), it calls the `generate_invoice_number` method
* on the `orm` service to fetch the invoice number for the order. The retrieved invoice number is then
* stored in the component state.
*
* This process ensures that the invoice number is available in the component's state and can be used
* for rendering on the receipt screen template.
*/
async setup(){
super.setup();
this.state = useState({
invoiceNumber: ""
});
this.pos = usePos();
this.orm = useService("orm");
console.log(this.pos.orders.length,'===', this.pos.orders[0].to_invoice, '====', this.pos.orders[0].server_id );
if (this.pos.orders.length && this.pos.orders[0].to_invoice && this.pos.orders[0].server_id){
const InvNumber = await this.orm.call('pos.order', 'generate_invoice_number', [this.context, this.pos.orders[0].server_id]);
this.state.invoiceNumber = InvNumber
}
},
});

Code 2 :

class PosOrder(models.Model):
"""Inherited: Pos Order"""

_inherit = "pos.order"

def generate_invoice_number(self, data):
"""
Generate the invoice number for a given POS order.

This method retrieves the invoice number for a POS order identified by the provided `data`.
It uses the `pos.order` model to browse the specific order and fetch its associated account move name,
which is used as the invoice number. If the order or account move is not found, an empty string is returned.

Returns:
str: The invoice number associated with the POS order. Returns an empty string if the invoice number
cannot be found.

"""
return self.env["pos.order"].sudo().browse(int(data)).account_move.name or ""

Code 3:

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<!--
This template extension modifies the ReceiptHeader view in the Point of Sale module.
It adds a new element to display the invoice number if it is present in the component's state.
-->
<t t-inherit="point_of_sale.ReceiptHeader" t-inherit-mode="extension">
<xpath expr="//div[hasclass('cashier')]" position="after">
<div class="fw-bolder" t-if="this.state.invoiceNumber">
<span class="fs-3" t-esc="state.invoiceNumber"/>
</div>
</xpath>
</t>
</templates>

İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Ara 24
1052
1
Ağu 15
3820
0
Ara 22
4532
1
Haz 25
2294
3
Tem 25
772