Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ

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?

Ảnh đại diện
Huỷ bỏ

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

Tác giả
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 19
3745
1
thg 11 22
7351
4
thg 8 20
9285
1
thg 12 19
5944
2
thg 9 24
1308