1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from report.interface import report_rml
25 from report.interface import toxml
27 from tools.translate import _
30 #FIXME: we should use toxml
31 class report_custom(report_rml):
32 def create_xml(self, cr, uid, ids, datas, context={}):
33 number = (datas.get('form', False) and datas['form']['number']) or 1
35 def process_bom(bom, currency_id):
39 prod = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, bom['product_id'])
41 prod_name = bom['name']
42 prod_qtty = bom['product_qty']
43 prod_uom = prod.uom_id.name
49 if prod.seller_ids and prod.seller_ids[0] :
50 main_sp_name = '<b>' + prod.seller_ids[0].name.name + '</b>\r\n'
51 pricelist_id = prod.seller_ids[0].name.property_product_pricelist_purchase.id
53 pricelist_obj = pooler.get_pool(cr.dbname).get('product.pricelist')
54 price = pricelist_obj.price_get(cr,uid,[pricelist_id], prod.id, number*prod_qtty or 1.0).setdefault(pricelist_id, 0)
55 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)
58 main_sp_price = '%.2f' % price + '\r\n'
59 sum += prod_qtty*price
61 main_strd_price = '%.2f' % prod.standard_price + '\r\n'
62 sum_strd = prod_qtty*prod.standard_price
66 for seller_id in prod.seller_ids:
67 sellers += '- <i>'+ seller_id.name.name +'</i>\r\n'
68 pricelist_id = seller_id.name.property_product_pricelist_purchase.id
70 pricelist_obj = pooler.get_pool(cr.dbname).get('product.pricelist')
71 price = pricelist_obj.price_get(cr,uid,[pricelist_id], prod.id, number*prod_qtty or 1.0).setdefault(pricelist_id, 0)
72 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)
75 sellers_price += '%.2f' % price + '\r\n'
77 xml += "<col para='yes'>" + prod_name + '</col>'
78 xml += "<col para='no'>" + main_sp_name + sellers + '</col>'
79 xml += "<col para='yes'>" + str(prod_qtty) + '</col>'
80 xml += "<col para='yes'>" + prod_uom + '</col>'
81 xml += "<col para='yes'>" + main_strd_price + '</col>'
82 xml += "<col para='no'>" + main_sp_price + sellers_price + '</col>'
86 return xml, sum, sum_strd
88 def process_workcenter(wrk):
91 workcenter = pooler.get_pool(cr.dbname).get('mrp.workcenter').browse(cr, uid, wrk['workcenter_id'])
93 xml += "<col para='yes'>" + wrk['name'] + '</col>'
94 xml += "<col para='yes'>" + '</col>'
95 xml += "<col para='no'>" + '</col>'
97 xml += "<col para='no'>" + str(wrk['cycle']*workcenter.costs_cycle) + '</col>'
98 xml += "<col para='yes'>" + str(wrk['hour']*workcenter.costs_hour) + '</col>'
102 return xml, wrk['cycle']*workcenter.costs_cycle+wrk['hour']*workcenter.costs_hour
108 <date>09/09/2005</date>
109 <PageSize>210.00mm,297.00mm</PageSize>
110 <PageWidth>595.27</PageWidth>
111 <PageHeight>841.88</PageHeight>
112 <tableSize>60.00mm,60.00mm, 20.00mm, 20.00mm, 20.00mm, 20.00mm</tableSize>
115 <report-footer>Generated by Open ERP</report-footer>
127 """ % (_('Product name'), _('Product supplier'), _('Product quantity'), _('Product uom'), _('Product Standard Price'), _('Unit Product Price'))
128 workcenter_header = """
129 <lines style='header'>
139 """ % (_('Workcenter name'), _('Cycles Cost'), _('Total hourly costs'))
141 <lines style='header'>
143 <col para='yes'>%s</col>
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>
151 """ % (_('Product name'), _('Product supplier'), _('Product Quantity'), _('Product uom'), _('Product Standard Price'), _('Unit Product Price'))
153 company_currency = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id.currency_id.id
156 bom_ids = pooler.get_pool(cr.dbname).get('mrp.bom').search(cr, uid, [('product_id','=',prod_id)])
157 prod = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, prod_id)
159 for bom_id in bom_ids:
160 bom = pooler.get_pool(cr.dbname).get('mrp.bom').browse(cr, uid, bom_id)
162 sub_boms = pooler.get_pool(cr.dbname).get('mrp.bom')._bom_explode(cr, uid, bom, number, [])
165 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}
167 for sub_bom in (sub_boms and sub_boms[0]) or [parent_bom]:
168 txt, sum, sum_strd = process_bom(sub_bom, company_currency)
171 total_strd += sum_strd
174 xml += "<lines style='lines'>" + xml_tmp + '</lines>'
175 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>'
178 for wrk in (sub_boms and sub_boms[1]):
179 txt, sum = process_workcenter(wrk)
183 xml += workcenter_header
184 xml += "<lines style='lines'>" + xml_tmp + '</lines>'
185 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>'
186 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>'
190 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>'
194 report_custom('report.product.price', 'product.product', '', 'addons/mrp/report/price.xsl')
196 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: