Skip to Content
Menu
This question has been flagged
1635 Views

I'm trying to pass more data to a custom report from JavaScript.

odoo.define('pos_control_cajero.MontosContadosScreen',function (require){
'use strict';

const PosComponent = require('point_of_sale.PosComponent');
const Registries = require('point_of_sale.Registries');
const useSelectEmployee = require('pos_hr.useSelectEmployee');
const { useBarcodeReader } = require('point_of_sale.custom_hooks');
const rpc = require("web.rpc");


class MontosContadosScreen extends PosComponent {
constructor() {
super(...arguments);
this.payment_methods = this.env.pos.payment_methods;
console.log('this',this)
}
async terminarTurnoControl() {
const data = this.getPaymentData();
console.log('data', data);

await this.imprimirReporte(data);

// await rpc.query({
// model: "pos.session",
// method: "action_pos_session_closing_control",
// args: [[this.env.pos.pos_session.id]]
// });
//
// this.trigger('close-pos');
}
getPaymentData() {
const paymentData = [];
this.env.pos.payment_methods.forEach(method => {
const amount = this.el.querySelector(`input[data-method="${method.id}"]`).value;
paymentData.push({ method: method.name, amount: amount });
});
return paymentData;
}
async imprimirReporte(data) {
if (!this.env.pos) {
console.error('Error: objeto pos no definido');
return;
}
// const reportId = 'pos_control_cajero.montos_contados_report'; // reemplazar con el nombre real del informe
const
reportParams = {
'data': data,
};
var reportParamsJSON = JSON.stringify(reportParams);

// var context = {};
// context['active_model'] = 'pos.session';
// context['active_ids'] = [this.env.pos.pos_session.id];
// context['methods'] = 'montos_contados';

// console.log('dataJSON', reportParamsJSON)

await this
.env.pos.do_action('pos_control_cajero.montos_contados_report', {
additional_context: {
active_ids: [2],
data: reportParamsJSON,
},
});

}
get shopName() {
return this.env.pos.config.name;
}

}

MontosContadosScreen.template = 'MontosContadosScreen';

Registries.Component.add(MontosContadosScreen);

return MontosContadosScreen;});

So the important part is:

await this.env.pos.do_action('pos_control_cajero.montos_contados_report', {
additional_context: {
active_ids: [2],
data: reportParamsJSON,
},
});


I have this in backend
class MontosContadosReport(models.AbstractModel):
_name = 'report.pos_control_cajero.report_montos_contados'
_description = "Reporte de Montos Contados por Cajero"

@api.model
def _get_report_values
(self, docids, data=None):
report_params = data.get('reportParamsJSON', {})

return {
'doc_ids': docids,
'doc_model': 'pos.session',
'data': report_params,
'docs': [],
'shop_name': self.env.user.company_id.name,
}



This is my definition of report
<record id="montos_contados_report" model="ir.actions.report">
<field name="name">Reporte Montos contados por Cajerofield>
<field name="model">pos.sessionfield>
<field name="report_type">qweb-pdffield>
<field name="report_name">pos_control_cajero.report_montos_contadosfield>
<field name="paperformat_id" ref="paperformat_montos_contados" />
<field name="print_report_name">'Reporte Montos contados'field>
record>

The problem is that _get_report_values don't recive the data i'm trying to send from JS.


Avatar
Discard
Related Posts Replies Views Activity
1
Mar 15
3649
1
Jun 25
449
1
Jun 25
379
1
May 25
991
0
Mar 25
577