/usr/share/pyshared/trytond/res/request.py is in tryton-server 2.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | #This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import time
import datetime
from trytond.model import ModelView, ModelSQL, fields
from trytond.pyson import Eval, If
from trytond.transaction import Transaction
from trytond.pool import Pool
_STATES = [
('draft', 'Draft'),
('waiting', 'Waiting'),
('chatting', 'Chatting'),
('closed', 'Closed'),
]
_PRIORITIES = [
('0', 'Low'),
('1', 'Normal'),
('2', 'High'),
]
_READONLY = If(Eval('state').in_(['waiting', 'closed']),
True,
If(Eval('state') == 'chatting',
Eval('act_from') != Eval('_user'),
False))
_DEPENDS = ['state', 'act_from']
class Request(ModelSQL, ModelView):
"Request"
_name = 'res.request'
_description = __doc__
name = fields.Char('Subject', states={
'readonly': _READONLY,
}, required=True, depends=_DEPENDS)
active = fields.Boolean('Active')
priority = fields.Selection(_PRIORITIES, 'Priority', states={
'readonly': _READONLY,
}, required=True, order_field='priority', depends=_DEPENDS)
act_from = fields.Many2One('res.user', 'From', required=True,
readonly=True)
act_to = fields.Many2One('res.user', 'To', required=True,
domain=[('active', '=', True)],
states={
'readonly': _READONLY,
}, depends=_DEPENDS)
body = fields.Text('Body', states={
'readonly': _READONLY,
}, depends=_DEPENDS)
date_sent = fields.DateTime('Date', readonly=True)
trigger_date = fields.DateTime('Trigger Date', states={
'readonly': _READONLY,
}, depends=_DEPENDS)
references = fields.One2Many('res.request.reference', 'request',
'References', states={
'readonly': If(Eval('state') == 'closed',
True,
Eval('act_from', 0) != Eval('_user', 0)),
}, depends=['state', 'act_from'])
number_references = fields.Function(fields.Integer('Number of References',
on_change_with=['references']), 'get_number_references')
state = fields.Selection(_STATES, 'State', required=True, readonly=True)
history = fields.One2Many('res.request.history', 'request',
'History', readonly=True)
def default_act_from(self):
return int(Transaction().user)
def default_state(self):
return 'draft'
def default_active(self):
return True
def default_priority(self):
return '1'
def __init__(self):
super(Request, self).__init__()
self._rpc.update({
'request_send': True,
'request_reply': True,
'request_close': True,
'request_get': False,
})
self._order.insert(0, ('priority', 'DESC'))
self._order.insert(1, ('trigger_date', 'DESC'))
self._order.insert(2, ('create_date', 'DESC'))
def on_change_with_number_references(self, vals):
if vals.get('references'):
return len(vals['references'])
return 0
def get_number_references(self, ids, name):
res = {}
for request in self.browse(ids):
if request.references:
res[request.id] = len(request.references)
else:
res[request.id] = 0
return res
def request_send(self, ids):
pool = Pool()
request_history_obj = pool.get('res.request.history')
for request in self.browse(ids):
values = {
'request': request.id,
'act_from': request.act_from.id,
'act_to': request.act_to.id,
'body': request.body,
'state': request.state,
'subject': request.name,
'number_references': request.number_references,
'priority': request.priority,
}
if values['body'] and len(values['body']) > 128:
values['name'] = values['body'][:125] + '...'
else:
values['name'] = values['body'] or '/'
request_history_obj.create(values)
self.write(ids, {
'state': 'waiting',
'date_send': datetime.datetime.now(),
})
return True
def request_reply(self, ids):
user = Transaction().user
for request in self.browse(ids):
self.write(request.id, {
'state': 'chatting',
'act_from': user,
'act_to': request.act_from.id,
'trigger_date': False,
'body': '',
})
return True
def request_close(self, ids):
self.write(ids, {'state': 'closed', 'active': False})
return True
def request_get(self):
user = Transaction().user
ids = self.search([
('act_to', '=', user),
['OR',
('trigger_date', '<=', datetime.datetime.now()),
('trigger_date', '=', False),
],
('active', '=', True),
])
ids2 = self.search([
('act_from', '=', user),
('act_to', '!=', user),
('state', '!=', 'draft'),
('active', '=', True),
])
return (ids, ids2)
Request()
class RequestLink(ModelSQL, ModelView):
"Request link"
_name = 'res.request.link'
_description = __doc__
name = fields.Char('Name', required=True, translate=True)
model = fields.Selection('models_get', 'Model', required=True)
priority = fields.Integer('Priority')
def __init__(self):
super(RequestLink, self).__init__()
self._order.insert(0, ('priority', 'ASC'))
def default_priority(self):
return 5
def models_get(self):
pool = Pool()
model_obj = pool.get('ir.model')
model_ids = model_obj.search([])
res = []
for model in model_obj.browse(model_ids):
res.append((model.model, model.name))
return res
RequestLink()
class RequestHistory(ModelSQL, ModelView):
"Request history"
_name = 'res.request.history'
_description = __doc__
name = fields.Char('Summary', required=True, readonly=True)
request = fields.Many2One('res.request', 'Request', required=True,
ondelete='CASCADE', select=1, readonly=True)
act_from = fields.Many2One('res.user', 'From', required=True,
readonly=True)
act_to = fields.Many2One('res.user', 'To', required=True, readonly=True)
body = fields.Text('Body', readonly=True)
date_sent = fields.DateTime('Date sent', required=True, readonly=True)
state = fields.Selection(_STATES, 'State', required=True, readonly=True)
subject = fields.Char('Subject', required=True, readonly=True)
number_references = fields.Integer('References', readonly=True)
priority = fields.Selection(_PRIORITIES, 'Priority', required=True,
readonly=True)
def __init__(self):
super(RequestHistory, self).__init__()
self._order.insert(0, ('date_sent', 'DESC'))
def default_name(self):
return 'No Name'
def default_act_from(self):
return int(Transaction().user)
def default_act_to(self):
return int(Transaction().user)
def default_date_sent(self):
return datetime.datetime.now()
def write(self, ids, vals):
pass
RequestHistory()
class RequestReference(ModelSQL, ModelView):
"Request Reference"
_name = 'res.request.reference'
_description = __doc__
_rec_name = 'reference'
request = fields.Many2One('res.request', 'Request', required=True,
ondelete="CASCADE", select=1)
reference = fields.Reference('Reference', selection='links_get',
required=True)
def links_get(self):
pool = Pool()
request_link_obj = pool.get('res.request.link')
ids = request_link_obj.search([])
request_links = request_link_obj.browse(ids)
return [(x.model, x.name) for x in request_links]
RequestReference()
|