Merge lp:~therp-nl/openobject-addons/7.0_lp1234004_configurable_auto_confirm_mo into lp:openobject-addons/7.0

Proposed by Ronald Portier (Therp)
Status: Needs review
Proposed branch: lp:~therp-nl/openobject-addons/7.0_lp1234004_configurable_auto_confirm_mo
Merge into: lp:openobject-addons/7.0
Diff against target: 117 lines (+70/-1)
3 files modified
mrp/procurement.py (+9/-1)
mrp/res_config.py (+57/-0)
mrp/res_config_view.xml (+4/-0)
To merge this branch: bzr merge lp:~therp-nl/openobject-addons/7.0_lp1234004_configurable_auto_confirm_mo
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+189006@code.launchpad.net

Description of the change

Fix lp1234004. Should be possible to create manufacturing orders from procurement in draft state.

Although a new configuration option is added to mrp, care has been taken not to need a database update.

Creating a new module to fix the bug was not a good option for maintainability.

To post a comment you must log in.

Unmerged revisions

9494. By Ronald Portier (Therp)

[FIX] Fixes lp1234004 by giving users the choice wether to automatically
      confirm Manufacturing Orders, created from prcurements.
      For compatibility with existing code, the default is to automatically
      comfirm MO's. This is fine when there is only one location, there is
      no need to edit planned dates etc.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mrp/procurement.py'
2--- mrp/procurement.py 2013-05-28 12:48:49 +0000
3+++ mrp/procurement.py 2013-10-03 08:23:50 +0000
4@@ -83,6 +83,13 @@
5 res = procurement_obj.make_mo(cr, uid, ids, context=context)
6 res = res.values()
7 return len(res) and res[0] or 0
8+
9+ def _get_auto_confirm_mo(self, cr, uid, context=None):
10+ val = self.pool.get('ir.config_parameter').get_param(
11+ cr, uid, 'auto_confirm_mo')
12+ if val and val in ['f', 'F', 'false', 'False', '0']:
13+ return False
14+ return True
15
16 def make_mo(self, cr, uid, ids, context=None):
17 """ Make Manufacturing(production) order from procurement
18@@ -117,7 +124,8 @@
19 self.write(cr, uid, [procurement.id], {'state': 'running', 'production_id': produce_id})
20 bom_result = production_obj.action_compute(cr, uid,
21 [produce_id], properties=[x.id for x in procurement.property_ids])
22- wf_service.trg_validate(uid, 'mrp.production', produce_id, 'button_confirm', cr)
23+ if self._get_auto_confirm_mo(cr, uid, context=context):
24+ wf_service.trg_validate(uid, 'mrp.production', produce_id, 'button_confirm', cr)
25 if res_id:
26 move_obj.write(cr, uid, [res_id],
27 {'location_id': procurement.location_id.id})
28
29=== modified file 'mrp/res_config.py'
30--- mrp/res_config.py 2013-08-23 09:22:31 +0000
31+++ mrp/res_config.py 2013-10-03 08:23:50 +0000
32@@ -27,6 +27,54 @@
33 _name = 'mrp.config.settings'
34 _inherit = 'res.config.settings'
35
36+ def default_get(self, cr, uid, field_names, context=None):
37+
38+ def bool_from_string(a_string):
39+ if len(a_string) < 1:
40+ return False
41+ if a_string in ['f', 'F', 'false', 'False', '0']:
42+ return False
43+ return True
44+
45+ defaults = super(mrp_config_settings, self).default_get(
46+ cr, uid, field_names, context=context)
47+ config_model = self.pool.get('ir.config_parameter')
48+ # link fieldnames to conversion functions and defaults
49+ field_table = {
50+ 'auto_confirm_mo': (bool_from_string, True),
51+ }
52+ for field_name in field_names:
53+ if field_name in field_table:
54+ (conversion, default_value) = field_table[field_name]
55+ defaults[field_name] = default_value
56+ # Get values in try/catch, because they might not be
57+ # present, or may not be convertable to the right type
58+ try:
59+ val = config_model.get_param(cr, uid, field_name)
60+ if val:
61+ defaults[field_name] = conversion(val)
62+ except:
63+ pass
64+ return defaults
65+
66+ # use multi for function fields to get/set config parameters, even though
67+ # for the moment we use only one.
68+ def _get_config_parms(self, cr, uid, ids, field_names, args, context=None):
69+ res = {}
70+ if not len(ids):
71+ return res
72+ vals = self.default_get(cr, uid, field_names, context=context)
73+ for wizard_id in ids: # Should be only one
74+ res[wizard_id] = vals
75+ return res
76+
77+ def _write_config_parms(
78+ self, cr, uid, ids, field_name, field_value, arg, context):
79+ config_model = self.pool.get('ir.config_parameter')
80+ config_model.set_param(
81+ cr, uid, field_name, '%s' % (field_value,))
82+ return True
83+
84 _columns = {
85 'module_mrp_repair': fields.boolean("Manage repairs of products ",
86 help="""Allows to manage all product repairs.
87@@ -71,6 +119,15 @@
88 * Manufacturer Product Code
89 * Product Attributes.
90 This installs the module product_manufacturer."""),
91+ # using function field for auto_confirm_mo prevents db change for 7.0
92+ 'auto_confirm_mo': fields.function(
93+ _get_config_parms,
94+ fnct_inv=_write_config_parms,
95+ type='boolean', method=True, store=False, multi=True,
96+ string='Automatically confirm manufacturing orders',
97+ help="""When set, will automatically confirm Manufacturing Orders, created for procurements.
98+This will set defaults for BOM and Route, that can not be changed."""),
99+
100 }
101
102 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
103
104=== modified file 'mrp/res_config_view.xml'
105--- mrp/res_config_view.xml 2012-11-29 22:26:45 +0000
106+++ mrp/res_config_view.xml 2013-10-03 08:23:50 +0000
107@@ -39,6 +39,10 @@
108 <field name="module_stock_no_autopicking" class="oe_inline"/>
109 <label for="module_stock_no_autopicking" />
110 </div>
111+ <div>
112+ <field name="auto_confirm_mo" class="oe_inline"/>
113+ <label for="auto_confirm_mo" />
114+ </div>
115 </div>
116 </group>
117 <group >