Improvement in the english words in different modules
[odoo/odoo.git] / addons / mrp / report / price.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 import ir
23 import pooler
24 from report.interface import report_rml
25 from report.interface import toxml
26
27 from tools.translate import _
28
29
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
34
35         def process_bom(bom, currency_id):
36             xml = '<row>'
37             sum = 0
38             sum_strd = 0
39             prod = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, bom['product_id'])
40
41             prod_name = bom['name']
42             prod_qtty = bom['product_qty']
43             prod_uom = prod.uom_id.name
44             level = 1
45             main_sp_price = ''
46             main_sp_name = ''
47             main_strd_price = ''
48             main_strd_price = ''
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
52                 if pricelist_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)
56                 else:
57                     price = 0
58                 main_sp_price = '%.2f' % price + '\r\n'
59                 sum += prod_qtty*price
60
61             main_strd_price = '%.2f' % prod.standard_price + '\r\n'
62             sum_strd = prod_qtty*prod.standard_price
63
64             sellers = ''
65             sellers_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
69                 if pricelist_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)
73                 else:
74                     price = 0
75                 sellers_price += '%.2f' % price + '\r\n'
76
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>'
83
84
85             xml += '</row>'
86             return xml, sum, sum_strd
87
88         def process_workcenter(wrk):
89             xml = '<row>'
90
91             workcenter = pooler.get_pool(cr.dbname).get('mrp.workcenter').browse(cr, uid, wrk['workcenter_id'])
92
93             xml += "<col para='yes'>" + wrk['name'] + '</col>'
94             xml += "<col para='yes'>" +  '</col>'
95             xml += "<col para='no'>" + '</col>'
96             xml += "<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>'
99
100
101             xml += '</row>'
102             return xml, wrk['cycle']*workcenter.costs_cycle+wrk['hour']*workcenter.costs_hour
103
104
105         xml = ''
106         config_start = """
107         <config>
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>
113             """
114         config_stop = """
115             <report-footer>Generated by Open ERP</report-footer>
116         </config>
117         """
118         header = """
119             <header>
120             <field>%s</field>
121             <field>%s</field>
122             <field>%s</field>
123             <field>%s</field>
124             <field>%s</field>
125             <field>%s</field>
126             </header>
127             """ % (_('Product name'), _('Product supplier'), _('Product quantity'), _('Product uom'), _('Product Standard Price'), _('Unit Product Price'))
128         workcenter_header = """
129             <lines style='header'>
130                 <row>
131                     <col>%s</col>
132                     <col/>
133                     <col/>
134                     <col/>
135                     <col>%s</col>
136                     <col>%s</col>
137                 </row>
138             </lines>
139         """ % (_('Workcenter name'), _('Cycles Cost'), _('Total hourly costs'))
140         prod_header = """
141             <lines style='header'>
142                 <row>
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>
149                 </row>
150             </lines>
151         """ % (_('Product name'), _('Product supplier'), _('Product Quantity'), _('Product uom'), _('Product Standard Price'), _('Unit Product Price'))
152
153         company_currency = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid).company_id.currency_id.id
154         first = True
155         for prod_id in ids:
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)
158
159             for bom_id in bom_ids:
160                 bom = pooler.get_pool(cr.dbname).get('mrp.bom').browse(cr, uid, bom_id)
161
162                 sub_boms = pooler.get_pool(cr.dbname).get('mrp.bom')._bom_explode(cr, uid, bom, number, [])
163                 total = 0
164                 total_strd = 0
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}
166                 xml_tmp = ''
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)
169                     xml_tmp +=  txt
170                     total += sum
171                     total_strd += sum_strd
172                 if not first:
173                     xml += prod_header
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>'
176                 total2 = 0
177                 xml_tmp = ''
178                 for wrk in (sub_boms and sub_boms[1]):
179                     txt, sum = process_workcenter(wrk)
180                     xml_tmp += txt
181                     total2 += sum
182                 if xml_tmp:
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>'
187
188                 first = False
189
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>'
191
192         return xml
193
194 report_custom('report.product.price', 'product.product', '', 'addons/mrp/report/price.xsl')
195
196 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
197