~vauxoo/addons-vauxoo/rico_contract_fix_email_and_more_dev_ernesto

« back to all changes in this revision

Viewing changes to mrp_webkit_report_wizard/report/report_webkit_variation_group.mako

[ADD]mrp_webkit_report_wizard Se agregó un wizard para reportear usando webkit, las variaciones en las órdenes de producción, de los productos que se seleccionen en el wizard, en el rango de fecha dado.Lo hace también para sus supproducciones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
    <head>
 
3
        <style type="text/css">
 
4
            ${css}
 
5
        </style>
 
6
    </head>
 
7
    <body>
 
8
        <div class="basic_header">
 
9
            <table class="basic_table">
 
10
                <tr><td style="text-align:center;">${helper.embed_logo_by_name('company_logo',75, 53)|n}</td>
 
11
                <td class="basic_td">
 
12
                    <table class="basic_table">
 
13
                        <tr><td class="basic_td">${_("Company:")} ${company.name |entity}</td></tr>
 
14
                        <tr><td class="basic_td">${_("Address:")} ${company.partner_id.address and company.partner_id.address[0].street or ''|entity}</td></tr>
 
15
                        <tr><td class="basic_td">${_("Phone:")} ${company.partner_id.address and company.partner_id.address[0].phone or ''|entity}</td></tr>
 
16
                        <tr><td class="basic_td">${_("Mail:")} ${company.partner_id.address and company.partner_id.address[0].email or ''|entity}</td></tr>
 
17
                        <tr><td class="basic_td">${_("User:")} ${user.name or ''|entity}</td></tr>
 
18
                    </table>
 
19
                </td></tr>
 
20
            </table>
 
21
        </div>
 
22
        
 
23
        <%
 
24
        wiz_user = this_self.pool.get('res.users').browse(cr, uid, uid, context=context)
 
25
        company_id = context.get('company_id', wiz_user.company_id.id)
 
26
        mrp_obj = this_self.pool.get('mrp.production')
 
27
        product_uom_pool = this_self.pool.get('product.uom')
 
28
        %>
 
29
        
 
30
        <p><h3>${_("Report of product variation group")}</h3></p>
 
31
        ${_("From:")} ${formatLang(data['form'].get('date_start'), date=True)|entity} to: ${formatLang(data['form'].get('date_finished'), date=True)|entity}
 
32
        <br/>${_("For products:")}<br/>
 
33
            %for line in data['form'].get('product_ids'):
 
34
                <%product_data = this_self.pool.get('product.product').browse(cr, uid, line, context)%>
 
35
                ${product_data.name_template or ''|entity}
 
36
                <br>
 
37
            %endfor
 
38
        
 
39
        <%
 
40
        production_ids = mrp_obj.search(cr, uid , [('state', 'not in', ('draft', 'cancel')), \
 
41
            ('product_id', 'in', data['form']['product_ids']), ('date_planned', '>', data['form']['date_start']), \
 
42
            ('date_planned', '<', data['form']['date_finished']), ('company_id', '=', company_id)])
 
43
        cr.execute("""
 
44
SELECT mrp_variation_finished_product.product_id, mrp_production.name ,standard_price * quantity AS mul, name_template FROM mrp_variation_finished_product
 
45
INNER JOIN mrp_production
 
46
ON mrp_production.id = mrp_variation_finished_product.production_id
 
47
INNER JOIN product_product
 
48
ON product_product.id = mrp_variation_finished_product.product_id
 
49
INNER JOIN product_template
 
50
ON product_template.id = product_product.product_tmpl_id
 
51
WHERE production_id IN 
 
52
%s
 
53
ORDER BY mul
 
54
        """, (tuple(production_ids),))
 
55
 
 
56
        records = cr.fetchall()
 
57
        %>
 
58
        <%#Obtener los totales
 
59
        mrp_data = mrp_obj.browse(cr, uid, production_ids, context=context)
 
60
        no_children_flag = False
 
61
        %>
 
62
        <p><h4>${_("Productions matching your query:")}</h4></p>
 
63
        <table class="basic_table">
 
64
            <tr>
 
65
                %for line in mrp_data:
 
66
                    %if line.subproduction_ids:
 
67
                        <td class="basic_td">
 
