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.

42 lines
1.3 KiB

  1. # Copyright 2020 Akretion (https://www.akretion.com).
  2. # @author Sébastien BEAU <sebastien.beau@akretion.com>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  4. from odoo import api, fields, models
  5. class IapAccount(models.Model):
  6. _inherit = ["iap.account", "server.env.mixin"]
  7. _name = "iap.account"
  8. name = fields.Char()
  9. provider = fields.Selection([("odoo", "Odoo IAP")], required=True, default="odoo")
  10. @property
  11. def _server_env_fields(self):
  12. return {
  13. "provider": {},
  14. "account_token": {},
  15. }
  16. def _get_service_from_provider(self):
  17. """In case that the provider only propose one service you can
  18. return the service_name in you module to simplify the user interface"""
  19. return None
  20. def _set_service_from_provider(self):
  21. for record in self:
  22. service = record._get_service_from_provider()
  23. if service and record.service_name != service:
  24. record.service_name = service
  25. @api.model_create_multi
  26. def create(self, vals_list):
  27. record = super().create(vals_list)
  28. record._set_service_from_provider()
  29. return record
  30. def write(self, vals):
  31. super().write(vals)
  32. self._set_service_from_provider()
  33. return True