Merge lp:~camptocamp/openerp-manufacturing/6.1-add-mrp_split_units-lep into lp:openerp-manufacturing/6.1

Proposed by Leonardo Pistone
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 10
Merged at revision: 8
Proposed branch: lp:~camptocamp/openerp-manufacturing/6.1-add-mrp_split_units-lep
Merge into: lp:openerp-manufacturing/6.1
Diff against target: 204 lines (+183/-0)
4 files modified
mrp_split_units/__init__.py (+22/-0)
mrp_split_units/__openerp__.py (+46/-0)
mrp_split_units/mrp_view.xml (+21/-0)
mrp_split_units/stock.py (+94/-0)
To merge this branch: bzr merge lp:~camptocamp/openerp-manufacturing/6.1-add-mrp_split_units-lep
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code review, no tests Approve
Romain Deheele - Camptocamp (community) code review, no test Approve
Review via email: mp+200544@code.launchpad.net

Description of the change

New module mrp_split_units. Thanks!

To post a comment you must log in.
Revision history for this message
Leonardo Pistone (lepistone) wrote :

flake8 says OK. Thanks for reviewing!

Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Hi,

LGTM,

Romain

review: Approve (code review, no test)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

l95 and l98 you can use relative xpath expr like

<xpath expr="//field[@name='move_created_ids']/tree/button[@string='Scrap Products']" position="after">

That way adding a html level or moving the field won't affect your changes.

Otherwise looks good to me.

review: Needs Fixing (code review, no tests)
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Yannick,

I changed as you suggest.

Thanks

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks for the changes.

Sorry, it seems I missed those in python code the first time:

l138 could you use orm.Model instead of osv.osv

l174 missing context propagation

review: Needs Fixing (code review, no tests)
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Thanks Yannick, fixed

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks

LGTM

review: Approve (code review, no tests)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

in mrp_split_units/__openerp__.py please use data keyword instead of deprecated
init_xml
update_xml
demo_xml

review: Needs Fixing (code review, no tests)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Yes, I know I'm a turncoat sorry for that

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

6.1 here not needed

