跳至內容
選單
此問題已被標幟
1 回覆
19864 瀏覽次數

Hi Friends ,

I like to know about Fields Type / Relation Fields - many2many syntax

From the existing code : server/openerp/addons/base/res/res_partner.py

  1. class res_partner(osv.osv, format_address):

    _columns= {
             ..............
              'category_id': fields.many2many('res.partner.category', id1='partner_id', id2='category_id', string='category'),
    
    .......
               }
    
  2. class res_partner_category(osv.osv):

    _columns={ ............

              'partner_ids': fields.many2many('res.partner', id1='category_id', id2='partner_id', string='Partners'),
            }
    

    Actually my doubt is from the syntax i can't understand id1 & id2 . Please explain me .

Thanks & Regards

OMPRAKASH.A

頭像
捨棄
最佳答案

id1 is actual.object.id and id2 is other.object.id. Actual object.id and other.object.id are the fields' names used in the relation table, and 'res.partner.category' is the relational object.

The syntax of M2M is fields.many2many('other.object.name', 'relation object', 'actual.object.id', 'other.object.id', 'Field Name')

*'other.object.name' is optional for v7.

Thank you

頭像
捨棄
作者

Hi Hiral Patel , Thanks for immediate reply .. I have doubt in < id1 is actual.object.id and id2 is other.object.id. Actual object.id and other.object.id are the fields' names used in the relation table, > from this point what is relation table from this example & where i can find it ?

You can find this in the 6.0 documentation. The second argument is the relation name (and table name). https://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/field_type.html/ ... fields.many2many('other.object.name', 'relation object', ... Where: relation object is the table that makes the link (...) Example: 'category_ids': fields.many2many( 'res.partner.category', 'res_partner_category_rel', 'partner_id', 'category_id', 'Categories'),

I want to use partner's name from 'partner_ids' field which is a 'many2many' field in the 'partner.ledger.webkit' model, in the attachment prefix for the report 'Partner Ledger Report' example 'object.company_id.name.pdf'. Please help!

相關帖文 回覆 瀏覽次數 活動
2
9月 15
6881
1
2月 24
1960
0
7月 24
3003
0
2月 23
2011
0
7月 22
60