title: Upload File in Signup form Odoo 12
body: <p>Iam trying to add a field "attachment" into the Signup form of Odoo 12. I share with you my work if you can correct me please :</p>
  
  <p>In my file_one.xml : </p>
  
  <pre><code>&lt;template id="auth_signup_fields_extend" inherit_id="auth_signup.fields" name="Signup Fields Extend"&gt;
  &lt;xpath expr="//div[hasclass('field-confirm_password')]" position="after"&gt;
  &lt;div class="form-group field-attachment"&gt;
  &lt;label for="attachment" class="control-label"&gt;Attachment&lt;/label&gt;
  &lt;input type="file" name="attachment"  multiple="true" data-show-upload="true" data-show- 
  caption="true" id="project.id" data-show-preview="true" class="form-control" required="required" t- 
  att-readonly="'readonly' if only_passwords else None" t-att-autofocus="'autofocus' if login and not 
  only_passwords else None"/&gt;
  &lt;/div&gt;
  &lt;/xpath&gt;
  &lt;/template&gt;
  </code></pre>
  
  <p>In my file_2.xml :</p>
  
  <pre><code>&lt;data&gt;
  &lt;record id="res_partner_form_inherit" model="ir.ui.view"&gt;
  &lt;field name="name"&gt;res.partner.form.inherit&lt;/field&gt;
  &lt;field name="model"&gt;res.partner&lt;/field&gt;
  &lt;field name="inherit_id" ref="base.view_partner_form"/&gt;
  &lt;field name="arch" type="xml"&gt;
  &lt;xpath expr="//field[@name='function']" position="after"&gt;
  &lt;field name="attachment"/&gt;
  &lt;/xpath&gt;
  &lt;/field&gt;
  &lt;/record&gt;
  &lt;/data&gt;
  </code></pre>
  
  <p>In my model.py</p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  from odoo import fields, models
  
  class ResPartner(models.Model):
      _inherit = "res.partner"
      attachment = fields.Binary(string='File of User',attachment=True)
  </code></pre>
  
  <p>In my file controller.py :</p>
  
  <pre><code>@http.route('/web/signup', type='http', auth='public', website=True, 
  sitemap=False)
  def web_auth_signup(self,**post):
      qcontext = self.get_auth_signup_qcontext()
      values = {}
      if post.get('attachment',False):
          Attachments = request.env['ir.attachment']
          name = post.get('attachment').filename      
          file = post.get('attachment')
          project_id = post.get('project_id')
          attachment = file.read() 
          attachment_id = Attachments.sudo().create({
              'name':name,
              'datas_fname': name,
              'res_name': name,
              'type': 'binary',   
              'res_model': 'model.model',
              'datas': attachment.encode('base64'),
          })
          value = {
              'attachment' : attachment_id
          }
          return request.render("fl_auth_signup.users", value)
  </code></pre>
  
  <p>I saw many tutorials and questions/answers about that but my module doesn't work, for now, i have the error : local variable 'Attachments' referenced before assignment</p>
  
  <p>Please, help, can you correct me? ...</p>