Files
pms/hotel_channel_connector/models/channel_backend/common.py
2018-08-20 04:06:21 +02:00

38 lines
1.4 KiB
Python

# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from contextlib import contextmanager
from odoo import models, api, fields
from ...components.backend_adapter import WuBookLogin, WuBookAdapter
class ChannelBackend(models.Model):
_name = 'channel.backend'
_description = 'Hotel Channel Backend'
_inherit = 'connector.backend'
username = fields.Char('Channel Service Username')
passwd = fields.Char('Channel Service Password')
lcode = fields.Char('Channel Service lcode')
server = fields.Char('Channel Service Server',
default='https://wired.wubook.net/xrws/')
pkey = fields.Char('Channel Service PKey')
@contextmanager
@api.multi
def work_on(self, model_name, **kwargs):
self.ensure_one()
lang = self.default_lang_id
if lang.code != self.env.context.get('lang'):
self = self.with_context(lang=lang.code)
wubook_login = WuBookLogin(
self.server,
self.username,
self.passwd,
self.lcode,
self.pkey)
with WuBookAdapter(wubook_login) as channel_api:
_super = super(ChannelBackend, self)
# from the components we'll be able to do: self.work.magento_api
with _super.work_on(model_name, **kwargs) as work:
yield work