Merge lp:~vauxoo/addons-vauxoo/addons-vauxoo-mrp_consume_produce-dev-julio into lp:addons-vauxoo

Proposed by Julio Serna-http://www.vauxoo.com
Status: Merged
Merged at revision: 453
Proposed branch: lp:~vauxoo/addons-vauxoo/addons-vauxoo-mrp_consume_produce-dev-julio
Merge into: lp:addons-vauxoo
Diff against target: 509 lines (+467/-0)
8 files modified
mrp_consume_produce/__init__.py (+27/-0)
mrp_consume_produce/__openerp__.py (+48/-0)
mrp_consume_produce/mrp.py (+75/-0)
mrp_consume_produce/mrp_consume_produce_view.xml (+43/-0)
mrp_consume_produce/patch/stock.patch (+31/-0)
mrp_consume_produce/wizard/__init__.py (+26/-0)
mrp_consume_produce/wizard/mrp_consume_produce.py (+115/-0)
mrp_consume_produce/wizard/wizard_view.xml (+102/-0)
To merge this branch: bzr merge lp:~vauxoo/addons-vauxoo/addons-vauxoo-mrp_consume_produce-dev-julio
Reviewer Review Type Date Requested Status
Gabriela Quilarque Pending
Moisés López - http://www.vauxoo.com Pending
Review via email: mp+124533@code.launchpad.net

Description of the change

agrega dos wizard para consumos y productos finalizados

To post a comment you must log in.
456. By Julio Serna-http://www.vauxoo.com

[REF][mrp_consume_produce] changed position button of finished production

457. By Julio Serna-http://www.vauxoo.com

[IMP][mrp_consume_produce] added context with values of uom convert

458. By Julio Serna-http://www.vauxoo.com

[ADD][mrp_consume_produce] added patch to action_consume

459. By Julio Serna-http://www.vauxoo.com

