1
##############################################################################
3
# Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the impli(ed warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
28
from osv import fields, osv
30
from datetime import date,timedelta
36
('none', 'Non Member'),
37
('canceled', 'Canceled Member'),
38
('old', 'Old Member'),
39
('waiting', 'Waiting Member'),
40
('invoiced', 'Invoiced Member'),
41
('associated', 'Associated Member'),
42
('free', 'Free Member'),
43
('paid', 'Paid Member'),
46
class res_partner(osv.osv):
47
_inherit = 'res.partner'
48
_description = 'res.partner'
51
'asker_name': fields.char('Asker Name',size=50),
52
'asker_address': fields.char('Asker Address',size=50),
53
'asker_zip_id': fields.many2one('res.partner.zip','Asker Zip Code'),
54
'sender_name': fields.char('Sender Name',size=50),
55
'insurer_id' : fields.char('Insurer ID',size=50),
60
class cci_missions_site(osv.osv):
61
_name = 'cci_missions.site'
62
_description = 'cci_missions.site'
65
'name' : fields.char('Name of the Site',size=50,required=True),
66
'official_name_1' : fields.char('Official Name of the Site',size=50,required=True),
67
'official_name_2' : fields.char('Official Name of the Site',size=50),
68
'official_name_3' : fields.char('Official Name of the Site',size=50),
69
'official_name_4' : fields.char('Official Name of the Site',size=50),
70
'embassy_sequence_id' : fields.many2one('ir.sequence','Sequence for Embassy Folder'),
75
class cci_missions_embassy_folder(osv.osv):
76
_name = 'cci_missions.embassy_folder'
77
_description = 'cci_missions.embassy_folder'
78
_inherits = {'crm.case': 'crm_case_id'}
80
def _cci_mission_send(self, cr, uid, ids, *args):
81
self.write(cr, uid, ids, {'state':'pending',})
82
cases = self.browse(cr, uid, ids)
83
self._history(cr, uid, cases, 'Send', history=True,)
86
def _cci_mission_got_back(self,cr,uid,ids,*args):
87
self.write(cr, uid, ids, {'state':'open',})
88
cases = self.browse(cr, uid, ids)
89
self._history(cr, uid, cases, 'Got Back', history=True)
92
def _cci_mission_done_folder(self,cr,uid,ids,*args):
93
self.write(cr, uid, ids, {'state':'done','invoice_date': time.strftime('%Y-%m-%d %H:%M:%S')})
94
cases = self.browse(cr, uid, ids)
95
self._history(cr, uid, cases, 'Invoiced', history=True)
98
def _history(self, cr, uid,ids,keyword, history=False, email=False, context={}):
103
'canal_id': case.canal_id.id,
105
'case_id': case.crm_case_id.id
107
obj = self.pool.get('crm.case.log')
108
# if history and case.description:
109
# obj = self.pool.get('crm.case.history')
110
# data['description'] = case.description
111
# data['email'] = email or \
112
# (case.user_id and case.user_id.address_id and \
113
# case.user_id.address_id.email) or False
114
obj.create(cr, uid, data, context)
117
def create(self, cr, uid, vals, *args, **kwargs):
118
# Overwrite the name field to set next sequence according to the sequence in for the embassy folder related in the site_id
120
data = self.pool.get('cci_missions.site').browse(cr, uid,vals['site_id'])
121
seq = self.pool.get('ir.sequence').get(cr, uid,data.embassy_sequence_id.code)
123
vals.update({'name': seq})
124
temp = super(osv.osv,self).create(cr, uid, vals, *args, **kwargs)
125
self._history(cr, uid,self.browse(cr, uid, [temp]), 'Created', history=True)
130
def onchange_partner_id(self, cr, uid, ids, part):
132
return {'value':{'partner_address_id': False}}
133
part_obj = self.pool.get('res.partner')
134
data_partner = part_obj.browse(cr,uid,part)
135
if data_partner.alert_legalisations:
136
raise osv.except_osv('Error!',data_partner.alert_explanation or 'Partner is not valid')
137
addr = part_obj.address_get(cr, uid, [part], ['contact'])
138
data = {'partner_address_id':addr['contact']}
139
return {'value':data}
141
def check_folder_line(self, cr, uid, ids):
142
#CONSTRAINT: For each embassy Folder, it can only be one embassy_folder_line of each type.
143
data_folder = self.browse(cr,uid,ids)
145
for folder in data_folder:
146
for line in folder.embassy_folder_line_ids:
147
if line.type and line.type in list:
149
list.append(line.type)
153
'crm_case_id' : fields.many2one('crm.case','Case'),
154
'member_price' : fields.boolean('Member Price Allowed'),
155
'customer_reference' : fields.char('Folders Reference for the Customer',size=30),
156
'destination_id' : fields.many2one('res.country','Destination Country'),
157
'link_ids': fields.one2many('cci_missions.dossier','embassy_folder_id','Linked Documents'),
158
'internal_note': fields.text('Internal Note'),
159
'invoice_note':fields.text('Note to Display on the Invoice',help='to display as the last embassy_folder_line of this embassy_folder.'),
160
'embassy_folder_line_ids' : fields.one2many('cci_missions.embassy_folder_line','folder_id','Details'),
161
'site_id': fields.many2one('cci_missions.site','Site', required=True),
162
'invoice_date' : fields.datetime('Invoice Date', readonly=True) ,
163
"invoice_id":fields.many2one("account.invoice","Invoice"),
167
'section_id': lambda obj, cr, uid, context: obj.pool.get('crm.case.section').search(cr, uid, [('name','=','Embassy Folder')])[0],
168
'invoice_date': lambda *a: False,
169
'name': lambda *args: '/',
170
'state' : lambda *a : 'draft'
173
_constraints = [(check_folder_line, 'Error: Only One Embassy Folder line allowed for each type!', ['embassy_folder_line_ids'])]
175
cci_missions_embassy_folder()
177
class cci_missions_embassy_folder_line (osv.osv):
178
_name = 'cci_missions.embassy_folder_line'
179
_description = 'cci_missions.embassy_folder_line '
182
def create(self, cr, uid, vals, *args, **kwargs):
184
prod_name= vals['type'] + str(' Product')
185
cr.execute('select id from product_template where name='"'%s'"''%str(prod_name))
190
prod_info = self.pool.get('product.product').browse(cr, uid,product_id)
191
account = prod_info.product_tmpl_id.property_account_income.id
193
account = prod_info.categ_id.property_account_income_categ.id
194
vals['account_id']=account
195
return super(osv.osv,self).create(cr, uid, vals, *args, **kwargs)
197
def write(self, cr, uid, ids,vals, *args, **kwargs):
199
prod_name= vals['type'] + str(' Product')
200
cr.execute('select id from product_template where name='"'%s'"''%str(prod_name))
205
prod_info = self.pool.get('product.product').browse(cr, uid,product_id)
206
account = prod_info.product_tmpl_id.property_account_income.id
208
account = prod_info.categ_id.property_account_income_categ.id
209
vals['account_id']=account
211
return super(osv.osv,self).write( cr, uid, ids,vals, *args, **kwargs)
213
def onchange_line_type(self,cr,uid,ids,type):
215
data['courier_cost']=data['customer_amount']=data['account_id']=data['name']=False
218
return {'value' : data }
221
prod_name= str(type) + str(' Product')
222
cr.execute('select id from product_template where name='"'%s'"''%str(prod_name))
226
return {'value' : data }
229
prod_info = self.pool.get('product.product').browse(cr, uid,product_id)
230
data['courier_cost']=prod_info.standard_price
231
data['customer_amount']=prod_info.list_price
232
account = prod_info.product_tmpl_id.property_account_income.id
234
account = prod_info.categ_id.property_account_income_categ.id
235
data['account_id']=account
237
return {'value' : data }
240
'name' : fields.char('Description',size=50,required=True),
241
'folder_id' : fields.many2one('cci_missions.embassy_folder','Related Embassy Folder',required=True),
242
'courier_cost' : fields.float('Couriers Costs'),
243
'customer_amount' : fields.float('Invoiced Amount'),
244
'tax_rate': fields.many2one('account.tax','Tax Rate'),
245
'type' : fields.selection([('CBA','CBA'),('Ministry','Ministry'),('Embassy Consulate','Embassy Consulate'),('Translation','Translation'),('Administrative','Administrative'),('Travel Costs','Travel Costs'),('Others','Others')],'Type'),
246
'account_id' : fields.many2one('account.account', 'Account',required=True),
249
cci_missions_embassy_folder_line()
251
class cci_missions_dossier_type(osv.osv):
252
_name = 'cci_missions.dossier_type'
253
_description = 'cci_missions.dossier_type'
256
'code' : fields.char('Code',size=3,required=True),
257
'name' : fields.char('Description',size=50,required=True),
258
'original_product_id' : fields.many2one('product.product','Reference for Original Copies',required=True,help='for the association with a pricelist'),
259
'copy_product_id' : fields.many2one('product.product','Reference for Copies',required=True,help='for the association with a pricelist'),
260
'site_id' : fields.many2one('cci_missions.site','Site',required=True),
261
'sequence_id' : fields.many2one('ir.sequence','Sequence',required=True,help='for association with a sequence'),
262
'section' : fields.selection([('certificate','Certificate'),('legalization','Legalization'),('ATA','ATA Carnet')],'Type',required=True),
263
'warranty_product_1': fields.many2one('product.product', 'Warranty product for ATA carnet if Own Risk'),
264
'warranty_product_2': fields.many2one('product.product', 'Warranty product for ATA carnet if not own Risk'),
267
cci_missions_dossier_type()
269
class cci_missions_dossier(osv.osv):
270
_name = 'cci_missions.dossier'
271
_description = 'cci_missions.dossier'
273
def create(self, cr, uid, vals, *args, **kwargs):
274
#overwrite the create: if the text_on_invoice field is empty then fill it with name + destination_id.name + (quantity_original)
275
if not vals['text_on_invoice']:
276
invoice_text = vals['name']
277
if vals['destination_id']:
278
destination_data = self.pool.get('res.country').browse(cr,uid,vals['destination_id'])
279
invoice_text = vals['name'] + ' ' + destination_data.name + ' (' + str(vals['quantity_original']) + ')'
280
vals.update({'text_on_invoice': invoice_text})
281
return super(osv.osv,self).create(cr, uid, vals, *args, **kwargs)
283
def get_partner_details(self, cr, uid, ids,order_partner_id):
288
partner_info = self.pool.get('res.partner').browse(cr, uid,order_partner_id)
289
if not partner_info.asker_name:
290
asker_name=partner_info.name
292
asker_name=partner_info.asker_name
293
if not partner_info.sender_name:
294
sender_name=partner_info.name
296
sender_name=partner_info.sender_name
298
'asker_name': asker_name,
299
'sender_name': sender_name}
303
# def _amount_total(self, cr, uid, ids, name, args, context=None):
305
# data_dosseir = self.browse(cr,uid,ids)
306
# for data in data_dosseir:
307
# if data.state =='draft':
310
# res[data.id]=data.invoiced_amount
313
def _amount_subtotal(self, cr, uid, ids, name, args, context=None):
315
data_dosseir = self.browse(cr,uid,ids)
316
for data in data_dosseir:
318
for product in data.product_ids:
319
sum += product.price_subtotal
324
'id': fields.integer('ID', readonly=True),
325
'name' : fields.char('Reference',size=20,required=True),
326
'type_id' : fields.many2one('cci_missions.dossier_type','Dossier Type',required=True),
327
'date' : fields.date('Creation Date',required=True),
328
'order_partner_id': fields.many2one('res.partner','Billed Customer',required=True),
329
'asker_name':fields.char('Asker Name',size=50),
330
'sender_name':fields.char('Sender Name',size=50),
331
'to_bill':fields.boolean('To Be Billed'),
332
'state':fields.selection([('draft','Confirmed'),('invoiced','Invoiced'),('cancel_customer','Canceled by Customer'),('cancel_cci','Canceled by the CCI')],'State',),
333
'goods':fields.char('Goods Description',size=100),
334
'goods_value':fields.float('Value of the Sold Goods'),#Monetary; must be greater than zero
335
'destination_id':fields.many2one('res.country','Destination Country'),
336
'embassy_folder_id':fields.many2one('cci_missions.embassy_folder','Related Embassy Folder'),
337
'quantity_copies':fields.integer('Number of Copies'),
338
'quantity_original' : fields.integer('Quantity of Originals',required=True),
339
'sub_total':fields.function(_amount_subtotal, method=True, string='Sub Total for Extra Products', store=True),
340
'text_on_invoice':fields.text('Text to Display on the Invoice'),
341
'product_ids': fields.one2many('product.lines', 'dossier_product_line_id', 'Products'),
342
'invoice_id':fields.many2one("account.invoice","Invoice"),
343
'invoiced_amount': fields.float('Total'),
347
'name': lambda *args: '/',
348
'date': lambda *a: time.strftime('%Y-%m-%d'),
349
'to_bill' : lambda *b : True,
350
'state' : lambda *a : 'draft',
351
'quantity_original' : lambda *a : 1
354
cci_missions_dossier()
356
class cci_missions_custom_code(osv.osv):
357
_name= 'cci_missions.custom_code'
358
_desctiption = 'cci_missions.custom_code'
360
'name' : fields.char('Name',size=8,required=True),
361
'meaning' : fields.char('Meaning',size=250,required=True),
362
'official' : fields.boolean('Official Code'),
366
'official': lambda *a: False,
369
cci_missions_custom_code()
371
class cci_missions_certificate(osv.osv):
372
_name = 'cci_missions.certificate'
373
_description = 'cci_missions.certificate'
374
_inherits = {'cci_missions.dossier': 'dossier_id' }
376
def _amount_total(self, cr, uid, ids, name, args, context=None):
378
data_dosseir = self.browse(cr,uid,ids)
380
for data in data_dosseir:
381
if data.state =='draft':
382
data_partner = self.pool.get('res.partner').browse(cr,uid,data.order_partner_id.id)
383
context.update({'partner_id':data_partner})
384
context.update({'force_member':False})
385
context.update({'force_non_member':False})
386
context.update({'date':data.date})
387
context.update({'value_goods':data.goods_value})
388
context.update({'pricelist':data_partner.property_product_pricelist.id})
389
price_org = self.pool.get('product.product')._product_price(cr, uid, [data.type_id.original_product_id.id], False, False, context)
390
price_copy = self.pool.get('product.product')._product_price(cr, uid, [data.type_id.copy_product_id.id], False, False, context)
391
cost_org=price_org[data.type_id.original_product_id.id]
392
cost_copy=price_copy[data.type_id.copy_product_id.id]
393
qty_org = data.quantity_original
394
qty_copy = data.quantity_copies
395
subtotal = data.sub_total
396
if qty_org < 0 or qty_copy < 0:
397
raise osv.except_osv('Input Error!','No. of Copies and Quantity of Originals should be positive.')
398
total = ((cost_org * qty_org ) + (cost_copy * qty_copy) + subtotal)
401
res[data.id]=data.invoiced_amount
404
def cci_dossier_cancel_cci(self, cr, uid, ids, *args):
405
data=self.browse(cr,uid,ids[0])
406
if data.invoice_id.state == 'paid':
407
new_ids = self.pool.get('account.invoice').refund(cr, uid,[data.invoice_id.id])
408
self.write(cr, uid,ids, {'invoice_id' : new_ids[0]})
410
wf_service = netsvc.LocalService('workflow')
411
wf_service.trg_validate(uid, 'account.invoice', data.invoice_id.id, 'invoice_cancel', cr)
412
self.write(cr, uid, ids, {'state':'cancel_cci',})
415
def get_certification_details(self, cr, uid, ids,order_partner_id):
423
partner_info = self.pool.get('res.partner').browse(cr, uid,order_partner_id)
424
if partner_info.alert_legalisations:
425
raise osv.except_osv('Error!',partner_info.alert_explanation or 'Partner is not valid')
426
if not partner_info.asker_name:
427
asker_name=partner_info.name
429
asker_name=partner_info.asker_name
430
if not partner_info.sender_name:
431
sender_name=partner_info.name
433
sender_name=partner_info.sender_name
434
if not partner_info.asker_address:
435
if partner_info.address!=[]:
436
for add in partner_info.address:
437
if add.type=='default':
438
asker_address=add.street
441
asker_address=partner_info.asker_address
442
if not partner_info.asker_zip_id.id:
443
if partner_info.address!=[]:
444
for add in partner_info.address:
445
if add.type=='default':
449
zip=partner_info.asker_zip_id.id
452
'asker_name': asker_name,
453
'asker_address': asker_address,
455
'sender_name': sender_name}
459
def create(self, cr, uid, vals, *args, **kwargs):
460
# Overwrite the name fields to set next sequence according to the sequence in the certification type (type_id)
461
#vals['type_id']=self.pool.get('cci_missions.dossier_type').search(cr, uid, [('name','=','Certificate')])[0]
463
data = self.pool.get('cci_missions.dossier_type').browse(cr, uid,vals['type_id'])
464
seq = self.pool.get('ir.sequence').get(cr, uid,data.sequence_id.code)
466
vals.update({'name': seq})
467
return super(osv.osv,self).create(cr, uid, vals, *args, **kwargs)
470
'dossier_id' : fields.many2one('cci_missions.dossier','Dossier'),
471
'total':fields.function(_amount_total, method=True, string='Total', store=True),# sum of the price for copies, originals and extra_products
472
'asker_address' : fields.char('Asker Address',size=50),#by default, res.partner->asker_adress or, res_partner.address[default]->street
473
'asker_zip_id' : fields.many2one('res.partner.zip','Asker Zip Code'),#by default, res.partner->asker_zip_id or, res_partner.address[default]->zip_id
474
'special_reason' : fields.selection([('none','None'),('Commercial Reason','Commercial Reason'),('Substitution','Substitution')],'For special cases'),
475
'legalization_ids' : fields.one2many('cci_missions.legalization','certificate_id','Related Legalizations'),
476
'customs_ids' : fields.many2many('cci_missions.custom_code','certificate_custome_code_rel','certificate_id','custom_id','Custom Codes'),
477
'sending_SPF': fields.date('SPF Sending Date',help='Date of the sending of this record to the external database'),
478
'origin_ids' : fields.many2many('res.country','certificate_country_rel','certificate_id','country_id','Origin Countries')
482
'special_reason': lambda *a: 'none',
485
cci_missions_certificate()
487
class cci_missions_legalization(osv.osv):
488
_name = 'cci_missions.legalization'
489
_description = 'cci_missions.legalization'
490
_inherits = {'cci_missions.dossier': 'dossier_id'}
492
def _amount_total(self, cr, uid, ids, name, args, context=None):
494
data_dosseir = self.browse(cr,uid,ids)
496
for data in data_dosseir:
497
if data.state =='draft':
498
data_partner = self.pool.get('res.partner').browse(cr,uid,data.order_partner_id.id)
500
force_member=force_non_member=False
501
if data.member_price==1:
504
force_non_member=True
505
context.update({'partner_id':data_partner})
506
context.update({'force_member':force_member})
507
context.update({'force_non_member':force_non_member})
508
context.update({'date':data.date})
509
context.update({'value_goods':data.goods_value})
510
context.update({'pricelist':data_partner.property_product_pricelist.id})
511
price_org = self.pool.get('product.product')._product_price(cr, uid, [data.type_id.original_product_id.id], False, False, context)
512
price_copy = self.pool.get('product.product')._product_price(cr, uid, [data.type_id.copy_product_id.id], False, False, context)
513
cost_org=price_org[data.type_id.original_product_id.id]
514
cost_copy=price_copy[data.type_id.copy_product_id.id]
515
qty_org = data.quantity_original
516
qty_copy = data.quantity_copies
517
subtotal = data.sub_total
519
if qty_org < 0 or qty_copy < 0:
520
raise osv.except_osv('Input Error!','No. of Copies and Quantity of Originals should be positive.')
521
total = ((cost_org * qty_org ) + (cost_copy * qty_copy) + subtotal)
524
res[data.id]=data.invoiced_amount
527
def cci_dossier_cancel_cci(self, cr, uid, ids, *args):
528
data=self.browse(cr,uid,ids[0])
529
if data.invoice_id.state == 'paid':
530
new_ids = self.pool.get('account.invoice').refund(cr, uid,[data.invoice_id.id])
531
self.write(cr, uid,ids, {'invoice_id' : new_ids[0]})
533
wf_service = netsvc.LocalService('workflow')
534
wf_service.trg_validate(uid, 'account.invoice', data.invoice_id.id, 'invoice_cancel', cr)
535
self.write(cr, uid, ids, {'state':'cancel_cci',})
538
def get_legalization_details(self, cr, uid, ids,order_partner_id):
544
partner_info = self.pool.get('res.partner').browse(cr, uid,order_partner_id)
545
if partner_info.alert_legalisations:
546
raise osv.except_osv('Error!',partner_info.alert_explanation or 'Partner is not valid')
547
if partner_info.membership_state == 'none': #the boolean "Apply the member price" should be set to TRUE or FALSE when the partner is changed in regard of the membership state of him.
551
if not partner_info.asker_name:
552
asker_name=partner_info.name
554
asker_name=partner_info.asker_name
555
if not partner_info.sender_name:
556
sender_name=partner_info.name
558
sender_name=partner_info.sender_name
560
'asker_name': asker_name,
561
'sender_name': sender_name,
562
'member_price':member_state
567
def create(self, cr, uid, vals, *args, **kwargs):
568
# Overwrite the name fields to set next sequence according to the sequence in the legalization type (type_id)
569
#vals['type_id']=self.pool.get('cci_missions.dossier_type').search(cr, uid, [('name','=','Legalization')])[0]
571
data = self.pool.get('cci_missions.dossier_type').browse(cr, uid,vals['type_id'])
572
seq = self.pool.get('ir.sequence').get(cr, uid,data.sequence_id.code)
574
vals.update({'name': seq})
575
return super(osv.osv,self).create(cr, uid, vals, *args, **kwargs)
577
def _get_member_state(self, cr, uid, ids, name, args, context=None):
579
leg_ids = self.browse(cr,uid,ids)
581
res[p_id.id]=p_id.dossier_id.order_partner_id.membership_state
585
'dossier_id' : fields.many2one('cci_missions.dossier','Dossier'),#added for inherits
586
#'quantity_original' : fields.integer('Quantity of Originals',required=True),
587
'total':fields.function(_amount_total, method=True, string='Total', store=True),# sum of the price for copies, originals and extra_products
588
'certificate_id' : fields.many2one('cci_missions.certificate','Related Certificate'),
589
'partner_member_state': fields.function(_get_member_state, method=True,selection=STATE,string='Member State of the Partner',readonly=True,type="selection"),
590
'member_price' : fields.boolean('Apply the Member Price'),
593
cci_missions_legalization()
595
class cci_missions_courier_log(osv.osv):
596
_name = 'cci_missions.courier_log'
597
_description = 'cci_missions.courier_log'
599
'embassy_folder_id' : fields.many2one('cci_missions.embassy_folder','Related Embassy Folder',required=True),
600
'cba': fields.boolean('CBA'),
601
'ministry' : fields.boolean('Ministry'),
602
'translation' : fields.boolean('Translation'),
603
'embassy_name' : fields.char('Embassy Name',size=30),
604
'consulate_name' : fields.char('Consulate Name',size=30),
605
'others' : fields.char('Others',size=200),
606
'copy_cba' : fields.boolean('Photocopy Before CBA'),
607
'copy_ministry' : fields.boolean('Photocopy Before Ministry'),
608
'copy_embassy_consulate' : fields.boolean('Photocopy Before Embassy or Consulate'),
609
'documents' : fields.integer('Number of Documents to Legalize'),
610
'documents_certificate' : fields.text('List of Certificates'),
611
'documents_invoice' : fields.text('List of Invoices'),
612
'documents_others' : fields.text('Others'),
613
'message' : fields.text('Message to the Courier'),
614
'return_address' : fields.selection([('A la CCI','A la CCI'),('Au clent','Au client')],'Address of Return',required=True),#onchange
615
'address_name_1' : fields.char('Company Name',size=80),
616
'address_name_2' : fields.char('Contact Name',size=80),
617
'address_street' : fields.char('Street',size=80),
618
'address_city' : fields.char('City',size=80),
619
'qtty_to_print' : fields.integer('Number of Sheets'),
620
'partner_address_id' : fields.many2one('res.partner.address','Courier'),
623
cci_missions_courier_log()
625
class cci_missions_area(osv.osv):
626
_name = 'cci_missions.area'
627
_description = 'cci_missions.area'
629
'name' : fields.char('Description',size=50,required=True,transtale=True),
630
'country_ids': fields.many2many('res.country','area_country_rel','area','country',"Countries"),
635
class cci_missions_ata_usage(osv.osv):
636
_name = 'cci_missions.ata_usage'
637
_description = 'cci_missions.ata_usage'
639
'name' : fields.char('Usage',size=80,required=True),
642
cci_missions_ata_usage()
644
class cci_missions_ata_carnet(osv.osv):
645
_name = 'cci_missions.ata_carnet'
646
_description = 'cci_missions.ata_carnet'
648
def create(self, cr, uid, vals, *args, **kwargs):
650
data_partner=self.pool.get('res.partner').browse(cr,uid,vals['partner_id'])
651
context.update({'pricelist':data_partner.property_product_pricelist.id})
653
if 'creation_date' in vals:
654
context.update({'date':vals['creation_date']})
655
context.update({'emission_date':vals['creation_date']})
656
if 'partner_id' in vals:
657
context.update({'partner_id':vals['partner_id']})
658
if 'goods_value' in vals:
659
context.update({'value_goods':vals['goods_value']})
660
if 'double_signature' in vals:
661
context.update({'double_signature':vals['double_signature']})
662
force_member=force_non_member=False
663
if 'member_price' in vals and vals['member_price']==1:
666
force_non_member=True
667
context.update({'force_member':force_member})
668
context.update({'force_non_member':force_non_member})
670
data = self.pool.get('cci_missions.dossier_type').browse(cr, uid,vals['type_id'])
671
if 'own_risk' in vals and vals['own_risk']:
672
warranty_product = data.warranty_product_1.id
674
warranty_product = data.warranty_product_2.id
676
warranty= self.pool.get('product.product').price_get(cr,uid,[warranty_product],'list_price', context)[warranty_product]
677
vals.update({'warranty_product_id' : warranty_product, 'warranty': warranty})
679
seq = self.pool.get('ir.sequence').get(cr, uid,data.sequence_id.code)
681
vals.update({'name': seq})
682
return super(osv.osv,self).create(cr, uid, vals, *args, **kwargs)
684
def write(self, cr, uid, ids,vals, *args, **kwargs):
685
#super(cci_missions_ata_carnet,self).write(cr, uid, ids,vals, *args, **kwargs)
686
data_carnet = self.browse(cr,uid,ids[0])
688
if 'creation_date' in vals:
689
context.update({'date':vals['creation_date']})
690
context.update({'emission_date':vals['creation_date']})
692
context.update({'date':data_carnet.creation_date})
693
context.update({'emission_date':data_carnet.creation_date})
695
if 'partner_id' in vals:
696
context.update({'partner_id':vals['partner_id']})
697
data_partner=self.pool.get('res.partner').browse(cr,uid,vals['partner_id'])
699
context.update({'partner_id':data_carnet.partner_id.id})
700
data_partner=self.pool.get('res.partner').browse(cr,uid,data_carnet.partner_id.id)
702
if 'goods_value' in vals:
703
context.update({'value_goods':vals['goods_value']})
705
context.update({'value_goods':data_carnet.goods_value})
706
if 'double_signature' in vals:
707
context.update({'double_signature':vals['double_signature']})
709
context.update({'double_signature':data_carnet.double_signature})
710
force_member=force_non_member=False
712
context.update({'pricelist':data_partner.property_product_pricelist.id})
713
if 'member_price' in vals:
714
if vals['member_price']==1:
717
force_non_member=True
719
if data_carnet.member_price==1:
722
force_non_member=True
723
context.update({'force_member':force_member})
724
context.update({'force_non_member':force_non_member})
726
if 'own_risk' in vals:
728
warranty_product = data_carnet.type_id.warranty_product_1.id
730
warranty_product = data_carnet.type_id.warranty_product_2.id
732
if data_carnet.own_risk:
733
warranty_product = data_carnet.type_id.warranty_product_1.id
735
warranty_product = data_carnet.type_id.warranty_product_2.id
736
warranty= self.pool.get('product.product').price_get(cr,uid,[warranty_product],'list_price', context)[warranty_product]
738
vals.update({'warranty_product_id' : warranty_product, 'warranty': warranty})
739
super(cci_missions_ata_carnet,self).write(cr, uid, ids,vals, *args, **kwargs)
742
def button_uncertain(self, cr, uid, ids, *args):
743
self.write(cr, uid, ids, {'state':'pending',})
746
def button_correct(self, cr, uid, ids, *args):
747
self.write(cr, uid, ids, {'state':'correct','ok_state_date':time.strftime('%Y-%m-%d')})
750
def button_dispute(self, cr, uid, ids, *args):
751
self.write(cr, uid, ids, {'state':'dispute',})
754
def button_closed(self, cr, uid, ids, *args):
755
self.write(cr, uid, ids, {'state':'closed',})
758
def cci_ata_created(self, cr, uid, ids):
759
self.write(cr, uid, ids, {'state':'created','return_date':time.strftime('%Y-%m-%d')})
762
def _get_insurer_id(self, cr, uid, ids, name, args, context=None):
764
partner_ids = self.browse(cr,uid,ids)
765
for p_id in partner_ids:
766
res[p_id.id]=p_id.partner_id.insurer_id
769
def onchange_type_carnet(self, cr, uid, ids,type_id,own_risk):
771
data={'warranty_product_id' : False,'warranty':False}
773
return {'value':data}
774
data_carnet_type = self.pool.get('cci_missions.dossier_type').browse(cr,uid,type_id)
776
warranty_prod=data_carnet_type.warranty_product_1.id
778
warranty_prod=data_carnet_type.warranty_product_2.id
779
data['warranty_product_id'] =warranty_prod
780
dict1=self.onchange_warranty_product_id(cr,uid,ids,warranty_prod)
781
data.update(dict1['value'])
782
return {'value':data}
784
def onchange_own_risk(self,cr,uid,ids,type_id,own_risk):
786
data={'warranty_product_id' : False,'warranty':False}
788
return {'value': data}
789
warranty_prod = False
790
data_carnet_type = self.pool.get('cci_missions.dossier_type').browse(cr,uid,type_id)
792
warranty_prod =data_carnet_type.warranty_product_1.id
794
warranty_prod = data_carnet_type.warranty_product_2.id
795
data['warranty_product_id'] =warranty_prod
796
dict1=self.onchange_warranty_product_id(cr,uid,ids,warranty_prod)
797
data.update(dict1['value'])
799
return {'value':data}
801
def _get_member_state(self, cr, uid, ids, name, args, context=None):
803
partner_ids = self.browse(cr,uid,ids)
804
for p_id in partner_ids:
805
res[p_id.id]=p_id.partner_id.membership_state
808
def check_ata_carnet(self,cr, uid, ids):
809
data_carnet=self.browse(cr, uid, ids)
810
for data in data_carnet:
811
if (data.own_risk) or (data.insurer_agreement > 0 and data.partner_id.insurer_id > 0):
815
def _default_validity_date(self,cr,uid,context={}):
816
creation_date=datetime.datetime.today()
817
year=datetime.date(creation_date.year + 1,creation_date.month,creation_date.day)
818
validity_date= year - timedelta(days=1)
819
return validity_date.strftime('%Y-%m-%d')
821
def _tot_products(self, cr, uid, ids, name, args, context=None):
823
carnet_ids = self.browse(cr,uid,ids)
824
for p_id in carnet_ids:
826
for line_id in p_id.product_ids:
827
sum += line_id.price_subtotal
831
def onchange_partner_id(self,cr,uid,ids,partner_id):
832
#the boolean "Apply the member price" should be set to TRUE or FALSE when the partner is changed in regard of the membership state of him.
835
partner_info = self.pool.get('res.partner').browse(cr, uid,partner_id)
836
if partner_info.alert_legalisations:
837
raise osv.except_osv('Error!',partner_info.alert_explanation or 'Partner is not valid')
838
if partner_info.membership_state == 'none':
842
return {'value':{'member_price' : member_state}}
844
def onchange_warranty_product_id(self,cr,uid,ids,prod_id):
845
warranty_price= False
847
prod_info = self.pool.get('product.product').browse(cr, uid,prod_id)
848
warranty_price=prod_info.list_price
849
return {'value':{'warranty' : warranty_price}}
852
'id': fields.integer('ID', readonly=True),
853
'type_id' : fields.many2one('cci_missions.dossier_type','Related Type of Carnet',required=True),
854
'creation_date' : fields.date('Emission Date',required=True),
855
'validity_date' : fields.date('Validity Date',required=True),
856
'partner_id': fields.many2one('res.partner','Partner',required=True),
857
'holder_name' : fields.char('Holder Name',size=50),
858
'holder_address' : fields.char('Holder Address',size=50),
859
'holder_city' : fields.char('Holder City',size=50),
860
'representer_name' : fields.char('Representer Name',size=50),
861
'representer_address' : fields.char('Representer Address',size=50),
862
'representer_city' : fields.char('Representer City',size=50),
863
'usage_id': fields.many2one('cci_missions.ata_usage','Usage',required=True),
864
'goods': fields.char('Goods',size=80),
865
'area_id': fields.many2one('cci_missions.area','Area',required=True),
866
'insurer_agreement' : fields.char('Insurer Agreement',size=50),
867
'own_risk' : fields.boolean('Own Risks'),
868
'goods_value': fields.float('Goods Value',required=True),
869
'double_signature' : fields.boolean('Double Signature'),
870
'initial_pages' : fields.integer('Initial Number of Pages',required=True),
871
'additional_pages' : fields.integer('Additional Number of Pages'),
872
'warranty':fields.float('Warranty',readonly=True),
873
'warranty_product_id': fields.many2one('product.product','Related Warranty Product',required=True),
874
'return_date' : fields.date('Date of Return'),
875
'state':fields.selection([('draft','Draft'),('created','Created'),('pending','Pending'),('dispute','Dispute'),('correct','Correct'),('closed','Closed')],'State',required=True,readonly=True),
876
'ok_state_date' : fields.date('Date of Closure'),
877
'federation_sending_date' : fields.date('Date of Sending to the Federation', readonly=True),
878
'name' : fields.char('Name',size=50,required=True),
879
'partner_insurer_id': fields.function(_get_insurer_id, method=True,string='Insurer ID of the Partner',readonly=True),
880
'partner_member_state': fields.function(_get_member_state, method=True,selection=STATE,string='Member State of the Partner',readonly=True,type="selection"),
881
'member_price' : fields.boolean('Apply the Member Price'),
882
'product_ids': fields.one2many('product.lines', 'product_line_id', 'Products'),
883
'letter_ids':fields.one2many('cci_missions.letters_log','ata_carnet_id','Letters'),
884
'sub_total': fields.function(_tot_products, method=True, string='Subtotal of Extra Products',type="float"),
885
"invoice_id":fields.many2one("account.invoice","Invoice"),
889
'own_risk' : lambda *b : False,
890
'double_signature' : lambda *b : False,
891
'state' : lambda *a : 'draft',
892
'validity_date' : _default_validity_date,
893
'name': lambda *args: '/',
894
'creation_date': lambda *a: time.strftime('%Y-%m-%d'),
896
_constraints = [(check_ata_carnet, 'Error: Please Select (Own Risk) OR ("Insurer Agreement" and "Parnters Insure id" should be greater than Zero)', ['own_risk','insurer_agreement','partner_insurer_id'])]
898
cci_missions_ata_carnet()
900
class cci_missions_letters_log(osv.osv):
901
_name = 'cci_missions.letters_log'
902
_description = 'cci_missions.letters_log'
905
'ata_carnet_id' : fields.many2one('cci_missions.ata_carnet','Related ATA Carnet',required=True),
906
'letter_type' : fields.selection([('Rappel avant echeance','Rappel avant echeance'),('Rappel apres echeance','Rappel apres echeance'),('Suite lettre A','Suite lettre A'),('Suite lettre C','Suite lettre C'),('Suite lettre C1','Suite lettre C1'),('Suite lettre I','Suite lettre I'),('Demande de remboursement','Demande de remboursement'),('Rappel a remboursement','Rappel a remboursement'),('Mise en demeure','Mise en demeure')],'Type of Letter',required=True),
907
'date' : fields.date('Date of Sending',required=True),
910
'date': lambda *args: time.strftime('%Y-%m-%d')
913
cci_missions_letters_log()
915
class product_lines(osv.osv):
916
_name = "product.lines"
917
_description = "Product Lines"
919
def create(self, cr, uid, vals, *args, **kwargs):
920
if vals['product_id']:
922
data_product = self.pool.get('product.product').browse(cr,uid,vals['product_id'])
923
a = data_product.product_tmpl_id.property_account_income.id
925
a = data_product.categ_id.property_account_income_categ.id
926
accnt_dict['account_id']=a
927
vals.update(accnt_dict)
928
return super(product_lines,self).create(cr, uid, vals, *args, **kwargs)
930
def write(self, cr, uid, ids,vals, *args, **kwargs):
931
data_product_line= self.pool.get('product.lines').browse(cr,uid,ids[0])
932
if (not data_product_line.product_id.id == vals['product_id']):
934
data_product = self.pool.get('product.product').browse(cr,uid,vals['product_id'])
935
a = data_product.product_tmpl_id.property_account_income.id
937
a = data_product.categ_id.property_account_income_categ.id
938
accnt_dict['account_id']=a
939
vals.update(accnt_dict)
940
return super(product_lines,self).write( cr, uid, ids,vals, *args, **kwargs)
942
def _product_subtotal(self, cr, uid, ids, name, args, context=None):
944
for line in self.browse(cr, uid, ids):
945
res[line.id] = round(line.price_unit * line.quantity)
948
def product_id_change(self, cr, uid, ids,product_id,):
949
price_unit=uos_id=prod_name=data_partner=False
951
data_product = self.pool.get('product.product').browse(cr,uid,product_id)
952
uos_id=data_product.uom_id.id
953
price=self.pool.get('product.product').price_get(cr,uid,[product_id])
954
price_unit=price[product_id]
955
prod_name=data_product.name
958
'price_unit': price_unit,
964
'name': fields.char('Description', size=256, required=True),
965
'product_line_id': fields.many2one('cci_missions.ata_carnet', 'Product Ref',select=True),
966
'dossier_product_line_id': fields.many2one('cci_missions.dossier', 'Product Ref',select=True),
967
'uos_id': fields.many2one('product.uom', 'Unit', ondelete='set null'),
968
'product_id': fields.many2one('product.product', 'Product', ondelete='set null',required=True),
969
'price_unit': fields.float('Unit Price', required=True, digits=(16,2)),
970
'price_subtotal': fields.function(_product_subtotal, method=True, string='Subtotal'),
971
'quantity': fields.float('Quantity', required=True),
972
'account_id' : fields.many2one('account.account', 'Account', required=True),
975
'quantity': lambda *a: 1,
980
class Product(osv.osv):
982
_inherit = 'product.product'
984
#this function will have to be corrected in order to match the criteria grid of the CCI
985
def price_get(self, cr, uid, ids, ptype='list_price',context={}):
986
#get the price from the pricelist
987
res = super(Product, self).price_get(cr, uid, ids, ptype, context)
988
for product in self.browse(cr, uid, ids, context=context):
990
#change the price only for ATA originals
991
if product.name.find('ATA - original') != -1:
992
if context and ('value_goods' in context):
993
if context['value_goods'] < 25000:
994
res[product.id] = res[product.id] + context['value_goods']*0.008903875
995
elif 25000 <= context['value_goods'] < 75000 :
996
res[product.id] = res[product.id] + context['value_goods']*0.006937375
997
elif 75000 <= context['value_goods'] < 250000 :
998
res[product.id] = res[product.id] + context['value_goods']*0.004446475
1000
res[product.id] = res[product.id] + context['value_goods']*0.002764025
1001
if context and ('double_signature' in context):
1002
if context['double_signature'] == False:
1003
res[product.id] = res[product.id] + 5.45
1005
#change the price only for warranty own risk on ATA carnet
1006
if product.name.find('ATA - Own Risk Warranty') != -1:
1007
if context and ('value_goods' in context):
1008
if context['value_goods'] > 15000:
1009
res[product.id] = round(context['value_goods']*0.03)