Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to filter 2 relational fields selection content?

By
Simon
on 8/5/15, 9:59 AM 277 views


I need to filter a content of 2 relational fields 

My case is I have Person that have enemy list and only one best friend.

It is required that one person can not be a friend and an enemy of another.

So I need if person is in the enemy list to not be shown in the best friend selection and

the opposite if a person is best friend to not be shown in enemy selection


Also that a person can not be best friend and enemy to it self.



example code:

person.py

# -*- coding: utf-8 -*-

from openerp import models, fields, api

class person(models.Model):

    _name = 'Person'

    _description = 'Person is a human being with a name’

    name = fields.Char('Name')

    enemyRecordset = fields.Many2many(comodel_name='person',

        relation='person_rel',

        column1='person1_id',

        column2='person2_id', string='Enemy')

    bestFriendRecordset = fields.Many2one('person', 'Best Friend’)



person_view.xml

<openerp>

    <data>

        <record>

            <field>

                <form>

                    <sheet>

                        <group name="groupRight">

                            <tree>

                                <!-- Must not contain person it self and best friends -->

                                <field name="enemyRecordset" />

                            </tree>

                        </group>

                        <group> name="groupLeft">

                             <form>

                                <!-- Must not contain person it self and enemies -->

                                <field name="bestFriendRecordset" />

                            </form>

                        </group>

                    </sheet>

                </form>

            </field>

        </record>

    </data>

</openerp>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/5/15, 9:59 AM
Seen: 277 times
Last updated: 8/5/15, 9:59 AM