This question has been flagged
1 Reply
5249 Views

Hi everybody

I'm in the progress of adding a new tab under sales > Customers > New.

I've added the code for the model under sale/res_partner.py like this:

columns = {
        'sale_order_count': fields.function(_sale_order_count, string='# of Sales Order', type='integer'),
        'sale_order_ids': fields.one2many('sale.order','partner_id','Sales Order'),
        'x_testpersoon': fields.boolean('Testpersoon'),
        'x_geslacht': fields.selection([('M', 'Man / Male / Homme'), ('F', 'Vrouw / Female / Femme')], 'Geslacht'),
        'x_geboortedatum': fields.date('Geboortedatum'),
        'x_opleiding': fields.selection([('Middelbaar', 'Middelbaar / Secondary school / Études secondaires'),
        ('Bachelor', 'Bachelor / Bachelor / Bachelier'), 
        ('Master', 'Master / Master / Master'), 
        ('Universiteit', 'Universiteit / University / Université')], 'Opleiding'),
        'x_beroep': fields.char('Beroep', size=64),
        'x_taal': fields.selection([('NL', 'Nederlands / Dutch / Néerlandais'),
        ('EN', 'Engels / English / Anglais'), 
        ('FR', 'Frans / French / Français')], 'Taal'),
        'session_ids': fields.one2many('res.partner', 'id', string="Gebruikers"),
    }


I've added the code for a new view under /sale/res_partner_view.xml like this:

<page string="Externe personen">
                <field name="session_ids">
                        <tree string="Gebruikers">
                                 <field name="name"/>
                                 <field name="phone"/>
                        </tree>
                </field>
   </page>

I now get this view:

Which is exactly what I want. But when I now click on "Add an Item" it opens up a menu to make a new customer, like this:


I want a selection showing ALL customers / partners in our system and the ability to check the ones I want, like this:

And then the chosen people should show up in my previous form(view).
What I believe to have wrong is the session_ids in the model. 
My question is how can I show the dialog which will show me ALL customers/partners in a dialog where I can let the user choose from?

NOTE: I know the problem is I need a many2many but this is not allowed because I would need a many2many from the same model?

With kind regards
Yenthe

Avatar
Discard
Author Best Answer

The problem was just as I thought in the line 'session_ids': fields.one2many('res.partner', 'id', string="Gebruikers") of the models.
I needed a many2many here which referenced an external table to 'save' the records.

The final result should be like this:

'session_ids': fields.many2many('res.partner', 'custom_model_multi_customers_to_customer', 'session_id', 'partner_id', string="Sessions"),

 

Avatar
Discard