You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

  1. from openerp import api, models, fields, exceptions, _
  2. from openerp.modules.module import get_module_resource
  3. class SettingCurrency(models.Model):
  4. _name = 'setting.currency'
  5. @api.model
  6. def _update_currency(self):
  7. data_obj = self.env['ir.model.data']
  8. eur = data_obj.xmlid_to_object('base.EUR')
  9. usd = data_obj.xmlid_to_object('base.USD')
  10. eur.base = False
  11. self.env['res.currency.rate'].search([
  12. ('currency_id', '=', eur.id)
  13. ]).write({'rate': 0.8000})
  14. main_company = data_obj.xmlid_to_object('base.main_company')
  15. main_company.auto_currency_up = True
  16. services = self.env['currency.rate.update.service'].search(
  17. [('company_id', '=', main_company.id),
  18. ('service', '=', 'ECB_getter')]
  19. )
  20. if services:
  21. main_company.services_to_use = services[0]
  22. else:
  23. main_company.services_to_use = self.env[
  24. 'currency.rate.update.service'
  25. ].create({
  26. 'service': 'ECB_getter',
  27. 'max_delta_days': 1,
  28. 'currency_to_update': [(6, 0, [eur.id, usd.id])]
  29. })
  30. main_company.button_refresh_currency()