python - How to set this specific domain on OpenERP/Odoo? -


i have next table in odoo, named relationship, comes relation between table girl , table boy:

| girl_id | boy_id | relationship_type |

| 1 | 2 | friends |

| 1 | 3 | siblings |

| 2 | 7 | lovers |

so:

  • in table girl there's field relationships one2many pointing table relationship.
  • in table boy there's field relationships one2many pointing table relationship.
  • in table relationship there 2 fields, girl_id , boy_id, both pointing tables girl , boy respectively.

scenario:

in forms of girl , boy there's field relationships. when add new relationship girl or boy, form opened fill in fields of table relationship (girl_id, boy_id , relationship_type). imagine i'm in form of girl, click on add new relationship , form opened. implemented in order not see girl_id (it's invisible contains id of current girl). can see 2 fields (boy_id , relationship_type).

what want:

keeping on example, if open dropdown of boy_id, i'll see boys, ones related girl. example, if i'm adding relationship girl id 1, must not see boys ids 2 , 3, if girl 1 id 2, must not see boy id 7.

my attempt

i've created 2 fields in table relationships, named boys_of_the_girl (one2many related 'girl_id.relationships') , girls_of_the_boy (one2many related 'boy_id.relationships').

my code: (example: creating relationship girl)

<field name="girl_id" invisible="1"/> <field name="boys_of_the_girl" invisible="1"/> <field name="boy_id" domain="[('id', 'not in', boys_of_the_girl)]"/> <field name="relationship_type"/> 

the error:

runtimeerror: maximum recursion depth exceeded while calling python object

can me, please? thank you!

edit

table boy

relationships = fields.one2many(comodel_name='relationship',                                 inverse_name='boy_id',                                 string='relationships') 

table girl

relationships = fields.one2many(comodel_name='relationship', inverse_name='girl_id', string='relationships') 

table relationship

boy_id = fields.many2one(comodel_name='boy', string='boy', required=true) girl_id = fields.many2one(comodel_name='girl', string='girl', required=true) relationship_type = fields.char(string='relationship type') 

well, found out it's not possible manage through xml code, it's possible achieve same purpose through python:

only function (and 1 similar domain of girl_id in other form):

@api.onchange('girl_id') def on_change_girl_id(self):     current_girl_id = self.env.context.get('default_girl_id', false)     relationship_recordset = self.search([('girl_id', '=', current_girl_id)])     boy_recordset = relationship_recordset.mapped('boy_id')     boy_ids = boy_recordset.mapped('id')     boy_id_domain = [         ('id', 'not in', boy_ids)     ]     result = {         'domain': {             'boy_id': boy_id_domain,         },     }     return result 

and way it's not necessary add domain field boy_id in xml form. function affect form set relationship girl, wrote above, similar function must declared manage right behaviour when setting relationship boy.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -