1 # -*- coding: 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 ##############################################################################
25 from report.interface import report_rml
26 from report.interface import toxml
28 from tools.translate import _
31 #FIXME: we should use toxml
32 class report_custom(report_rml):
33 def create_xml(self, cr, uid, ids, datas, context={}):
34 number = (datas.get('form', False) and datas['form']['number']) or 1
36 def process_bom(bom, currency_id):
40 prod = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, bom['product_id'])
42 prod_name = bom['name']
43 prod_qtty = bom['product_qty']
44 prod_uom = prod.uom_id.name
50 if prod.seller_ids and prod.seller_ids[0] :
51 main_sp_name = '<b>' + prod.seller_ids[0].name.name + '</b>\r\n'
52 pricelist_id = prod.seller_ids[0].name.property_product_pricelist_purchase.id
54 pricelist_obj = pooler.get_pool(cr.dbname).get('product.pricelist')
55 price = pricelist_obj.price_get(cr,uid,[pricelist_id], prod.id, number*prod_qtty or 1.0).setdefault(pricelist_id, 0)
56 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)
59 main_sp_price = '%.2f' % price + '\r\n'
60 sum += prod_qtty*price
62 main_strd_price = '%.2f' % prod.standard_price + '\r\n'
63 sum_strd = prod_qtty*prod.standard_price
67 for seller_id in prod.seller_ids:
68 sellers += '- <i>'+ seller_id.name.name +'</i>\r\n'
69 pricelist_id = seller_id.name.property_product_pricelist_purchase.id
71 pricelist_obj = pooler.get_pool(cr.dbname).get('product.pricelist')
72 price = pricelist_obj.price_get(cr,uid,[pricelist_id], prod.id, number*prod_qtty or 1.0).setdefault(pricelist_id, 0)
73 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)
76 sellers_price += '%.2f' % price + '\r\n'
78 xml += "<col para='yes'>" + prod_name + '</col>'
79 xml += "<col para='no'>" + main_sp_name + sellers + '</col>'
80 xml += "<col para='yes'>" + str(prod_qtty) + '</col>'
81 xml += "<col para='yes'>" + prod_uom + '</col>'
82 xml += "<col para='yes'>" + main_strd_price + '</col>'
83 xml += "<col para='no'>" + main_sp_price + sellers_price + '</col>'
87 return xml, sum, sum_strd
89 def process_workcenter(wrk):
92 workcenter = pooler.get_pool(cr.dbname).get('mrp.workcenter').browse(cr, uid, wrk['workcenter_id'])
94 xml += "<col para='yes'>" + wrk['name'] + '</col>'
95 xml += "<col para='yes'>" + '</col>'
96 xml += "<col para='no'>" + '</col>'
98 xml += "<col para='no'>" + str(wrk['cycle']*workcenter.costs_cycle) + '</col>'
99 xml += "<col para='yes'>" + str(wrk['hour']*workcenter.costs_hour) + '</col>'
103 return xml, wrk['cycle']*workcenter.costs_cycle+wrk['hour']*workcenter.costs_hour
109 <date>09/09/2005</date>
110 <PageSize>210.00mm,297.00mm</PageSize>
111 <PageWidth>595.27</PageWidth>
112 <PageHeight>841.88</PageHeight>
113 <tableSize>60.00mm,60.00mm, 20.00mm, 20.00mm, 20.00mm, 20.00mm</tableSize>
116 <report-footer>Generated by Open ERP</report-footer>
128 """ % (_('Product name'), _('Product supplier'), _('Product quantity'), _('Product uom'), _('Product Standard Price'), _('Unit Product Price'))
129 workcenter_header = """
130 <lines style='header'>
140 """ % (_('Workcenter name'), _('Cycles Cost'), _('Hours Cost'))
142 <lines style='header'>
144 <col para='yes'>%s</col>
145 <col para='yes'>%s</col>
146 <col para='yes'>%s</col>
147 <col para='yes'>%s</col>
148 <col para='yes'>%s</col>
149 <col para='yes'>%s</col>
152 """ % (_('Product name'), _('Product supplier'), _('Product Quantity'), _('Product uom'), _('Product Standard Price'), _('Unit Product Price'))
154 company_currency = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id.currency_id.id
157 bom_ids = pooler.get_pool(cr.dbname).get('mrp.bom').search(cr, uid, [('product_id','=',prod_id)])
158 prod = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, prod_id)
160 for bom_id in bom_ids:
161 bom = pooler.get_pool(cr.dbname).get('mrp.bom').browse(cr, uid, bom_id)
163 sub_boms = pooler.get_pool(cr.dbname).get('mrp.bom')._bom_explode(cr, uid, bom, number, [])
166 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}
168 for sub_bom in (sub_boms and sub_boms[0]) or [parent_bom]:
169 txt, sum, sum_strd = process_bom(sub_bom, company_currency)
172 total_strd += sum_strd
175 xml += "<lines style='lines'>" + xml_tmp + '</lines>'
176 xml += "<lines style='sub_total'><row><col>%s : </col><col>(" % (_('SUBTOTAL')) + str(number) + " %s)</col><col/><col/><col>" % (_('products')) + '%.2f' % total_strd + '</col><col>' + '%.2f' % total + '</col></row></lines>'
179 for wrk in (sub_boms and sub_boms[1]):
180 txt, sum = process_workcenter(wrk)
184 xml += workcenter_header
185 xml += "<lines style='lines'>" + xml_tmp + '</lines>'
186 xml += "<lines style='sub_total'><row><col>%s : </col><col>(" % (_('SUBTOTAL')) + str(number) + " %s)</col><col/><col/><col/><col>" % (_('products')) + '%.2f' % total2 + '</col></row></lines>'
187 xml += "<lines style='total'><row><col>%s : </col><col>(" % (_('TOTAL')) + str(number) + " %s)</col><col/><col/><col>" % (_('products')) + '%.2f' % (total_strd+total2) + "</col><col>" + '%.2f' % (total+total2) + '</col></row></lines>'
191 xml = '<?xml version="1.0" ?><report>' + config_start + '<report-header>%s\n\r' % (_('Product Cost Structure')) + prod.name + '</report-header>'+ config_stop + header + xml + '</report>'
195 report_custom('report.product.price', 'product.product', '', 'addons/mrp/report/price.xsl')
197 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: