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 have checkbox depends on other fields?

By
Jérôme
on 10/21/15, 4:12 AM 285 views

Hello

I would like to have a checkbox on my app employee, and I would like this check box is check or uncheck on depends on 2 other fields!


explication:

on my form i have two fields :

'user_id' (the user relative to the employee)

'x_user_id' (a personal field and it's the id of the connected user)

So if the connected user is the same of the employee in the view i want my checkbox is uncheck

else if the connected user is different of the employee in the view i want my checkbox is check.


I try to create à boolean field with a compute arg !!! but i don't know how to write this in the compute cells!

I try to create a simple module like this but it doesn't work !!!

from openerp import SUPERUSER_ID
from openerp.osv import fields, osv
class hremployee(models.Model):
 _name = "hr.employee"
 _description = "Employee"
 _inherit = "hr.employee"
def _get_employee_user(self, cr, uid, ids, field_name, args, context=None):
 if context is None:
 context = {}
 if isinstance(ids, (int, long)):
 ids = [ids]
 res = {}
 for emp in self.browse(cr, uid, ids, context=context):
 res[emp.id] = True
 if emp.user_id == uid:
 res[emp.id] = False
 return res
 invisible = fields.Boolean(compute='_get_employee_user')


Can you help me?

0

Axel Mendoza

--Axel Mendoza--
10228
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 10/21/15, 4:48 AM

Try this way in the old api (you had defined to import osv instead of models)

from openerp.osv import fields, osv

class hremployee(osv.osv):
   _inherit = "hr.employee"

    def _get_employee_user(self, cr, uid, ids, field_name, args, context=None):
       if context is None:
           context = {}
       if isinstance(ids, (int, long)):
           ids = [ids]
       res = {}
       for emp in self.browse(cr, uid, ids, context=context):
           if emp.user_id == uid:
               res[emp.id] = False
            else:
    res[emp.id] = True
       return res

    _columns = {
       'invisible': fields.function(_get_employee_user, type='boolean', string='Invisible')
    }

Or this way in the new api:

from openerp import models, fields, api

class hremployee(models.Model):
_inherit = "hr.employee"

@api.multi
   def _get_employee_user(self):
for emp in self:
if emp.user_id == uid:
emp.invisible = False
            else:
               emp.invisible = True

invisible = fields.Boolean(compute='_get_employee_user')

 

hello axel and thanks for you're help. i try with the new api, the install is ok and the fields invisible was created in model employee, but after adding this fields in the form i had an error when i try to view my data: File "/usr/lib/python2.7/dist-packages/openerp/addons/hr_inv/hr_inv.py", line 10, in _get_employee_user if emp.user_id == uid: NameError: global name 'uid' is not defined

Jérôme
on 10/21/15, 12:16 PM

I change if emp.user_id == uid: by if emp.user_id == emp.x_user_uid: and i have no errors but my check box is always check!!! the first if is never verified!!!! i don't understand

Jérôme
on 10/21/15, 12:36 PM

Yes, I only rearrange your code in the way that should work, I don't check your business rules

Axel Mendoza
on 10/21/15, 1:24 PM

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

2 follower(s)

Stats

Asked: 10/21/15, 4:12 AM
Seen: 285 times
Last updated: 10/21/15, 4:48 AM