XML : Odoo partner title is bool when is_company is True

I have made some changes in Odoo to be able to format the partner name automatically. Now it seems that in the res.partner title field I can input both company and peronal titles.

enter image description here

enter image description here

I use title, name, first_name and last_name to automatically format the name after input.

  @api.one  @api.onchange("name", "title", "first_name", "last_name")  def onchange_name(self):      if self.title and self.is_company:          title = u" {}".format(self.title.name)      elif self.title and not self.is_company:          title = u"{} ".format(self.title.name)      else:          title = ""      if self.first_name:          first_name = self.first_name      else:          first_name = ""      if self.last_name and self.first_name:          last_name = u" {}".format(self.last_name)      elif self.last_name:          last_name = self.last_name      else:          last_name = ""        if self.is_company:          self.name = u"{0}{1}".format(self.name, title)      else:          self.name = u"{0}{1}{2}".format(title, first_name, last_name)    

in the view I first removed the original title field and put it back where I wanted it to be.

              <field name="title" position="replace"></field>              <xpath expr="//div[1]/div[1]" position="after">                  <div class="oe_edit_only" attrs="{'invisible': [('is_company','=', False)]}">                      <label for="title" string="Company Type"/>                      <field name="title" class="oe_inline"/>                  </div>                  <div class="oe_edit_only" attrs="{'invisible': [('is_company','=', True)]}">                      <field name="title" style="width:20%%" options='{"no_open": True}' placeholder="Title"/>                      <field name="first_name" style="width: 40%%" placeholder="First Name"/>                      <field name="last_name" style="width: 40%%" placeholder="Last Name"/>                  </div>              </xpath>    

Of course it never works like you want it to be the first time. When I have is_company False everything works perfectly, but when is_company is set to True it doesn't work at all.

After debugging I found that when is_company is set to False, title.name is the value that is in the dropdown. But when is_company is set to True and I put a value into the title field the debuggers shows that the value is a boolean set to False. If I save the value in the dropdown stays but when I debug again it still is a boolean set to False.

Could someone help me to fix this?

No comments:

Post a Comment