What’s new?
What’s new?¶
Active Record¶
Model register¶
class instead of instance in
Pool
using metaclass
MetaPool
trytond calls:
module.register()
def register():
Pool.register(
Party,
module='party', type_='model')
Model attributes¶
-
_description and
_reset_colums removed
-
_name ->
__name__
-
__init__ ->
__setup__
-
_rpc ->
__rpc__
RPC¶
RPC(readonly=True, instantiate=None, result=None)
-
readonly: transaction mode
-
instantiate: position to instanciate
-
result: transform method
Model fields¶
__setup__ deepcopy all fields
More objects¶
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,
}
default values¶
@classmethod
def default_active(cls):
return True
Function getter¶
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())
Bonus¶
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
Unified API¶
-
Always list of instances (except
browse,
read)
-
write and
delete returns nothing
-
search returns list of instances
Cache¶
Explicit
LRU
Cache management
class Cache(object):
def get(self, key, default=None):
...
def set(self, key, value):
...
def clear(self):
...
Wizard¶
The instance is the session
Report¶
TODO
Sequence¶
Problem: sequence field increase every time
Solution¶
-
default_sequence removed
-
empty sequence at the end
order_field='(%(table)s.sequence IS NULL) %(order)s, ' \
'%(table)s.sequence %(order)s'
Time Format¶
-
on
Time and
DateTime
-
example drop second:
time = fields.Time(string='Time', format='%H:%M')
Reference field for xxx2Many¶
size attribute¶
-
added to
One2Many &
Many2Many
-
Dynamic:
PYSON
create/delete field access¶
-
Only for relation fields
Merge all kinds of button¶
-
New
ModelView.button_action(action)
-
button == method
-
launch action: return
action_id
View in XML file¶
-
in
module/view directory
-
view name is the file name
-
editor with
rng validation
-
change automatically reloaded
Pre-validation¶
-
validation without DB save
-
to activate on view
-
client calls for
One2Many
What’s new?¶
Active Record¶
Model register¶
class instead of instance in Pool using metaclass MetaPool
trytond calls: module.register()
def register():
Pool.register(
Party,
module='party', type_='model')
Model attributes¶
- _description and _reset_colums removed
- _name -> __name__
- __init__ -> __setup__
- _rpc -> __rpc__
RPC¶
RPC(readonly=True, instantiate=None, result=None)
- readonly: transaction mode
- instantiate: position to instanciate
- result: transform method
Model fields¶
__setup__ deepcopy all fields
More objects¶
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,
}
default values¶
@classmethod
def default_active(cls):
return True
Function getter¶
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())
Bonus¶
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
Unified API¶
- Always list of instances (except browse, read)
- write and delete returns nothing
- search returns list of instances
Cache¶
Explicit LRU Cache management
class Cache(object):
def get(self, key, default=None):
...
def set(self, key, value):
...
def clear(self):
...
Wizard¶
The instance is the session
Report¶
TODO
Sequence¶
Problem: sequence field increase every time
Solution¶
- default_sequence removed
- empty sequence at the end
order_field='(%(table)s.sequence IS NULL) %(order)s, ' \
'%(table)s.sequence %(order)s'
Time Format¶
- on Time and DateTime
- example drop second:
time = fields.Time(string='Time', format='%H:%M')
Reference field for xxx2Many¶
size attribute¶
- added to One2Many & Many2Many
- Dynamic: PYSON
create/delete field access¶
- Only for relation fields
Merge all kinds of button¶
- New ModelView.button_action(action)
- button == method
- launch action: return action_id
View in XML file¶
- in module/view directory
- view name is the file name
- editor with rng validation
- change automatically reloaded
Pre-validation¶
- validation without DB save
- to activate on view
- client calls for One2Many