2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2009-11-13 05:41:16 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2009-11-13 05:41:16 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
import ir
|
|
|
|
import pooler
|
|
|
|
from report.interface import report_rml
|
|
|
|
from report.interface import toxml
|
|
|
|
|
2008-12-08 17:08:40 +00:00
|
|
|
from tools.translate import _
|
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
#FIXME: we should use toxml
|
|
|
|
class report_custom(report_rml):
|
2008-07-22 15:11:28 +00:00
|
|
|
def create_xml(self, cr, uid, ids, datas, context={}):
|
|
|
|
number = (datas.get('form', False) and datas['form']['number']) or 1
|
2010-07-23 13:17:30 +00:00
|
|
|
pool = pooler.get_pool(cr.dbname)
|
|
|
|
product_pool = pool.get('product.product')
|
|
|
|
product_uom_pool = pool.get('product.uom')
|
|
|
|
supplier_info_pool = pool.get('product.supplierinfo')
|
|
|
|
workcenter_pool = pool.get('mrp.workcenter')
|
|
|
|
user_pool = pool.get('res.users')
|
|
|
|
bom_pool = pool.get('mrp.bom')
|
|
|
|
def process_bom(bom, currency_id, factor=1):
|
2008-07-22 15:11:28 +00:00
|
|
|
xml = '<row>'
|
|
|
|
sum = 0
|
|
|
|
sum_strd = 0
|
2010-07-23 13:17:30 +00:00
|
|
|
prod = product_pool.browse(cr, uid, bom['product_id'])
|
2008-07-22 15:11:28 +00:00
|
|
|
|
|
|
|
prod_name = bom['name']
|
2010-07-23 13:17:30 +00:00
|
|
|
prod_qtty = factor * bom['product_qty']
|
|
|
|
product_uom = product_uom_pool.browse(cr, uid, bom['product_uom'], context=context)
|
2008-07-22 15:11:28 +00:00
|
|
|
level = 1
|
2010-07-23 13:17:30 +00:00
|
|
|
main_sp_price, main_sp_name , main_strd_price = '','',''
|
|
|
|
sellers, sellers_price = '',''
|
|
|
|
|
|
|
|
if prod.seller_id:
|
|
|
|
main_sp_name = "<b>%s</b>\r\n" %(prod.seller_id.name)
|
|
|
|
price = supplier_info_pool.price_get(cr, uid, prod.seller_id.id, prod.id, number*prod_qtty)[prod.seller_id.id]
|
|
|
|
price = product_uom_pool._compute_price(cr, uid, prod.uom_id.id, price, to_uom_id=product_uom.id)
|
|
|
|
main_sp_price = '%s\r\n' %(str(price))
|
2008-07-22 15:11:28 +00:00
|
|
|
sum += prod_qtty*price
|
2010-07-23 13:17:30 +00:00
|
|
|
std_price = product_uom_pool._compute_price(cr, uid, prod.uom_id.id, prod.standard_price, to_uom_id=product_uom.id)
|
|
|
|
main_strd_price = str(std_price) + '\r\n'
|
|
|
|
sum_strd = prod_qtty*std_price
|
2008-07-22 15:11:28 +00:00
|
|
|
|
|
|
|
for seller_id in prod.seller_ids:
|
|
|
|
sellers += '- <i>'+ seller_id.name.name +'</i>\r\n'
|
2010-07-23 13:17:30 +00:00
|
|
|
price = supplier_info_pool.price_get(cr, uid, seller_id.name.id, prod.id, number*prod_qtty)[seller_id.name.id]
|
|
|
|
price = product_uom_pool._compute_price(cr, uid, prod.uom_id.id, price, to_uom_id=product_uom.id)
|
|
|
|
sellers_price += str(price) + '\r\n'
|
2008-07-22 15:11:28 +00:00
|
|
|
|
|
|
|
xml += "<col para='yes'>" + prod_name + '</col>'
|
|
|
|
xml += "<col para='no'>" + main_sp_name + sellers + '</col>'
|
|
|
|
xml += "<col para='yes'>" + str(prod_qtty) + '</col>'
|
2010-07-23 13:17:30 +00:00
|
|
|
xml += "<col para='yes'>" + product_uom.name + '</col>'
|
2008-07-22 15:11:28 +00:00
|
|
|
xml += "<col para='yes'>" + main_strd_price + '</col>'
|
|
|
|
xml += "<col para='no'>" + main_sp_price + sellers_price + '</col>'
|
|
|
|
|
|
|
|
|
|
|
|
xml += '</row>'
|
|
|
|
return xml, sum, sum_strd
|
|
|
|
|
|
|
|
def process_workcenter(wrk):
|
|
|
|
xml = '<row>'
|
|
|
|
|
2010-07-23 13:17:30 +00:00
|
|
|
workcenter = workcenter_pool.browse(cr, uid, wrk['workcenter_id'])
|
2008-07-22 15:11:28 +00:00
|
|
|
|
2010-07-23 13:17:30 +00:00
|
|
|
xml += "<col para='yes'>" + workcenter.name + '</col>'
|
2008-07-22 15:11:28 +00:00
|
|
|
xml += "<col para='yes'>" + '</col>'
|
|
|
|
xml += "<col para='no'>" + '</col>'
|
|
|
|
xml += "<col/>"
|
|
|
|
xml += "<col para='no'>" + str(wrk['cycle']*workcenter.costs_cycle) + '</col>'
|
|
|
|
xml += "<col para='yes'>" + str(wrk['hour']*workcenter.costs_hour) + '</col>'
|
|
|
|
|
|
|
|
|
|
|
|
xml += '</row>'
|
|
|
|
return xml, wrk['cycle']*workcenter.costs_cycle+wrk['hour']*workcenter.costs_hour
|
|
|
|
|
|
|
|
|
|
|
|
xml = ''
|
|
|
|
config_start = """
|
|
|
|
<config>
|
|
|
|
<date>09/09/2005</date>
|
|
|
|
<PageSize>210.00mm,297.00mm</PageSize>
|
|
|
|
<PageWidth>595.27</PageWidth>
|
|
|
|
<PageHeight>841.88</PageHeight>
|
|
|
|
<tableSize>60.00mm,60.00mm, 20.00mm, 20.00mm, 20.00mm, 20.00mm</tableSize>
|
|
|
|
"""
|
|
|
|
config_stop = """
|
2008-12-10 22:55:43 +00:00
|
|
|
<report-footer>Generated by Open ERP</report-footer>
|
2008-07-22 15:11:28 +00:00
|
|
|
</config>
|
|
|
|
"""
|
|
|
|
header = """
|
|
|
|
<header>
|
2008-12-08 17:08:40 +00:00
|
|
|
<field>%s</field>
|
|
|
|
<field>%s</field>
|
|
|
|
<field>%s</field>
|
|
|
|
<field>%s</field>
|
|
|
|
<field>%s</field>
|
|
|
|
<field>%s</field>
|
2008-07-22 15:11:28 +00:00
|
|
|
</header>
|
2008-12-08 17:08:40 +00:00
|
|
|
""" % (_('Product name'), _('Product supplier'), _('Product quantity'), _('Product uom'), _('Product Standard Price'), _('Unit Product Price'))
|
2008-07-22 15:11:28 +00:00
|
|
|
workcenter_header = """
|
|
|
|
<lines style='header'>
|
|
|
|
<row>
|
2008-12-08 17:08:40 +00:00
|
|
|
<col>%s</col>
|
2008-07-22 15:11:28 +00:00
|
|
|
<col/>
|
|
|
|
<col/>
|
|
|
|
<col/>
|
2008-12-08 17:08:40 +00:00
|
|
|
<col>%s</col>
|
|
|
|
<col>%s</col>
|
2008-07-22 15:11:28 +00:00
|
|
|
</row>
|
|
|
|
</lines>
|
2009-12-14 14:56:27 +00:00
|
|
|
""" % (_('Work Center name'), _('Cycles Cost'), _('Total hourly costs'))
|
2008-07-22 15:11:28 +00:00
|
|
|
prod_header = """
|
|
|
|
<lines style='header'>
|
|
|
|
<row>
|
2008-12-08 17:08:40 +00:00
|
|
|
<col para='yes'>%s</col>
|
|
|
|
<col para='yes'>%s</col>
|
|
|
|
<col para='yes'>%s</col>
|
|
|
|
<col para='yes'>%s</col>
|
|
|
|
<col para='yes'>%s</col>
|
|
|
|
<col para='yes'>%s</col>
|
2008-07-22 15:11:28 +00:00
|
|
|
</row>
|
|
|
|
</lines>
|
2008-12-08 17:08:40 +00:00
|
|
|
""" % (_('Product name'), _('Product supplier'), _('Product Quantity'), _('Product uom'), _('Product Standard Price'), _('Unit Product Price'))
|
2008-07-22 15:11:28 +00:00
|
|
|
|
2010-07-23 13:17:30 +00:00
|
|
|
company_currency = user_pool.browse(cr, uid, uid).company_id.currency_id.id
|
2008-07-22 15:11:28 +00:00
|
|
|
first = True
|
2010-07-23 13:17:30 +00:00
|
|
|
for product in product_pool.browse(cr, uid, ids, context=context):
|
|
|
|
bom_ids = bom_pool.search(cr, uid, [('product_id','=',product.id)])
|
|
|
|
for bom in bom_pool.browse(cr, uid, bom_ids, context=context):
|
|
|
|
sub_boms = bom_pool._bom_explode(cr, uid, bom, number, [])
|
2008-07-22 15:11:28 +00:00
|
|
|
total = 0
|
|
|
|
total_strd = 0
|
2010-07-23 13:17:30 +00:00
|
|
|
parent_bom = {
|
|
|
|
'product_qty': bom.product_qty,
|
|
|
|
'name': bom.product_id.name,
|
|
|
|
'product_uom': bom.product_uom.id,
|
|
|
|
'product_id': bom.product_id.id
|
|
|
|
}
|
2008-07-22 15:11:28 +00:00
|
|
|
xml_tmp = ''
|
|
|
|
for sub_bom in (sub_boms and sub_boms[0]) or [parent_bom]:
|
2010-07-23 13:17:30 +00:00
|
|
|
txt, sum, sum_strd = process_bom(sub_bom, company_currency, factor=1/bom.product_qty)
|
2008-07-22 15:11:28 +00:00
|
|
|
xml_tmp += txt
|
|
|
|
total += sum
|
|
|
|
total_strd += sum_strd
|
|
|
|
if not first:
|
|
|
|
xml += prod_header
|
|
|
|
xml += "<lines style='lines'>" + xml_tmp + '</lines>'
|
2008-12-08 17:08:40 +00:00
|
|
|
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>'
|
2008-07-22 15:11:28 +00:00
|
|
|
total2 = 0
|
|
|
|
xml_tmp = ''
|
|
|
|
for wrk in (sub_boms and sub_boms[1]):
|
|
|
|
txt, sum = process_workcenter(wrk)
|
|
|
|
xml_tmp += txt
|
|
|
|
total2 += sum
|
|
|
|
if xml_tmp:
|
|
|
|
xml += workcenter_header
|
|
|
|
xml += "<lines style='lines'>" + xml_tmp + '</lines>'
|
2008-12-08 17:08:40 +00:00
|
|
|
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>'
|
|
|
|
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>'
|
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
first = False
|
|
|
|
|
2010-07-23 13:17:30 +00:00
|
|
|
xml = '<?xml version="1.0" ?><report>' + config_start + '<report-header>%s\n\r' % (_('Product Cost Structure')) + product.name + '</report-header>'+ config_stop + header + xml + '</report>'
|
2008-07-22 15:11:28 +00:00
|
|
|
|
|
|
|
return xml
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
report_custom('report.product.price', 'product.product', '', 'addons/mrp/report/price.xsl')
|
2008-07-23 14:41:47 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|