-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinsurance_followup.py
More file actions
252 lines (227 loc) · 9.75 KB
/
insurance_followup.py
File metadata and controls
252 lines (227 loc) · 9.75 KB
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
# -*- coding: utf-8 -*-
##############################################################################
#
# This module uses OpenERP, Open Source Management Solution Framework.
# Copyright (C) 2015-Today BrowseInfo (<http://www.browseinfo.in>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
from openerp.osv import osv
from openerp.osv import fields
from datetime import datetime
from dateutil.relativedelta import relativedelta
class insurance_department(osv.osv):
_description = "Insurance Department"
_name = 'insurance.department'
_columns = {
'name': fields.char('Name', size=64, required=True),
'code': fields.char('Code', size=64),
}
insurance_department()
class insurance_payment(osv.osv):
_description = "Insurance Payment"
_name = 'insurance.payment'
_columns = {
'paid_amt': fields.float('Paid Amount'),
'date': fields.date('Date'),
'payment_id': fields.many2one('insurance.followup', 'Payment')
}
insurance_payment()
class insurance_followup(osv.osv):
""" insurance_followup """
_name = "insurance.followup"
_description = "insurance followup"
def _due_date(self, cr, uid, ids, field_name, arg, context=None):
if context is None:
context = {}
if not ids:
ids = self.search(cr, uid, [])
res = {}.fromkeys(ids, 0.0)
if not ids:
return res
cur_obj = self.browse(cr, uid, ids, context=context)
iss_date = datetime.now()
pay_freq = datetime.now()
for field in cur_obj:
if field.issue_date and field.payment_frequency:
iss_date = datetime.strptime(field.issue_date, '%Y-%m-%d')
pay_freq = field.payment_frequency
freq = 12 / pay_freq
cur_date = datetime.today()
add_month = iss_date
while add_month <= cur_date:
if str(add_month).split(' ')[0] == str(cur_date).split(' ')[0]:
break
add_month = add_month + relativedelta(months=freq)
res.update({field.id: str(add_month)})
return res
_columns = {
'name': fields.char(
'Name', size=64, required=True,
states={'paid': [('readonly', True)]},),
'surname': fields.char(
'Surname', size=64, states={'paid': [('readonly', True)]},),
'address_id': fields.char(
'Address', states={'paid': [('readonly', True)]},),
'phone': fields.char(
'Phone', size=64, states={'paid': [('readonly', True)]},),
'email': fields.char(
'Email', size=240, states={'paid': [('readonly', True)]},),
'issue_date': fields.date(
'Issue Date', readonly=True,
states={'draft': [('readonly', False)]}, select=True),
'date_due': fields.function(
_due_date, type='date', string="Payment date", store=True),
'expiry_date': fields.date(
'CREDIT CARD EXPIRATION DATE',
states={'paid': [('readonly', True)]},),
'payment_frequency': fields.integer(
'FREQUENCY OF PAYMENT',
states={'paid': [('readonly', True)]}),
'sum_insured': fields.integer(
'SUM INSURED', states={'paid': [('readonly', True)]},),
'no_of_policy': fields.integer(
'Number of Policy', states={'paid': [('readonly', True)]},),
'insurance_issuer_id': fields.many2one(
'insurance.issuer', 'Insurance Issuer',
states={'paid': [('readonly', True)]},),
'prime': fields.float(
'Prime', size=64, states={'paid': [('readonly', True)]},),
'form': fields.char(
'Form', size=64, states={'paid': [('readonly', True)]},),
'plan': fields.char(
'Plan', size=64, states={'paid': [('readonly', True)]},),
'user_id': fields.many2one(
'res.users', 'Agent', states={'paid': [('readonly', True)]},),
'partner_id': fields.many2one(
'res.partner', 'Customer',
states={'paid': [('readonly', True)]}, required=True,),
'department_id': fields.many2one(
'insurance.department', 'Insurance Department',
states={'paid': [('readonly', True)]},),
'amount': fields.float('Amount', required=True,),
'state': fields.selection([
('draft', 'Draft'),
('open', 'Open'),
('paid', 'Paid'),
('cancel', 'Cancelled'),
], 'Status', select=True,),
'notes': fields.text('Notes'),
'policy_status': fields.boolean('Policy Status'),
'divisiones': fields.char('DIVISIONES'),
'payment_ids': fields.one2many(
'insurance.payment', 'payment_id', 'Insurance Payment'),
'off_payment': fields.boolean('Off Payment?')
}
_defaults = {
'state': 'draft'
}
def check_date(self, cr, uid, ins_ids=None, context=None):
ins_ids = self.search(
cr, uid, [('state', 'in', ['draft', 'open', 'paid'])],
context=context)
for ins_obj in self.browse(cr, uid, ins_ids, context=context):
if ins_obj.issue_date and ins_obj.payment_frequency:
iss_date = datetime.strptime(ins_obj.issue_date, '%Y-%m-%d')
pay_freq = ins_obj.payment_frequency
freq = 12 / pay_freq
cur_date = datetime.today()
add_month = iss_date
while add_month <= cur_date:
if str(add_month).split(' ')[0] == str(cur_date).split(' ')[0]:
break
add_month = add_month + relativedelta(months=freq)
if add_month < cur_date:
add_month = add_month + relativedelta(months=freq)
self.write(cr, uid, ins_ids, {'date_due': add_month},
context)
vals = {}
vals = {
'name': ins_obj.name,
'partner_phone': ins_obj.phone,
'date': ins_obj.issue_date,
'partner_id': ins_obj.partner_id.id or False,
'user_id': ins_obj.user_id.id or False,
}
for45 = cur_date + relativedelta(days=45)
for15 = cur_date + relativedelta(days=15)
for15 = str(for15).split(' ')[0]
for45 = str(for45).split(' ')[0]
if (for45 == ins_obj.date_due) or (for15 == ins_obj.date_due):
res = self.pool.get('crm.phonecall').create(
cr, uid, vals, context=context)
return True
insurance_followup()
class insurance_followup_followup(osv.osv):
_name = 'insurance_followup.followup'
_description = 'Insurance Follow-up'
_columns = {
'followup_line': fields.one2many(
'insurance_followup.followup.line', 'followup_id', 'Follow-up'),
'company_id': fields.many2one('res.company', 'Company', required=True),
'name': fields.related(
'company_id', 'name', type='char', string="Name"),
}
_sql_constraints = [('company_uniq', 'unique(company_id)',
'Only one follow-up per company is allowed')]
insurance_followup_followup()
class payment_frequency(osv.osv):
_name = 'payment.frequency'
_rec_name = 'no'
_columns = {
'no': fields.char('Frequency', required=True),
'desc': fields.char('Description'),
}
payment_frequency()
class insurance_followup_followup_line(osv.osv):
_name = 'insurance_followup.followup.line'
_description = 'Follow-up Criteria'
_columns = {
'name': fields.char('Follow-Up Action', size=64, required=True),
'sequence': fields.integer(
'Sequence', help="Gives the sequence order when displaying"
"a list of follow-up lines."),
'delay': fields.integer(
'Due Days',
help="The number of days after the due date of the invoice"
"to wait before sending the reminder. Could be negative if you"
"want to send a polite alert beforehand.", required=True),
'followup_id': fields.many2one(
'insurance_followup.followup', 'Follow Ups', required=True,
ondelete="cascade"),
'description': fields.text('Printed Message', translate=True),
'send_email': fields.boolean(
'Send an Email', help="When processing, it will send an email"),
'email_template_id': fields.many2one(
'email.template', 'Email Template', ondelete='set null'),
'state': fields.selection([
('before', 'Before'),
('after', 'After'),
], 'Status', select=True, required=True),
}
_order = 'sequence'
_sql_constraints = [
('days_uniq', 'unique(followup_id, delay)',
'Days of the follow-up levels must be different')]
_defaults = {
'send_email': True,
}
insurance_followup_followup_line()
class insurance_issuer(osv.osv):
_name = 'insurance.issuer'
_columns = {
'name': fields.char('Name'),
}
insurance_issuer()