This question has been flagged
1 Reply
4499 Views

Hi All,

I'd like to know how I can add a notebook page in one of my custom module which will contain multiple line items from another custom module, along with the create/edit option in the drop down.

For example as we have products list under invoice tab while creating suppliers/clients invoice. There we are able to add multiple products for 1 invoice. I want similar structure with 2 of my custom modules. I want this to be bidirectional for both the modules.

Suppose I've created 2 custom modules A & B

Both contains Name field, and now I'd like to add some 2 way relation between these 2 modules, so that when I create a record for module A, in the form view, i can have a list of records from B to add as line item below with create/edit option for module B

So once I create a record for A with 2/3 line items from B then, the new item for A must also be listing in module B for the corresponding items/records from B.

Please help me with this. Any help would be appreciated. Thanks in advance :)

Cheers

ASP

Avatar
Discard
Best Answer

I guess you are looking for a bidirectional many2many relation.

Check the developer book for type of fields.

class A(osv.osv):

   _name = 'model.a'

   _columns = {
      'name': fields.char('Name',  size=64),
      'b_ids': fields.many2many('model.b', 'a_b_relation', 'a_id', 'b_id', 'Field Name A')
   }

class B(osv.osv):

   _name = 'model.b'

   _columns = {
      'name': fields.char('Name',  size=64),
      'a_ids': fields.many2many('model.a', 'a_b_relation', 'b_id', 'a_id', 'Field Name B')
   }

You can use these many2many fields in the xml view:

<notebook>
    <page string="Page">  
          <field name="b_ids" widget="many2many"/>
    </page>
</notebook>

Regards.

Avatar
Discard
Author

Thanks a lot Rene, for the quick response and also it works fine :) The only thing is, in the add item section in the form view when i click add item, instead of a drop down from the related module and window is opening. :) I need a drop down list there...............cheers :)

Sorry, but I do not know how to get a dropdown list... Maybe it's not even possible.

I would try to trick openerp by trying different widgets for the many2many field.