Files
tryton/trytond/model/fields/boolean.py
T

40 lines
1.4 KiB
Python
Raw Normal View History

2014-12-02 12:54:01 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2009-02-03 18:58:25 +01:00
2013-09-06 22:32:37 +02:00
from .field import Field, SQLType
2009-02-03 18:58:25 +01:00
class Boolean(Field):
2009-03-01 13:37:31 +01:00
'''
Define a boolean field (``True`` or ``False``).
'''
2009-02-03 18:58:25 +01:00
_type = 'boolean'
def __init__(self, string='', help='', readonly=False, domain=None,
2011-12-22 22:03:15 +01:00
states=None, select=False, on_change=None, on_change_with=None,
2013-09-06 22:32:37 +02:00
depends=None, context=None, loading='eager'):
super(Boolean, self).__init__(string=string, help=help, required=False,
2011-12-22 22:03:15 +01:00
readonly=readonly, domain=domain, states=states, select=select,
on_change=on_change, on_change_with=on_change_with,
2013-09-06 22:32:37 +02:00
depends=depends, context=context, loading=loading)
__init__.__doc__ = Field.__init__.__doc__
2013-09-06 22:32:37 +02:00
def sql_type(self):
return SQLType('BOOL', 'BOOL')
def _domain_add_null(self, column, operator, value, expression):
expression = super(Boolean, self)._domain_add_null(
column, operator, value, expression)
if operator in ('=', '!='):
conv = {
False: None,
None: False,
}
if value is False or value is None:
if operator == '=':
expression |= (column == conv[value])
else:
expression &= (column != conv[value])
return expression