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

Domain in on2many field [Closed]

By
Maniganda
on 6/13/13, 5:52 AM 1,585 views

The Question has been closed

by
Sudhir Arya (SA)
on 06/13/2013 11:32:26

I Have master class with Dep1 and Dep2 , I need to assign Dep1 and Dep2 to user , for the fist time for EMP A i select Dep1 ,next time if i select the same employee it should show only Dep2

Which is your one2many field?

Sudhir Arya (SA)
on 6/13/13, 9:00 AM

dep:fields.many2one('Department')

Maniganda
on 6/13/13, 10:00 AM

But in which object you have added this field and where is your one2many? You should post relevant code.

Sudhir Arya (SA)
on 6/13/13, 10:12 AM

class Department(osv.osv) _name = 'department' _columns = { 'name' :fields.char('Department',size=128),
} Depertment()

class Employee(osv.osv) _name='employee' _columns = { 'name':fields.many2one('department','Employee Department'),
} Employee()

for ex department has Dep1 , Dep2 , Dep3 if i assigh Dep1 to any Employee then the Dep1 Should not appear in Many2one field for other employees

Maniganda
on 6/13/13, 10:20 AM
0

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 6/13/13, 10:41 AM

I think that is not possible.

You can create one boolean field in department and make it true when department is allocated to any employee. Use that field in domain ([('is_allocated', '=', False)])

class Department(osv.osv):
    _name = 'department'
    _columns = {
        'name' :fields.char('Department',size=128),
        'is_allocated': fields.boolean('Is Allocated'),
    }

Depertment()

Make is_allocated field's value True in create and write method of employee if department is selected.

class Employee(osv.osv):
    _name='employee'
    _columns = {
        'name':fields.many2one('department','Employee Department'),
    }

    def create(self, cr, uid, vals, context=None):
        if vals.get('name', False):
            self.pool.get('department').write(cr, uid, vals['name'], {'is_allocated': True}, context=context)
        return super(employee, super).create(cr, uid, vals, context=context)

    def write(self, cr, uid, ids, vals, context=None):
        if vals.get('name', False):
            self.pool.get('department').write(cr, uid, vals['name'], {'is_allocated': True}, context=context)
        return super(employee, super).write(cr, uid, ids, vals, context=context)

Employee()

Add domain in xml of employee.

<field name='name' domain="[('is_allocated', '=', False)]"/>

Thanks for your reply , It is working

Maniganda
on 6/13/13, 10:51 AM

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 6/13/13, 5:52 AM
Seen: 1585 times
Last updated: 3/16/15, 8:10 AM