~openerp-commiter/openobject-addons/stable-sja-branch

« back to all changes in this revision

Viewing changes to cci_account/report/cci_draft_invoice_info.py

  • Committer: sja-axelor
  • Date: 2009-10-13 09:52:57 UTC
  • Revision ID: suniljagyasi@gmail.com-20091013095257-8u26ww0r20z9y6ey
add

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
import time
 
23
import pooler
 
24
from report import report_sxw
 
25
 
 
26
 
 
27
STATE = [
 
28
    ('none', 'Non Member'),
 
29
    ('canceled', 'Canceled Member'),
 
30
    ('old', 'Old Member'),
 
31
    ('waiting', 'Waiting Member'),
 
32
    ('invoiced', 'Invoiced Member'),
 
33
    ('associated', 'Associated Member'),
 
34
    ('free', 'Free Member'),
 
35
    ('paid', 'Paid Member'),
 
36
]
 
37
 
 
38
class account_invoice_draft(report_sxw.rml_parse):
 
39
    def __init__(self, cr, uid, name, context):
 
40
        super(account_invoice_draft, self).__init__(cr, uid, name, context)
 
41
        self.localcontext.update({
 
42
            'time': time,
 
43
            'partner_objects':self.partner_objects,
 
44
            'member_type':self.member_type,
 
45
            'nationality':self.nationality,
 
46
            'lines':self.lines,
 
47
            'sum_amt_untaxed':self.sum_amt_untaxed,
 
48
            'sum_amt_tax':self.sum_amt_tax,
 
49
            'sum_total':self.sum_total,
 
50
        })
 
51
        self.sum_untaxed=0.00
 
52
        self.sum_tax=0.00
 
53
        self.sum_tot=0.00
 
54
 
 
55
    def partner_objects(self,ids={}):
 
56
        if not ids:
 
57
            ids = self.ids
 
58
        partner_objects = pooler.get_pool(self.cr.dbname).get('res.partner').browse(self.cr, self.uid, ids)
 
59
        return partner_objects
 
60
 
 
61
    def member_type(self, object):
 
62
        membership=object.membership_state
 
63
        for member_type in STATE:
 
64
            if membership==member_type[0]:
 
65
                membership=member_type[1]
 
66
                break
 
67
        return membership
 
68
 
 
69
    def nationality(self, object):
 
70
        nationality='Not Mentioned'
 
71
        if object.address:
 
72
            for ads in object.address:
 
73
                if ads.type=='default':
 
74
                  if ads.country_id:
 
75
                        if ads.country_id.code=='BE':
 
76
                            nationality='Belgian'
 
77
                        else:
 
78
                            nationality='Non-Belgian'
 
79
 
 
80
        return nationality
 
81
 
 
82
    def lines(self, object):
 
83
        result=[]
 
84
        obj_inv=pooler.get_pool(self.cr.dbname).get('account.invoice')
 
85
        list_ids=obj_inv.search(self.cr,self.uid,[('state','=','draft'),('partner_id','=',object.id),('type','=','out_invoice')])
 
86
        invoices=obj_inv.browse(self.cr,self.uid,list_ids)
 
87
 
 
88
        self.sum_untaxed=0.00
 
89
        self.sum_tax=0.00
 
90
        self.sum_tot=0.00
 
91
        for invoice in invoices:
 
92
            self.sum_untaxed +=invoice.amount_untaxed
 
93
 
 
94
            self.sum_tax +=invoice.amount_tax
 
95
 
 
96
            self.sum_tot +=invoice.amount_total
 
97
 
 
98
            if not invoice.invoice_line:
 
99
                continue
 
100
 
 
101
            for line in invoice.invoice_line:
 
102
 
 
103
                res={}
 
104
                res['name']=line.name
 
105
                res['date']=invoice.date_invoice
 
106
                untaxed=line.price_unit * line.quantity
 
107
                discounted=(untaxed) * line.discount / 100
 
108
 
 
109
                res['amt_untaxed']=(untaxed) - discounted
 
110
                tax_info=pooler.get_pool(self.cr.dbname).get('account.tax').compute(self.cr,self.uid,line.invoice_line_tax_id, line.price_unit,line.quantity)
 
111
                taxed = 0.00
 
112
                if tax_info:
 
113
                    for record in tax_info:
 
114
                        taxed += record['amount']
 
115
                res['vat']=taxed
 
116
 
 
117
                res['total']=untaxed - discounted + taxed
 
118
                res['gen_acc']=line.account_id.name
 
119
                res['analytic_acc']=line.account_analytic_id and line.account_analytic_id.name or '-'
 
120
                result.append(res)
 
121
        return result
 
122
 
 
123
    def sum_amt_untaxed(self):
 
124
        return self.sum_untaxed
 
125
 
 
126
    def sum_amt_tax(self):
 
127
        return self.sum_tax
 
128
 
 
129
    def sum_total(self):
 
130
        return self.sum_tot
 
131
 
 
132
report_sxw.report_sxw('report.partner.draft_invoices', 'res.partner', 'addons/cci_account/report/cci_draft_invoice_info.rml', parser=account_invoice_draft,header=False)
 
133
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
134