تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
10094 أدوات العرض

HI,

 

I have been trying for days to develop a module which extends crm (and later res.partner) with a field lead source.

I managed to get the datamodel amended by the model so that I now have an object res.partner.leadsource (cols: id [int], name [char], description[char], active[bool])

I'd now like to use that field in crm and make it a selection teh newly created leadsource object. The form view should only give the option to select a lead souce that's marked 'active','=','yes'.

The tupels for the selection shall be res.partner.leadsource(id,name).

I am having a hard time finding current/valid information for v7 whether to use fields.selection() or fields.many2one().

I tried both and failed. My latest approach is

class crm_lead(osv.osv):
     _inherit = "crm.lead"

     _columns = {
      'res_partner_leadsource_id': fields.many2one('res.partner.leadsource', 'contact source'),
     }

crm_lead();

This seems to be the same approach as in base/res/res_partner.py's "country_id" column.

I don't get an error anymore, which is great, but I am not getting the new field displayed in the Create Lead form:

The xml in the data[] section of __openerp__.py

is

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
    <!-- ========================This is Form layout===============================-->
    <record id="crm_case_form_view_leads_extended" model="ir.ui.view">
        <field name="name">CRM - Leads Form</field>
        <field name="model">crm.lead</field>
        <field name="inherit_id" ref="crm.crm_case_form_view_leads" />
        <field name="arch" type="xml">
            <field name="partner_name" postion="after">
            <field name="res_partner_leadsource_id" placeholder="Source" class="oe_no_button" />
<!--                <field name="res_partner_leadsource_id" widget="selection"
                   domain="[(;object_id.model','=','crm.lead')]"
                   context="{'object_name': 'crm_lead'}"
//-->
                />
            </field>
       </field>
    </record>
</data>
</openerp>

 

Can you help me please, how to get the selection list shown on the form?

الصورة الرمزية
إهمال
الكاتب

Hi René, thanks for your quick answer. I started off at the link you sent. The provided example states "selection=_sel_func" as field option. Apparently, this is not supported in v7 anymore but one should rather use fields.selection instead. I never got the example from the dev page working def _sel_func(self, cr, uid, context=None): obj = self.pool.get('mymodule.relation.model') ids = obj.search(cr, uid, []) res = obj.read(cr, uid, ids, ['name', 'id'], context) res = [(r['id'], r['name']) for r in res] return res This always threw an error back at me stating that cursor had no attribute uid. So I did some more reading and found that it's recommended to do it in XML via "widget='selection' ", which I didn't get to work either. I have put the code snippet in place you sent. I understand that this would affect the filter for active=true. At this stage i cannot see the field at all. (i.e. I am at a stage prior to the filtering). How can I make the field appear? Lastly, I'd like to give users the option to add/(de-)activate lead source records  rather than me pumping them straight into the DB table. How would I do that? I do like the "create and edit" option in other selection fields, e.g. contact state. but this wouldn't give us the option to (de-)activate records.

الكاتب

I tried your solution from https://www.odoo.com/forum/help-1/question/how-to-use-selection-on-many2one-46450 which doesn't give me an error anymore, but the field still doesn't show up. In debug "fields view get" shows the code has been added but it's wrapped by the partner_name field which doesn't seem right. However, if I change the XML code to I get an error about the XML not being valid for for the architecture.

الكاتب

typo in the position attribute of partner_name field: position="after"

أفضل إجابة

In your view, remove the context and change the domain to:

domain="[('active','=',True)]"

I don't know the effect of class="oe_no_button" but try to omit it if you don't need it.

You can find more information on selection or many2one fields here:
https://doc.odoo.com/6.0/developer/2_5_Objects_Fields_Methods/field_type/#basic-types

 

Regards.

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Hi Rene,

well spotted with the "position" typo. That solved it, even with "widget='selection' ". It's now visible and selectible.

I am not sure, how I managed to take over your comment. Even though your original "answer" didn't solve it, I still wanted you to get the karma, hence I marked it as answer :)

Cheers,

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
4
ديسمبر 23
22953
5
يوليو 24
16296
1
يونيو 22
27952
9
مايو 22
54233
0
يوليو 20
3491