[英]How to add custom button to POS Receipt in Odoo 10
我正在使用Odoo10,我想在POS Receip中添加一個產品明細表,並且還添加另一個“打印”按鈕以僅打印明細表。 我遇到了麻煩,我不知道如何向按鈕添加事件。 這是我的模塊,請檢查一下。
Qweb:
<?xml version="1.0" encoding="UTF-8"?>
<templates id="point_of_sale_template" xml:space="preserve">
<t t-extend="PosTicket">
<t t-jquery='.pos-sale-ticket' t-operation='after'>
<div class="pos-sale-ticket-appended" style="clear:both; text-align: left; width: 300px; background-color: white; margin: 20px; padding: 15px; font-size: 14px;padding-bottom: 30px; display: inline-block;font-family: 'Inconsolata'; border: solid 1px rgb(220,220,220); border-radius: 3px; overflow: hidden;">
<div style="background: white; margin: 20px auto;">
<h4>Products Detail</h4>
<div style="display: inline-block">
<table class='receipt-orderlines' style="width: 300px; border">
<colgroup>
<col width='50%' />
<col width='25%' />
<col width='25%' />
</colgroup>
<tr>
<th>Name</th>
<th>SKU</th>
<th>Cost</th>
</tr>
<tr t-foreach="orderlines" t-as="orderline">
<t t-log="orderline.get_product().cost_method" />
<t t-log="orderline.get_product().property_cost_method" />
<td>
<t t-esc="orderline.get_product().display_name"/>
</td>
<td>
<t t-esc="orderline.get_product().default_code"/>
</td>
<td>
<t t-esc="orderline.get_product().standard_price"/>
</td>
</tr>
</table>
<br />
</div>
</div>
</div>
</t>
</t>
<t t-extend="ReceiptScreenWidget">
<t t-jquery='div.receipt-screen.screen > div > div.centered-content.touch-scrollable > div.button.print' t-operation="after">
<div class="button print-detail">
<i class='fa fa-print'></i> Print Detail
</div>
</t>
</t>
</templates>
JS:我只是擴展了pos模型並添加了standard_price字段
odoo.define('pos_receipt_extend', function (require) {
"use strict";
var $ = require('jquery');
// Add cost field to product model
var models = require('point_of_sale.models');
models.load_fields('product.product', 'standard_price');
var screens = require('point_of_sale.screens');
});
清單 .py
# -*- coding: utf-8 -*-
{
"name": "Pos extend Receipt",
"summary": "pos_es_receipt",
"version": "8.0.1.0",
"category": "Point Of Sale",
"website": "http://www.difusionvisual.com",
"author": "Difusión Visual",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"base",
"point_of_sale",
],
"qweb": [
'static/src/xml/receipt.xml'
],
"data":["views/pos_es_receipt.xml"]
}
請告訴我如何添加操作onClick on Print Detail按鈕
在定義qwerb的xml文件中,嘗試在j-query
使用第一種/最后一種詞,而不是此層次結構。 jQuery可能找不到該路徑。 確保您添加了正確的路徑。
之后,在js文件中,您需要擴展“ export_for_printing ”方法。 通常,以這種方法寫入的數據將返回打印。
同樣在清單文件中,參數的首選項也是如此:'depends','data','qweb'。 在您看來,不要忘記添加js文件的路徑。 在所有這些之后,嘗試輸入pos會話並檢查天氣,通過輸入“ alert”,代碼是否成功運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.