~camptocamp/account-invoice-report/invoice_webkit_VRE

« back to all changes in this revision

Viewing changes to invoice_webkit/invoice.py

  • Committer: nicolas.bessi at camptocamp
  • Date: 2012-12-18 16:24:39 UTC
  • mfrom: (0.1.45 account-invoice-report)
  • Revision ID: nicolas.bessi@camptocamp.com-20121218162439-io5wrhjw328hh5we
[FIX] account invoice webkit compatibility for V7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#   Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com)
 
5
#   @author Bessi Nicolas, Vicent Renaville
 
6
#
 
7
# WARNING: This program as such is intended to be used by professional
 
8
# programmers who take the whole responsability of assessing all potential
 
9
# consequences resulting from its eventual inadequacies and bugs
 
10
# End users who are looking for a ready-to-use solution with commercial
 
11
# garantees and support are strongly adviced to contract a Free Software
 
12
# Service Company
 
13
#
 
14
# This program is Free Software; you can redistribute it and/or
 
15
# modify it under the terms of the GNU General Public License
 
16
# as published by the Free Software Foundation; either version 2
 
17
# of the License, or (at your option) any later version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
27
#
 
28
##############################################################################
 
29
from openerp.osv.orm import Model, fields
 
30
 
 
31
class InvoiceConditionText(Model):
 
32
    """add info condition in the invoice"""
 
33
    _name = "account.condition_text"
 
34
    _description = "Invoices conditions"
 
35
 
 
36
    _columns = {
 
37
        'name' : fields.char('Condition summary', required=True, size=128),
 
38
        'type' : fields.selection([('header','Top condition'),
 
39
                                   ('footer','Bottom condition')],
 
40
                                    'type', required=True),
 
41
 
 
42
        'text': fields.text('Condition', translate=True, required=True)}
 
43
 
 
44
class AccountInvoice(Model):
 
45
    """ Add account.condition_text to invoice"""
 
46
 
 
47
    _inherit = "account.invoice"
 
48
 
 
49
    def _set_condition(self, cr, uid, inv_id, commentid, key):
 
50
        """Set the text of the notes in invoices"""
 
51
        if not commentid :
 
52
            return {}
 
53
        try :
 
54
            lang = self.browse(cr, uid, inv_id)[0].partner_id.lang
 
55
        except :
 
56
            lang = 'en_US'
 
57
        cond = self.pool.get('account.condition_text').browse(cr, uid, commentid, {'lang': lang})
 
58
        return {'value': {key: cond.text}}
 
59
 
 
60
    def set_header(self, cr, uid, inv_id, commentid):
 
61
        return self._set_condition(cr, uid, inv_id, commentid, 'note1')
 
62
 
 
63
    def set_footer(self, cr, uid, inv_id, commentid):
 
64
        return self._set_condition(cr, uid, inv_id, commentid, 'note2')
 
65
 
 
66
    _columns = {'text_condition1': fields.many2one('account.condition_text', 'Header condition'),
 
67
                'text_condition2': fields.many2one('account.condition_text', 'Footer condition'),
 
68
                'note1' : fields.text('Header'),
 
69
                'note2' : fields.text('Footer'),}