Merge pull request #2 from akretion/10.0-fix-currency_rate_update-domain

[FIX] Crash when you add currencies to "Currencies to update with this service"
This commit is contained in:
Niki Waibel
2017-04-05 10:10:57 +02:00
committed by GitHub
2 changed files with 11 additions and 3 deletions

View File

@@ -30,6 +30,7 @@ class CurrencyRateUpdateService(models.Model):
have to be updated"""
_name = "currency.rate.update.service"
_description = "Currency Rate Update"
_rec_name = "service"
@api.multi
@api.constrains('max_delta_days')
@@ -56,13 +57,20 @@ class CurrencyRateUpdateService(models.Model):
@api.onchange('service')
def _onchange_service(self):
currency_list = ''
res = {'domain': {
'currency_to_update': "[('id', '=', False)]",
}}
if self.service:
currencies = []
getter = CurrencyGetterType.get(self.service)
currency_list = getter.supported_currency_array
currencies = self.env['res.currency'].search(
[('name', 'in', currency_list)])
self.currency_list = [(6, 0, [curr.id for curr in currencies])]
currency_list = [(6, 0, currencies.ids)]
res['domain']['currency_to_update'] =\
"[('id', 'in', %s)]" % currencies.ids
self.currency_list = currency_list
return res
def _selection_service(self, *a, **k):
res = [(x.code, x.name) for x in CurrencyGetterType.getters.values()]

View File

@@ -28,6 +28,7 @@
<group name="main">
<group name="left">
<field name="service"/>
<field name="currency_list" invisible="1"/>
<field name="currency_list_readonly" widget="many2many_tags"/>
<field name="company_id" groups="base.group_multi_company"/>
</group>
@@ -40,8 +41,7 @@
</group>
<group string="Currencies to update with this service" name="currencies">
<!-- I need to have currency_list as r+w for the on_change -->
<field name="currency_list" invisible="1"/>
<field name="currency_to_update" nolabel="1" domain="[('id','in', currency_list[0][2])]"/>
<field name="currency_to_update" nolabel="1"/>
</group>
<group string="Logs" name="logs">
<field name="note" nolabel="1"/>