Reputation: 430
Hi there i'm using custom wizard on my custom module to upload file heres my code
class BillWizardUpload(models.TransientModel):
_name = "uploadbillpostfinance.wizard"
_description = "For XML Postfinance"
data = fields.Binary(string="Upload File")
file_name = fields.Char(string="File Name")
@api.multi
def import_file(self):
# your treatment
return {}
my XML file
<record id="upload_xml_view" model="ir.ui.view">
<field name="name">Upload XML PostFinance</field>
<field name="model">uploadbillpostfinance.wizard</field>
<field name="arch" type="xml">
<form>
<group>
<field name="data" filename="file_name" />
<field name="file_name" invisible="1"/>
</group>
<footer>
<button name="import_file" string="Import" type="object" class="oe_highlight" />
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
I'm a little bit confused what todo inside function import file, the file i'm going to upload is XML and want to directly process the xml without saving it to Database or file any idea or example how to do it?
Regard
Danial
Upvotes: 0
Views: 731
Reputation: 430
I managed to solve this problem by using normal get/post request like this
@api.multi
def import_file(self,context=None):
decoded_data = base64.b64decode(self.data)
xml_filelike = io.BytesIO(decoded_data)
do what you want with file here
Upvotes: 0
Reputation: 685
You don't need to add functions. Just a binary field is required in Odoo for file upload.
Upvotes: 2