class instead of instance in Pool using metaclass MetaPool
trytond calls: module.register()
def register():
Pool.register(
Party,
module='party', type_='model')
RPC(readonly=True, instantiate=None, result=None)
__setup__ deepcopy all fields
No more dictionary values
Before
def on_change_product(self, values):
product_obj = pool.get('product.product')
product = product_obj.browse(values['product'])
return {
'description': product.rec_name,
}
After
def on_change_product(self):
return {
'description': self.product.rec_name,
}
@classmethod
def default_active(cls):
return True
instance method
def get_rec_name(self, name):
return '%s: %s' % (
self.rec_name, self.party.rec_name)
but also class method
def get_amount(cls, records, name):
cursor.execute('SELECT id, SUM(...)',
map(int, records))
return dict(cursor.fetchall())
merge on_change_with with getter
currency_digits = fields.Function(fields.Integer('Digits',
on_change_with=['currency']),
'on_change_with_currency_digits')
def on_change_with_currency_digits(self, name=None):
if self.currency:
return self.currency.digits
return 2
Explicit LRU Cache management
class Cache(object):
def get(self, key, default=None):
...
def set(self, key, value):
...
def clear(self):
...
The instance is the session
TODO
Problem: sequence field increase every time
order_field='(%(table)s.sequence IS NULL) %(order)s, ' \
'%(table)s.sequence %(order)s'
time = fields.Time(string='Time', format='%H:%M')