~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to cci_translation/cci_translation.py

  • Committer: qdp
  • Date: 2007-12-19 09:07:27 UTC
  • Revision ID: qdp-1a523a1413a15f6e7632a0d64bab451805320f69
configuration of the partner portal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##############################################################################
2
 
#
3
 
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
 
#                    Fabien Pinckaers <fp@tiny.Be>
5
 
#
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
11
 
# Service Company
12
 
#
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.
17
 
#
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.
22
 
#
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.
26
 
#
27
 
##############################################################################
28
 
 
29
 
import netsvc
30
 
import time
31
 
from osv import fields, osv
32
 
 
33
 
 
34
 
class credit_line(osv.osv):
35
 
        _name = 'credit.line'
36
 
        _description = 'Credit line'
37
 
 
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]
40
 
 
41
 
                #sum the eligible amounts for translation folder + embassy folder line for all customers
42
 
                tot_sum = 0
43
 
                partner_sum = 0
44
 
 
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
51
 
 
52
 
                partner_remaining_amount = this.customer_credit - partner_sum
53
 
                tot_remaining_amount = this.global_credit - tot_sum
54
 
 
55
 
                res = min(base_amount / 2, partner_remaining_amount, tot_remaining_amount)
56
 
                if res < 0:
57
 
                        return 0
58
 
                return res
59
 
 
60
 
        _columns = {
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)
66
 
        }
67
 
credit_line()
68
 
 
69
 
class translation_folder(osv.osv):
70
 
        _name = 'translation.folder'
71
 
        _description = 'Translation Folder'
72
 
 
73
 
        def cci_translation_folder_confirmed(self, cr, uid, ids, *args):
74
 
                for id in self.browse(cr, uid, ids):
75
 
                        data = {}
76
 
                        data['state']='confirmed'
77
 
                        if id.awex_eligible and id.partner_id.awex_eligible == 'yes':
78
 
                                print 'go'
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'))])
81
 
                                if credit_line:
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)
84
 
                                        if amount > 0:
85
 
                                                data['awex_amount'] = amount
86
 
                                                data['credit_line_id'] =  credit_line[0]
87
 
                                        else:
88
 
                                                data['awex_eligible'] = False
89
 
                        self.write(cr, uid, [id.id], data)
90
 
                return True
91
 
 
92
 
        _columns = {
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)
104
 
                }
105
 
        _defaults = {
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'),
109
 
        }
110
 
translation_folder()
111
 
 
112
 
class letter_credence(osv.osv):
113
 
        _name = 'letter.credence'
114
 
        _description = 'Letter of Credence'
115
 
        _columns = {
116
 
                'emission_date':fields.date('Emission Date', required=True),
117
 
                'asked_amount':fields.float('Asked Amount', required=True)
118
 
        }
119
 
letter_credence()
120
 
 
121
 
class res_partner(osv.osv):
122
 
        _inherit = 'res.partner'
123
 
        _description = 'Partner'
124
 
        _columns = {
125
 
                'awex_eligible':fields.selection([('unknown','Unknown'),('yes','Yes'),('no','No')], "AWEX Eligible"),
126
 
        }
127
 
        _defaults = {
128
 
                'awex_eligible' : lambda *a : 'unknown',
129
 
        }
130
 
res_partner()