How to print a POS receipt from Sale Order?

ⅰ亾dé卋堺 提交于 2021-02-04 19:41:00

问题


I need to print POS receipt from sale order with same products qty etc.

In Sale order I have created a button "Print POS receIpt". with this button I want to trigger a method that prints out a receipt with sale order lines on it.

So I need to find the method that creates POS receipts and pass the sale order line values to it.

So which method is printing receipts in POS and how can I trigger it? Is it in models.js?


回答1:


In those Odoo versions, the receipts that are being printed in the POS are a screen capture (actually only the receipt div) made by JavaScript. But you cannot use this approach on the Sale Order view.

However, there is another way to print tickets into PDF with a normal Qweb Report. If you click on the POS menu you will find the "Orders" menu option on the left margin. You will have the print option under the "Print" menu on the form and list view.

If you go to the point_of_sale module you will find the report_receipt.xml file written with the Qweb language. You can customize it to make it work with the sale.order model. But take into account that the paperformat should be point_of_sale.paperformat_posreceipt, you will find the paperformat assigment at the bottom of these code:

<template id="report_receipt">
    <t t-call="report.html_container">
        <t t-foreach="docs" t-as="o">
            <div class="page">
                <div class="row">
                    <div class="col-xs-12 text-center">
                        <h2 t-esc="o.user_id.company_id.name"/>
                        <div t-field="o.partner_id"
                            t-field-options='{"widget": "contact", "fields": ["address", "name", "phone", "fax"], "no_marker": true}'/>
                        User: <span t-field="o.user_id"/><br/>
                        Date: <span t-field="o.date_order"/><br/>
                    </div>
                </div>

                <div class="row">
                </div>

                <table class="table table-condensed">
                    <thead>
                        <tr>
                            <th>Description</th>
                            <th class="text-right">Quantity</th>
                            <th class="text-right">Price</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr t-foreach="o.lines" t-as="line">
                            <td><span t-field="line.product_id"/></td>
                            <td class="text-right">
                                <t t-if="o.state != 'cancel' and o.statement_ids">
                                    <span t-field="line.qty"/>
                                </t>
                            </td>
                            <td class="text-right">
                                <t t-if="o.state != 'cancel' and o.statement_ids">
                                    <span t-esc="formatLang(net(line.id), currency_obj=res_company.currency_id)"/>
                                </t>
                                <t t-if="line.discount != 0.0">
                                    <span t-esc="line.discount"/>%
                                </t>
                            </td>
                        </tr>
                    </tbody>
                </table>

                <div class="row">
                    <div class="col-xs-12 pull-right">
                        <table class="table table-condensed">
                            <tr class="border-black">
                                <td><strong>Taxes</strong></td>
                                <td class="text-right">
                                    <strong t-esc="formatLang(o.amount_tax, currency_obj=res_company.currency_id)"/>
                                </td>
                            </tr>
                            <tr>
                                <td><strong>Total</strong></td>
                                <td class="text-right">
                                    <strong t-esc="formatLang(o.amount_total, currency_obj=res_company.currency_id)"/>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>

                <table class="table table-condensed">
                    <thead>
                        <tr>
                            <th>Payment Mode</th>
                            <th>Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr t-foreach="get_journal_amt(o)" t-as="d">
                            <td>
                                <span t-esc="d['name']"/>
                            </td>
                            <td>
                                <span t-esc="formatLang(d['amt'], currency_obj=res_company.currency_id)"/>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </t>
    </t>
</template>

<report
    id="action_report_pos_receipt"
    string="Receipt"
    model="pos.order"
    report_type="qweb-pdf"
    name="point_of_sale.report_receipt"
    file="point_of_sale.report_receipt"
/>

<record id="action_report_pos_receipt" model="ir.actions.report.xml">
    <field name="paperformat_id" ref="point_of_sale.paperformat_posreceipt"/>
</record>


来源:https://stackoverflow.com/questions/51633901/how-to-print-a-pos-receipt-from-sale-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!