Skip to Content
Menu
This question has been flagged

Odoo version: 12

 Hello everyone, I am trying to create a form and send some images by POST method in a Module that I set up. 

I created the fields and the controlled and the xml, below.

Controller:

On the controller I didn't worry now about making it work perfectly yet I will implement it better

class PackagesEnhanced(http.Controller):
@http.route(['/my/account'], type='http'auth='user'website=True)
def account(selfredirect=None, **post):
  partner = request.env.user.partner_id
  Attachments = request.env['ir.attachment']
  name = post.get('attachment').filename
  file = post.get('attachment')
  attachment_id = Attachments.create({
'name': name,
'type''binary',
'datas': base64.b64encode(file.read()),
'res_model': partner._name,
'res_id': partner.id
  })
  partner.update({
'attachment': [(4, attachment_id.id)],
  })


Xml

<form string="Transfer" action="/my/account" method="post" class="s_website_form" enctype="multipart/form-data" >
<input type="file" name="attachment" class="file" multiple="true" data-show-upload="true" data-show-caption="true" lass="file" data-show-preview="true" id="project.id"></input>
<button type="submit" name="Upload" style="margin-top:20px;" class="fa fa-upload">
 Upload
</button>
</form>

Fields:

attachment = fields.Many2many('ir.attachment''attach_rel''doc_id''attach_id3',
string="Attachment",
help='You can attach the copy of your document'copy=False)


When I click Upload nothing happens.
When I try to directly access the link 127.0.0.1:8069/my/account I see that the system performs the function of the controller

I am not sure how Odoo generates his page, but I tried to see the code of the page to see if the <Form> field was showing, and I noticed that he is not on the page but the other fields are:

<div class="col-md-offset-5 col-sm-offset-4 col-sm-8 col-md-7" style="margin-top:30px;">
<div class="s_website_form">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()">
<input type="file" name="attachment" class="file" multiple="multiple" data-show-upload="true" data-show-caption="true" lass="file" data-show-preview="true" id="project.id">
<button type="button" name="Upload" style="margin-top:20px;" class="btn fa fa-upload" data-original-title="" title="">
Upload
</button></div></div>
I didn't try to venture too much, I just tried to copy the code and add it to mine with minor changes to work, but I can't find what I'm doing wrong. If anyone can help me thank you very much :)
Avatar
Discard

Hi, i have the same problem. Did you solve this ? if yes pls help me

Related Posts Replies Views Activity
2
Sep 23
2920
2
Sep 22
2579
1
Jun 22
1887
0
Jun 21
2258
6
May 19
5405