Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4582 มุมมอง

I want to add attachment while edit a form named my information on website and i want to save the attachment on the backend. I have added input field in the form for attachment but while saving the form i am not getting the attachment in the backend. Here is my code:-

template file:-

    <div class="form-group row">

     <div class="col-lg-3 col-md-4">
      <label class="control-label" for="Attachments">
       Attach Files
      </label>
     </div>
     <div class="col-lg-7 col-md-12">
       <input id='attachment' type="file"
       class="form-control o_website_form_input"
       name="attachment" multiple="true"
       data-show-preview="true"                                                                          
       accept="application/pdf"/>
      </div>
</div>


controller file:-


    @route(['/path/to/template'], type='http', auth='public', website=True)

def account(self, redirect=None, **post):
    values = self._prepare_portal_layout_values()
    User = request.env.user
    partner = User.partner_id
    
    if post:

        print("post::::::::::::::::::::::", post, values)
        attachment_ids = []
        attachment_list = request.httprequest.files.getlist('attachment')
        print("attachment_list::::::::::::::::", attachment_list)
        for att in attachment_list:
            if post.get('attachment'):
                attachments = {
                    'res_name': att.filename,
                    'res_model': 'res.partner',
                    'res_id': partner.sudo().id,
                    'datas': base64.encodestring(att.read()),
                    'type': 'binary',
                    'datas_fname': att.filename,
                    'name': att.filename,
                }
                attachment_obj = http.request.env['ir.attachment']
                att_record = attachment_obj.sudo().create(attachments)
                attachment_ids.append(att_record.id)
        if attachment_ids:
            values.update({'attachment_ids': [(6, 0, attachment_ids)]})

So Can anyone give me some idea what i am missing?

อวตาร
ละทิ้ง

Hi Gautam, did you solve your problem? i'm facing the same issue, so if you can help

ผู้เขียน
Related Posts ตอบกลับ มุมมอง กิจกรรม
Overriding "Product" in odoo 12 website? แก้ไขแล้ว
2
ธ.ค. 19
3746
1
พ.ย. 22
7359
4
ส.ค. 20
9292
1
ธ.ค. 19
5947
2
ก.ย. 24
1314