68
                    %else:
 
69
                        <td class="basic_td" style="color:red">
 
70
                        <%no_children_flag = True%>
 
71
                    %endif
 
72
                    % if loop is UNDEFINED:
 
73
                        ${line.name or ''|entity}
 
74
                    % else:
 
75
                        ${loop.index+1 or ''|entity} - ${line.name or ''|entity}</td>
 
76
                        %if ((loop.index+1) %5 ==0):
 
77
                            </tr>
 
78
                            <tr>
 
79
                        %endif
 
80
                    % endif
 
81
                %endfor
 
82
            </tr>
 
83
        </table>
 
84
        %if (no_children_flag == True):
 
85
            <p class="basic_td" style="color:red">${_("Productions marked in red don't have a subproduction children associated with them")}</p>
 
86
        %endif
 
87
        <br/>
 
88
        
 
89
        %if data['query_dict']:
 
90
            <table class="basic_table">
 
91
                <tr>
 
92
                    <td class="basic_td">${_("Variation in consumed products")}</td>
 
93
                    <td class="basic_td"> &nbsp; </td>
 
94
                    <td class="basic_td"> &nbsp; </td>
 
95
                    <td class="basic_td"> &nbsp; </td>
 
96
                </tr>
 
97
 
 
98
                <tr>
 
99
                    <th class="basic_th">${_("Reference:")}</th>
 
100
                    <th class="basic_th">${_("Quantity:")}</th>
 
101
                    <th class="basic_th">${_("Unit of M:")}</th>
 
102
                    <th class="basic_th">${_("Variation cost:")}</th>
 
103
                </tr>
 
104
                <%row_count=1%>
 
105
                <%total_consumed_cost=0%>
 
106
                %for line in data['query_dict']:
 
107
                    %if (row_count%2==0):
 
108
                        <tr  class="nonrow">
 
109
                    %else:
 
110
                        <tr>
 
111
                    %endif
 
112
                        <td class="basic_td"> ${line[0] or ''|entity}</td>
 
113
                        <td class="number_td"> ${ formatLang(line[1]) }</td>
 
114
                        <td class="basic_td"> ${line[2] or ''|entity}</td>
 
115
                        <td class="number_td"> $ ${ formatLang(line[3]) }</td>
 
116
                    </tr>
 
117
                <%total_consumed_cost+=line[3]%>
 
118
                <%row_count+=1%>
 
119
                %endfor
 
120
                <tr>
 
121
                    <td class="lastrow"></td>
 
122
                    <td class="lastrow">${_("Total:")}</td>
 
123
                    <td class="lastrow"></td>
 
124
                    <td class="lastrow">$ ${ formatLang(total_consumed_cost) }</td>
 
125
                </tr>
 
126
            </table>
 
127
        %else:
 
128
            <p>${_("The consulted productions don't have variations.")}</p>
 
129
        %endif
 
130
 
 
131
        <br/>
 
132
        %if data['finished_dict']:
 
133
            <table class="basic_table">
 
134
                <tr>
 
135
                    <td class="basic_td">${_("Variation in finished products / details")}</td>
 
136
                    <th class="basic_th">${_("Production name")} </th>
 
137
                    <th class="basic_th">${_("Variation price")} </th>
 
138
                    <th class="basic_th">${_("Not consumed")} </th>
 
139
                </tr>
 
140
                
 
141
                <%row_count=1%>
 
142
                <%mrp_data = mrp_obj.browse(cr, uid, production_ids, this_context)%>
 
143
                %for production in mrp_data:
 
144
                    <%
 
145
                    total_produced = 0
 
146
                    if production.move_created_ids2:
 
147
                        for finished in production.move_created_ids2:
 
148
                            if (finished.product_id.id == production.product_id.id and finished.state in ('done')):
 
149
                                total_produced += product_uom_pool._compute_qty(cr, uid, finished.product_uom.id, finished.product_qty, to_uom_id=production.product_uom.id)
 
150
                    for subprods in production.subproduction_ids:
 
151
                        if subprods.move_lines2:
 
152
                            for consumed in subprods.move_lines2:
 
153
                                if (consumed.product_id.id == production.product_id.id and consumed.state in ('done')):
 