review: Approve (code review, no tests)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'mrp_split_units'
=== added file 'mrp_split_units/__init__.py'
--- mrp_split_units/__init__.py 1970-01-01 00:00:00 +0000
+++ mrp_split_units/__init__.py 2014-01-15 09:07:47 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3# #
4# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
5# Copyright 2014 Camptocamp SA #
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
22from . import stock # noqa
023
=== added file 'mrp_split_units/__openerp__.py'
--- mrp_split_units/__openerp__.py 1970-01-01 00:00:00 +0000
+++ mrp_split_units/__openerp__.py 2014-01-15 09:07:47 +0000
@@ -0,0 +1,46 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3# #
4# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
5# Copyright 2014 Camptocamp SA #
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{
23 'name': 'MRP Split Units',
24 'version': '0.1',
25 'category': 'Generic Modules/Others',
26 'license': 'AGPL-3',
27 'description': """
28MRP Split one line into many lines with quantity one each
29in a production order.
30
31This module adds a button in each line of the Products to Finish and Finished
32Products to automatically split one line with integer quantity into many lines,
33each with quantity 1. After the split, the module performs a
34"poor man's refresh" (i.e. manually reloads the page) as a workaround for the
35bug lp:1083253.
36""",
37 'complexity': 'easy',
38 'author': 'Camptocamp',
39 'website': 'http://www.camptocamp.com/',
40 'depends': ['mrp'],
41 'init_xml': [],
42 'update_xml': ['mrp_view.xml'],
43 'demo_xml': [],
44 'installable': True,
45 'active': False,
46}
047
=== added directory 'mrp_split_units/i18n'
=== added file 'mrp_split_units/mrp_view.xml'
--- mrp_split_units/mrp_view.xml 1970-01-01 00:00:00 +0000
+++ mrp_split_units/mrp_view.xml 2014-01-15 09:07:47 +0000
@@ -0,0 +1,21 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4
5 <record id="mrp_production_form_lot_attribute_view" model="ir.ui.view">
6 <field name="name">mrp.production.lot.attribute.form</field>
7 <field name="model">mrp.production</field>
8 <field name="inherit_id" ref="mrp.mrp_production_form_view"/>
9 <field name="type">form</field>
10 <field name="arch" type="xml">
11 <xpath expr="//field[@name='move_created_ids']/tree/button[@string='Scrap Products']" position="after">
12 <button name="split_units_to_finish" string="Split Units" type="object" icon="gtk-jump-to"/>
13 </xpath>
14 <xpath expr="//field[@name='move_created_ids2']/tree/button[@string='Scrap Products']" position="after">
15 <button name="split_units_finished" string="Split Units" type="object" icon="gtk-jump-to"/>
16 </xpath>
17 </field>
18 </record>
19
20 </data>
21</openerp>
022
=== added file 'mrp_split_units/stock.py'
--- mrp_split_units/stock.py 1970-01-01 00:00:00 +0000
+++ mrp_split_units/stock.py 2014-01-15 09:07:47 +0000
@@ -0,0 +1,94 @@
1# -*- coding: utf-8 -*-
2"""Add to the stock move the methods to split MO lines."""
3###############################################################################
4# #
5# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
6# Copyright 2014 Camptocamp SA #
7# #
8# This program is free software: you can redistribute it and/or modify #
9# it under the terms of the GNU Affero General Public License as #
10# published by the Free Software Foundation, either version 3 of the #
11# License, or (at your option) any later version. #
12# #
13# This program is distributed in the hope that it will be useful, #
14# but WITHOUT ANY WARRANTY; without even the implied warranty of #
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16# GNU Affero General Public License for more details. #
17# #
18# You should have received a copy of the GNU Affero General Public License #
19# along with this program. If not, see <http://www.gnu.org/licenses/>. #
20# #
21###############################################################################
22
23from osv import orm
24from tools.translate import _
25import decimal_precision as dp
26
27
28class stock_move(orm.Model):
29
30 """Stock move. Add methods to split moves in manufacturing orders."""
31
32 _inherit = 'stock.move'
33
34 def split_units(self, cr, uid, ids, context=None):
35 """Split the current move creating moves with quantity one.
36
37 Return an action to reload the current record as a poor man's refresh.
38
39 """
40
41 def almost_integer(cr, qty, int_qty):
42 return (
43 qty - int_qty < 10 ** -dp.get_precision('Product UoM')(cr)[1]
44 )
45
46 for move in self.browse(cr, uid, ids, context=context):
47 int_qty = int(move.product_qty)
48
49 if not almost_integer(cr, move.product_qty, int_qty):
50 raise orm.except_osv(
51 _('Error'),
52 _('Quantity needs to be integer.')
53 )
54
55 if int_qty <= 1:
56 raise orm.except_osv(
57 _('Error'),
58 _('Quantity needs to be more than 1.')
59 )
60
61 self.write(cr, uid, move.id, {
62 'product_qty': 1.0,
63 'product_uos_qty': 1.0,
64 }, context=context)
65
66 default_val = {
67 'product_qty': 1.0,
68 'product_uos_qty': 1.0,
69 'state': move.state,
70 'prodlot_id': False,
71 }
72
73 #create the new moves
74 for i in xrange(int_qty - 1):
75 self.copy(cr, uid, move.id, default_val, context=context)
76
77 # poor man's refresh
78 return {
79 'view_type': 'form',
80 'view_mode': 'form',
81 'res_model': 'mrp.production',
82 'type': 'ir.actions.act_window',
83 'target': 'current',
84 'context': context,
85 'res_id': move.production_id.id,
86 }
87
88 def split_units_finished(self, cr, uid, ids, context=None):
89 """Split a line in the Finished Products. Return an action."""
90 return self.split_units(cr, uid, ids, context=context)
91
92 def split_units_to_finish(self, cr, uid, ids, context=None):
93 """Split a line in the Products to Finish. Return an action."""
94 return self.split_units(cr, uid, ids, context=context)

Subscribers

People subscribed via source and target branches