[mrp]:Product Cost Structure:use formatLang function for changes date and amount according to lang.

bzr revid: apa@tinyerp.com-20100916120521-215fcw96iz7f1zqt
This commit is contained in:
apa-tiny 2010-09-16 17:35:21 +05:30
parent 05898a20d4
commit 96b3dc9cb7
1 changed files with 37 additions and 45 deletions

View File

@ -23,7 +23,9 @@ import ir
import pooler
from report.interface import report_rml
from report.interface import toxml
from tools import to_xml
from report import report_sxw
from datetime import datetime
from tools.translate import _
@ -38,6 +40,9 @@ class report_custom(report_rml):
workcenter_pool = pool.get('mrp.workcenter')
user_pool = pool.get('res.users')
bom_pool = pool.get('mrp.bom')
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
def process_bom(bom, currency_id, factor=1):
xml = '<row>'
sum = 0
@ -55,7 +60,7 @@ class report_custom(report_rml):
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 = '<b>%.2f</b>\r\n' %(price)
main_sp_price = """<b>"""+rml_obj.formatLang(price)+' '+ company_currency.symbol+"""</b>\r\n"""
sum += prod_qtty*price
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'
@ -64,13 +69,12 @@ class report_custom(report_rml):
sellers += '- <i>'+ seller_id.name.name +'</i>\r\n'
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 += """<i>%.2f</i>\r\n"""%(price)
xml += """<col para='yes'> %s </col>
<col para='yes'> %s </col>
<col f='yes'>%.2f</col>
<col f='yes'>%s</col>
<col f='yes'>%.2f</col>
<col f='yes'>%s</col>'"""%(prod_name,main_sp_name + sellers ,prod_qtty, product_uom.name,float(main_strd_price),main_sp_price + sellers_price)
sellers_price += """<i>"""+rml_obj.formatLang(price) +' '+ company_currency.symbol +"""</i>\r\n"""
xml += """<col para='yes'> """+ prod_name +""" </col>
<col para='yes'> """+ main_sp_name + sellers + """ </col>
<col f='yes'>"""+ rml_obj.formatLang(prod_qtty) +' '+ product_uom.name +"""</col>
<col f='yes'>"""+ rml_obj.formatLang(float(main_strd_price)) +' '+ company_currency.symbol +"""</col>
<col f='yes'>""" + main_sp_price + sellers_price + """</col>'"""
xml += '</row>'
return xml, sum, sum_strd
@ -83,10 +87,9 @@ class report_custom(report_rml):
xml = '<row>'
xml += "<col para='yes'>" + workcenter.name + '</col>'
xml += "<col/>"
xml += "<col/>"
xml += """<col f='yes'>%.2f</col>"""%(cost_cycle)
xml += """<col f='yes'>%.2f</col>"""%(cost_hour)
xml += """<col f='yes'>%.2f</col>"""%(cost_hour + cost_cycle)
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>"""
xml += '</row>'
return xml, total
@ -95,13 +98,13 @@ class report_custom(report_rml):
xml = ''
config_start = """
<config>
<date>%s</date>
<date>""" + to_xml(rml_obj.formatLang(datetime.now().strftime('%Y-%m-%d %H:%M:%S'),date_time=True)) + """</date>
<company>%s</company>
<PageSize>210.00mm,297.00mm</PageSize>
<PageWidth>595.27</PageWidth>
<PageHeight>841.88</PageHeight>
<tableSize>55.00mm,55.00mm, 20.00mm, 22.00mm, 22.00mm, 25.00mm</tableSize>
""" % (time.strftime('%m/%d/%Y %H:%M'),user_pool.browse(cr, uid, uid).company_id.name)
<tableSize>55.00mm,58.00mm,29.00mm,29.00mm,29.00mm</tableSize>
""" % (user_pool.browse(cr, uid, uid).company_id.name)
config_stop = """
<report-footer>Generated by OpenERP</report-footer>
</config>
@ -111,14 +114,13 @@ class report_custom(report_rml):
<lines style='header'>
<row>
<col>%s</col>
<col/>
<col t='yes'/>
<col t='yes'>%s</col>
<col t='yes'>%s</col>
<col t='yes'>%s</col>
</row>
</lines>
""" % (_('Work Center name'), _('Cycles Cost'), _('Hourly Cost'),_('Work Cost'))
""" % (_('Work Center name'), _('Cycles Cost')+'('+company_currency.code+')', _('Hourly Cost')+'('+company_currency.code+')',_('Work Cost')+'('+company_currency.code+')')
prod_header = """
<row>
<col>%s</col>
@ -126,11 +128,9 @@ class report_custom(report_rml):
<col t='yes'>%s</col>
<col t='yes'>%s</col>
<col t='yes'>%s</col>
<col t='yes'>%s</col>
</row>
""" % (_('Component'), _('Component suppliers'), _('Quantity'), _('Uom'), _('Cost Price per Uom'), _('Supplier Price per Uom'))
""" % (_('Component'), _('Component suppliers'), _('Quantity'),_('Cost Price per Uom')+'('+company_currency.code+')', _('Supplier Price per Uom')+'('+company_currency.code+')')
company_currency = user_pool.browse(cr, uid, uid).company_id.currency_id.id
for product in product_pool.browse(cr, uid, ids, context=context):
bom_id = bom_pool._bom_find(cr, uid, product.id, product.uom_id.id)
title = "<title>%s</title>" %(_("Cost Structure"))
@ -145,16 +145,14 @@ class report_custom(report_rml):
<col para='yes'>-</col>
<col para='yes'>-</col>
<col para='yes'>-</col>
<col para='yes'>-</col>
</row></lines>"""
xml += """<lines style='total'> <row>
<col>%s %s %s %s : </col>
<col/>
<col> """ + _('Total Cost ') + _('of ') + str(number) +' '+ product.uom_id.name +'('+company_currency.code+')'+ """: </col>
<col/>
<col f='yes'/>
<col f='yes'>%.2f</col>
<col f='yes'>%.2f</col>
</row></lines>'"""%(_('Total Cost'), _('of'), str(number), product.uom_id.name, total_strd, total)
<col f='yes'>"""+ rml_obj.formatLang(total_strd) +' '+ company_currency.symbol + """</col>
<col f='yes'>"""+ rml_obj.formatLang(total) +' '+ company_currency.symbol + """</col>
</row></lines>'"""
else:
bom = bom_pool.browse(cr, uid, bom_id, context=context)
factor = number * product.uom_id.factor / bom.product_uom.factor
@ -169,20 +167,19 @@ class report_custom(report_rml):
}
xml_tmp = ''
for sub_bom in (sub_boms and sub_boms[0]) or [parent_bom]:
txt, sum, sum_strd = process_bom(sub_bom, company_currency)
txt, sum, sum_strd = process_bom(sub_bom, company_currency.id)
xml_tmp += txt
total += sum
total_strd += sum_strd
xml += "<lines style='lines'>" + xml_tmp + '</lines>'
xml += """<lines style='sub_total'> <row>
<col>%s %s %s %s : </col>
<col/>
<col> """ + _('Cost ') + _('of ') + str(number) +' '+ product.uom_id.name +'(' + company_currency.code +')'+ """: </col>
<col/>
<col t='yes'/>
<col t='yes'>%.2f</col>
<col t='yes'>%.2f</col>
</row></lines>'"""%(_('Cost'), _('of'), str(number), product.uom_id.name, total_strd, total)
<col t='yes'>"""+ rml_obj.formatLang(total_strd) +' '+ company_currency.symbol + """</col>
<col t='yes'>"""+ rml_obj.formatLang(total) +' '+ company_currency.symbol + """</col>
</row></lines>'"""
total2 = 0
xml_tmp = ''
@ -194,27 +191,22 @@ class report_custom(report_rml):
xml += workcenter_header
xml += "<lines style='lines'>" + xml_tmp + '</lines>'
xml += """<lines style='sub_total'> <row>
<col>%s %s %s %s : </col>
<col> """ + _('Work Cost ') + _('of ') + str(number) +' '+ product.uom_id.name +'('+company_currency.code+')'+""": </col>
<col/>
<col/>
<col/>
<col/>
<col t='yes'>%.2f</col>
</row></lines>'"""%(_('Work Cost'), _('of'), str(number), product.uom_id.name, total2)
<col t='yes'>"""+ rml_obj.formatLang(total2) +' '+ company_currency.symbol +"""</col>
</row></lines>'"""
xml += """<lines style='total'> <row>
<col>%s %s %s %s : </col>
<col/>
<col> """ + _('Total Cost ') + _('of ') + str(number) +' '+ product.uom_id.name +'('+company_currency.code+')'+ """: </col>
<col/>
<col t='yes'/>
<col t='yes'>%.2f</col>
<col t='yes'>%.2f</col>
</row></lines>'"""%(_('Total Cost'), _('of'), str(number), product.uom_id.name, total_strd+total2, total+total2)
<col t='yes'>"""+ rml_obj.formatLang(total_strd+total2) +' '+ company_currency.symbol + """</col>
<col t='yes'>"""+ rml_obj.formatLang(total+total2) +' '+ company_currency.symbol + """</col>
</row></lines>'"""
xml = '<?xml version="1.0" ?><report>' + config_start + config_stop + xml + '</report>'
return xml
report_custom('report.product.price', 'product.product', '', 'addons/mrp/report/price.xsl')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: