Hello, I am generating a .xls file with xlwt python-package and writing generated .xls in a binary field. To see that .xls I need to click on binary field then it gives me file to download and after download I can open. I want to omit this step of clicking binary to download file.
I would prefer to click on "Generate Excel" button and it should show me dialogue box to download file. ( without clicking the binary field where file is being saved)
Thanks in advance , any help would be appreciated!!
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
@api.one
def _get_template(self):
self.contract_template = base64.b64encode(open("/path/contract_template.xls", "rb").read())
contract_template = fields.Binary('Template', compute="_get_template")
@api.multi
def get_contract_template(self):
return {
'type': 'ir.actions.act_url',
'name': 'contract',
'url': '/web/content/model.name/%s/contract_template/contract_template.xls?download=true' %(self.id),
}
XML:
<button name="get_contract_template" string="Download Template" type="object" class="oe_link oe_right"/>
the fastest and the most useful answer to me
Hello,
Please have a look on the complete blog "How to Download any File on Button Click".
I am sure that it will help a lot.
Thanks.
Hello, u managed to solve this problem? kindly share with me how u solved it. i had the same problem but still did not able to solve it. thank you.
def get_contract_template(self):
url = str('/madel_name/static/src/xls/template.xlsx')
return {'type' : 'ir.actions.act_url','url': url,'target': 'self','tag': 'reload', }
You need to create a computed binary field. On the property compute assign the name of the function that calculates the field value of this field. '_compute_field' in this example.
@api.one
def _compute_field(self):
r = open(filename, 'rb').read().encode('base64')
self.computed_field = r
That would compute each time whenever you open form.
Hi, this is one more option. On clicking the "Generate Excel" button, you can open a wizard, which contains a button "print xls" (and possibly some entries to pass to the report parser if needed), on that button call a python method, which is defined on the transient model, for eg:
- this is my button on wizard:
<button icon="gtk-execute" name="get_report" string="Export xls" type="object" context="{'xls_export':1}"/>;
- the method in transient model, in my case I have both pdf or excel report, thats why am passing context in button:
@api.v7
def get_report(self, cr, uid, ids, context=None):
if context is None:
context = {}
data = {}
data['ids'] = context.get('active_ids', [])
data['model'] = context.get('active_model', 'ir.ui.menu')
data['form'] = self.read(cr, uid, ids, ['pricelist_type', 'hek', 'pek', 'dek'], context=context)[0]
if context.get('xls_export'):
return {'type': 'ir.actions.report.xml',
'report_name': 'product.pricelist.xls',
'datas': data['form']
}
else:
return self.pool['report'].get_action(cr, uid, [], 'custom_module.report_pricelist', data=data, context=context)
then you just need to create one .py file containing the parser and code to generate the excel report. In my case I want to generate excel report of the products pricelist. I suppose you have the parser and code to generate xls. If you don't have, I can send you the code for reference, by email.
Hope this helps you.
Which reporting engine you are using? It doesn't make any difference you are generating report through for or wizard.
I thought you want to have a pop-up and print xls, as you might have seen with some financial report module. Am also talking about generating .xls file with xlwt python-package. Anyway if you solved your issue, none of these matters :)
Hi, Did you manage to resolve? I have the same issue and not able to find an answer. Many thanks,
Yes, I managed to do ,I am out will post answer as soon as I get back to computer.
Downloading file on button click: http://learnopenerp.blogspot.com/2020/06/write-binary-data-nto-zip-file-and-downlaod-it-on-button-click-in-odoo.html