~serpent-consulting-services/openerp-usa/shipping_api_6-1

« back to all changes in this revision

Viewing changes to reports_address_us/report/report_account_invoice_layout_us.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6
 
#
7
 
#    This program is free software: you can redistribute it and/or modify
8
 
#    it under the terms of the GNU Affero General Public License as
9
 
#    published by the Free Software Foundation, either version 3 of the
10
 
#    License, or (at your option) any later version.
11
 
#
12
 
#    This program is distributed in the hope that it will be useful,
13
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
#    GNU Affero General Public License for more details.
16
 
#
17
 
#    You should have received a copy of the GNU Affero General Public License
18
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
#
20
 
##############################################################################
21
 
 
22
 
import time
23
 
 
24
 
from report import report_sxw
25
 
 
26
 
 
27
 
class account_invoice_1(report_sxw.rml_parse):
28
 
    def __init__(self, cr, uid, name, context):
29
 
        print "adsfa"
30
 
        super(account_invoice_1, self).__init__(cr, uid, name, context=context)
31
 
        self.localcontext.update({
32
 
            'time': time,
33
 
            'invoice_lines': self.invoice_lines,
34
 
        })
35
 
        self.context = context
36
 
        self._node = None
37
 
 
38
 
    def invoice_lines(self, invoice):
39
 
        result = []
40
 
        sub_total = {}
41
 
        info = []
42
 
        invoice_list = []
43
 
        res = {}
44
 
        list_in_seq = {}
45
 
        ids = self.pool.get('account.invoice.line').search(self.cr, self.uid, [('invoice_id', '=', invoice.id)])
46
 
        ids.sort()
47
 
        for id in range(0, len(ids)):
48
 
            info = self.pool.get('account.invoice.line').browse(self.cr, self.uid, ids[id], self.context.copy())
49
 
            list_in_seq[info] = info.sequence
50
 
        i = 1
51
 
        j = 0
52
 
        final=sorted(list_in_seq.items(), lambda x, y: cmp(x[1], y[1]))
53
 
        invoice_list = [x[0] for x in final]
54
 
        sum_flag = {}
55
 
        sum_flag[j] = -1
56
 
        for entry in invoice_list:
57
 
            res = {}
58
 
            if entry.state == 'article':
59
 
                self.cr.execute('select tax_id from account_invoice_line_tax where invoice_line_id=%s', (entry.id,))
60
 
                tax_ids = self.cr.fetchall()
61
 
                if tax_ids == []:
62
 
                    res['tax_types'] = ''
63
 
                else:
64
 
                    tax_names_dict = {}
65
 
                    for item in range(0, len(tax_ids)):
66
 
                        self.cr.execute('select name from account_tax where id=%s', (tax_ids[item][0],))
67
 
                        type = self.cr.fetchone()
68
 
                        tax_names_dict[item] = type[0]
69
 
                    tax_names = ','.join([tax_names_dict[x] for x in range(0, len(tax_names_dict))])
70
 
                    res['tax_types'] = tax_names
71
 
                res['name'] = entry.name
72
 
                res['quantity'] = self.formatLang(entry.quantity, digits=self.get_digits(dp='Account'))
73
 
                res['price_unit'] = self.formatLang(entry.price_unit, digits=self.get_digits(dp='Account'))
74
 
                res['discount'] = self.formatLang(entry.discount, digits=self.get_digits(dp='Account'))
75
 
                res['price_subtotal'] = self.formatLang(entry.price_subtotal, digits=self.get_digits(dp='Account'))
76
 
                sub_total[i] = entry.price_subtotal
77
 
                i = i + 1
78
 
                res['note'] = entry.note
79
 
                res['currency'] = invoice.currency_id.symbol
80
 
                res['type'] = entry.state
81
 
 
82
 
                if entry.uos_id.id == False:
83
 
                    res['uos'] = ''
84
 
                else:
85
 
                    uos_name = self.pool.get('product.uom').read(self.cr, self.uid, entry.uos_id.id, ['name'], self.context.copy())
86
 
                    res['uos'] = uos_name['name']
87
 
            else:
88
 
                res['quantity'] = ''
89
 
                res['price_unit'] = ''
90
 
                res['discount'] = ''
91
 
                res['tax_types'] = ''
92
 
                res['type'] = entry.state
93
 
                res['note'] = entry.note
94
 
                res['uos'] = ''
95
 
 
96
 
                if entry.state == 'subtotal':
97
 
                    res['name'] = entry.name
98
 
                    sum = 0
99
 
                    sum_id = 0
100
 
                    if sum_flag[j] == -1:
101
 
                        temp = 1
102
 
                    else:
103
 
                        temp = sum_flag[j]
104
 
 
105
 
                    for sum_id in range(temp, len(sub_total)+1):
106
 
                        sum += sub_total[sum_id]
107
 
                    sum_flag[j+1] = sum_id +1
108
 
 
109
 
                    j = j + 1
110
 
                    res['price_subtotal'] = "%.2f" % (sum)
111
 
                    res['currency'] = invoice.currency_id.symbol
112
 
                    res['quantity'] = ''
113
 
                    res['price_unit'] = ''
114
 
                    res['discount'] = ''
115
 
                    res['tax_types'] = ''
116
 
                    res['uos'] = ''
117
 
                elif entry.state == 'title':
118
 
                    res['name'] = entry.name
119
 
                    res['price_subtotal'] = ''
120
 
                    res['currency'] = ''
121
 
                elif entry.state == 'text':
122
 
                    res['name'] = entry.name
123
 
                    res['price_subtotal'] = ''
124
 
                    res['currency'] = ''
125
 
                elif entry.state == 'line':
126
 
                    res['quantity'] = '_______________'
127
 
                    res['price_unit'] = '______________'
128
 
                    res['discount'] = '____________'
129
 
                    res['tax_types'] = '____________________'
130
 
                    res['uos'] = '_____'
131
 
                    res['name'] = '_______________________________________________'
132
 
                    res['price_subtotal'] = '____________'
133
 
                    res['currency'] = '____'
134
 
                elif entry.state == 'break':
135
 
                    res['type'] = entry.state
136
 
                    res['name'] = entry.name
137
 
                    res['price_subtotal'] = ''
138
 
                    res['currency'] = ''
139
 
                else:
140
 
                    res['name'] = entry.name
141
 
                    res['price_subtotal'] = ''
142
 
                    res['currency'] = invoice.currency_id.symbol
143
 
 
144
 
            result.append(res)
145
 
        return result
146
 
report_sxw.report_sxw('report.account.invoice.layout.us', 'account.invoice', 'addons/reports_address_us/report/report_account_invoice_layout_us.rml', parser=account_invoice_1)
147
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
148