rate: optimize for speed
This commit is contained in:
parent
9d461b6d76
commit
11e9134dc9
1 changed files with 34 additions and 27 deletions
61
rate.py
61
rate.py
|
@ -22,15 +22,14 @@ class Rate(SymbolMixin, ModelSQL, ModelView):
|
|||
depends=['asset_digits'])
|
||||
|
||||
asset_digits = fields.Function(fields.Integer(string='Digits',
|
||||
readonly=True), 'on_change_with_asset_digits')
|
||||
readonly=True), 'get_rate_data')
|
||||
currency = fields.Function(fields.Many2One(string='Currency',
|
||||
readonly=True, model_name='currency.currency'),
|
||||
'on_change_with_currency')
|
||||
'get_rate_data')
|
||||
uom = fields.Function(fields.Many2One(string='Uom',
|
||||
readonly=True, model_name='product.uom'),
|
||||
'on_change_with_uom')
|
||||
readonly=True, model_name='product.uom'), 'get_rate_data')
|
||||
symbol = fields.Function(fields.Char(string='Symbol',
|
||||
readonly=True), 'on_change_with_symbol')
|
||||
readonly=True), 'get_rate_data')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -53,31 +52,39 @@ class Rate(SymbolMixin, ModelSQL, ModelView):
|
|||
IrDate = Pool().get('ir.date')
|
||||
return IrDate.today()
|
||||
|
||||
def on_change_with_symbol(self, name=None):
|
||||
""" symbol:%
|
||||
@classmethod
|
||||
def get_rate_data(cls, rates, names):
|
||||
""" speed up: get values for rate
|
||||
"""
|
||||
return '%'
|
||||
pool = Pool()
|
||||
Asset = pool.get('investment.asset')
|
||||
tab_asset = Asset.__table__()
|
||||
tab_rate = cls.__table__()
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
||||
@fields.depends('asset', '_parent_asset.uom')
|
||||
def on_change_with_uom(self, name=None):
|
||||
""" get unit of asset
|
||||
"""
|
||||
if self.asset:
|
||||
return self.asset.uom.id
|
||||
query = tab_asset.join(tab_rate,
|
||||
condition=tab_asset.id==tab_rate.asset,
|
||||
).select(
|
||||
tab_rate.id,
|
||||
tab_asset.uom,
|
||||
tab_asset.currency,
|
||||
tab_asset.currency_digits,
|
||||
where=tab_rate.id.in_([x.id for x in rates]),
|
||||
)
|
||||
cursor.execute(*query)
|
||||
records = cursor.fetchall()
|
||||
|
||||
@fields.depends('asset', '_parent_asset.currency')
|
||||
def on_change_with_currency(self, name=None):
|
||||
""" get currency
|
||||
"""
|
||||
if self.asset:
|
||||
return self.asset.currency.id
|
||||
result = {x:{y.id: None for y in rates} for x in names}
|
||||
for record in records:
|
||||
r1 = {
|
||||
'symbol': '%',
|
||||
'uom': record[1],
|
||||
'currency': record[2],
|
||||
'asset_digits': record[3],
|
||||
}
|
||||
|
||||
@fields.depends('asset', '_parent_asset.currency_digits')
|
||||
def on_change_with_asset_digits(self, name=None):
|
||||
""" get digits for asset
|
||||
"""
|
||||
if self.asset:
|
||||
return self.asset.currency_digits
|
||||
return 4
|
||||
for n in names:
|
||||
result[n][record[0]] = r1[n]
|
||||
return result
|
||||
|
||||
# Rate
|
||||
|
|
Loading…
Reference in a new issue