154
                                    total_produced -= product_uom_pool._compute_qty(cr, uid, consumed.product_uom.id, consumed.product_qty, to_uom_id=production.product_uom.id)
 
155
                    %>
 
156
                    %for variation in production.variation_finished_product_ids:
 
157
                        %if variation.quantity:
 
158
                            %if (row_count%2==0):
 
159
                                <tr  class="nonrow">
 
160
                            %else:
 
161
                                <tr>
 
162
                            %endif
 
163
                                <td class="basic_td">
 
164
                                    ${production.product_id.name or ''|entity} 
 
165
                                    %if (production.product_id.name != variation.product_id.name): 
 
166
                                        [${variation.product_id.name or ''|entity}] 
 
167
                                    %endif
 
168
                                </td>
 
169
                                <td class="basic_td"> ${production.name or ''|entity} </td>
 
170
                                <td class="number_td"> $ ${ formatLang(variation.cost_variation) } </td>
 
171
                                <td class="number_td"> ${ formatLang(total_produced) } ${production.product_uom.name or ''|entity}</td>
 
172
                            </tr>
 
173
                            <%row_count+=1%>
 
174
                        %endif
 
175
                    %endfor
 
176
                %endfor
 
177
                <tr>
 
178
                    <hr>
 
179
                </tr>
 
180
                <tr>
 
181
                    <th class="basic_th">${_("Reference:")}</th>
 
182
                    <th class="basic_th">${_("Quantity:")}</th>
 
183
                    <th class="basic_th">${_("Unit of M:")}</th>
 
184
                    <th class="basic_th">${_("Variation cost:")}</th>
 
185
                </tr>
 
186
                <%row_count=1%>
 
187
                <%total_finished_cost=0%>
 
188
                <%total_finished_qty=0%>
 
189
                %for line in data['finished_dict']:
 
190
                    %if (row_count%2==0):
 
191
                        <tr  class="nonrow">
 
192
                    %else:
 
193
                        <tr>
 
194
                    %endif
 
195
                        <td class="basic_td"> ${line[0] or ''|entity}</td>
 
196
                        <td class="number_td"> ${ formatLang(line[1]) }</td>
 
197
                        <td class="basic_td"> ${line[2] or ''|entity}</td>
 
198
                        <td class="number_td"> $ ${ formatLang(line[3]) }</td>
 
199
                    </tr>
 
200
                    <%total_finished_cost+=line[3]%>
 
201
                    <%total_finished_qty+=line[1]%>
 
202
                    <%row_count+=1%>
 
203
                %endfor
 
204
                
 
205
                <%#Obtener los totales
 
206
                total_produced = 0
 
207
                total_res_dict = {}
 
208
                for production in mrp_data:
 
209
                    total_res_dict.setdefault(production.product_id.name, [0, production.product_id.uom_id.name])
 
210
                    total_produced = product_uom_pool._compute_qty(cr, uid, production.product_uom.id, production.product_qty, to_uom_id=production.product_id.uom_id.id)
 
211
                    total_res_dict[production.product_id.name][0] += total_produced
 
212
                total_produced = 0
 
213
                %>
 
214
 
 
215
                %for key, value in dict.items(total_res_dict):
 
216
                    <tr>
 
217
                        <td class="lastrow" style="text-align:left">${_("Product:")} ${key or ''|entity}</td>
 
218
                        <td class="lastrow">${_("Total planned to produce:")}</td>
 
219
                        <td class="lastrow">${ formatLang(value[0]) } ${value[1] or ''|entity}</td>
 
220
                        %if (len(total_res_dict) == 1):
 
221
                            <td class="lastrow">${_("Really produced:")} ${ formatLang(value[0]+total_finished_qty) } ${value[1] or ''|entity}</td>
 
222
                        %endif
 
223
                    </tr>
 
224
                    <%total_produced += value[0]%>
 
225
                %endfor
 
226
                <tr>
 
227
                    <td class="lastrow" style="text-align:left">${_("Production eficiency:")} ${ formatLang(100 + (total_finished_qty*100/total_produced)) } %</td>
 
228
                    <td class="lastrow">${_("Total variation cost")}</td>
 
229
                    <td class="lastrow">$ ${ formatLang(total_finished_cost) }</td>
 
