1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Parthiv Pate, Tech Receptives, Open Source For Ideas
5
# Copyright (C) 2009-Today Tech Receptives(http://techreceptives.com).
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program. If not, see http://www.gnu.org/licenses/.
22
##############################################################################
24
from openerp.osv import fields, orm
25
from openerp.tools.translate import _
29
class res_letter(orm.Model):
30
"""A register class to log all movements regarding letters"""
32
_description = _("Log of Letter Movements")
33
_inherit = 'mail.thread'
35
def _get_number(self, cr, uid, context=None):
38
sequence_pool = self.pool.get('ir.sequence')
39
move_type = context.get('move', 'in')
40
return sequence_pool.get(cr, uid, '%s.letter' % move_type, context=context)
43
'name': fields.text('Subject', help="Subject of letter."),
44
'folder_id': fields.many2one('letter.folder', string='Folder',
45
help='Folder which contains letter.'),
46
'number': fields.char('Number', size=32, help="Auto Generated Number of letter.", required=True),
47
'move': fields.selection([('in', 'IN'), ('out', 'OUT')], 'Move', readonly=True,
48
help="Incoming or Outgoing Letter."),
49
'type': fields.many2one('letter.type', 'Type', help="Type of Letter, Depending upon size."),
50
'class': fields.many2one('letter.class', 'Class', help="Classification of Document."),
51
'date': fields.datetime('Letter Date', required=True, help='Created Date of Letter Logging.'),
52
'snd_rec_date': fields.datetime('Sent / Received Date'),
53
'partner_id': fields.many2one('res.partner', string='Follow up by', help='Recipient of letter.'),
54
'recipient_ids': fields.many2many('res.users', string="Send to", help="Persons who will receive Letter."),
55
'send_id': fields.many2one('res.users', "Send By", help="Person who sent Letter."),
56
'send_street': fields.char('Street'),
57
'send_city': fields.char('City'),
58
'send_zip': fields.char('Zip'),
59
'send_country': fields.many2one('res.country', 'Country'),
60
'note': fields.text('Note'),
61
'state': fields.selection([('draft', 'Draft'),
62
('created', 'Created'),
63
('validated', 'Validated'),
66
('rec_bad', 'Received Damage'),
67
('rec_ret', 'Received But Returned'),
68
('cancel', 'Cancelled')],
69
'State', readonly=True),
70
'parent_id': fields.many2one('res.letter', 'Parent'),
71
'child_line': fields.one2many('res.letter', 'parent_id', 'Letter Lines'),
72
'channel_id': fields.many2one('letter.channel', 'Sent / Receive Source'),
73
'history_line': fields.one2many('letter.history', 'register_id', 'History'),
74
'orig_ref': fields.char('Original Reference', help="Reference Number at Origin."),
75
'expeditor_ref': fields.char('Expeditor Reference', help="Reference Number used by Expeditor."),
76
'track_ref': fields.char('Tracking Reference', help="Reference Number used for Tracking."),
77
'weight': fields.float('Weight (in KG)'),
78
'size': fields.char('Size', size=64),
79
'reassignment_ids': fields.one2many('letter.reassignment', 'letter_id',
80
string='Reassignment lines',
81
help='Reassignment users and comments'),
82
'extern_partner_ids': fields.many2many('res.partner', string='Recipients'),
86
'number': _get_number,
87
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
88
'move': lambda self, cr, uid, context: context.get('move', 'in'),
92
def history(self, cr, uid, ids, keyword=False, context=None):
93
lh_pool = self.pool.get('letter.history')
95
lh_pool.create(cr, uid, {'name': keyword, 'user_id': uid, 'register_id': id}, context=context)
98
def action_received(self, cr, uid, ids, context=None):
99
"""Put the state of the letter into Received"""
100
for letter in self.browse(cr, uid, ids, context=context):
101
self.write(cr, uid, [letter.id], {'state': 'rec'}, context=context)
104
def action_cancel(self, cr, uid, ids, context=None):
105
"""Put the state of the letter into Cancelled"""
106
for letter in self.browse(cr, uid, ids, context=context):
107
self.write(cr, uid, [letter.id], {'state': 'cancel'}, context=context)
110
def action_create(self, cr, uid, ids, context=None):
111
"""Put the state of the letter into Crated"""
112
for letter in self.browse(cr, uid, ids, context=context):
113
self.write(cr, uid, [letter.id], {'state': 'created'}, context=context)
116
def action_validate(self, cr, uid, ids, context=None):
117
"""Put the state of the letter into Validated"""
118
for letter in self.browse(cr, uid, ids, context=context):
119
self.write(cr, uid, [letter.id], {'state': 'validated'}, context=context)
122
def action_send(self, cr, uid, ids, context=None):
123
"""Put the state of the letter into sent"""
124
for letter in self.browse(cr, uid, ids, context=context):
125
self.write(cr, uid, [letter.id], {'state': 'sent'}, context=context)
128
def action_rec_ret(self, cr, uid, ids, context=None):
129
"""Put the state of the letter into Received but Returned"""
130
for letter in self.browse(cr, uid, ids, context=context):
131
self.write(cr, uid, [letter.id], {'state': 'rec_ret'}, context=context)
134
def action_rec_bad(self, cr, uid, ids, context=None):
135
"""Put the state of the letter into Received but Damaged"""
136
for letter in self.browse(cr, uid, ids, context=context):
137
self.write(cr, uid, [letter.id], {'state': 'rec_bad'}, context=context)
140
def action_set_draft(self, cr, uid, ids, context=None):
141
"""Put the state of the letter into draft"""
142
for letter in self.browse(cr, uid, ids, context=context):
143
self.write(cr, uid, [letter.id], {'state': 'draft'}, context=context)
146
def onchange_send_id(self, cr, uid, ids, send_id=False, context=None):
147
"""Automatically set address from Receiver/Sender"""
150
user = self.pool['res.users'].browse(cr, uid, send_id, context=context)
153
'send_street': user.street,
154
'send_city': user.city,
155
'send_zip': user.zip,
156
'send_country': user.country_id.id,
160
def create(self, cr, user, vals, context=None):
161
"""Set address from Receiver/Sender on create"""
162
address_vals = self.onchange_send_id(cr, user, [], vals.get('send_id'), context=context)
163
vals = dict(vals.items() + address_vals.get('value', {}).items())
164
return super(res_letter, self).create(cr, user, vals, context=context)
166
def write(self, cr, user, ids, vals, context=None):
167
"""Set address from Receiver/Sender on write"""
168
address_vals = self.onchange_send_id(cr, user, ids, vals.get('send_id'), context=context)
169
vals = dict(vals.items() + address_vals.get('value', {}).items())
170
return super(res_letter, self).write(cr, user, ids, vals, context=context)