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
|
|
|
#
|
|
|
|
##############################################################################
|
2010-12-30 07:31:46 +00:00
|
|
|
|
2011-07-28 09:31:26 +00:00
|
|
|
import time
|
2013-03-27 13:47:02 +00:00
|
|
|
|
|
|
|
import openerp
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.report.interface import report_rml
|
|
|
|
from openerp.tools import to_xml
|
|
|
|
from openerp.report import report_sxw
|
2010-09-16 12:05:21 +00:00
|
|
|
from datetime import datetime
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.tools.translate import _
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
class report_custom(report_rml):
|
2010-11-19 13:48:01 +00:00
|
|
|
def create_xml(self, cr, uid, ids, datas, context=None):
|
2008-07-22 15:11:28 +00:00
|
|
|
number = (datas.get('form', False) and datas['form']['number']) or 1
|
2013-03-27 13:47:02 +00:00
|
|
|
registry = openerp.registry(cr.dbname)
|
|
|
|
product_pool = registry.get('product.product')
|
|
|
|
product_uom_pool = registry.get('product.uom')
|
|
|
|
workcenter_pool = registry.get('mrp.workcenter')
|
|
|
|
user_pool = registry.get('res.users')
|
|
|
|
bom_pool = registry.get('mrp.bom')
|
|
|
|
pricelist_pool = registry.get('product.pricelist')
|
2010-09-16 12:05:21 +00:00
|
|
|
rml_obj=report_sxw.rml_parse(cr, uid, product_pool._name,context)
|
|
|
|
rml_obj.localcontext.update({'lang':context.get('lang',False)})
|
|
|
|
company_currency = user_pool.browse(cr, uid, uid).company_id.currency_id
|
2011-12-07 07:02:10 +00:00
|
|
|
company_currency_symbol = company_currency.symbol or company_currency.name
|
2010-07-23 13:17:30 +00:00
|
|
|
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
|
|
|
|
2011-10-19 12:15:49 +00:00
|
|
|
prod_name = to_xml(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)
|
2011-11-03 13:03:55 +00:00
|
|
|
product_uom_name = to_xml(product_uom.name)
|
2010-07-23 13:17:30 +00:00
|
|
|
main_sp_price, main_sp_name , main_strd_price = '','',''
|
|
|
|
sellers, sellers_price = '',''
|
|
|
|
|
|
|
|
if prod.seller_id:
|
2011-11-03 12:56:48 +00:00
|
|
|
main_sp_name = '- <b>'+ to_xml(prod.seller_id.name) +'</b>\r\n'
|
2011-07-28 09:31:26 +00:00
|
|
|
pricelist = prod.seller_id.property_product_pricelist_purchase
|
|
|
|
price = pricelist_pool.price_get(cr,uid,[pricelist.id],
|
|
|
|
prod.id, number*prod_qtty or 1.0, prod.seller_id.id, {
|
|
|
|
'uom': prod.uom_po_id.id,
|
|
|
|
'date': time.strftime('%Y-%m-%d'),
|
|
|
|
})[pricelist.id]
|
2011-12-07 07:02:10 +00:00
|
|
|
main_sp_price = """<b>"""+rml_obj.formatLang(price)+' '+ (company_currency_symbol)+"""</b>\r\n"""
|
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:
|
2013-12-11 13:41:20 +00:00
|
|
|
if seller_id.name.id == prod.seller_id.id:
|
|
|
|
continue
|
2011-10-19 12:15:49 +00:00
|
|
|
sellers += '- <i>'+ to_xml(seller_id.name.name) +'</i>\r\n'
|
2011-07-28 09:31:26 +00:00
|
|
|
pricelist = seller_id.name.property_product_pricelist_purchase
|
|
|
|
price = pricelist_pool.price_get(cr,uid,[pricelist.id],
|
|
|
|
prod.id, number*prod_qtty or 1.0, seller_id.name.id, {
|
|
|
|
'uom': prod.uom_po_id.id,
|
|
|
|
'date': time.strftime('%Y-%m-%d'),
|
|
|
|
})[pricelist.id]
|
2011-12-07 07:02:10 +00:00
|
|
|
sellers_price += """<i>"""+rml_obj.formatLang(price) +' '+ (company_currency_symbol) +"""</i>\r\n"""
|
2011-11-03 12:56:48 +00:00
|
|
|
xml += """<col para='yes'> """+ prod_name +""" </col>
|
|
|
|
<col para='yes'> """+ main_sp_name + sellers + """ </col>
|
2011-11-03 13:03:55 +00:00
|
|
|
<col f='yes'>"""+ rml_obj.formatLang(prod_qtty) +' '+ product_uom_name +"""</col>
|
2011-12-07 07:02:10 +00:00
|
|
|
<col f='yes'>"""+ rml_obj.formatLang(float(main_strd_price)) +' '+ (company_currency_symbol) +"""</col>
|
2010-09-16 12:05:21 +00:00
|
|
|
<col f='yes'>""" + main_sp_price + sellers_price + """</col>'"""
|
2008-07-22 15:11:28 +00:00
|
|
|
|
|
|
|
xml += '</row>'
|
|
|
|
return xml, sum, sum_strd
|
|
|
|
|
|
|
|
def process_workcenter(wrk):
|
2010-07-23 13:17:30 +00:00
|
|
|
workcenter = workcenter_pool.browse(cr, uid, wrk['workcenter_id'])
|
2010-07-24 09:15:37 +00:00
|
|
|
cost_cycle = wrk['cycle']*workcenter.costs_cycle
|
|
|
|
cost_hour = wrk['hour']*workcenter.costs_hour
|
|
|
|
total = cost_cycle + cost_hour
|
|
|
|
xml = '<row>'
|
2011-11-03 12:56:48 +00:00
|
|
|
xml += "<col para='yes'>" + to_xml(workcenter.name) + '</col>'
|
2008-07-22 15:11:28 +00:00
|
|
|
xml += "<col/>"
|
2011-12-07 07:02:10 +00:00
|
|
|
xml += """<col f='yes'>"""+rml_obj.formatLang(cost_cycle)+' '+ (company_currency_symbol) + """</col>"""
|
|
|
|
xml += """<col f='yes'>"""+rml_obj.formatLang(cost_hour)+' '+ (company_currency_symbol) + """</col>"""
|
|
|
|
xml += """<col f='yes'>"""+rml_obj.formatLang(cost_hour + cost_cycle)+' '+ (company_currency_symbol) + """</col>"""
|
2008-07-22 15:11:28 +00:00
|
|
|
xml += '</row>'
|
2010-08-10 11:35:06 +00:00
|
|
|
|
2010-07-24 09:15:37 +00:00
|
|
|
return xml, total
|
2008-07-22 15:11:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
xml = ''
|
|
|
|
config_start = """
|
|
|
|
<config>
|
2010-09-16 12:05:21 +00:00
|
|
|
<date>""" + to_xml(rml_obj.formatLang(datetime.now().strftime('%Y-%m-%d %H:%M:%S'),date_time=True)) + """</date>
|
2010-09-13 13:28:41 +00:00
|
|
|
<company>%s</company>
|
2008-07-22 15:11:28 +00:00
|
|
|
<PageSize>210.00mm,297.00mm</PageSize>
|
|
|
|
<PageWidth>595.27</PageWidth>
|
|
|
|
<PageHeight>841.88</PageHeight>
|
2010-09-16 12:05:21 +00:00
|
|
|
<tableSize>55.00mm,58.00mm,29.00mm,29.00mm,29.00mm</tableSize>
|
2012-11-01 07:25:11 +00:00
|
|
|
""" % to_xml(user_pool.browse(cr, uid, uid).company_id.name)
|
2008-07-22 15:11:28 +00:00
|
|
|
config_stop = """
|
2014-07-09 11:39:38 +00:00
|
|
|
<report-footer>Generated by Odoo</report-footer>
|
2008-07-22 15:11:28 +00:00
|
|
|
</config>
|
|
|
|
"""
|
2010-08-10 11:35:06 +00:00
|
|
|
|
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>
|
2010-08-20 11:25:24 +00:00
|
|
|
<col t='yes'/>
|
|
|
|
<col t='yes'>%s</col>
|
|
|
|
<col t='yes'>%s</col>
|
|
|
|
<col t='yes'>%s</col>
|
2008-07-22 15:11:28 +00:00
|
|
|
</row>
|
|
|
|
</lines>
|
2010-10-14 07:39:49 +00:00
|
|
|
""" % (_('Work Center name'), _('Cycles Cost'), _('Hourly Cost'),_('Work Cost'))
|
2008-07-22 15:11:28 +00:00
|
|
|
prod_header = """
|
|
|
|
<row>
|
2010-08-20 11:25:24 +00:00
|
|
|
<col>%s</col>
|
|
|
|
<col>%s</col>
|
|
|
|
<col t='yes'>%s</col>
|
|
|
|
<col t='yes'>%s</col>
|
|
|
|
<col t='yes'>%s</col>
|
2008-07-22 15:11:28 +00:00
|
|
|
</row>
|
2012-04-25 08:54:15 +00:00
|
|
|
""" % (_('Components'), _('Components suppliers'), _('Quantity'),_('Cost Price per Unit of Measure'), _('Supplier Price per Unit of Measure'))
|
2008-07-22 15:11:28 +00:00
|
|
|
|
2012-07-11 13:06:15 +00:00
|
|
|
purchase_price_digits = rml_obj.get_digits(dp='Product Price')
|
2010-10-01 13:47:00 +00:00
|
|
|
|
2010-07-23 13:17:30 +00:00
|
|
|
for product in product_pool.browse(cr, uid, ids, context=context):
|
2011-11-03 13:03:55 +00:00
|
|
|
product_uom_name = to_xml(product.uom_id.name)
|
2014-09-26 08:40:55 +00:00
|
|
|
bom_id = bom_pool._bom_find(cr, uid, product_id=product.id, context=context)
|
2010-07-24 09:15:37 +00:00
|
|
|
title = "<title>%s</title>" %(_("Cost Structure"))
|
2011-11-03 12:56:48 +00:00
|
|
|
title += "<title>%s</title>" % (to_xml(product.name))
|
2010-08-20 11:25:24 +00:00
|
|
|
xml += "<lines style='header'>" + title + prod_header + "</lines>"
|
2010-07-24 09:15:37 +00:00
|
|
|
if not bom_id:
|
|
|
|
total_strd = number * product.standard_price
|
|
|
|
total = number * product_pool.price_get(cr, uid, [product.id], 'standard_price')[product.id]
|
|
|
|
xml += """<lines style='lines'><row>
|
|
|
|
<col para='yes'>-</col>
|
|
|
|
<col para='yes'>-</col>
|
|
|
|
<col para='yes'>-</col>
|
|
|
|
<col para='yes'>-</col>
|
|
|
|
<col para='yes'>-</col>
|
|
|
|
</row></lines>"""
|
|
|
|
xml += """<lines style='total'> <row>
|
2011-11-03 13:03:55 +00:00
|
|
|
<col> """ + _('Total Cost of %s %s') % (str(number), product_uom_name) + """: </col>
|
2010-07-24 09:15:37 +00:00
|
|
|
<col/>
|
2010-08-20 11:25:24 +00:00
|
|
|
<col f='yes'/>
|
2011-12-07 07:02:10 +00:00
|
|
|
<col t='yes'>"""+ rml_obj.formatLang(total_strd, digits=purchase_price_digits) +' '+ (company_currency_symbol) + """</col>
|
|
|
|
<col t='yes'>"""+ rml_obj.formatLang(total, digits=purchase_price_digits) +' '+ (company_currency_symbol) + """</col>
|
2010-09-16 12:05:21 +00:00
|
|
|
</row></lines>'"""
|
2010-07-24 09:15:37 +00:00
|
|
|
else:
|
|
|
|
bom = bom_pool.browse(cr, uid, bom_id, context=context)
|
|
|
|
factor = number * product.uom_id.factor / bom.product_uom.factor
|
2014-09-09 17:06:26 +00:00
|
|
|
sub_boms = bom_pool._bom_explode(cr, uid, bom, product, factor / bom.product_qty, context=context)
|
2008-07-22 15:11:28 +00:00
|
|
|
total = 0
|
|
|
|
total_strd = 0
|
2010-07-23 13:17:30 +00:00
|
|
|
parent_bom = {
|
2010-08-20 11:25:24 +00:00
|
|
|
'product_qty': bom.product_qty,
|
|
|
|
'name': bom.product_id.name,
|
|
|
|
'product_uom': bom.product_uom.id,
|
2010-07-23 13:17:30 +00:00
|
|
|
'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-09-16 12:05:21 +00:00
|
|
|
txt, sum, sum_strd = process_bom(sub_bom, company_currency.id)
|
2008-07-22 15:11:28 +00:00
|
|
|
xml_tmp += txt
|
|
|
|
total += sum
|
|
|
|
total_strd += sum_strd
|
2010-08-20 11:25:24 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
xml += "<lines style='lines'>" + xml_tmp + '</lines>'
|
2010-07-24 09:15:37 +00:00
|
|
|
xml += """<lines style='sub_total'> <row>
|
2011-11-03 13:03:55 +00:00
|
|
|
<col> """ + _('Components Cost of %s %s') % (str(number), product_uom_name) + """: </col>
|
2010-07-24 09:15:37 +00:00
|
|
|
<col/>
|
2010-08-20 11:25:24 +00:00
|
|
|
<col t='yes'/>
|
2011-12-07 07:02:10 +00:00
|
|
|
<col t='yes'>"""+ rml_obj.formatLang(total_strd, digits=purchase_price_digits) +' '+ (company_currency_symbol) + """</col>
|
2010-11-10 08:59:07 +00:00
|
|
|
<col t='yes'></col>
|
2010-09-16 12:05:21 +00:00
|
|
|
</row></lines>'"""
|
2010-07-24 09:15:37 +00:00
|
|
|
|
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>'
|
2010-07-24 09:15:37 +00:00
|
|
|
xml += """<lines style='sub_total'> <row>
|
2011-11-03 13:03:55 +00:00
|
|
|
<col> """ + _('Work Cost of %s %s') % (str(number), product_uom_name) +""": </col>
|
2010-07-24 09:15:37 +00:00
|
|
|
<col/>
|
|
|
|
<col/>
|
|
|
|
<col/>
|
2011-12-07 07:02:10 +00:00
|
|
|
<col t='yes'>"""+ rml_obj.formatLang(total2, digits=purchase_price_digits) +' '+ (company_currency_symbol) +"""</col>
|
2010-09-16 12:05:21 +00:00
|
|
|
</row></lines>'"""
|
2010-07-24 09:15:37 +00:00
|
|
|
xml += """<lines style='total'> <row>
|
2011-11-03 13:03:55 +00:00
|
|
|
<col> """ + _('Total Cost of %s %s') % (str(number), product_uom_name) + """: </col>
|
2010-07-24 09:15:37 +00:00
|
|
|
<col/>
|
2010-08-20 11:25:24 +00:00
|
|
|
<col t='yes'/>
|
2011-12-07 07:02:10 +00:00
|
|
|
<col t='yes'>"""+ rml_obj.formatLang(total_strd+total2, digits=purchase_price_digits) +' '+ (company_currency_symbol) + """</col>
|
2010-11-10 08:59:07 +00:00
|
|
|
<col t='yes'></col>
|
2010-09-16 12:05:21 +00:00
|
|
|
</row></lines>'"""
|
2008-07-22 15:11:28 +00:00
|
|
|
|
2010-07-24 09:15:37 +00:00
|
|
|
xml = '<?xml version="1.0" ?><report>' + config_start + config_stop + xml + '</report>'
|
2010-08-20 11:25:24 +00:00
|
|
|
|
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')
|
2011-11-22 08:51:38 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|