Skip to Content
Menú
This question has been flagged
1 Respondre
7626 Vistes

I created a new model and report for this model.

In this new model, one of the fields is a Many2one with the model sale.order

In can easily print my report from the new model views.

And I would also be able to print this same report from the sale.order form view.
I want to add a button that call a method (done), this method get all new model records linked to my sale.order id and i lunch the print.

But i am completely lost and i cannot find the good keywords to find my answer on Google.

So, need your help :0

Avatar
Descartar
Best Answer

Hi you can write a code that will call your method and return report action to print report.

May be below code helps you.

@api.multi
def your_method_name(self):
     #your code to call method(done)
     #code for print report
     data = {'ids': self.ids,(list of ids that you need for print report)
             'model': 'model',(eg.'sale.order')
             'form': self.read([])[0],
             }
     return {'type': 'ir.actions.report.xml',
             'report_name': 'your report name',
             'report_type': "qweb-pdf",
             'datas': data }
Avatar
Descartar
Autor

Hi,

Thanks, but I still need some help.

I have this error : TypeError: sale.order.products(1, 2, 3) is not JSON serializable

And, the model that i put data json, should be sale.order or sale.order.products ?

-----------------------------------------------------------------

class my_class(models.Model):

_inherit = 'sale.order'

products = fields.One2many(comodel_name='sale.order.products', inverse_name='order_id')

@api.multi

def my_print_method(self):

data = {'ids': self.products,

'model': 'sale.order.products',

'form': self.read([])[0],

}

return {'type': 'ir.actions.report.xml',

'report_name': 'mymodule.sale_order_products_report',

'report_type': "qweb-pdf",

'datas': data

}

please use 'ids': self.products.ids instead of self.products

Autor

thanks.

I get this message:

QWebException: ('MissingError', u'Record does not exist or has been deleted.')

I tried to change:

'model': 'sale.order.products',

to

'model': 'sale.order',

But same result. Of course the ids exist.

Don't know what i am missing.

Autor

I am still stucked on it, if you have some idea

Related Posts Respostes Vistes Activitat
2
d’ag. 17
8978
1
d’oct. 15
3467
3
de set. 15
3687
3
de febr. 24
12607
5
de gen. 20
8196