230
                </tr>
 
231
            </table>
 
232
        %endif
 
233
        
 
234
        
 
235
        <br/>
 
236
        %if data['child_consumed']:
 
237
            <hr/>
 
238
            <table class="basic_table">
 
239
                <tr>
 
240
                    <td class="basic_td">${_("Variation in children consumed products")}</td>
 
241
                    <td class="basic_td"> &nbsp; </td>
 
242
                    <td class="basic_td"> &nbsp; </td>
 
243
                    <td class="basic_td"> &nbsp; </td>
 
244
                </tr>
 
245
                <tr>
 
246
                    <th class="basic_th">${_("Reference:")}</th>
 
247
                    <th class="basic_th">${_("Quantity:")}</th>
 
248
                    <th class="basic_th">${_("Unit of M:")}</th>
 
249
                    <th class="basic_th">${_("Variation cost:")}</th>
 
250
                </tr>
 
251
                <%row_count=1%>
 
252
                <%total_child_consumed_cost=0%>
 
253
                %for line in data['child_consumed']:
 
254
                    %if (row_count%2==0):
 
255
                        <tr  class="nonrow">
 
256
                    %else:
 
257
                        <tr>
 
258
                    %endif
 
259
                        <td class="basic_td"> ${line[0] or ''|entity}</td>
 
260
                        <td class="number_td"> ${ formatLang(line[1]) }</td>
 
261
                        <td class="basic_td"> ${line[2] or ''|entity}</td>
 
262
                        <td class="number_td"> $ ${ formatLang(line[3]) }</td>
 
263
                    </tr>
 
264
                <%total_child_consumed_cost+=line[3]%>
 
265
                <%row_count+=1%>
 
266
                %endfor
 
267
                <tr>
 
268
                    <td class="lastrow"></td>
 
269
                    <td class="lastrow">${_("Total:")}</td>
 
270
                    <td class="lastrow"></td>
 
271
                    <td class="lastrow">$ ${ formatLang(total_child_consumed_cost) }</td>
 
272
                </tr>
 
273
            </table>
 
274
        %endif
 
275
        
 
276
        <br/>
 
277
        %if data['child_finished']:
 
278
            <table class="basic_table">
 
279
                <tr>
 
280
                    <td class="basic_td">${_("Variation in children finished products")}</td>
 
281
                    <td class="basic_td"> &nbsp; </td>
 
282
                    <td class="basic_td"> &nbsp; </td>
 
283
                    <td class="basic_td"> &nbsp; </td>
 
284
                </tr>
 
285
                <tr>
 
286
                    <th class="basic_th">${_("Reference:")}</th>
 
287
                    <th class="basic_th">${_("Quantity:")}</th>
 
288
                    <th class="basic_th">${_("Unit of M:")}</th>
 
289
                    <th class="basic_th">${_("Variation cost:")}</th>
 
290
                </tr>
 
291
                <%row_count=1%>
 
292
                <%total_child_finished_cost=0%>
 
293
                %for line in data['child_finished']:
 
294
                    %if (row_count%2==0):
 
295
                        <tr  class="nonrow">
 
296
                    %else:
 
297
                        <tr>
 
298
                    %endif
 
299
                        <td class="basic_td"> ${line[0] or ''|entity}</td>
 
300
                        <td class="number_td"> ${ formatLang(line[1]) }</td>
 
301
                        <td class="basic_td"> ${line[2] or ''|entity}</td>
 
302
                        <td class="number_td"> $ ${ formatLang(line[3]) }</td>
 
303
                    </tr>
 
304
                <%total_child_finished_cost+=line[3]%>
 
305
                <%row_count+=1%>
 
306
                %endfor
 
307
                <tr>
 
308
                    <td class="lastrow"></td>
 
309
                    <td class="lastrow">${_("Total:")}</td>
 
310
                    <td class="lastrow"></td>
 
311
                    <td class="lastrow">$ ${ formatLang(total_child_finished_cost) }</td>
 
312
                </tr>
 
313
            </table>
 
314
        %endif
 
315
        
 
316
        <br/>
 
317
        <p style="page-break-after:always"></p>
 
318
     </body>
 
319
</html>
 
 
b'\\ No newline at end of file'