actually i want print to report using javascript butoon function in the view.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
Write an onclick event on the button and in that event call the python function using __rpc function(Backend javascript) or rpc.query(frontend javascript).
for example
---------------------------------------------------------------------------------------------
python file:-
class SaleReport(models.TransientModel):
_name = "sale.report"
_description = "Sale Report"
def print_sale_report(self):
return self.env.ref( 'module_name.report_id').report_action(
self, data={})
-------------------------------------------------------------------------------------------
javascript(backend):-
odoo.define('school.practice', function (require) {
"use strict";
var AbstractAction = require('web.AbstractAction');
var core = require('web.core');
var QWeb = core.qweb;
var PrintReport = AbstractAction.extend({
contentTemplate: 'HelloWorldTemplate',
events: {
"click .button_class": function () {
var self = this;
var def = this._rpc({
model: 'sale.report',
method: ' print_sale_report',
args: [[]],
})
.then(function (res) {
console.log("Success");
});
},
core.action_registry.add('print_action', PrintReport);
return PrintReport;
});
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden
receiptinvoice.py:
from odoo import api, models,fields
class ReceiptInvoice(models.Model):
_inherit = 'account.invoice'
# _name = 'account.invoice_extends'
_description = 'pos receipt'
@api.multi
def sale_receipt(self):
return self.env['report'].get_action(self, 'receipt.sales_report')
def print_sale_report(self):
return self.env.ref('receipt.report_receipt').report_action(
self, data={})
my view where i define button called account_invoice_view.xml:
?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="inherit_view_invoice_form" model="ir.ui.view">
<field name="name">inherit.account.invoice.form.shop</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<button name="187" position="after">
<button name="sale_receipt" string="Receipt" type="object" class="myClass" custom = "click"/>
<input name="ak" type="button" value="Test" class="myId" />
<button name="%(report_receipt)d" type="action" string="Click me" />
<button name="btn" class="my_class" string="Call" type="button"/>
<script type="text/javascript" src="receipt/static/src/js/js_example.js">
</script>
<script type="text/javascript" src="receipt/static/src/js/print.min.js">
</script>
</button>
</field>
</record>
</data>
</odoo>
report i want to print is sales_receipt.xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="sales_report">
<t t-name="test">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<div class="page" id="ID" >
<div>
<h4 style="text-align:center;"> <t t-esc="res_company.name"/> </h4>
</div>
<div>
Invoice:<t t-esc="o.number"/><![CDATA[ ]]><![CDATA[ ]]><![CDATA[ ]]>
Date:<t t-esc="o.date_invoice"/><br/>
Customer:<t t-esc="o.partner_id.name"/><br/>
Salesperson:<t t-esc="o.user_id.name"/>
</div>
<table class="table table-striped" style="border-collapse: collapse;" >
<tr >
<th>Product</th>
<th>Qty</th>
<th>Unit Price</th>
<th>Amount</th>
</tr>
<tr t-foreach="o.invoice_line_ids" t-as="l" >
<td class="col-xs-2" style="width:100000px;">
<span t-field="l.name"/>
</td>
<td>
<span t-field="l.quantity"/>
</td>
<td>
<span t-field="l.price_unit"/>
</td>
<td>
<span t-esc="'%.2f'%(l.price_unit*l.quantity)"/>
</td>
</tr>
</table>
<div>
Amount:<![CDATA[ ]]><![CDATA[ ]]><t t-esc="'%.2f'%(o.amount_untaxed)"/><br/>
Discount Percentage:<![CDATA[ ]]><![CDATA[ ]]><t t-esc="'%.0f'%(o.discount_percentage)"/>%<br/>
Discount:<![CDATA[ ]]><![CDATA[ ]]><t t-esc="'%.2f'%(o.discount)"/><br/>
<h4><strong>Amount to be paid:<![CDATA[ ]]><![CDATA[ ]]><t t-esc="'%.2f'%(o.amount_total)"/></strong><br/>
<strong>Paid:<![CDATA[ ]]><![CDATA[ ]]><t t-esc="'%.2f'%(o.amount_total-o.residual)"/></strong><br/>
<strong>Amount Due:<![CDATA[ ]]><![CDATA[ ]]><t t-esc="'%.2f'%(o.residual)"/></strong><br/></h4>
</div>
</div>
</t>
</t>
</t>
</template>
</odoo>
and my js file:
odoo.define('receipt.hellojs', function (require) {
"use strict";
console.log('Hello Js');
var AbstractAction = require('web.AbstractAction');
var core = require('web.core');
var QWeb = core.qweb;
var PrintReport = AbstractAction.extend({
contentTemplate: 'test',
events: {
"click .my_class": function () {
var self = this;
var def = this._rpc({
model: 'account.invoice_extends',
method: ' print_sale_report',
args: [[]],
}).then(function (res) {
console.log("Success");
});
}
}
});
core.action_registry.add('print_action', PrintReport);
return PrintReport;
});
but it is not working