[REF][mrp_consume_produce] modfied description __openerp__.py

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'mrp_consume_produce'
2=== added file 'mrp_consume_produce/__init__.py'
3--- mrp_consume_produce/__init__.py 1970-01-01 00:00:00 +0000
4+++ mrp_consume_produce/__init__.py 2012-09-17 21:54:24 +0000
5@@ -0,0 +1,27 @@
6+# -*- encoding: utf-8 -*-
7+###########################################################################
8+# Module Writen to OpenERP, Open Source Management Solution
9+#
10+# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
11+# All Rights Reserved.
12+# info@vauxoo.com
13+############################################################################
14+# Coded by: julio (julio@vauxoo.com)
15+############################################################################
16+#
17+# This program is free software: you can redistribute it and/or modify
18+# it under the terms of the GNU Affero General Public License as
19+# published by the Free Software Foundation, either version 3 of the
20+# License, or (at your option) any later version.
21+#
22+# This program is distributed in the hope that it will be useful,
23+# but WITHOUT ANY WARRANTY; without even the implied warranty of
24+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+# GNU Affero General Public License for more details.
26+#
27+# You should have received a copy of the GNU Affero General Public License
28+# along with this program. If not, see <http://www.gnu.org/licenses/>.
29+#
30+##############################################################################
31+import wizard
32+import mrp
33
34=== added file 'mrp_consume_produce/__openerp__.py'
35--- mrp_consume_produce/__openerp__.py 1970-01-01 00:00:00 +0000
36+++ mrp_consume_produce/__openerp__.py 2012-09-17 21:54:24 +0000
37@@ -0,0 +1,48 @@
38+# -*- encoding: utf-8 -*-
39+###########################################################################
40+# Module Writen to OpenERP, Open Source Management Solution
41+#
42+# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
43+# All Rights Reserved.
44+# info@vauxoo.com
45+############################################################################
46+# Coded by: julio (julio@vauxoo.com)
47+############################################################################
48+#
49+# This program is free software: you can redistribute it and/or modify
50+# it under the terms of the GNU Affero General Public License as
51+# published by the Free Software Foundation, either version 3 of the
52+# License, or (at your option) any later version.
53+#
54+# This program is distributed in the hope that it will be useful,
55+# but WITHOUT ANY WARRANTY; without even the implied warranty of
56+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57+# GNU Affero General Public License for more details.
58+#
59+# You should have received a copy of the GNU Affero General Public License
60+# along with this program. If not, see <http://www.gnu.org/licenses/>.
61+#
62+##############################################################################
63+
64+{
65+ "name": "MRP Consume Produce",
66+ "version": "1.1",
67+ "author" : "Vauxoo",
68+ "category": "Generic Modules/Production",
69+ "website" : "http://www.vauxoo.com/",
70+ "description": """ Add wizard to consume and produce.It will be necesary to apply the patch
71+ patch/stock.patch located in this module ( useatch -b stock.py stock.patch )
72+ """,
73+ 'depends': ['mrp'],
74+ 'init_xml': [],
75+ 'update_xml': [
76+ 'wizard/wizard_view.xml',
77+ 'mrp_consume_produce_view.xml',
78+ ],
79+ 'demo_xml': [],
80+ 'test': [],
81+ 'installable': True,
82+ 'active': False,
83+}
84+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
85+
86
87=== added file 'mrp_consume_produce/mrp.py'
88--- mrp_consume_produce/mrp.py 1970-01-01 00:00:00 +0000
89+++ mrp_consume_produce/mrp.py 2012-09-17 21:54:24 +0000
90@@ -0,0 +1,75 @@
91+# -*- encoding: utf-8 -*-
92+###########################################################################
93+# Module Writen to OpenERP, Open Source Management Solution
94+#
95+# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
96+# All Rights Reserved.
97+# info@vauxoo.com
98+############################################################################
99+# Coded by: julio (julio@vauxoo.com)
100+############################################################################
101+#
102+# This program is free software: you can redistribute it and/or modify
103+# it under the terms of the GNU Affero General Public License as
104+# published by the Free Software Foundation, either version 3 of the
105+# License, or (at your option) any later version.
106+#
107+# This program is distributed in the hope that it will be useful,
108+# but WITHOUT ANY WARRANTY; without even the implied warranty of
109+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
110+# GNU Affero General Public License for more details.
111+#
112+# You should have received a copy of the GNU Affero General Public License
113+# along with this program. If not, see <http://www.gnu.org/licenses/>.
114+#
115+##############################################################################
116+from osv import osv,fields
117+from tools.translate import _
118+import netsvc
119+
120+class mrp_production(osv.osv):
121+ _inherit='mrp.production'
122+
123+ def _check_boolean(self,cr,uid,ids,field_name,args,context={}):
124+ res = {}
125+ for production in self.browse(cr,uid,ids,context=context):
126+ moves = [move for move in production.move_lines]
127+ if len(moves)==0 and production.state<>'draft':
128+ res[production.id]=True
129+ else:
130+ res[production.id]=False
131+ return res
132+
133+ def _check_len_move(self,cr,uid,ids,field_name,args,context={}):
134+ res = {}
135+ for production in self.browse(cr,uid,ids,context=context):
136+ moves = [move for move in production.move_lines2 if move.state=='done']
137+ res[production.id]=len(moves)
138+ return res
139+
140+ _columns = {
141+ 'consumed' : fields.function(_check_boolean, string='consumed?', type='boolean', help="indicates if product to consume have been consumed or canceled"),
142+ 'len_move' : fields.function(_check_len_move, string='moves', type='float')
143+ }
144+
145+ def action_finished_consume(self,cr,uid,ids,context={}):
146+ stock_move = self.pool.get('stock.move')
147+ for production in self.browse(cr,uid,ids,context=context):
148+ for moves in production.move_lines:
149+ stock_move.write(cr,uid,[moves.id],{'state':'cancel'})
150+ return True
151+
152+ def action_finish(self,cr,uid,ids,context={}):
153+ stock_move = self.pool.get('stock.move')
154+ for production in self.browse(cr,uid,ids,context=context):
155+ for moves in production.move_created_ids:
156+ stock_move.write(cr,uid,[moves.id],{'state':'cancel'})
157+ try:
158+ wf_service = netsvc.LocalService("workflow")
159+ wf_service.trg_validate(uid, 'mrp.production', production.id, 'button_produce_done', cr)
160+ except:
161+ pass
162+ return True
163+
164+mrp_production()
165+
166
167=== added file 'mrp_consume_produce/mrp_consume_produce_view.xml'
168--- mrp_consume_produce/mrp_consume_produce_view.xml 1970-01-01 00:00:00 +0000
169+++ mrp_consume_produce/mrp_consume_produce_view.xml 2012-09-17 21:54:24 +0000
170@@ -0,0 +1,43 @@
171+<?xml version="1.0" encoding="utf-8"?>
172+<openerp>
173+ <data>
174+
175+ <record model="ir.ui.view" id="view_mrp_production_inherit2">
176+ <field name="name">view.mrp.production.inherit2</field>
177+ <field name="model">mrp.production</field>
178+ <field name="inherit_id" ref="mrp.mrp_production_form_view" />
179+ <field name="type">form</field>
180+ <field name="arch" type="xml">
181+ <xpath expr="/form/notebook/page[@string='Consumed Products']/group/button[@name='%(mrp.act_mrp_product_produce)d']" position="replace">
182+ <button name="%(mrp.act_mrp_product_produce)d" states="in_production" string="Produce" icon="gtk-ok" type="action" invisible="1"/>
183+ </xpath>
184+
185+ <xpath expr="/form/notebook/page[@string='Consumed Products']/group/button[@name='%(mrp.act_mrp_product_produce)d']" position="after">
186+ <button name="%(create_consume_action)d" states="in_production" string="Consumed" icon="gtk-ok" type="action" attrs="{'invisible': ['|',('consumed','=',True),('state','!=','in_production')]}"/>
187+ </xpath>
188+
189+ <xpath expr="/form/group/field[@name='origin']" position="after">
190+ <field name="consumed"/>
191+ </xpath>
192+
193+ <xpath expr="/form/notebook/page[@string='Consumed Products']/group/button[@name='%(create_consume_action)d']" position="after">
194+ <button name="action_finished_consume" string="Finished Consumed" icon="gtk-convert" type="object" attrs="{'invisible': ['|',('consumed','=',True),('state','!=','in_production')]}"/>
195+ </xpath>
196+
197+ <xpath expr="/form/notebook/page[@string='Finished Products']" position="inside">
198+ <button name="%(create_produce_action)d" string="Products Produced" icon="gtk-yes" type="action" attrs="{'invisible': ['|',('len_move','=',0),('state','=','done')]}"/>
199+ </xpath>
200+
201+ <xpath expr="/form/notebook/page[@string='Finished Products']" position="inside">
202+ <button name="action_finish" string="Finish Production" icon="gtk-ok" type="object" attrs="{'invisible': ['|',('consumed','=',False),('state','=','done')]}"/>
203+ </xpath>
204+
205+ <xpath expr="/form/group/field[@name='origin']" position="after">
206+ <field name="len_move" invisible="1"/>
207+ </xpath>
208+ </field>
209+ </record>
210+
211+
212+ </data>
213+</openerp>
214
215=== added directory 'mrp_consume_produce/patch'
216=== added file 'mrp_consume_produce/patch/stock.patch'
217--- mrp_consume_produce/patch/stock.patch 1970-01-01 00:00:00 +0000
218+++ mrp_consume_produce/patch/stock.patch 2012-09-17 21:54:24 +0000
219@@ -0,0 +1,31 @@
220+=== modified file 'stock/stock.py'
221+--- stock/stock.py 2012-03-29 15:29:29 +0000
222++++ stock/stock.py 2012-09-17 21:30:39 +0000
223+@@ -2445,6 +2445,9 @@
224+ #quantity should in MOVE UOM
225+ if context is None:
226+ context = {}
227++
228++ quantity=self.pool.get('product.uom')._compute_qty(cr, uid, context.get('product_uom',False), quantity, to_uom_id=context.get('product_uom_move',False))
229++
230+ if quantity <= 0:
231+ raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !'))
232+ res = []
233+@@ -2458,13 +2461,14 @@
234+ if quantity_rest <= 0:
235+ quantity_rest = 0
236+ uos_qty_rest = 0
237+- quantity = move.product_qty
238++ quantity = quantity
239+
240+ uos_qty = quantity / move_qty * move.product_uos_qty
241+ if quantity_rest > 0:
242+ default_val = {
243+- 'product_qty': quantity,
244++ 'product_qty': context.get('quantity',quantity),
245+ 'product_uos_qty': uos_qty,
246++ 'product_uom' : context.get('product_uom',move.product_uom.id),
247+ 'state': move.state,
248+ 'location_id': location_id or move.location_id.id,
249+ }
250+
251
252=== added directory 'mrp_consume_produce/wizard'
253=== added file 'mrp_consume_produce/wizard/__init__.py'
254--- mrp_consume_produce/wizard/__init__.py 1970-01-01 00:00:00 +0000
255+++ mrp_consume_produce/wizard/__init__.py 2012-09-17 21:54:24 +0000
256@@ -0,0 +1,26 @@
257+# -*- encoding: utf-8 -*-
258+###########################################################################
259+# Module Writen to OpenERP, Open Source Management Solution
260+#
261+# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
262+# All Rights Reserved.
263+# info@vauxoo.com
264+############################################################################
265+# Coded by: julio (julio@vauxoo.com)
266+############################################################################
267+#
268+# This program is free software: you can redistribute it and/or modify
269+# it under the terms of the GNU Affero General Public License as
270+# published by the Free Software Foundation, either version 3 of the
271+# License, or (at your option) any later version.
272+#
273+# This program is distributed in the hope that it will be useful,
274+# but WITHOUT ANY WARRANTY; without even the implied warranty of
275+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
276+# GNU Affero General Public License for more details.
277+#
278+# You should have received a copy of the GNU Affero General Public License
279+# along with this program. If not, see <http://www.gnu.org/licenses/>.
280+#
281+##############################################################################
282+import mrp_consume_produce
283
284=== added file 'mrp_consume_produce/wizard/mrp_consume_produce.py'
285--- mrp_consume_produce/wizard/mrp_consume_produce.py 1970-01-01 00:00:00 +0000
286+++ mrp_consume_produce/wizard/mrp_consume_produce.py 2012-09-17 21:54:24 +0000
287@@ -0,0 +1,115 @@
288+# -*- encoding: utf-8 -*-
289+###########################################################################
290+# Module Writen to OpenERP, Open Source Management Solution
291+#
292+# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
293+# All Rights Reserved.
294+# info@vauxoo.com
295+############################################################################
296+# Coded by: julio (julio@vauxoo.com)
297+############################################################################
298+#
299+# This program is free software: you can redistribute it and/or modify
300+# it under the terms of the GNU Affero General Public License as
301+# published by the Free Software Foundation, either version 3 of the
302+# License, or (at your option) any later version.
303+#
304+# This program is distributed in the hope that it will be useful,
305+# but WITHOUT ANY WARRANTY; without even the implied warranty of
306+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
307+# GNU Affero General Public License for more details.
308+#
309+# You should have received a copy of the GNU Affero General Public License
310+# along with this program. If not, see <http://www.gnu.org/licenses/>.
311+#
312+##############################################################################
313+import time
314+from osv import osv, fields
315+import decimal_precision as dp
316+
317+class mrp_consume(osv.osv_memory):
318+ _name='mrp.consume'
319+ _columns={
320+ 'consume_line_ids' : fields.one2many('mrp.consume.line','wizard_id','Consume')
321+ }
322+ def action_consume(self,cr,uid,ids,context={}):
323+ for production in self.browse(cr,uid,ids,context=context):
324+ for raw_product in production.consume_line_ids:
325+ context.update({'product_uom':raw_product.product_uom.id,
326+ 'product_uom_move':raw_product.move_id.product_uom.id,
327+ 'quantity':raw_product.quantity})
328+ raw_product.move_id.action_consume(raw_product.quantity, raw_product.location_id.id, context=context)
329+ return {}
330+
331+ def default_get(self, cr, uid, fields, context=None):
332+ if context is None: context = {}
333+ res = super(mrp_consume, self).default_get(cr, uid, fields, context=context)
334+ mrp_ids = context.get('active_ids', [])
335+ if not mrp_ids or (not context.get('active_model') == 'mrp.production') \
336+ or len(mrp_ids) != 1:
337+ return res
338+ mrp_id, = mrp_ids
339+ if 'consume_line_ids' in fields:
340+ mrp = self.pool.get('mrp.production').browse(cr, uid, mrp_id, context=context)
341+ moves = [self._partial_move_for(cr, uid, m) for m in mrp.move_lines if m.state not in ('done','cancel')]
342+ res.update(consume_line_ids=moves)
343+ return res
344+
345+ def _partial_move_for(self, cr, uid, move):
346+ partial_move = {
347+ 'product_id' : move.product_id.id,
348+ 'quantity' : move.product_qty,
349+ 'product_uom' : move.product_uom.id,
350+ 'prodlot_id' : move.prodlot_id.id,
351+ 'move_id' : move.id,
352+ 'location_id' : move.location_id.id,
353+ 'location_dest_id' : move.location_dest_id.id,
354+ }
355+ return partial_move
356+mrp_consume()
357+
358+class mrp_produce(osv.osv_memory):
359+ _name='mrp.produce'
360+ _columns={
361+ 'produce_line_ids' : fields.one2many('mrp.consume.line','wizard2_id','Consume')
362+ }
363+
364+ def default_get(self, cr, uid, fields, context=None):
365+ if context is None: context = {}
366+ res = super(mrp_produce, self).default_get(cr, uid, fields, context=context)
367+ mrp_ids = context.get('active_ids', [])
368+ if not mrp_ids or (not context.get('active_model') == 'mrp.production') \
369+ or len(mrp_ids) != 1:
370+ return res
371+ mrp_id, = mrp_ids
372+ if 'produce_line_ids' in fields:
373+ mrp = self.pool.get('mrp.production').browse(cr, uid, mrp_id, context=context)
374+ moves = [self.pool.get('mrp.consume')._partial_move_for(cr, uid, m) for m in mrp.move_created_ids if m.state not in ('done','cancel')]
375+ res.update(produce_line_ids=moves)
376+ return res
377+
378+ def action_produce(self,cr,uid,ids,context={}):
379+ for production in self.browse(cr,uid,ids,context=context):
380+ for raw_product in production.produce_line_ids:
381+ context.update({'product_uom':raw_product.product_uom.id,
382+ 'product_uom_move':raw_product.move_id.product_uom.id,
383+ 'quantity':raw_product.quantity})
384+ raw_product.move_id.action_consume(raw_product.quantity, raw_product.location_id.id, context=context)
385+ return {}
386+mrp_produce()
387+
388+class mrp_consume_line(osv.osv_memory):
389+ _name='mrp.consume.line'
390+ _rec_name = 'product_id'
391+ _columns = {
392+ 'product_id' : fields.many2one('product.product', string="Product", required=True),
393+ 'quantity' : fields.float("Quantity", digits_compute=dp.get_precision('Product UoM'), required=True),
394+ 'product_uom': fields.many2one('product.uom', 'Unit of Measure', required=True,),
395+ 'location_id': fields.many2one('stock.location', 'Location', required=True),
396+ 'location_dest_id': fields.many2one('stock.location', 'Dest. Location', required=True),
397+ 'move_id' : fields.many2one('stock.move', "Move"),
398+ 'wizard_id' : fields.many2one('mrp.consume', string="Wizard"),
399+ 'wizard2_id' : fields.many2one('mrp.produce', string="Wizard"),
400+ }
401+
402+mrp_consume_line()
403
404=== added file 'mrp_consume_produce/wizard/wizard_view.xml'
405--- mrp_consume_produce/wizard/wizard_view.xml 1970-01-01 00:00:00 +0000
406+++ mrp_consume_produce/wizard/wizard_view.xml 2012-09-17 21:54:24 +0000
407@@ -0,0 +1,102 @@
408+<?xml version="1.0" encoding="utf-8"?>
409+<openerp>
410+ <data>
411+<!--
412+ View to wizard Consume
413+-->
414+ <record id="mrp_consume_produce_form" model="ir.ui.view">
415+ <field name="name">mrp.consume.produce.form</field>
416+ <field name="model">mrp.consume</field>
417+ <field name="type">form</field>
418+ <field name="arch" type="xml">
419+ <form string="Consume">
420+ <field name="consume_line_ids" mode="tree" nolabel="1">
421+ <tree string="Consume" editable="bottom">
422+ <field name="product_id"/>
423+ <field name="quantity"/>
424+ <field name="product_uom"/>
425+ </tree>
426+ <form string="Consume">
427+ <field name="product_id"/>
428+ <field name="quantity"/>
429+ <field name="product_uom"/>
430+ </form>
431+ </field>
432+ <group colspan="4">
433+ <button string="Cancel" icon="gtk-cancel" type="object" special="cancel"/>
434+ <button string="Consume" icon="gtk-ok" name="action_consume" type="object"/>
435+ </group>
436+ </form>
437+ </field>
438+ </record>
439+
440+ <act_window id="consume_wizard"
441+ name="Consume"
442+ src_model="mrp.production"
443+ res_model="mrp.consume"
444+ view_mode="form"
445+ target="new"
446+ key2="client_action_multi"
447+ multi="True"
448+ />
449+
450+
451+ <record id="create_consume_action" model="ir.actions.act_window">
452+ <field name="name">Consume</field>
453+ <field name="res_model">mrp.consume</field>
454+ <field name="view_type">form</field>
455+ <field name="view_mode">form</field>
456+ <field name="target">new</field>
457+ </record>
458+
459+
460+<!--
461+ View to wizard Produce
462+-->
463+
464+ <record id="mrp_consume_produce2_form" model="ir.ui.view">
465+ <field name="name">mrp.consume.produce.form</field>
466+ <field name="model">mrp.produce</field>
467+ <field name="type">form</field>
468+ <field name="arch" type="xml">
469+ <form string="Produce">
470+ <field name="produce_line_ids" mode="tree" nolabel="1">
471+ <tree string="Produce" editable="bottom">
472+ <field name="product_id"/>
473+ <field name="quantity"/>
474+ <field name="product_uom"/>
475+ </tree>
476+ <form string="Produce">
477+ <field name="product_id"/>
478+ <field name="quantity"/>
479+ <field name="product_uom"/>
480+ </form>
481+ </field>
482+ <group colspan="4">
483+ <button string="Cancel" icon="gtk-cancel" type="object" special="cancel"/>
484+ <button string="Produced Products" icon="gtk-ok" name="action_produce" type="object"/>
485+ </group>
486+ </form>
487+ </field>
488+ </record>
489+
490+ <act_window id="produce_wizard"
491+ name="Produce"
492+ src_model="mrp.production"
493+ res_model="mrp.produce"
494+ view_mode="form"
495+ target="new"
496+ key2="client_action_multi"
497+ multi="True"
498+ />
499+
500+ <record id="create_produce_action" model="ir.actions.act_window">
501+ <field name="name">Produce</field>
502+ <field name="res_model">mrp.produce</field>
503+ <field name="view_type">form</field>
504+ <field name="view_mode">form</field>
505+ <field name="target">new</field>
506+ </record>
507+ </data>
508+</openerp>
509+