Help

1

[Odoo10] How to add custom field in pos receipt screen from pos order?

Avatar
Jignesh Mehta

Hello,

I have added 1 custom field in pos.order model that is seq_no.
When order is validate from pos screen, update seq_no in related order which is created on back-end.

Now I want to print seq_no field from pos.order model to pos receipt screen.

How can I achieve this?

Here is a code for that:

pos_data.xml :-

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="seq_pos_order_seq" model="ir.sequence">
        <field name="name">Order POS</field>
        <field name="code">pos.order</field>
        <field name="prefix"></field>
        <field name="padding">3</field>
        <field name="company_id" eval="False"/>
    </record>
</odoo>

pos_order.py :-


from odoo import models, fields, api

class PosOrder(models.Model):
    _inherit = 'pos.order'

    @api.multi
    def pos_order_order_seq(self):
        seq_id = self.env.ref('pos_order_sequence_no.seq_pos_order_seq')
        seq_id.number_next_actual = 1

    seq_no = fields.Char(string="Order Sequence No", default='New')

    @api.model
    def _order_fields(self, ui_order):
        order_fields = super(PosOrder, self)._order_fields(ui_order)
        order_fields['seq_no'] = ui_order.get('seq_no', False)
        return order_fields

    @api.model
    def create(self, values):
        seq_id = self.env.ref('pos_order_sequence_no.seq_pos_order_seq')
        values['seq_no'] = seq_id.number_next_actual
        seq_id.number_next_actual = seq_id.number_next_actual + 1
        return super(PosOrder, self).create(values)

pos.xml :-

<?xml version="1.0" encoding="UTF-8"?>
<templates id="point_of_sale.template" xml:space="preserve">
    <t t-extend="PosTicket">
        <t t-jquery='.pos-center-align' t-operation='replace'>
            <div class="pos-center-align">
               Order: <t t-esc="order.seq_no"/>
            </div>
        </t>
    </t>
</templates>


Any answer will be appreciable.
Thanks,

Avatar
Discard
1 Answer
0
Avatar
Prakash
Best Answer
t-extend OrderReceipt template and add new field.

Default core module "pos_cash_rounding"  used, sample code

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="OrderReceipt">
<t t-jquery='.pos-receipt-amount:first' t-operation='after'>
<t t-if="receipt.total_rounded != receipt.total_with_tax">
<div class="pos-receipt-amount">
ROUNDED
<span t-esc='widget.format_currency(receipt.total_rounded)' class="pos-receipt-right-align"/>
</div>
</t>
</t>
</t>
<t t-extend="PaymentScreen-Paymentlines">
<t t-jquery='.paymentlines-empty > .total' t-operation='replace'>
<div class='total'>
<t t-esc="widget.format_currency(order.get_total_with_tax() + order.get_rounding_applied())"/>
</div>
</t>
</t>
</templates>

https://www.odoo.com/forum/help-1/question/how-to-add-a-new-custom-field-in-pos-print-receipt-in-odoo-11-127505

https://apps.odoo.com/apps/modules/13.0/custom_pos_receipt/#
Avatar
Discard