res_config.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request
  3. _MODEL = 'res.config.settings'
  4. def get_pos_config():
  5. config = request.env[_MODEL].search([], limit=1, order='id desc')
  6. config = config.get_default_settings([])
  7. return {
  8. 'imageType': config.get('image_type'),
  9. 'allowCurrencyExchange': config.get('allow_currency_exchange'),
  10. 'viewCurrencyExchanges': config.get('view_currency_exchanges'),
  11. 'allowChangeUser': config.get('allow_change_user'),
  12. 'allowChangeDate': config.get('allow_change_date'),
  13. 'allowPricelist': config.get('allow_pricelist'),
  14. 'currencies': [
  15. {
  16. 'id': currency.id,
  17. 'name': currency.display_name,
  18. 'symbol': currency.symbol,
  19. 'position': currency.position,
  20. 'rateSilent': currency.rate_silent,
  21. 'decimalSeparator': currency.decimal_separator,
  22. 'decimalPlaces': currency.decimal_places,
  23. 'thousandsSeparator': currency.thousands_separator
  24. } for currency in request.env['res.currency'].browse(config.get('currency_ids'))
  25. ]
  26. }
  27. def save_pos_config(kw):
  28. values = {}
  29. if kw.get('setting') == 'imageType':
  30. values['image_type'] = ('big', 'small')[kw.get('value', False)]
  31. if kw.get('setting') == 'allowCurrencyExchange':
  32. values['allow_currency_exchange'] = kw.get('value', False)
  33. if kw.get('setting') == 'viewCurrencyExchanges':
  34. values['view_currency_exchanges'] = kw.get('value', False)
  35. settings = request.env[_MODEL].search([], limit=1, order='id desc')
  36. if settings:
  37. settings.write(values)
  38. else:
  39. settings = settings.create(values)
  40. settings.execute()
  41. return get_pos_config()