product_pricelist report made compatible to new report engine
bzr revid: nch@tinyerp.com-20090429105823-1ddnlexdw0rfd4b3
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
@@ -25,14 +25,6 @@ from report import report_sxw
|
||||
from osv import osv
|
||||
import pooler
|
||||
|
||||
from tools.translate import _
|
||||
|
||||
parents = {
|
||||
'tr':1,
|
||||
'li':1,
|
||||
'story': 0,
|
||||
'section': 0
|
||||
}
|
||||
class product_pricelist(report_sxw.rml_parse):
|
||||
def __init__(self, cr, uid, name, context):
|
||||
super(product_pricelist, self).__init__(cr, uid, name, context)
|
||||
@@ -44,44 +36,30 @@ class product_pricelist(report_sxw.rml_parse):
|
||||
'get_currency': self._get_currency,
|
||||
'get_categories': self._get_categories,
|
||||
'get_price': self._get_price,
|
||||
'get_quantity':self._get_quantity,
|
||||
'qty_header':self._qty_header,
|
||||
})
|
||||
def _qty_header(self,form):
|
||||
def _get_unit_text(obj, cr, uid, par_qty):
|
||||
if form[q]==1:
|
||||
return _('%d unit')%(par_qty)
|
||||
else:
|
||||
return _('%d units')%(par_qty)
|
||||
|
||||
qty=[]
|
||||
self.pricelist=form['price_list']
|
||||
def _set_quantity(self,form):
|
||||
for i in range(1,6):
|
||||
q = 'qty%d'%i
|
||||
if form[q]:
|
||||
self.quantity.append(form[q])
|
||||
qty.append(_get_unit_text(self, self.cr, self.uid, form[q]))
|
||||
return qty
|
||||
return True
|
||||
|
||||
|
||||
def _get_quantity(self,form):
|
||||
qty=[]
|
||||
for i in range(1,6):
|
||||
q = 'qty%d'%i
|
||||
if form[q]:
|
||||
qty.append(form[q])
|
||||
return qty
|
||||
def _get_pricelist(self, pricelist_id):
|
||||
pool = pooler.get_pool(self.cr.dbname)
|
||||
pricelist = pool.get('product.pricelist').read(self.cr,self.uid,[pricelist_id],['name'])[0]
|
||||
return pricelist['name']
|
||||
|
||||
def _get_currency(self, pricelist_id):
|
||||
pool = pooler.get_pool(self.cr.dbname)
|
||||
pricelist = pool.get('product.pricelist').read(self.cr,self.uid,[pricelist_id],['currency_id'])[0]
|
||||
return pricelist['currency_id'][1]
|
||||
def _get_categories(self, products):
|
||||
|
||||
def _get_categories(self, products,form):
|
||||
cat_ids=[]
|
||||
res=[]
|
||||
self.pricelist = form['price_list']
|
||||
self._set_quantity(form)
|
||||
pool = pooler.get_pool(self.cr.dbname)
|
||||
pro_ids=[]
|
||||
for product in products:
|
||||
@@ -98,10 +76,11 @@ class product_pricelist(report_sxw.rml_parse):
|
||||
'name':product.name,
|
||||
'code':product.code
|
||||
}
|
||||
i = 1
|
||||
for qty in self.quantity:
|
||||
val[str(qty)]=self._get_price(self.pricelist,product.id,qty)
|
||||
val['qty'+str(i)]=self._get_price(self.pricelist,product.id,qty)
|
||||
i += 1
|
||||
products.append(val)
|
||||
|
||||
res.append({'name':cat.name,'products':products})
|
||||
return res
|
||||
|
||||
@@ -115,42 +94,6 @@ class product_pricelist(report_sxw.rml_parse):
|
||||
price = self.formatLang(res[0]['list_price'])
|
||||
return price
|
||||
|
||||
def repeatIn(self, lst, name, nodes_parent=False,value=[],width=False,type=False):
|
||||
self._node.data = ''
|
||||
node = self._find_parent(self._node, nodes_parent or parents)
|
||||
ns = node.nextSibling
|
||||
if not lst:
|
||||
lst.append(1)
|
||||
for ns in node.childNodes :
|
||||
if ns and ns.nodeName!='#text' and ns.tagName=='blockTable' and len(value) :
|
||||
width_str = ns._attrs['colWidths'].nodeValue
|
||||
ns.removeAttribute('colWidths')
|
||||
if not width or width=='':
|
||||
width=30
|
||||
if type.lower() in ('title'):
|
||||
width=width*len(value)
|
||||
width_str= '%d'%(float(width_str)+width)
|
||||
ns.setAttribute('colWidths',width_str)
|
||||
else:
|
||||
for v in value:
|
||||
width_str +=',%d'%width
|
||||
|
||||
ns.setAttribute('colWidths',width_str)
|
||||
child_list = ns.childNodes
|
||||
for child in child_list:
|
||||
if child.nodeName=='tr':
|
||||
lc = child.childNodes[1]
|
||||
t=0
|
||||
for v in value:
|
||||
newnode = lc.cloneNode(1)
|
||||
if type.lower() in ('string'):
|
||||
newnode.childNodes[1].lastChild.data="[[ %s['%s'] ]]"%(name,v)
|
||||
elif type.lower() in ('label'):
|
||||
newnode.childNodes[1].lastChild.data= "%s"%(v)
|
||||
child.appendChild(newnode)
|
||||
newnode=False
|
||||
return super(product_pricelist,self).repeatIn(lst, name, nodes_parent=False)
|
||||
#end
|
||||
report_sxw.report_sxw('report.product.pricelist','product.product','addons/product/report/product_pricelist.rml',parser=product_pricelist)
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -13,103 +13,175 @@
|
||||
<blockTableStyle id="Table1">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
<blockBackground colorName="#e6e6e6" start="0,0" stop="0,0"/>
|
||||
<lineStyle kind="GRID" colorName="black"/>
|
||||
<blockBackground colorName="#e6e6e6" start="0,0" stop="0,0"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table6">
|
||||
<blockTableStyle id="Table2">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table7">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
<blockBackground colorName="#e6e6e6" />
|
||||
<lineStyle kind="GRID" colorName="black"/>
|
||||
<blockBackground colorName="#e6e6e6" start="0,0" stop="0,0"/>
|
||||
<blockBackground colorName="#e6e6e6" start="1,0" stop="1,0"/>
|
||||
<blockBackground colorName="#e6e6e6" start="2,0" stop="2,0"/>
|
||||
<blockBackground colorName="#e6e6e6" start="3,0" stop="3,0"/>
|
||||
<blockBackground colorName="#e6e6e6" start="4,0" stop="4,0"/>
|
||||
<blockBackground colorName="#e6e6e6" start="5,0" stop="5,0"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table3">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table5">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
<lineStyle kind="GRID" colorName="black"/>
|
||||
</blockTableStyle>
|
||||
<initialize>
|
||||
<paraStyle name="all" alignment="justify"/>
|
||||
</initialize>
|
||||
<paraStyle name="P1" fontName="Times-Roman" fontSize="9.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P2" fontName="Times-Roman" fontSize="9.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P3" fontName="Times-Roman" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P4" fontName="Times-Roman" alignment="CENTER"/>
|
||||
<paraStyle name="P5" fontName="Times-Roman" fontSize="8.0" leading="10"/>
|
||||
<paraStyle name="P6" fontName="Times-Bold" fontSize="11.0" leading="14" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P7" fontName="Times-Roman" alignment="LEFT"/>
|
||||
<paraStyle name="P8" fontName="Times-Roman" fontSize="20.0" leading="25" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P9" fontName="Times-Roman" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P10" fontName="Times-Roman" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P11" fontName="Times-Roman" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P12" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Standard" fontName="Times-Roman" fontSize="12"/>
|
||||
<paraStyle name="P1" fontName="Times-Roman" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P2" fontName="Helvetica-Bold" fontSize="16.0" leading="20" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P3" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P4" fontName="Times-Bold" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P5" fontName="Times-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P6" fontName="Times-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P7" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P8" fontName="Times-Roman" fontSize="8.0" leading="10"/>
|
||||
<paraStyle name="P9" fontName="Times-Bold" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P10" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P11" fontName="Times-Bold" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P12" fontName="Times-Bold" fontSize="8.0" leading="8" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P13" fontName="Times-Roman" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P14" fontName="Times-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P15" fontName="Times-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P16" fontName="Times-Roman" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P17" fontName="Times-Roman" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Standard" fontName="Times-Roman"/>
|
||||
<paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Table Contents" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Table Heading" fontName="Times-Roman" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Caption" fontName="Times-Roman" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Index" fontName="Times-Roman"/>
|
||||
<paraStyle name="cat" fontName="Times-Bold" textColor="blue" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/>
|
||||
</stylesheet>
|
||||
<story>
|
||||
<para style="P5">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<blockTable colWidths="530.0" repeatRows="1" style="Table1">
|
||||
<para style="P8">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<para style="P8">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<para style="P8">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<para style="P8">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<para style="P8">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<blockTable colWidths="482.0" style="Table1">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P8">Products Price List</para>
|
||||
<para style="P2">Products Price List</para>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</blockTable>
|
||||
<para style="P5">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<para style="Standard">
|
||||
<para style="P8">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<para style="Standard">Price List Name : [[ get_pricelist (data['form']['price_list']) ]]</para>
|
||||
<para style="Standard">Currency : [[ get_currency ( data['form']['price_list']) ]]</para>
|
||||
<para style="Standard">Printing Date: [[ formatLang(time.strftime('%Y-%m-%d'), date=True) ]]</para>
|
||||
<para style="P7">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<section>
|
||||
<para style="P6">[[repeatIn([],'qty_header',width=59,value=qty_header(data['form']),type='label') ]]</para>
|
||||
<blockTable colWidths="227.0" style="Table6">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P6">Description</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
</section>
|
||||
<section>
|
||||
<para style="Standard">[[ repeatIn(get_categories(objects), 'c',width=59,value=get_quantity(data['form']),type='title') ]]</para>
|
||||
<blockTable colWidths="227.0" style="Table3">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="cat">[[ c['name'] ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
|
||||
<section>
|
||||
<para style="Standard">[[repeatIn(c['products'], 'p',width=59,value=get_quantity(data['form']),type='string') ]]</para>
|
||||
<blockTable colWidths="227.0" style="Table3">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P1">[[ p['code'] and '[' + p['code'] + '] ' or '' ]] [[ p['name'] ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
</section>
|
||||
</section>
|
||||
<para style="P5"/>
|
||||
<blockTable colWidths="117.0,364.0" style="Table2">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P1">Price List Name:</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P3">[[ get_pricelist(data['form']['price_list']) ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P1">Currency :</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P3">[[ get_currency ( data['form']['price_list']) ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P1">Printing Date :</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P3">[[ formatLang(time.strftime('%Y-%m-%d'), date=True) ]]</para>
|
||||
<para style="P4">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<para style="P3">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<blockTable colWidths="80.0,80.0,80.0,80.0,80.0,80.0" style="Table7">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P6">Description</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P5">[[str( data['form']['qty1']) ]] units</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P6">[[ str(data['form']['qty2'] )]] units</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P6">[[ str(data['form']['qty3']) ]] units</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P6">[[ str(data['form']['qty4']) ]] units</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P6">[[ str(data['form']['qty5'] ) ]] units</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<blockTable colWidths="482.0" style="Table3">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P17">
|
||||
<font face="Times-Roman">[[repeatIn(get_categories(objects,data['form']), 'c')]][[ c['name'] ]]</font>
|
||||
</para>
|
||||
<blockTable colWidths="79.0,79.0,79.0,79.0,79.0,79.0" style="Table5">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P12">[[repeatIn(c['products'], 'p')]][[ p['code'] and '[' + p['code'] + '] ' or '' ]] [[ p['name'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">[[p['qty1'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">[[ p['qty2'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">[[ p['qty3'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">[[ p['qty4'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">[[ p['qty5'] ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<para style="P1">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</story>
|
||||
</document>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user