1
##############################################################################
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
# Fabien Pinckaers <fp@tiny.Be>
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
31
from osv import fields, osv
34
class credit_line(osv.osv):
36
_description = 'Credit line'
38
def get_available_amount(self, cr, uid, credit_line_id, base_amount, partner_id, context={}):
39
this = self.browse(cr, uid, [credit_line_id])[0]
41
#sum the eligible amounts for translation folder + embassy folder line for all customers
45
list = self.pool.get('translation.folder').search(cr, uid, [('credit_line_id','=',this.id),('state','<>','cancel')])
46
for item in self.pool.get('translation.folder').browse(cr, uid, list):
47
tot_sum += item.awex_amount
48
if item.partner_id.id == partner_id:
49
#sum the eligible amounts for translation folder + embassy folder line for this customer
50
partner_sum += item.awex_amount
52
partner_remaining_amount = this.customer_credit - partner_sum
53
tot_remaining_amount = this.global_credit - tot_sum
55
res = min(base_amount / 2, partner_remaining_amount, tot_remaining_amount)
61
'name':fields.char('Name', size=32, required=True),
62
'from_date':fields.date('From Date', required=True),
63
'to_date':fields.date('To Date', required=True),
64
'global_credit':fields.float('Global Credit', required=True),
65
'customer_credit':fields.float('Customer Max Credit', required=True)
69
class translation_folder(osv.osv):
70
_name = 'translation.folder'
71
_description = 'Translation Folder'
73
def cci_translation_folder_confirmed(self, cr, uid, ids, *args):
74
for id in self.browse(cr, uid, ids):
76
data['state']='confirmed'
77
if id.awex_eligible and id.partner_id.awex_eligible == 'yes':
79
#look for an existing credit line in the current time
80
credit_line = self.pool.get('credit.line').search(cr, uid, [('from_date','<=',time.strftime('%Y-%m-%d')), ('to_date', '>=', time.strftime('%Y-%m-%d'))])
82
#if there is one available: get available amount from it
83
amount = self.pool.get('credit.line').browse(cr, uid,[credit_line[0]])[0].get_available_amount(cr, uid, credit_line[0], id.base_amount, id.partner_id.id)
85
data['awex_amount'] = amount
86
data['credit_line_id'] = credit_line[0]
88
data['awex_eligible'] = False
89
self.write(cr, uid, [id.id], data)
93
'order_desc':fields.char('Description', size=64, required=True, select=True),
94
'name': fields.text('Name', required=True),
95
'partner_id': fields.many2one('res.partner', 'Partner', required=True),
96
'base_amount': fields.float('Base Amount', required=True, readonly=True, states={'draft':[('readonly',False)]}),
97
'awex_eligible':fields.boolean('AWEX Eligible', readonly=True, states={'draft':[('readonly',False)]}),
98
'awex_amount':fields.float('AWEX Amount', readonly=True),
99
'state':fields.selection([('draft','Draft'),('confirmed','Confirmed'),('invoiced','Invoiced'),('done', 'Done'),('cancel','Cancel')],'State',readonly=True),
100
'credit_line_id': fields.many2one('credit.line', 'Credit Line', readonly=True),
101
'invoice_id': fields.many2one('account.invoice', 'Invoice'),
102
'purchase_order': fields.many2one('purchase.order', 'Purchase Order'),
103
'order_date':fields.date('Order Date',required=True)
106
'state' : lambda *a : 'draft',
107
'order_date': lambda *b: time.strftime('%Y-%m-%d'),
108
'order_desc': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'translation.folder'),
112
class letter_credence(osv.osv):
113
_name = 'letter.credence'
114
_description = 'Letter of Credence'
116
'emission_date':fields.date('Emission Date', required=True),
117
'asked_amount':fields.float('Asked Amount', required=True)
121
class res_partner(osv.osv):
122
_inherit = 'res.partner'
123
_description = 'Partner'
125
'awex_eligible':fields.selection([('unknown','Unknown'),('yes','Yes'),('no','No')], "AWEX Eligible"),
128
'awex_eligible' : lambda *a : 'unknown',