91 lines
2.7 KiB
Python
91 lines
2.7 KiB
Python
# -*- coding: UTF-8 -*-
|
|
# This file is part electronic_mail_template module for Tryton.
|
|
# The COPYRIGHT file at the top level of this repository contains
|
|
# the full copyright notices and license terms.
|
|
from trytond.model import Workflow, ModelView, ModelSQL, fields
|
|
from trytond.pool import Pool
|
|
from trytond.pyson import Eval
|
|
from datetime import datetime, date, time, timedelta
|
|
|
|
__all__ = ['SaleWebChannel']
|
|
|
|
STATES = {
|
|
'readonly': (Eval('state') != 'draft'),
|
|
}
|
|
|
|
|
|
class SaleWebChannel(Workflow, ModelSQL, ModelView):
|
|
'Web Channel'
|
|
__name__ = 'sale.web_channel'
|
|
|
|
secret_key = fields.Char('Secret Key', states=STATES, required=True)
|
|
app_id = fields.Char('Application ID', states=STATES, required=True)
|
|
redirect_uri = fields.Char('Redirect URI', states=STATES)
|
|
authorization_code = fields.Char('Authorization Code', states=STATES)
|
|
access_token = fields.Char('Access Token', states=STATES)
|
|
creation_time = fields.DateTime('Creation Time')
|
|
status_token = fields.Function(fields.Selection([
|
|
('expired', 'Expired'),
|
|
('active', 'Active'),
|
|
], 'Status Token', readonly=True), 'get_status_token')
|
|
refresh_token = fields.Char('Refresh Token', states=STATES)
|
|
state = fields.Selection([
|
|
('draft', 'Draft'),
|
|
('active', 'Active'),
|
|
('finished', 'Finished'),
|
|
], 'State', select=True, readonly=True)
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super(SaleWebChannel, cls).__setup__()
|
|
cls._transitions |= set((
|
|
('draft', 'active'),
|
|
('active', 'draft'),
|
|
('active', 'finished'),
|
|
('finished', 'active'),
|
|
))
|
|
cls._buttons.update({
|
|
'draft': {
|
|
'invisible': Eval('state') != 'active',
|
|
},
|
|
'active': {
|
|
'invisible': Eval('state') == 'active',
|
|
},
|
|
'finished': {
|
|
'invisible': Eval('state') != 'active',
|
|
},
|
|
})
|
|
|
|
@staticmethod
|
|
def default_state():
|
|
return 'draft'
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('draft')
|
|
def draft(cls, records):
|
|
pass
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('active')
|
|
def active(cls, records):
|
|
pass
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('finished')
|
|
def finished(cls, records):
|
|
pass
|
|
|
|
def get_status_token(self, name):
|
|
if self.creation_time:
|
|
now = datetime.now()
|
|
res = now - self.creation_time
|
|
if res.seconds >= 21600:
|
|
return 'expired'
|
|
else:
|
|
return 'active'
|
|
else:
|
|
return 'expired'
|