Launchpad automatic translations update.
[odoo/odoo.git] / addons / l10n_it / report / libroIVA_debito.py
1 import datetime
2 import time
3 from report import report_sxw
4 from osv import osv
5 import pooler
6             
7
8 class l10n_chart_it_report_libroIVA_debito(report_sxw.rml_parse):
9         
10     def __init__(self, cr, uid, name, context):
11         super(l10n_chart_it_report_libroIVA_debito,self).__init__(cr,uid,name,context)
12         self.localcontext.update({
13             'time' : time,
14             'get_company' : self.get_company,
15             'get_periods' : self.get_periods,
16             'get_lines' : self.get_lines,
17         })
18         
19         
20     def get_company(self,fiscal_year):
21         #print 'COMP = ',fiscal_year
22         return ""
23         
24         
25     def get_periods(self,fiscal_year):
26         #print 'Fiscal year id:',fiscal_year.id
27         obj=pooler.get_pool(self.cr.dbname).get('account.fiscalyear')
28         fy=obj.browse(self.cr,self.uid,fiscal_year.id)
29         #print 'Periods = ',fy.period_ids
30         res=[rec for rec in fy.period_ids]
31         #return fy.periods  => non funziona?!? bool object !?!?
32         return res
33         
34     def get_invoices(self,period):
35         #print 'PERIOD = ',period.name
36         obj=pooler.get_pool(self.cr.dbname).get('account.invoice')
37         # Selezione tutte le fatture emesse nel periodo
38         self.cr.execute(        """
39                                         SELECT id FROM account_invoice 
40                                         WHERE   (state='open' OR state='paid') AND
41                                                         period_id="""+str(period.id)+"""
42                                                         AND (type='in_invoice' OR type='in_refund')
43                                         """)
44         ids=self.cr.fetchall()
45         #print 'IDS = ',
46         if ids:
47             ids=[id[0] for id in ids ]
48         invoices=obj.browse(self.cr,self.uid,ids)
49         #print 'INVOICES = ',invoices
50         return invoices
51         
52     def get_lines(self,fiscal_year):
53         res=[]
54         obj_fy=pooler.get_pool(self.cr.dbname).get('account.fiscalyear')
55         fy=obj_fy.browse(self.cr,self.uid,fiscal_year.id)
56         for period in fy.period_ids:
57             invoices=self.get_invoices(period)
58             for invoice in invoices:
59                 d={'periodo': period.name}
60                 d['protocollo']=invoice.number
61                 #print 'PARTNER ',invoice.partner_id.name
62                 causale=invoice.partner_id.name
63                 #print 'CAUSALE = ',causale
64                 d['causale']=causale
65                 d['numero']=invoice.reference
66                 d['data_doc']=invoice.date_invoice
67                 for tax in invoice.tax_line:
68                     #print '\tTAX: ',tax
69                     d['aliquota']=tax.tax_code_id.name
70                     d['imponibile']=tax.base
71                     d['imposta']=tax.amount
72                     res.append(d)
73                     d={'periodo':'', 'protocollo':'', 'causale':'', 'numero':'', 'data_doc':'', }
74         return res
75
76
77         
78 report_sxw.report_sxw('report.l10n_it.report.libroIVA_debito','account.report_libroiva',
79                       'l10n_it/report/libroIVA_debito.rml',
80                        parser=l10n_chart_it_report_libroIVA_debito,header=False)