1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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.
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.
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/>.
21 ##############################################################################
24 from report import report_sxw
33 class account_invoice_1(report_sxw.rml_parse):
34 def __init__(self, cr, uid, name, context):
35 super(account_invoice_1, self).__init__(cr, uid, name, context)
36 self.localcontext.update({
38 'invoice_lines': self.invoice_lines,
39 'repeat_In':self.repeat_In,
41 self.context = context
43 def repeat_In(self, lst, name, nodes_parent=False,td=False,width=[],value=[],type=[]):
45 node = self._find_parent(self._node, nodes_parent or parents)
48 value=['tax_types','quantity','uos','price_unit','discount','price_subtotal','currency']
49 type=['string','string','string','string','string','string','string']
50 width=[62,38,29,67,53,53,27]
57 for ns in node.childNodes :
60 if ns and ns.nodeName!='#text' and ns.tagName=='blockTable' and td :
63 width_str = ns._attrs['colWidths'].nodeValue
64 ns.removeAttribute('colWidths')
65 total_td = td * len(value)
70 for v in range(len(value)):
71 width_str +=',%d'%width[v]
73 ns.setAttribute('colWidths',width_str)
75 child_list = ns.childNodes
77 for child in child_list:
78 if child.nodeName=='tr':
79 lc = child.childNodes[1]
83 t2="[[%s['type']=='text' and removeParentNode('tr')]]"%(name)
84 t1= "[[ %s['%s'] ]]"%(name,v)
85 t3="[[ %s['type']=='subtotal' and ( setTag('para','para',{'fontName':'Times-bold'})) ]]"%name
86 newnode = lc.cloneNode(1)
88 newnode.childNodes[1].lastChild.data = t1 + t2 +t3
89 # newnode.childNodes[1].lastChild.data=[[ a['status']==1 and ( setTag('para','para',{'fontName':'Times-bold'})) ]]
90 child.appendChild(newnode)
95 return super(account_invoice_1,self).repeatIn(lst, name, nodes_parent=False)
97 def invoice_lines(self,invoice):
105 ids = self.pool.get('account.invoice.line').search(self.cr, self.uid, [('invoice_id', '=', invoice.id)])
107 for id in range(0,len(ids)):
108 info = self.pool.get('account.invoice.line').browse(self.cr, self.uid,ids[id], self.context.copy())
109 list_in_seq[info]=info.sequence
110 # invoice_list +=[info]
113 final=sorted(list_in_seq.items(), lambda x, y: cmp(x[1], y[1]))
114 invoice_list=[x[0] for x in final]
117 for entry in invoice_list:
120 if entry.state=='article':
121 self.cr.execute('select tax_id from account_invoice_line_tax where invoice_line_id=%s', (entry.id,))
122 tax_ids=self.cr.fetchall()
128 for item in range(0,len(tax_ids)) :
129 self.cr.execute('select name from account_tax where id=%s', (tax_ids[item][0],))
130 type=self.cr.fetchone()
131 tax_names_dict[item] =type[0]
132 tax_names = ','.join([tax_names_dict[x] for x in range(0,len(tax_names_dict))])
133 res['tax_types']=tax_names
134 res['name']=entry.name
135 res['quantity']="%.2f"%(entry.quantity)
136 res['price_unit']="%.2f"%(entry.price_unit)
137 res['discount']="%.2f"%(entry.discount)
138 res['price_subtotal']="%.2f"%(entry.price_subtotal)
139 sub_total[i]=entry.price_subtotal
141 res['note']=entry.note
142 res['currency']=invoice.currency_id.code
143 res['type']=entry.state
145 if entry.uos_id.id==False:
148 uos_name = self.pool.get('product.uom').read(self.cr,self.uid,entry.uos_id.id,['name'],self.context.copy())
149 res['uos'] = uos_name['name']
156 res['type']=entry.state
157 res['note']=entry.note
160 if entry.state=='subtotal':
161 res['name']=entry.name
169 for sum_id in range(temp,len(sub_total)+1):
170 sum+=sub_total[sum_id]
171 sum_flag[j+1]= sum_id +1
174 res['price_subtotal']="%.2f"%(sum)
175 res['currency']=invoice.currency_id.code
181 elif entry.state=='title':
182 res['name']=entry.name
183 res['price_subtotal']=''
185 elif entry.state=='text':
186 res['name']=entry.name
187 res['price_subtotal']=''
189 elif entry.state=='line':
190 res['quantity']='____________'
191 res['price_unit']='______________'
192 res['discount']='____________'
193 res['tax_types']='_________________'
195 res['name']='________________________________________'
196 res['price_subtotal']='_______________________'
197 res['currency']='_______'
198 elif entry.state=='break':
199 res['type']=entry.state
200 res['name']=entry.name
201 res['price_subtotal']=''
204 res['name']=entry.name
205 res['price_subtotal']=''
206 res['currency']=invoice.currency_id.code
210 report_sxw.report_sxw('report.account.invoice.layout', 'account.invoice', 'addons/account_invoice_layout/report/report_account_invoice_layout.rml', parser=account_invoice_1)
211 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: