1

I am building a module with a many2one field (to be inserted into CRM module) but when I click on add a new value, the fields I created are not showing:

What it happens

I wrote this in my files:

module.py

class tipo_facturacion(models.Model):
  _name = "tipo_facturacion"
  name = fields.Char(string="Tipo Facturación", size=50, required=True)
  otro = fields.Char("Esto", required=True)

class cant_neg_crm(models.Model):  
        _inherit = "crm.lead"
        _columns = {
        'modo_facturacion': fields.many2one('tipo_facturacion' ,'Tipo Facturacion'),   
    }

Thank you very much in advance for your help!

Kind regards,

2 Answers 2

1

You need to define that field in view as well, by view inheritance you can do it.

class tipo_facturacion(models.Model):
    _name = "tipo_facturacion"

    name = fields.Char(string="Tipo Facturación", size=50, required=True)
    otro = fields.Char("Esto", required=True)

class cant_neg_crm(models.Model):  
    _inherit = "crm.lead"
    _columns = {
        'modo_facturacion': fields.many2one('tipo_facturacion' ,'Tipo Facturacion'),   
    }

Now add this field (Many2one) to the existing view using inheritance.

(Base view ID => crm.crm_case_form_view_leads) it might differ in your case.

<record id="new_view_id" model="ir.ui.view">
    <field name="name">crm.lead.form</field>
    <field name="model">crm.lead</field>
    <field name="inherit_id" ref="crm.crm_case_form_view_leads" />
    <field name="priority" eval="40"/>
    <field name="arch" type="xml">
        <!-- field name which you specify here after then new field will be added. -->
        <field name="existing_field_name" position="after">
            <field name="modo_facturacion" />
        </field>
    </field>
</record> 

Similarly you can add field in list view as well. Condition is only that you must add this py file in __init__.py and xml file in __openerp__.py file and restart server and upgrade/install module.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much! I will try that and see how it works!
Unfortunately, that's not working. When opening the many2one field, it shows other fields... Such as EAN13 and many other that have nothing to do with the other fields created. Thank you for your help!
0

Sorry for the hussle. It worked now, but it is showing this instead of the Char value:

enter image description here

Thanks!

1 Comment

if the filed'd model (model of many2one field) contains name field then it shows name field over there other wise it will take the model name, id. If name field is not there then you can set _rec_name='other_field_name' by setting this property in model you will see the value of that field in many2one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.