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

« back to all changes in this revision

Viewing changes to c2c_invoice_report/view/invoice.py

adding ports or rewriting of some c2c modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python2.3
 
2
#
 
3
#  invoice.py
 
4
#
 
5
#  Created by Nicolas Bessi on 24.06.08.
 
6
#  Modified by Vincent Renaville
 
7
#  Copyright (c) 2008 CamptoCamp. All rights reserved.
 
8
#
 
9
from osv import osv, fields
 
10
import pooler
 
11
 
 
12
 
 
13
 
 
14
class invoice_condition_text(osv.osv):
 
15
        """add info condition in the invoice"""
 
16
        _name = "account.condition_text"
 
17
        _description = "Invoice condition text"
 
18
        
 
19
                
 
20
        _columns = {
 
21
                'name' : fields.char('Methode', required=True, size=128),
 
22
                'type' : fields.selection([('header','Header'),
 
23
                ('footer','Footer')
 
24
                ], 
 
25
                'type',required=True),
 
26
                'text': fields.text('text', translate=True,required=True),
 
27
        }
 
28
 
 
29
                
 
30
invoice_condition_text()
 
31
 
 
32
 
 
33
 
 
34
class account_invoice(osv.osv):
 
35
        """ Generated invoice does not advance in the workflow 
 
36
        and add text condition"""
 
37
        
 
38
        _inherit = "account.invoice"
 
39
        _description = 'Invoice'
 
40
        
 
41
        
 
42
        def get_trans(self, cr, uid, name, res_id, lang) :
 
43
                sql = " SELECT value     from ir_translation where name = '%s' \
 
44
                and res_id = %s and lang ='%s';" %(name, str(res_id), lang)
 
45
                cr.execute(sql)
 
46
                toreturn =  cr.fetchone()
 
47
                if toreturn :
 
48
                 return toreturn[0]
 
49
                else :
 
50
                        return toreturn
 
51
                
 
52
        def set_comment(self, cr,uid,id,commentid):
 
53
                if not commentid :
 
54
                        return {}
 
55
                cond = self.pool.get('account.condition_text').browse(
 
56
                        cr,uid,commentid,{})
 
57
                translation_obj = self.pool.get('ir.translation')
 
58
                
 
59
 
 
60
                text =''
 
61
                if cond :
 
62
                        text = cond.text
 
63
                        try :
 
64
                                lang = self.browse(cr, uid, id)[0].partner_id.lang
 
65
                        except :
 
66
                                lang = 'en_EN'
 
67
                        res_trans = self.get_trans(cr, uid, 'account.condition_text,text', commentid, lang )
 
68
                        if not res_trans :
 
69
                                res_trans = text
 
70
                
 
71
                return {'value': {
 
72
                                'note1': res_trans,
 
73
                                }}
 
74
                                
 
75
                                
 
76
        def set_note(self, cr,uid,id,commentid):
 
77
                if not commentid :
 
78
                        return {}
 
79
                cond = self.pool.get('account.condition_text').browse(
 
80
                        cr,uid,commentid,{})
 
81
                translation_obj = self.pool.get('ir.translation')
 
82
                
 
83
 
 
84
                text =''
 
85
                if cond :
 
86
                        text = cond.text
 
87
                        try :
 
88
                                lang = self.browse(cr, uid, id)[0].partner_id.lang
 
89
                        except :
 
90
                                lang = 'en_EN'
 
91
                        res_trans = self.get_trans(cr, uid, 
 
92
                                'account.condition_text,text', commentid, lang )
 
93
                        if not res_trans :
 
94
                                res_trans = text
 
95
                
 
96
                return {'value': {
 
97
                                'note2': res_trans,
 
98
                                }}
 
99
 
 
100
 
 
101
 
 
102
        
 
103
        def create(self, cr, uid, vals, context={}):
 
104
                tmp_id = super(account_invoice,self).create(cr, uid, vals, context)
 
105
                self.action_number(cr, uid, [tmp_id])
 
106
                return tmp_id
 
107
                
 
108
        _columns = {
 
109
                'text_condition1': fields.many2one('account.condition_text', 'Header'),
 
110
                'text_condition2': fields.many2one('account.condition_text', 'Footer'),
 
111
                'note1' : fields.text('Header'),
 
112
                'note2' : fields.text('Footer'),
 
113
                'project': fields.many2one(
 
114
                                                                        'account.analytic.account', 
 
115
                                                                        'Project',
 
116
                                                                         select=1
 
117
                                                                        ),
 
118
                }
 
119
 
 
120
account_invoice()
 
 
b'\\ No newline at end of file'