1 # -*-encoding: iso8859-1 -*-
2 ##############################################################################
4 # Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
6 # WARNING: This program as such is intended to be used by professional
7 # programmers who take the whole responsability of assessing all potential
8 # consequences resulting from its eventual inadequacies and bugs
9 # End users who are looking for a ready-to-use solution with commercial
10 # garantees and support are strongly adviced to contract a Free Software
13 # This program is Free Software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ##############################################################################
31 from report.interface import report_rml
32 from report.interface import toxml
35 #FIXME: we should use toxml
36 class report_custom(report_rml):
37 def create_xml(self, cr, uid, ids, datas, context={}):
38 number = (datas.get('form', False) and datas['form']['number']) or 1
40 def process_bom(bom, currency_id):
44 prod = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, bom['product_id'])
46 prod_name = bom['name']
47 prod_qtty = bom['product_qty']
48 prod_uom = prod.uom_id.name
54 if prod.seller_ids and prod.seller_ids[0] :
55 main_sp_name = '<b>' + prod.seller_ids[0].name.name + '</b>\r\n'
56 pricelist = prod.seller_ids[0].name.property_product_pricelist_purchase
58 pricelist_id = pricelist[0]
59 pricelist_obj = pooler.get_pool(cr.dbname).get('product.pricelist')
60 price = pricelist_obj.price_get(cr,uid,[pricelist_id], prod.id, number*prod_qtty or 1.0).setdefault(pricelist_id, 0)
61 price = pooler.get_pool(cr.dbname).get('res.currency').compute(cr, uid, pricelist_obj.browse(cr, uid, pricelist_id).currency_id.id, currency_id, price)
64 main_sp_price = '%.2f' % price + '\r\n'
65 sum += prod_qtty*price
67 main_strd_price = '%.2f' % prod.standard_price + '\r\n'
68 sum_strd = prod_qtty*prod.standard_price
72 for seller_id in prod.seller_ids:
73 sellers += '- <i>'+ seller_id.name.name +'</i>\r\n'
74 pricelist = seller_id.name.property_product_pricelist_purchase
76 pricelist_id = pricelist[0]
77 pricelist_obj = pooler.get_pool(cr.dbname).get('product.pricelist')
78 price = pricelist_obj.price_get(cr,uid,[pricelist_id], prod.id, number*prod_qtty or 1.0).setdefault(pricelist_id, 0)
79 price = pooler.get_pool(cr.dbname).get('res.currency').compute(cr, uid, pricelist_obj.browse(cr, uid, pricelist_id).currency_id.id, currency_id, price)
82 sellers_price += '%.2f' % price + '\r\n'
84 xml += "<col para='yes'>" + prod_name + '</col>'
85 xml += "<col para='no'>" + main_sp_name + sellers + '</col>'
86 xml += "<col para='yes'>" + str(prod_qtty) + '</col>'
87 xml += "<col para='yes'>" + prod_uom + '</col>'
88 xml += "<col para='yes'>" + main_strd_price + '</col>'
89 xml += "<col para='no'>" + main_sp_price + sellers_price + '</col>'
93 return xml, sum, sum_strd
95 def process_workcenter(wrk):
98 workcenter = pooler.get_pool(cr.dbname).get('mrp.workcenter').browse(cr, uid, wrk['workcenter_id'])
100 xml += "<col para='yes'>" + wrk['name'] + '</col>'
101 xml += "<col para='yes'>" + '</col>'
102 xml += "<col para='no'>" + '</col>'
104 xml += "<col para='no'>" + str(wrk['cycle']*workcenter.costs_cycle) + '</col>'
105 xml += "<col para='yes'>" + str(wrk['hour']*workcenter.costs_hour) + '</col>'
109 return xml, wrk['cycle']*workcenter.costs_cycle+wrk['hour']*workcenter.costs_hour
115 <date>09/09/2005</date>
116 <PageSize>210.00mm,297.00mm</PageSize>
117 <PageWidth>595.27</PageWidth>
118 <PageHeight>841.88</PageHeight>
119 <tableSize>60.00mm,60.00mm, 20.00mm, 20.00mm, 20.00mm, 20.00mm</tableSize>
122 <report-footer>Generated by Tiny ERP</report-footer>
127 <field>Product name</field>
128 <field>Product supplier</field>
129 <field>Product quantity</field>
130 <field>Product uom</field>
131 <field>Product Standard Price</field>
132 <field>Unit Product Price</field>
135 workcenter_header = """
136 <lines style='header'>
138 <col>Workcenter name</col>
142 <col>Cycles Cost</col>
143 <col>Hours Cost</col>
148 <lines style='header'>
150 <col para='yes'>Product name</col>
151 <col para='yes'>Product supplier</col>
152 <col para='yes'>Product Quantity</col>
153 <col para='yes'>Product uom</col>
154 <col para='yes'>Product Standard Price</col>
155 <col para='yes'>Unit Product Price</col>
160 company_currency = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id.currency_id.id
163 bom_ids = pooler.get_pool(cr.dbname).get('mrp.bom').search(cr, uid, [('product_id','=',prod_id)])
164 prod = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, prod_id)
166 for bom_id in bom_ids:
167 bom = pooler.get_pool(cr.dbname).get('mrp.bom').browse(cr, uid, bom_id)
169 sub_boms = pooler.get_pool(cr.dbname).get('mrp.bom')._bom_explode(cr, uid, bom, number, [])
172 parent_bom = {'product_qty': bom.product_qty, 'name': bom.product_id.name, 'product_uom': bom.product_id.uom_id.factor, 'product_id': bom.product_id.id}
174 for sub_bom in (sub_boms and sub_boms[0]) or [parent_bom]:
175 txt, sum, sum_strd = process_bom(sub_bom, company_currency)
178 total_strd += sum_strd
181 xml += "<lines style='lines'>" + xml_tmp + '</lines>'
182 xml += "<lines style='sub_total'><row><col>SUBTOTAL : </col><col>(for " + str(number) + " products)</col><col/><col/><col>" + '%.2f' % total_strd + '</col><col>' + '%.2f' % total + '</col></row></lines>'
186 for wrk in (sub_boms and sub_boms[1]):
187 txt, sum = process_workcenter(wrk)
191 xml += workcenter_header
192 xml += "<lines style='lines'>" + xml_tmp + '</lines>'
193 xml += "<lines style='sub_total'><row><col>SUBTOTAL : </col><col>(for " + str(number) + " products)</col><col/><col/><col/><col>" + '%.2f' % total2 + '</col></row></lines>'
194 xml += "<lines style='total'><row><col>TOTAL : </col><col>(for " + str(number) + " products)</col><col/><col/><col>" + '%.2f' % (total_strd+total2) + "</col><col>" + '%.2f' % (total+total2) + '</col></row></lines>'
197 xml = '<?xml version="1.0" ?><report>' + config_start + '<report-header>Product Cost Structure\n\r' + prod.name + '</report-header>'+ config_stop + header + xml + '</report>'
201 report_custom('report.product.price', 'product.product', '', 'addons/mrp/report/price.xsl')