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