Merge lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-hierarchical-ls into lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-hierarchical
- 7.0-inventory-hierarchical-ls
- Merge into 7.0-inventory-hierarchical
Proposed by
Lionel Sausin - Initiatives/Numérigraphe
Status: | Merged |
---|---|
Merged at revision: | 37 |
Proposed branch: | lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-hierarchical-ls |
Merge into: | lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-hierarchical |
Diff against target: |
3062 lines (+1032/-1166) 33 files modified
stock_inventory_hierarchical/__init__.py (+7/-0) stock_inventory_hierarchical/__openerp__.py (+13/-8) stock_inventory_hierarchical/exceptions.py (+26/-0) stock_inventory_hierarchical/hierarchical_inventory.py (+104/-102) stock_inventory_hierarchical/hierarchical_inventory_demo.xml (+11/-23) stock_inventory_hierarchical/hierarchical_inventory_view.xml (+16/-57) stock_inventory_hierarchical/i18n/fr.po (+12/-12) stock_inventory_hierarchical/test/hierarchical_inventory_test.yml (+54/-65) stock_inventory_hierarchical_location/__init__.py (+3/-3) stock_inventory_hierarchical_location/__openerp__.py (+19/-23) stock_inventory_hierarchical_location/i18n/fr.po (+4/-4) stock_inventory_hierarchical_location/inventory_hierarchical_location.py (+58/-104) stock_inventory_hierarchical_location/inventory_hierarchical_location_demo.xml (+16/-6) stock_inventory_hierarchical_location/inventory_hierarchical_location_view.xml (+10/-23) stock_inventory_hierarchical_location/test/inventory_hierarchical_location_test.yml (+14/-25) stock_inventory_hierarchical_location/wizard/__init__.py (+2/-2) stock_inventory_hierarchical_location/wizard/stock_confirm_uninventoried_location.py (+63/-0) stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations.py (+0/-82) stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations_view.xml (+0/-43) stock_inventory_location/__init__.py (+2/-0) stock_inventory_location/__openerp__.py (+44/-29) stock_inventory_location/exceptions.py (+26/-0) stock_inventory_location/i18n/fr.po (+20/-40) stock_inventory_location/stock_inventory_location.py (+249/-193) stock_inventory_location/stock_inventory_location_demo.xml (+18/-17) stock_inventory_location/stock_inventory_location_view.xml (+48/-48) stock_inventory_location/test/inventory_exhaustive_test.yml (+76/-61) stock_inventory_location/test/inventory_future_test.yml (+13/-0) stock_inventory_location/test/inventory_standard_test.yml (+41/-50) stock_inventory_location/wizard/stock_confirm_uninventoried_location.py (+26/-59) stock_inventory_location/wizard/stock_confirm_uninventoried_location.xml (+12/-12) stock_inventory_location/wizard/stock_fill_location_inventory.py (+24/-74) stock_inventory_location/wizard/stock_fill_location_inventory_view.xml (+1/-1) |
To merge this branch: | bzr merge lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-hierarchical-ls |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Loïc Bellier - Numérigraphe | Pending | ||
Review via email: mp+222680@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 62. By Numérigraphe
-
[FIX] avoid division by zero when no inventory is found (ie. new inventory is beeing created)
- 63. By Numérigraphe
-
[MERGE] update screenshots
- 64. By Laetitia Gangloff (Acsone)
-
[IMP] stock_inventory
_hierarchical : use different tree form for sub-inventories and propagate location and exhaustivity - courtesy of Laetitia Gangloff (Acsone) - 65. By Numérigraphe
-
[MERGE] stock_inventory
_location update
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'stock_inventory_hierarchical/__init__.py' | |||
2 | --- stock_inventory_hierarchical/__init__.py 2014-03-12 15:08:22 +0000 | |||
3 | +++ stock_inventory_hierarchical/__init__.py 2014-06-11 15:04:27 +0000 | |||
4 | @@ -18,4 +18,11 @@ | |||
5 | 18 | # | 18 | # |
6 | 19 | ############################################################################## | 19 | ############################################################################## |
7 | 20 | 20 | ||
8 | 21 | # This package-wide list keeps the names of the field that must be | ||
9 | 22 | # propagated from root inventories to their children. | ||
10 | 23 | # Add field names in the Model's definition. | ||
11 | 24 | PARENT_VALUES = [] | ||
12 | 25 | |||
13 | 21 | import hierarchical_inventory | 26 | import hierarchical_inventory |
14 | 27 | # Bring the main exception into the package's scope for easier reuse | ||
15 | 28 | from .exceptions import HierarchicalInventoryException | ||
16 | 22 | 29 | ||
17 | === modified file 'stock_inventory_hierarchical/__openerp__.py' | |||
18 | --- stock_inventory_hierarchical/__openerp__.py 2014-03-12 15:08:22 +0000 | |||
19 | +++ stock_inventory_hierarchical/__openerp__.py 2014-06-11 15:04:27 +0000 | |||
20 | @@ -20,22 +20,27 @@ | |||
21 | 20 | 20 | ||
22 | 21 | { | 21 | { |
23 | 22 | "name": "Hierarchical Physical Inventory", | 22 | "name": "Hierarchical Physical Inventory", |
25 | 23 | "version": "1.0", | 23 | "version": "1.1", |
26 | 24 | "depends": ["stock"], | 24 | "depends": ["stock"], |
27 | 25 | "author": "Numérigraphe", | 25 | "author": "Numérigraphe", |
29 | 26 | "category": "stock inventory", | 26 | "category": "Warehouse Management", |
30 | 27 | "description": """ | 27 | "description": """ |
31 | 28 | Hierarchical structure for Physical Inventories and sub-Inventories | 28 | Hierarchical structure for Physical Inventories and sub-Inventories |
32 | 29 | =================================================================== | 29 | =================================================================== |
33 | 30 | 30 | ||
36 | 31 | This module adds a parent-child relationship between Physical Inventories, to help users | 31 | This module adds a parent-child relationship between Physical Inventories, to |
37 | 32 | manage complex inventories. | 32 | help users manage complex inventories. |
38 | 33 | Using several inventories, you can distribute the counting to several persons | 33 | Using several inventories, you can distribute the counting to several persons |
39 | 34 | and still keep a clear overview of global Inventory's status. | 34 | and still keep a clear overview of global Inventory's status. |
40 | 35 | 35 | ||
42 | 36 | OpenERP will make sure the status of the Inventory and it's sub-Inventories are consistent. | 36 | OpenERP will make sure the status of the Inventory and it's Sub-Inventories are |
43 | 37 | consistent. | ||
44 | 37 | """, | 38 | """, |
48 | 38 | "update_xml": ["hierarchical_inventory_view.xml"], | 39 | "data": ["hierarchical_inventory_view.xml"], |
49 | 39 | "test": ["test/hierarchical_inventory_test.yml"], | 40 | "test": ["test/hierarchical_inventory_test.yml"], |
50 | 40 | "demo": ["hierarchical_inventory_demo.xml"] | 41 | "demo": ["hierarchical_inventory_demo.xml"], |
51 | 42 | "images": [ | ||
52 | 43 | "inventory_form.png", | ||
53 | 44 | "inventory_form_actions.png", | ||
54 | 45 | ], | ||
55 | 41 | } | 46 | } |
56 | 42 | 47 | ||
57 | === added file 'stock_inventory_hierarchical/exceptions.py' | |||
58 | --- stock_inventory_hierarchical/exceptions.py 1970-01-01 00:00:00 +0000 | |||
59 | +++ stock_inventory_hierarchical/exceptions.py 2014-06-11 15:04:27 +0000 | |||
60 | @@ -0,0 +1,26 @@ | |||
61 | 1 | # -*- coding: utf-8 -*- | ||
62 | 2 | ############################################################################## | ||
63 | 3 | # | ||
64 | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. | ||
65 | 5 | # | ||
66 | 6 | # This program is free software: you can redistribute it and/or modify | ||
67 | 7 | # it under the terms of the GNU General Public License as published by | ||
68 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
69 | 9 | # (at your option) any later version. | ||
70 | 10 | # | ||
71 | 11 | # This program is distributed in the hope that it will be useful, | ||
72 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
73 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
74 | 14 | # GNU General Public License for more details. | ||
75 | 15 | # | ||
76 | 16 | # You should have received a copy of the GNU General Public License | ||
77 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
78 | 18 | # | ||
79 | 19 | ############################################################################## | ||
80 | 20 | |||
81 | 21 | from openerp.osv import orm | ||
82 | 22 | |||
83 | 23 | |||
84 | 24 | class HierarchicalInventoryException(orm.except_orm): | ||
85 | 25 | """The operation is not possible for a hierarchical inventory""" | ||
86 | 26 | pass | ||
87 | 0 | 27 | ||
88 | === modified file 'stock_inventory_hierarchical/hierarchical_inventory.py' | |||
89 | --- stock_inventory_hierarchical/hierarchical_inventory.py 2014-03-12 15:08:22 +0000 | |||
90 | +++ stock_inventory_hierarchical/hierarchical_inventory.py 2014-06-11 15:04:27 +0000 | |||
91 | @@ -18,11 +18,17 @@ | |||
92 | 18 | # | 18 | # |
93 | 19 | ############################################################################## | 19 | ############################################################################## |
94 | 20 | 20 | ||
96 | 21 | from openerp.osv import osv, fields | 21 | from openerp.osv import orm, fields |
97 | 22 | from openerp.tools.translate import _ | 22 | from openerp.tools.translate import _ |
98 | 23 | 23 | ||
101 | 24 | 24 | from .exceptions import HierarchicalInventoryException | |
102 | 25 | class stock_inventory_hierarchical(osv.osv): | 25 | |
103 | 26 | # Add the date to the list of fields we must propagate to children inventories | ||
104 | 27 | from . import PARENT_VALUES | ||
105 | 28 | PARENT_VALUES.append('date') | ||
106 | 29 | |||
107 | 30 | |||
108 | 31 | class HierarchicalInventory(orm.Model): | ||
109 | 26 | _inherit = 'stock.inventory' | 32 | _inherit = 'stock.inventory' |
110 | 27 | 33 | ||
111 | 28 | _parent_store = True | 34 | _parent_store = True |
112 | @@ -30,7 +36,19 @@ | |||
113 | 30 | _order = 'parent_left' | 36 | _order = 'parent_left' |
114 | 31 | 37 | ||
115 | 32 | def name_get(self, cr, uid, ids, context=None): | 38 | def name_get(self, cr, uid, ids, context=None): |
117 | 33 | """Show the parent inventory's name in the name of the children""" | 39 | """Show the parent inventory's name in the name of the children |
118 | 40 | |||
119 | 41 | :param dict context: the ``inventory_display`` key can be | ||
120 | 42 | used to select the short version of the | ||
121 | 43 | inventory name (without the direct parent), | ||
122 | 44 | when set to ``'short'``. The default is | ||
123 | 45 | the long version.""" | ||
124 | 46 | if context is None: | ||
125 | 47 | context = {} | ||
126 | 48 | if context.get('inventory_display') == 'short': | ||
127 | 49 | # Short name context: just do the usual stuff | ||
128 | 50 | return super(HierarchicalInventory, self).name_get( | ||
129 | 51 | cr, uid, ids, context=context) | ||
130 | 34 | if isinstance(ids, (list, tuple)) and not len(ids): | 52 | if isinstance(ids, (list, tuple)) and not len(ids): |
131 | 35 | return [] | 53 | return [] |
132 | 36 | if isinstance(ids, (long, int)): | 54 | if isinstance(ids, (long, int)): |
133 | @@ -44,130 +62,105 @@ | |||
134 | 44 | res.append((record['id'], name)) | 62 | res.append((record['id'], name)) |
135 | 45 | return res | 63 | return res |
136 | 46 | 64 | ||
139 | 47 | def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100): | 65 | def name_search(self, cr, uid, name='', args=None, operator='ilike', |
140 | 48 | """Allow search on value returned by name_get ("parent/ child")""" | 66 | context=None, limit=100): |
141 | 67 | """Enable search on value returned by name_get ("parent / child")""" | ||
142 | 49 | if not args: | 68 | if not args: |
143 | 50 | args = [] | 69 | args = [] |
144 | 51 | if not context: | 70 | if not context: |
145 | 52 | context = {} | 71 | context = {} |
146 | 53 | if name: | 72 | if name: |
148 | 54 | # Be sure name_search is symetric to name_get | 73 | # Make sure name_search is symmetric to name_get |
149 | 55 | name = name.split(' / ')[-1] | 74 | name = name.split(' / ')[-1] |
151 | 56 | ids = self.search(cr, uid, [('name', operator, name)] + args, limit=limit, context=context) | 75 | ids = self.search(cr, uid, [('name', operator, name)] + args, |
152 | 76 | limit=limit, context=context) | ||
153 | 57 | else: | 77 | else: |
154 | 58 | ids = self.search(cr, uid, args, limit=limit, context=context) | 78 | ids = self.search(cr, uid, args, limit=limit, context=context) |
155 | 59 | return self.name_get(cr, uid, ids, context=context) | 79 | return self.name_get(cr, uid, ids, context=context) |
156 | 60 | 80 | ||
159 | 61 | def _name_get_fnc(self, cr, uid, ids, field_name, arg, context=None): | 81 | def _complete_name(self, cr, uid, ids, field_name, arg, context=None): |
160 | 62 | """Function field containing the long name""" | 82 | """Function-field wrapper to get the complete name from name_get""" |
161 | 63 | res = self.name_get(cr, uid, ids, context=context) | 83 | res = self.name_get(cr, uid, ids, context=context) |
162 | 64 | return dict(res) | 84 | return dict(res) |
163 | 65 | 85 | ||
166 | 66 | def _confirmed_rate(self, cr, uid, ids, field_name, arg, context=None): | 86 | def _progress_rate(self, cr, uid, ids, field_name, arg, context=None): |
167 | 67 | """Number of (sub)inventories confirmed/total""" | 87 | """Rate of (sub)inventories done/total""" |
168 | 68 | rates = {} | 88 | rates = {} |
174 | 69 | for id in ids: | 89 | for current_id in ids: |
175 | 70 | nb = self.search(cr, uid, [('parent_id', 'child_of', id)], context=context, count=True) | 90 | nb = self.search( |
176 | 71 | nb_confirmed = self.search(cr, uid, [('parent_id', 'child_of', id), | 91 | cr, uid, [('parent_id', 'child_of', current_id)], |
177 | 72 | ('state', 'in', ('confirm', 'done'))], context=context, count=True) | 92 | context=context, count=True) |
178 | 73 | rates[id] = 100 * nb_confirmed / nb | 93 | if not nb: |
179 | 94 | # No inventory, consider it's 0% done | ||
180 | 95 | rates[current_id] = 0 | ||
181 | 96 | continue | ||
182 | 97 | nb_done = self.search( | ||
183 | 98 | cr, uid, [('parent_id', 'child_of', current_id), | ||
184 | 99 | ('state', '=', 'done')], | ||
185 | 100 | context=context, count=True) | ||
186 | 101 | rates[current_id] = 100 * nb_done / nb | ||
187 | 74 | return rates | 102 | return rates |
188 | 75 | 103 | ||
189 | 76 | _columns = { | 104 | _columns = { |
194 | 77 | # XXX remove "method=True" in v7 ? | 105 | # name_get() only changes the default name of the record, not the |
195 | 78 | 'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Complete reference'), | 106 | # content of the field "name" so we add another field for that |
196 | 79 | 'parent_id': fields.many2one('stock.inventory', 'Parent', ondelete='cascade', readonly=True, states={'draft': [('readonly', False)]}), | 107 | 'complete_name': fields.function( |
197 | 80 | 'inventory_ids': fields.one2many('stock.inventory', 'parent_id', 'List of Sub-inventories', readonly=True, states={'draft': [('readonly', False)]}), | 108 | _complete_name, type="char", |
198 | 109 | string='Complete reference'), | ||
199 | 110 | 'parent_id': fields.many2one( | ||
200 | 111 | 'stock.inventory', 'Parent', ondelete='cascade', readonly=True, | ||
201 | 112 | states={'draft': [('readonly', False)]}), | ||
202 | 113 | 'inventory_ids': fields.one2many( | ||
203 | 114 | 'stock.inventory', 'parent_id', 'List of Sub-inventories', | ||
204 | 115 | readonly=True, states={'draft': [('readonly', False)]}), | ||
205 | 81 | 'parent_left': fields.integer('Parent Left', select=1), | 116 | 'parent_left': fields.integer('Parent Left', select=1), |
206 | 82 | 'parent_right': fields.integer('Parent Right', select=1), | 117 | 'parent_right': fields.integer('Parent Right', select=1), |
208 | 83 | 'confirmed_rate': fields.function(_confirmed_rate, method=True, string='Confirmed', type='float'), | 118 | 'progress_rate': fields.function( |
209 | 119 | _progress_rate, string='Progress', type='float'), | ||
210 | 84 | } | 120 | } |
211 | 85 | 121 | ||
212 | 86 | # XXX: drop this in v7 | ||
213 | 87 | def _check_recursion(self, cr, uid, ids, context=None, parent=None): | ||
214 | 88 | """Backport of osv.osv._check_recursion from v7.0, to allow writing parents and children in the same write()""" | ||
215 | 89 | if not parent: | ||
216 | 90 | parent = self._parent_name | ||
217 | 91 | |||
218 | 92 | # must ignore 'active' flag, ir.rules, etc. => direct SQL query | ||
219 | 93 | query = 'SELECT "%s" FROM "%s" WHERE id = %%s' % (parent, self._table) | ||
220 | 94 | for id in ids: | ||
221 | 95 | current_id = id | ||
222 | 96 | while current_id is not None: | ||
223 | 97 | cr.execute(query, (current_id,)) | ||
224 | 98 | result = cr.fetchone() | ||
225 | 99 | current_id = result[0] if result else None | ||
226 | 100 | if current_id == id: | ||
227 | 101 | return False | ||
228 | 102 | return True | ||
229 | 103 | |||
230 | 104 | # XXX: use this in v7 | ||
231 | 105 | # _constraints = [(osv.osv._check_recursion, 'Error! You can not create recursive inventories.', ['parent_id']), ] | ||
232 | 106 | _constraints = [ | 122 | _constraints = [ |
235 | 107 | (_check_recursion, | 123 | (orm.Model._check_recursion, |
236 | 108 | _('Error! You can not create recursive inventories.'), ['parent_id']), | 124 | 'Error: You can not create recursive inventories.', |
237 | 125 | ['parent_id']), | ||
238 | 109 | ] | 126 | ] |
239 | 110 | 127 | ||
269 | 111 | # This is the list of fields that must be forced from Inventories to Sub-Inventories | 128 | def create(self, cr, uid, vals, context=None): |
241 | 112 | # TODO: propose this as a new feature of the ORM's API using (using a field named _parent_values for example) | ||
242 | 113 | PARENT_VALUES = ['date'] | ||
243 | 114 | |||
244 | 115 | # XXX: Ideally we would have liked to have a button to open Sub-inventories, | ||
245 | 116 | # but unfortunately the v6.0 GTK client crashes, and the 6.0 web client opens a windows without action buttons. | ||
246 | 117 | # Maybe we may try that again with the new web client one day... | ||
247 | 118 | # def open_sub_inventory(self, cr, uid, id, context=None): | ||
248 | 119 | # """Method to open Sub-inventory from one2many list on new tab, with specific view.""" | ||
249 | 120 | # # Find out the form view id | ||
250 | 121 | # if not isinstance(id, list): | ||
251 | 122 | # id = [id] | ||
252 | 123 | # id = id[0] | ||
253 | 124 | # res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'view_inventory_form') | ||
254 | 125 | # view_id = res and res[1] or False | ||
255 | 126 | # inv = self.browse(cr, uid, id, context=context) | ||
256 | 127 | # return { | ||
257 | 128 | # 'type': 'ir.actions.act_window', | ||
258 | 129 | # 'name': _("Sub-inventory : %s") % inv.name, | ||
259 | 130 | # 'view_type': 'form', | ||
260 | 131 | # 'view_mode': 'form', | ||
261 | 132 | # 'view_id': [view_id], | ||
262 | 133 | # 'res_model': 'stock.inventory', | ||
263 | 134 | # 'res_id': id, | ||
264 | 135 | # } | ||
265 | 136 | # return True | ||
266 | 137 | |||
267 | 138 | # TODO: propose this as a new feature of the ORM's API using (using a field named _parent_values for example) | ||
268 | 139 | def create(self, cr, user, vals, context=None): | ||
270 | 140 | """Copy selected values from parent to child""" | 129 | """Copy selected values from parent to child""" |
271 | 141 | if vals and vals.get('parent_id'): | 130 | if vals and vals.get('parent_id'): |
277 | 142 | for f in self.PARENT_VALUES: | 131 | existing_fields = self.fields_get_keys(cr, uid, context=context) |
278 | 143 | parent_field = self.read(cr, user, [vals['parent_id']], [f], context=context) | 132 | parent_values = self.read(cr, uid, [vals['parent_id']], |
279 | 144 | vals = vals.copy() | 133 | PARENT_VALUES, context=context) |
280 | 145 | vals[f] = parent_field[0][f] | 134 | vals = vals.copy() |
281 | 146 | return super(stock_inventory_hierarchical, self).create(cr, user, vals, context=context) | 135 | vals.update({field: parent_values[0][field] |
282 | 136 | for field in PARENT_VALUES | ||
283 | 137 | if field in existing_fields}) | ||
284 | 138 | return super(HierarchicalInventory, self).create( | ||
285 | 139 | cr, uid, vals, context=context) | ||
286 | 147 | 140 | ||
287 | 148 | # TODO: propose this as a new feature of the ORM's API using (using a field named _parent_values for example) | ||
288 | 149 | def write(self, cr, uid, ids, vals, context=None): | 141 | def write(self, cr, uid, ids, vals, context=None): |
289 | 150 | """Copy selected values from parent to children""" | 142 | """Copy selected values from parent to children""" |
290 | 151 | if context is None: | 143 | if context is None: |
291 | 152 | context = {} | 144 | context = {} |
292 | 153 | 145 | ||
295 | 154 | values = super(stock_inventory_hierarchical, self).write(cr, uid, ids, vals, context=context) | 146 | values = super(HierarchicalInventory, self).write( |
296 | 155 | if not vals or context.get('norecurs'): | 147 | cr, uid, ids, vals, context=context) |
297 | 148 | if not vals or context.get('norecurse', False): | ||
298 | 156 | return values | 149 | return values |
299 | 157 | 150 | ||
305 | 158 | record = {} | 151 | # filter the fields we want to propagate |
306 | 159 | for f in self.PARENT_VALUES: | 152 | children_values = { |
307 | 160 | if f in vals: | 153 | field: vals[field] for field in PARENT_VALUES if field in vals |
308 | 161 | record[f] = vals[f] | 154 | } |
309 | 162 | if not record: | 155 | if not children_values: |
310 | 163 | return values | 156 | return values |
311 | 164 | 157 | ||
312 | 165 | if not isinstance(ids, list): | 158 | if not isinstance(ids, list): |
313 | 166 | ids = [ids] | 159 | ids = [ids] |
318 | 167 | children_ids = self.search(cr, uid, [('parent_id', 'child_of', ids)]) | 160 | # The context disables recursion - children are already included |
319 | 168 | ctx = context.copy() | 161 | return self.write( |
320 | 169 | ctx['norecurs'] = True # needed to write children once. | 162 | cr, uid, self.search(cr, uid, [('parent_id', 'child_of', ids)]), |
321 | 170 | return self.write(cr, uid, children_ids, record, context=ctx) | 163 | children_values, context=dict(context, norecurse=True)) |
322 | 171 | 164 | ||
323 | 172 | def action_cancel_inventory(self, cr, uid, ids, context=None): | 165 | def action_cancel_inventory(self, cr, uid, ids, context=None): |
324 | 173 | """Cancel inventory only if all the parents are canceled""" | 166 | """Cancel inventory only if all the parents are canceled""" |
325 | @@ -176,25 +169,34 @@ | |||
326 | 176 | while inventory.parent_id: | 169 | while inventory.parent_id: |
327 | 177 | inventory = inventory.parent_id | 170 | inventory = inventory.parent_id |
328 | 178 | if inventory.state != 'cancel': | 171 | if inventory.state != 'cancel': |
332 | 179 | raise osv.except_osv(_('Warning !'), | 172 | raise HierarchicalInventoryException( |
333 | 180 | _('One of the parent Inventories is not canceled.')) | 173 | _('Warning'), |
334 | 181 | return super(stock_inventory_hierarchical, self).action_cancel_inventory(cr, uid, ids, context=context) | 174 | _('One of the parent Inventories is not canceled.')) |
335 | 175 | return super(HierarchicalInventory, | ||
336 | 176 | self).action_cancel_inventory(cr, uid, ids, | ||
337 | 177 | context=context) | ||
338 | 182 | 178 | ||
339 | 183 | def action_confirm(self, cr, uid, ids, context=None): | 179 | def action_confirm(self, cr, uid, ids, context=None): |
340 | 184 | """Confirm inventory only if all the children are confirmed""" | 180 | """Confirm inventory only if all the children are confirmed""" |
343 | 185 | children_count = self.search(cr, uid, [('parent_id', 'child_of', ids), | 181 | children_count = self.search( |
344 | 186 | ('state', 'not in', ['confirm', 'done'])], context=context, count=True) | 182 | cr, uid, [('parent_id', 'child_of', ids), |
345 | 183 | ('state', 'not in', ['confirm', 'done'])], | ||
346 | 184 | context=context, count=True) | ||
347 | 187 | if children_count > 1: | 185 | if children_count > 1: |
351 | 188 | raise osv.except_osv(_('Warning !'), | 186 | raise HierarchicalInventoryException( |
352 | 189 | _('Some Sub-inventories are not confirmed.')) | 187 | _('Warning'), |
353 | 190 | return super(stock_inventory_hierarchical, self).action_confirm(cr, uid, ids, context=context) | 188 | _('Some Sub-inventories are not confirmed.')) |
354 | 189 | return super(HierarchicalInventory, self).action_confirm( | ||
355 | 190 | cr, uid, ids, context=context) | ||
356 | 191 | 191 | ||
357 | 192 | def action_done(self, cr, uid, ids, context=None): | 192 | def action_done(self, cr, uid, ids, context=None): |
358 | 193 | """Perform validation only if all the children states are 'done'.""" | 193 | """Perform validation only if all the children states are 'done'.""" |
359 | 194 | children_count = self.search(cr, uid, [('parent_id', 'child_of', ids), | 194 | children_count = self.search(cr, uid, [('parent_id', 'child_of', ids), |
360 | 195 | ('state', '!=', 'done')], | 195 | ('state', '!=', 'done')], |
362 | 196 | context=context, count=True) | 196 | context=context, count=True) |
363 | 197 | if children_count > 1: | 197 | if children_count > 1: |
367 | 198 | raise osv.except_osv(_('Warning !'), | 198 | raise HierarchicalInventoryException( |
368 | 199 | _('Some Sub-inventories are not done.')) | 199 | _('Warning'), |
369 | 200 | return super(stock_inventory_hierarchical, self).action_done(cr, uid, ids, context=context) | 200 | _('Some Sub-inventories are not validated.')) |
370 | 201 | return super(HierarchicalInventory, self).action_done( | ||
371 | 202 | cr, uid, ids, context=context) | ||
372 | 201 | 203 | ||
373 | === modified file 'stock_inventory_hierarchical/hierarchical_inventory_demo.xml' | |||
374 | --- stock_inventory_hierarchical/hierarchical_inventory_demo.xml 2014-03-12 15:08:22 +0000 | |||
375 | +++ stock_inventory_hierarchical/hierarchical_inventory_demo.xml 2014-06-11 15:04:27 +0000 | |||
376 | @@ -1,30 +1,18 @@ | |||
377 | 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
378 | 2 | <openerp> | 2 | <openerp> |
379 | 3 | <data noupdate="0"> | 3 | <data noupdate="0"> |
391 | 4 | 4 | <!-- Example Inventory with Sub-Inventories. --> | |
381 | 5 | <!-- Record a production lot we can use in the tests. --> | ||
382 | 6 | <record id="lot_test0" model="stock.production.lot"> | ||
383 | 7 | <field name="product_id" ref="product.product_product_10" /> | ||
384 | 8 | </record> | ||
385 | 9 | |||
386 | 10 | <!-- Record inventories we can use in the tests. --> | ||
387 | 11 | <!-- We need them in the demo data because test data is rolled back | ||
388 | 12 | whenever an exception is raised. --> | ||
389 | 13 | |||
390 | 14 | <!-- Record an inventory to make sure the next one will have stock moves posted. --> | ||
392 | 15 | <record id="stock_inventory_parent0" model="stock.inventory"> | 5 | <record id="stock_inventory_parent0" model="stock.inventory"> |
395 | 16 | <field name="name">Parent test inventory</field> | 6 | <field name="name">Main Inventory</field> |
394 | 17 | <field name="state">draft</field> | ||
396 | 18 | <field name="date">2020-01-01 00:00:00</field> | 7 | <field name="date">2020-01-01 00:00:00</field> |
407 | 19 | </record> | 8 | </record> |
408 | 20 | <record id="stock_inventory_line" model="stock.inventory.line"> | 9 | <record id="child_1_id" model="stock.inventory"> |
409 | 21 | <field name="inventory_id" ref="stock_inventory_parent0" /> | 10 | <field name="name">Sub-Inventory 1</field> |
410 | 22 | <field name="product_id" ref="product.product_product_10" /> | 11 | <field name="parent_id" ref="stock_inventory_parent0" /> |
411 | 23 | <field name="prod_lot_id" ref="lot_test0"/> | 12 | </record> |
412 | 24 | <field name="product_uom" ref="product.product_uom_unit" /> | 13 | <record id="child_2_id" model="stock.inventory"> |
413 | 25 | <field name="product_qty">27.0</field> | 14 | <field name="name">Sub-Inventory 2</field> |
414 | 26 | <field name="location_id" ref="stock.stock_location_components" /> | 15 | <field name="parent_id" ref="stock_inventory_parent0" /> |
415 | 27 | </record> | 16 | </record> |
406 | 28 | |||
416 | 29 | </data> | 17 | </data> |
417 | 30 | </openerp> | 18 | </openerp> |
418 | 31 | 19 | ||
419 | === modified file 'stock_inventory_hierarchical/hierarchical_inventory_view.xml' | |||
420 | --- stock_inventory_hierarchical/hierarchical_inventory_view.xml 2014-03-12 15:08:22 +0000 | |||
421 | +++ stock_inventory_hierarchical/hierarchical_inventory_view.xml 2014-06-11 15:04:27 +0000 | |||
422 | @@ -5,16 +5,14 @@ | |||
423 | 5 | <record model="ir.ui.view" id="stock_inventory_hierarchical_tree_view"> | 5 | <record model="ir.ui.view" id="stock_inventory_hierarchical_tree_view"> |
424 | 6 | <field name="name">hierarchical.inventory.tree</field> | 6 | <field name="name">hierarchical.inventory.tree</field> |
425 | 7 | <field name="model">stock.inventory</field> | 7 | <field name="model">stock.inventory</field> |
426 | 8 | <field name="type">tree</field> | ||
427 | 9 | <field name="inherit_id" ref="stock.view_inventory_tree" /> | 8 | <field name="inherit_id" ref="stock.view_inventory_tree" /> |
428 | 10 | <field name="field_parent">inventory_ids</field> | 9 | <field name="field_parent">inventory_ids</field> |
429 | 11 | <field name="arch" type="xml"> | 10 | <field name="arch" type="xml"> |
430 | 12 | <xpath expr="//field[@name='name']" position="replace"> | 11 | <xpath expr="//field[@name='name']" position="replace"> |
432 | 13 | <field name="complete_name"/> | 12 | <field name="complete_name" string="Reference"/> |
433 | 14 | </xpath> | 13 | </xpath> |
434 | 15 | <xpath expr="//field[@name='state']" position="after"> | 14 | <xpath expr="//field[@name='state']" position="after"> |
437 | 16 | <field name="confirmed_rate" widget="progressbar" /> | 15 | <field name="progress_rate" widget="progressbar" /> |
436 | 17 | <field name="inventory_ids" string="Number of Sub-inventories" /> | ||
438 | 18 | </xpath> | 16 | </xpath> |
439 | 19 | </field> | 17 | </field> |
440 | 20 | </record> | 18 | </record> |
441 | @@ -23,7 +21,6 @@ | |||
442 | 23 | <record model="ir.ui.view" id="view_inventory_subinventories_filter"> | 21 | <record model="ir.ui.view" id="view_inventory_subinventories_filter"> |
443 | 24 | <field name="name">hierarchical.inventory.filter</field> | 22 | <field name="name">hierarchical.inventory.filter</field> |
444 | 25 | <field name="model">stock.inventory</field> | 23 | <field name="model">stock.inventory</field> |
445 | 26 | <field name="type">search</field> | ||
446 | 27 | <field name="inherit_id" ref="stock.view_inventory_filter" /> | 24 | <field name="inherit_id" ref="stock.view_inventory_filter" /> |
447 | 28 | <field name="arch" type="xml"> | 25 | <field name="arch" type="xml"> |
448 | 29 | <xpath expr="//field[@name='name']" position="before"> | 26 | <xpath expr="//field[@name='name']" position="before"> |
449 | @@ -43,9 +40,11 @@ | |||
450 | 43 | <record model="ir.ui.view" id="stock_inventory_hierarchical_form_view"> | 40 | <record model="ir.ui.view" id="stock_inventory_hierarchical_form_view"> |
451 | 44 | <field name="name">hierarchical.inventory.form</field> | 41 | <field name="name">hierarchical.inventory.form</field> |
452 | 45 | <field name="model">stock.inventory</field> | 42 | <field name="model">stock.inventory</field> |
453 | 46 | <field name="type">form</field> | ||
454 | 47 | <field name="inherit_id" ref="stock.view_inventory_form" /> | 43 | <field name="inherit_id" ref="stock.view_inventory_form" /> |
455 | 48 | <field name="arch" type="xml"> | 44 | <field name="arch" type="xml"> |
456 | 45 | <xpath expr="/form//field[@name='name']" position="after"> | ||
457 | 46 | <field name="parent_id"/> | ||
458 | 47 | </xpath> | ||
459 | 49 | <xpath expr="/form//field[@name='date']" position="attributes"> | 48 | <xpath expr="/form//field[@name='date']" position="attributes"> |
460 | 50 | <attribute name="attrs">{'readonly':[('parent_id', '!=', False)]}</attribute> | 49 | <attribute name="attrs">{'readonly':[('parent_id', '!=', False)]}</attribute> |
461 | 51 | </xpath> | 50 | </xpath> |
462 | @@ -53,62 +52,22 @@ | |||
463 | 53 | expr="//page[@string='General Information']" | 52 | expr="//page[@string='General Information']" |
464 | 54 | position="after"> | 53 | position="after"> |
465 | 55 | <page string="Sub-inventories"> | 54 | <page string="Sub-inventories"> |
469 | 56 | <field name="parent_id" invisible="1" /> | 55 | <field name="inventory_ids" nolabel="1" context="{'default_parent_id': active_id}"> |
470 | 57 | <field name="inventory_ids" nolabel="1" | 56 | <tree> |
471 | 58 | context="{'form_view_ref' : 'stock_inventory_hierarchical.stock_inventory_hierarchical_subinventory_form_view', 'tree_view_ref' : 'stock_inventory_hierarchical.stock_inventory_hierarchical_subinventory_tree_view'}" /> | 57 | <field name="name" /> |
472 | 58 | <field name="state" /> | ||
473 | 59 | <field name="progress_rate" widget="progressbar" /> | ||
474 | 60 | </tree> | ||
475 | 61 | </field> | ||
476 | 59 | </page> | 62 | </page> |
477 | 60 | </xpath> | 63 | </xpath> |
478 | 61 | </field> | 64 | </field> |
479 | 62 | </record> | 65 | </record> |
480 | 63 | 66 | ||
529 | 64 | <record model="ir.ui.view" | 67 | <!-- Open the children of the current Inventory in a distinct list |
530 | 65 | id="stock_inventory_hierarchical_subinventory_tree_view"> | 68 | to let users work in a normal window instead of a popup --> |
531 | 66 | <field name="name">hierarchical.inventory.subinventory.tree</field> | 69 | <act_window id="action_view_sub_inventory" |
532 | 67 | <field name="model">stock.inventory</field> | 70 | name="View Sub-inventories" |
485 | 68 | <field name="type">tree</field> | ||
486 | 69 | <field name="priority" eval="99" /> | ||
487 | 70 | <field name="arch" type="xml"> | ||
488 | 71 | <tree string="Sub-inventories" version="7.0"> | ||
489 | 72 | <field name="name" /> | ||
490 | 73 | <field name="state" /> | ||
491 | 74 | <field name="confirmed_rate" widget="progressbar" /> | ||
492 | 75 | <field name="inventory_ids" string="Number of Sub-inventories"/> | ||
493 | 76 | <!-- XXX: Ideally we would have liked to have a button to open Sub-inventories, | ||
494 | 77 | but unfortunately the v6.0 GTK client crashes, and the 6.0 web client opens a windows without action buttons. | ||
495 | 78 | Maybe we may try that again with the new web client one day... | ||
496 | 79 | <button string="View this inventory" type="object" name="open_sub_inventory"/> | ||
497 | 80 | --> | ||
498 | 81 | </tree> | ||
499 | 82 | </field> | ||
500 | 83 | </record> | ||
501 | 84 | |||
502 | 85 | <record model="ir.ui.view" | ||
503 | 86 | id="stock_inventory_hierarchical_subinventory_form_view"> | ||
504 | 87 | <field name="name">hierarchical.inventory.subinventory.form</field> | ||
505 | 88 | <field name="model">stock.inventory</field> | ||
506 | 89 | <field name="type">form</field> | ||
507 | 90 | <field name="priority" eval="99" /> | ||
508 | 91 | <field name="arch" type="xml"> | ||
509 | 92 | <form string="Sub-inventories" version="7.0"> | ||
510 | 93 | <group colspan="4" col="2"> | ||
511 | 94 | <field name="name" default_focus="1"/> | ||
512 | 95 | </group> | ||
513 | 96 | <field name="inventory_ids" nolabel="1" colspan="4" | ||
514 | 97 | context="{'form_view_ref' : 'stock_inventory_hierarchical.stock_inventory_hierarchical_subinventory_form_view', 'tree_view_ref' : 'stock_inventory_hierarchical.stock_inventory_hierarchical_subinventory_tree_view'}" /> | ||
515 | 98 | <group colspan="4" col="3"> | ||
516 | 99 | <field name="state" /> | ||
517 | 100 | <!-- XXX: Ideally we would have liked to have a button to open Sub-inventories, | ||
518 | 101 | but unfortunately the v6.0 GTK client crashes, and the 6.0 web client opens a windows without action buttons. | ||
519 | 102 | Maybe we may try that again with the new web client one day... | ||
520 | 103 | <button string="View this inventory" type="object" name="open_sub_inventory"/> | ||
521 | 104 | --> | ||
522 | 105 | </group> | ||
523 | 106 | </form> | ||
524 | 107 | </field> | ||
525 | 108 | </record> | ||
526 | 109 | |||
527 | 110 | <act_window id="action_view_sub_inventory" | ||
528 | 111 | name="Sub-inventories" | ||
533 | 112 | res_model="stock.inventory" | 71 | res_model="stock.inventory" |
534 | 113 | src_model="stock.inventory" | 72 | src_model="stock.inventory" |
535 | 114 | view_mode="tree,form" | 73 | view_mode="tree,form" |
536 | 115 | 74 | ||
537 | === modified file 'stock_inventory_hierarchical/i18n/fr.po' | |||
538 | --- stock_inventory_hierarchical/i18n/fr.po 2014-03-12 15:08:22 +0000 | |||
539 | +++ stock_inventory_hierarchical/i18n/fr.po 2014-06-11 15:04:27 +0000 | |||
540 | @@ -21,16 +21,16 @@ | |||
541 | 21 | msgstr "Réference complète" | 21 | msgstr "Réference complète" |
542 | 22 | 22 | ||
543 | 23 | #. module: stock_inventory_hierarchical | 23 | #. module: stock_inventory_hierarchical |
547 | 24 | #: field:stock.inventory,confirmed_rate:0 | 24 | #: field:stock.inventory,progress_rate:0 |
548 | 25 | msgid "Confirmed" | 25 | msgid "Done" |
549 | 26 | msgstr "Confirmé" | 26 | msgstr "Terminé" |
550 | 27 | 27 | ||
551 | 28 | #. module: stock_inventory_hierarchical | 28 | #. module: stock_inventory_hierarchical |
552 | 29 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:108 | 29 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:108 |
553 | 30 | #: constraint:stock.inventory:0 | 30 | #: constraint:stock.inventory:0 |
554 | 31 | #, python-format | 31 | #, python-format |
557 | 32 | msgid "Error! You can not create recursive inventories." | 32 | msgid "Error: You can not create recursive inventories." |
558 | 33 | msgstr "Erreur! Vous ne pouvez pas créer d'inventaire récursifs." | 33 | msgstr "Erreur : Vous ne pouvez pas créer d'inventaire récursifs." |
559 | 34 | 34 | ||
560 | 35 | #. module: stock_inventory_hierarchical | 35 | #. module: stock_inventory_hierarchical |
561 | 36 | #: model:ir.model,name:stock_inventory_hierarchical.model_stock_inventory | 36 | #: model:ir.model,name:stock_inventory_hierarchical.model_stock_inventory |
562 | @@ -61,7 +61,7 @@ | |||
563 | 61 | #. module: stock_inventory_hierarchical | 61 | #. module: stock_inventory_hierarchical |
564 | 62 | #: constraint:stock.inventory:0 | 62 | #: constraint:stock.inventory:0 |
565 | 63 | msgid "Other Physical inventories are being conducted using the same Locations." | 63 | msgid "Other Physical inventories are being conducted using the same Locations." |
567 | 64 | msgstr "Erreur: certains emplacements sont déjà dans un autre inventaire." | 64 | msgstr "Certains emplacements sont déjà dans un autre inventaire." |
568 | 65 | 65 | ||
569 | 66 | #. module: stock_inventory_hierarchical | 66 | #. module: stock_inventory_hierarchical |
570 | 67 | #: field:stock.inventory,parent_id:0 | 67 | #: field:stock.inventory,parent_id:0 |
571 | @@ -87,19 +87,19 @@ | |||
572 | 87 | #. module: stock_inventory_hierarchical | 87 | #. module: stock_inventory_hierarchical |
573 | 88 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:196 | 88 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:196 |
574 | 89 | #, python-format | 89 | #, python-format |
576 | 90 | msgid "Some Sub-inventories are not done." | 90 | msgid "Some Sub-inventories are not validated." |
577 | 91 | msgstr "Certains sous-inventaires ne sont pas terminés." | 91 | msgstr "Certains sous-inventaires ne sont pas terminés." |
578 | 92 | 92 | ||
579 | 93 | #. module: stock_inventory_hierarchical | 93 | #. module: stock_inventory_hierarchical |
580 | 94 | #: model:ir.actions.act_window,name:stock_inventory_hierarchical.action_view_sub_inventory | 94 | #: model:ir.actions.act_window,name:stock_inventory_hierarchical.action_view_sub_inventory |
581 | 95 | #: view:stock.inventory:0 | 95 | #: view:stock.inventory:0 |
584 | 96 | msgid "Sub-inventories" | 96 | msgid "View Sub-inventories" |
585 | 97 | msgstr "Sous-inventaires" | 97 | msgstr "Voir les sous-inventaires" |
586 | 98 | 98 | ||
587 | 99 | #. module: stock_inventory_hierarchical | 99 | #. module: stock_inventory_hierarchical |
588 | 100 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:130 | 100 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:130 |
589 | 101 | #, python-format | 101 | #, python-format |
591 | 102 | msgid "Sub-inventory : %s" | 102 | msgid "Sub-inventory: %s" |
592 | 103 | msgstr "Sous-inventaire : %s" | 103 | msgstr "Sous-inventaire : %s" |
593 | 104 | 104 | ||
594 | 105 | #. module: stock_inventory_hierarchical | 105 | #. module: stock_inventory_hierarchical |
595 | @@ -107,6 +107,6 @@ | |||
596 | 107 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:188 | 107 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:188 |
597 | 108 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:196 | 108 | #: code:addons/stock_inventory_hierarchical/hierarchical_inventory.py:196 |
598 | 109 | #, python-format | 109 | #, python-format |
601 | 110 | msgid "Warning !" | 110 | msgid "Warning" |
602 | 111 | msgstr "Attention !" | 111 | msgstr "Attention" |
603 | 112 | 112 | ||
604 | 113 | 113 | ||
605 | === added directory 'stock_inventory_hierarchical/images' | |||
606 | === added file 'stock_inventory_hierarchical/images/inventory_form.png' | |||
607 | 114 | Binary files stock_inventory_hierarchical/images/inventory_form.png 1970-01-01 00:00:00 +0000 and stock_inventory_hierarchical/images/inventory_form.png 2014-06-11 15:04:27 +0000 differ | 114 | Binary files stock_inventory_hierarchical/images/inventory_form.png 1970-01-01 00:00:00 +0000 and stock_inventory_hierarchical/images/inventory_form.png 2014-06-11 15:04:27 +0000 differ |
608 | === added file 'stock_inventory_hierarchical/images/inventory_form_actions.png' | |||
609 | 115 | Binary files stock_inventory_hierarchical/images/inventory_form_actions.png 1970-01-01 00:00:00 +0000 and stock_inventory_hierarchical/images/inventory_form_actions.png 2014-06-11 15:04:27 +0000 differ | 115 | Binary files stock_inventory_hierarchical/images/inventory_form_actions.png 1970-01-01 00:00:00 +0000 and stock_inventory_hierarchical/images/inventory_form_actions.png 2014-06-11 15:04:27 +0000 differ |
610 | === added directory 'stock_inventory_hierarchical/static' | |||
611 | === added directory 'stock_inventory_hierarchical/static/src' | |||
612 | === added directory 'stock_inventory_hierarchical/static/src/img' | |||
613 | === added file 'stock_inventory_hierarchical/static/src/img/icon.png' | |||
614 | 116 | Binary files stock_inventory_hierarchical/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and stock_inventory_hierarchical/static/src/img/icon.png 2014-06-11 15:04:27 +0000 differ | 116 | Binary files stock_inventory_hierarchical/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and stock_inventory_hierarchical/static/src/img/icon.png 2014-06-11 15:04:27 +0000 differ |
615 | === modified file 'stock_inventory_hierarchical/test/hierarchical_inventory_test.yml' | |||
616 | --- stock_inventory_hierarchical/test/hierarchical_inventory_test.yml 2014-03-12 15:08:22 +0000 | |||
617 | +++ stock_inventory_hierarchical/test/hierarchical_inventory_test.yml 2014-06-11 15:04:27 +0000 | |||
618 | @@ -1,48 +1,39 @@ | |||
619 | 1 | - | 1 | - |
620 | 2 | In this file, i check rules about hierarchical inventories. | 2 | In this file, i check rules about hierarchical inventories. |
645 | 3 | children date must be the same of parent date for each state, | 3 | Children date must be the same of parent date for each state, |
646 | 4 | the state of parent and children can change only if conditions are true. | 4 | the state of parent and children can change only if conditions are correct. |
647 | 5 | First, i'll create two children inventory of stock_inventory_parent inventory. | 5 | - |
648 | 6 | - | 6 | Check if date of children are the same as the parent's. |
649 | 7 | !python {model: stock.inventory}: | | 7 | - |
650 | 8 | from osv import orm | 8 | !python {model: stock.inventory}: | |
651 | 9 | self.child_1_id = self.create(cr, uid, {'parent_id': ref('stock_inventory_parent0'), | 9 | parent_date = self.read( |
652 | 10 | 'inventory_ids': [], | 10 | cr, uid, [ref('stock_inventory_parent0')], ['date'])[0]['date'] |
653 | 11 | 'name': 'Children 1 test inventory'}) | 11 | child_1_date = self.read( |
654 | 12 | self.child_2_id = self.create(cr, uid, {'parent_id': ref('stock_inventory_parent0'), | 12 | cr, uid, [ref('child_1_id')], ['date'])[0]['date'] |
655 | 13 | 'inventory_ids': [], | 13 | assert child_1_date == parent_date, "Date are different: %s - %s" % (parent_date, child_1_date) |
656 | 14 | 'name': 'Children 2 test inventory'}) | 14 | |
657 | 15 | - | 15 | child_2_date = self.read( |
658 | 16 | Check if date of children are the same than parent date. | 16 | cr, uid, [ref('child_2_id')], ['date'])[0]['date'] |
659 | 17 | I'll read the date for 2 children and compare them with parent inventory date. | 17 | assert child_2_date == parent_date, "Date are different: %s - %s" % (parent_date, child_2_date) |
636 | 18 | - | ||
637 | 19 | !python {model: stock.inventory}: | | ||
638 | 20 | from osv import orm | ||
639 | 21 | parent_date = self.read(cr, uid, [ref('stock_inventory_parent0')], ['date'])[0]['date'] | ||
640 | 22 | child_1_date = self.read(cr, uid, [self.child_1_id], ['date'])[0]['date'] | ||
641 | 23 | assert child_1_date == parent_date, "Date are not equals : %s - %s" % (parent_date, child_1_date) | ||
642 | 24 | |||
643 | 25 | child_2_date = self.read(cr, uid, [self.child_2_id], ['date'])[0]['date'] | ||
644 | 26 | assert child_2_date == parent_date, "Date are not equals : %s - %s" % (parent_date, child_2_date) | ||
660 | 27 | 18 | ||
661 | 28 | - | 19 | - |
662 | 29 | Check if children cannot be canceled if the parent was not canceled. | 20 | Check if children cannot be canceled if the parent was not canceled. |
663 | 30 | I'll try to cancel both children inventory while parent inventory having "draft" state. | 21 | I'll try to cancel both children inventory while parent inventory having "draft" state. |
665 | 31 | After, i'll verify the state of each inventory. | 22 | After, i'll verify the state of each inventory. |
666 | 32 | - | 23 | - |
678 | 33 | !python {model: stock.inventory}: | | 24 | !python {model: stock.inventory}: | |
679 | 34 | from osv import orm, osv | 25 | from stock_inventory_hierarchical import HierarchicalInventoryException |
680 | 35 | try: | 26 | try: |
681 | 36 | self.action_cancel_inventary(cr, uid, [self.child_1_id]) | 27 | self.action_cancel_inventory(cr, uid, [ref('child_1_id')]) |
682 | 37 | except osv.except_osv as e: | 28 | except HierarchicalInventoryException as e: |
683 | 38 | log("Good ! The Inventory could not be canceled : %s" % e) | 29 | log("Good ! The Inventory could not be canceled: %s" % e) |
684 | 39 | try: | 30 | try: |
685 | 40 | self.action_cancel_inventary(cr, uid, [self.child_2_id]) | 31 | self.action_cancel_inventory(cr, uid, [ref('child_2_id')]) |
686 | 41 | except osv.except_osv as e: | 32 | except HierarchicalInventoryException as e: |
687 | 42 | log("Good ! The Inventory could not be canceled : %s" % e) | 33 | log("Good ! The Inventory could not be canceled: %s" % e) |
688 | 43 | child_1_state = self.read(cr, uid, [self.child_1_id], ['state'])[0]['state'] | 34 | child_1_state = self.read(cr, uid, [ref('child_1_id')], ['state'])[0]['state'] |
689 | 44 | assert child_1_state == 'draft', "Child inventory 1 have '%s' state. It should be 'draft'" % child_1_state | 35 | assert child_1_state == 'draft', "Child inventory 1 have '%s' state. It should be 'draft'" % child_1_state |
691 | 45 | child_2_state = self.read(cr, uid, [self.child_2_id], ['state'])[0]['state'] | 36 | child_2_state = self.read(cr, uid, [ref('child_2_id')], ['state'])[0]['state'] |
692 | 46 | assert child_2_state == 'draft', "Child inventory 2 have '%s' state. It should be 'draft'" % child_2_state | 37 | assert child_2_state == 'draft', "Child inventory 2 have '%s' state. It should be 'draft'" % child_2_state |
693 | 47 | 38 | ||
694 | 48 | - | 39 | - |
695 | @@ -50,58 +41,56 @@ | |||
696 | 50 | To check this, i'll try to confirm parent inventory when children inventory having "draft" state, | 41 | To check this, i'll try to confirm parent inventory when children inventory having "draft" state, |
697 | 51 | and i'll check if state is still 'draft'. | 42 | and i'll check if state is still 'draft'. |
698 | 52 | - | 43 | - |
701 | 53 | !python {model: stock.inventory}: | | 44 | !python {model: stock.inventory}: | |
702 | 54 | from osv import orm, osv | 45 | from stock_inventory_hierarchical import HierarchicalInventoryException |
703 | 55 | try: | 46 | try: |
707 | 56 | self.action_confirm(cr, uid, [ref('stock_inventory_parent0')]) | 47 | self.action_confirm(cr, uid, [ref('stock_inventory_parent0')]) |
708 | 57 | except osv.except_osv as e: | 48 | except HierarchicalInventoryException as e: |
709 | 58 | log("Good, the inventory could not be confirm : %s", e) | 49 | log("Good, the inventory could not be confirmed: %s", e) |
710 | 59 | parent_state = self.read(cr, uid, [ref('stock_inventory_parent0')], ['state'])[0]['state'] | 50 | parent_state = self.read(cr, uid, [ref('stock_inventory_parent0')], ['state'])[0]['state'] |
711 | 60 | assert parent_state == 'draft', "Parent inventory have '%s' state. It should be 'draft'" % parent_state | 51 | assert parent_state == 'draft', "Parent inventory have '%s' state. It should be 'draft'" % parent_state |
712 | 61 | 52 | ||
713 | 62 | - | 53 | - |
714 | 63 | In order, i'll confirm the children inventories, and the parent inventory after. | 54 | In order, i'll confirm the children inventories, and the parent inventory after. |
715 | 64 | - | 55 | - |
720 | 65 | !python {model: stock.inventory}: | | 56 | !python {model: stock.inventory}: | |
721 | 66 | from osv import orm, osv | 57 | self.action_confirm(cr, uid, [ref('child_1_id')]) |
722 | 67 | self.action_confirm(cr, uid, [self.child_1_id]) | 58 | child_1_state = self.read(cr, uid, [ref('child_1_id')], ['state'])[0]['state'] |
719 | 68 | child_1_state = self.read(cr, uid, [self.child_1_id], ['state'])[0]['state'] | ||
723 | 69 | assert child_1_state == 'confirm', "Child inventory 1 have '%s' state. It should be 'confirm'" % child_1_state | 59 | assert child_1_state == 'confirm', "Child inventory 1 have '%s' state. It should be 'confirm'" % child_1_state |
727 | 70 | 60 | ||
728 | 71 | self.action_confirm(cr, uid, [self.child_2_id]) | 61 | self.action_confirm(cr, uid, [ref('child_2_id')]) |
729 | 72 | child_2_state = self.read(cr, uid, [self.child_2_id], ['state'])[0]['state'] | 62 | child_2_state = self.read(cr, uid, [ref('child_2_id')], ['state'])[0]['state'] |
730 | 73 | assert child_2_state == 'confirm', "Child inventory 2 have '%s' state. It should be 'confirm'" % child_2_state | 63 | assert child_2_state == 'confirm', "Child inventory 2 have '%s' state. It should be 'confirm'" % child_2_state |
732 | 74 | 64 | ||
733 | 75 | self.action_confirm(cr, uid, [ref('stock_inventory_parent0')]) | 65 | self.action_confirm(cr, uid, [ref('stock_inventory_parent0')]) |
734 | 76 | parent_state = self.read(cr, uid, [ref('stock_inventory_parent0')], ['state'])[0]['state'] | 66 | parent_state = self.read(cr, uid, [ref('stock_inventory_parent0')], ['state'])[0]['state'] |
735 | 77 | assert parent_state == 'confirm', "Parent inventory have '%s' state. It should be 'confirm'" % parent_state | 67 | assert parent_state == 'confirm', "Parent inventory have '%s' state. It should be 'confirm'" % parent_state |
737 | 78 | 68 | ||
738 | 79 | - | 69 | - |
739 | 80 | Check if children inventory have done state before validate parent inventory. | 70 | Check if children inventory have done state before validate parent inventory. |
741 | 81 | I'll try to validate parent inventory before children. | 71 | I'll try to validate parent inventory before children. |
742 | 82 | - | 72 | - |
745 | 83 | !python {model: stock.inventory}: | | 73 | !python {model: stock.inventory}: | |
746 | 84 | from osv import orm, osv | 74 | from stock_inventory_hierarchical import HierarchicalInventoryException |
747 | 85 | try: | 75 | try: |
748 | 86 | self.action_done(cr, uid, [ref('stock_inventory_parent0')]) | 76 | self.action_done(cr, uid, [ref('stock_inventory_parent0')]) |
751 | 87 | except osv.except_osv as e: | 77 | except HierarchicalInventoryException as e: |
752 | 88 | log("Good, the inventory could not be validate : %s", e) | 78 | log("Good, the inventory could not be validated: %s", e) |
753 | 89 | parent_state = self.read(cr, uid, [ref('stock_inventory_parent0')], ['state'])[0]['state'] | 79 | parent_state = self.read(cr, uid, [ref('stock_inventory_parent0')], ['state'])[0]['state'] |
754 | 90 | assert parent_state == 'confirm', "Parent inventory have '%s' state. It should be 'confirm'" % parent_state | 80 | assert parent_state == 'confirm', "Parent inventory have '%s' state. It should be 'confirm'" % parent_state |
755 | 91 | 81 | ||
756 | 92 | - | 82 | - |
757 | 93 | Now, i'll validate all children inventory before validate the parent. | 83 | Now, i'll validate all children inventory before validate the parent. |
758 | 94 | - | 84 | - |
763 | 95 | !python {model: stock.inventory}: | | 85 | !python {model: stock.inventory}: | |
764 | 96 | from osv import orm, osv | 86 | self.action_done(cr, uid, [ref('child_1_id')]) |
765 | 97 | self.action_done(cr, uid, [self.child_1_id]) | 87 | child_1_state = self.read(cr, uid, [ref('child_1_id')], ['state'])[0]['state'] |
762 | 98 | child_1_state = self.read(cr, uid, [self.child_1_id], ['state'])[0]['state'] | ||
766 | 99 | assert child_1_state == 'done', "Child inventory 1 have '%s' state. It should be 'done'" % child_1_state | 88 | assert child_1_state == 'done', "Child inventory 1 have '%s' state. It should be 'done'" % child_1_state |
770 | 100 | 89 | ||
771 | 101 | self.action_done(cr, uid, [self.child_2_id]) | 90 | self.action_done(cr, uid, [ref('child_2_id')]) |
772 | 102 | child_2_state = self.read(cr, uid, [self.child_2_id], ['state'])[0]['state'] | 91 | child_2_state = self.read(cr, uid, [ref('child_2_id')], ['state'])[0]['state'] |
773 | 103 | assert child_2_state == 'done', "Child inventory 2 have '%s' state. It should be 'done'" % child_2_state | 92 | assert child_2_state == 'done', "Child inventory 2 have '%s' state. It should be 'done'" % child_2_state |
775 | 104 | 93 | ||
776 | 105 | self.action_done(cr, uid, [ref('stock_inventory_parent0')]) | 94 | self.action_done(cr, uid, [ref('stock_inventory_parent0')]) |
777 | 106 | parent_state = self.read(cr, uid, [ref('stock_inventory_parent0')], ['state'])[0]['state'] | 95 | parent_state = self.read(cr, uid, [ref('stock_inventory_parent0')], ['state'])[0]['state'] |
779 | 107 | assert parent_state == 'done', "Parent inventory have '%s' state. It should be 'done'" % parent_state | 96 | assert parent_state == 'done', "Parent inventory have '%s' state. It should be 'done'" % parent_state |
780 | 108 | 97 | ||
781 | === modified file 'stock_inventory_hierarchical_location/__init__.py' | |||
782 | --- stock_inventory_hierarchical_location/__init__.py 2014-03-12 15:08:22 +0000 | |||
783 | +++ stock_inventory_hierarchical_location/__init__.py 2014-06-11 15:04:27 +0000 | |||
784 | @@ -1,4 +1,4 @@ | |||
786 | 1 | # -*- encoding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
787 | 2 | ############################################################################## | 2 | ############################################################################## |
788 | 3 | # | 3 | # |
789 | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. |
790 | @@ -18,5 +18,5 @@ | |||
791 | 18 | # | 18 | # |
792 | 19 | ############################################################################## | 19 | ############################################################################## |
793 | 20 | 20 | ||
796 | 21 | import inventory_hierarchical_location | 21 | from . import inventory_hierarchical_location |
797 | 22 | import wizard | 22 | from . import wizard |
798 | 23 | 23 | ||
799 | === modified file 'stock_inventory_hierarchical_location/__openerp__.py' | |||
800 | --- stock_inventory_hierarchical_location/__openerp__.py 2014-03-12 15:08:22 +0000 | |||
801 | +++ stock_inventory_hierarchical_location/__openerp__.py 2014-06-11 15:04:27 +0000 | |||
802 | @@ -1,4 +1,4 @@ | |||
804 | 1 | # -*- encoding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
805 | 2 | ############################################################################## | 2 | ############################################################################## |
806 | 3 | # | 3 | # |
807 | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. |
808 | @@ -19,34 +19,30 @@ | |||
809 | 19 | ############################################################################## | 19 | ############################################################################## |
810 | 20 | 20 | ||
811 | 21 | { | 21 | { |
814 | 22 | "name": "Exhaustive and hierachical Stock Inventories", | 22 | "name": "Exhaustive and hierarchical Stock Inventories", |
815 | 23 | "version": "1.0", | 23 | "version": "1.1", |
816 | 24 | "depends": ["stock_inventory_hierarchical", "stock_inventory_location"], | 24 | "depends": ["stock_inventory_hierarchical", "stock_inventory_location"], |
817 | 25 | "auto_install": True, | ||
818 | 25 | "author": u"Numérigraphe", | 26 | "author": u"Numérigraphe", |
820 | 26 | "category": "stock inventory", | 27 | "category": "Hidden", |
821 | 27 | "description": """ | 28 | "description": """ |
827 | 28 | This module makes exhaustive Inventories aware of their Sub-Inventories. | 29 | Make exhaustive Inventories aware of their Sub-Inventories. |
828 | 29 | ======================================================================== | 30 | =========================================================== |
824 | 30 | |||
825 | 31 | It should be installed if both modules "stock_inventory_location" | ||
826 | 32 | and "stock_inventory_hierarchical" are installed. | ||
829 | 33 | 31 | ||
830 | 34 | This module allows an inventory to contain a general Location, | 32 | This module allows an inventory to contain a general Location, |
831 | 35 | and it's sub-inventories to contain some of it's sub-Locations. | 33 | and it's sub-inventories to contain some of it's sub-Locations. |
835 | 36 | When you open an inventory, OpenERP will warn you if some of the sub-Locations | 34 | It will prevent you from setting the Inventories and sub-Inventories |
833 | 37 | of an inventory are absent from the sub-Inventories. | ||
834 | 38 | It will also prevent you from setting the Inventories and sub-Inventories | ||
836 | 39 | in inconsistent status. | 35 | in inconsistent status. |
837 | 36 | |||
838 | 37 | This module will be installed automatically if the modules | ||
839 | 38 | "stock_inventory_location" and "stock_inventory_hierarchical" are both | ||
840 | 39 | installed. | ||
841 | 40 | You must keep this module installed to ensure proper functioning. | ||
842 | 41 | |||
843 | 40 | """, | 42 | """, |
855 | 41 | "init_xml": [], | 43 | "data": [ |
856 | 42 | "update_xml": [ | 44 | "inventory_hierarchical_location_view.xml", |
857 | 43 | "wizard/stock_inventory_missing_locations_view.xml", | 45 | ], |
858 | 44 | "inventory_hierarchical_location_view.xml", | 46 | "test": ["test/inventory_hierarchical_location_test.yml"], |
859 | 45 | ], | 47 | "demo": ["inventory_hierarchical_location_demo.xml"], |
849 | 46 | |||
850 | 47 | "test": ["test/inventory_hierarchical_location_test.yml"], | ||
851 | 48 | "demo": ["inventory_hierarchical_location_demo.xml"], | ||
852 | 49 | |||
853 | 50 | # Will work with v6.1 and later | ||
854 | 51 | "auto_install": True, | ||
860 | 52 | } | 48 | } |
861 | 53 | 49 | ||
862 | === modified file 'stock_inventory_hierarchical_location/i18n/fr.po' | |||
863 | --- stock_inventory_hierarchical_location/i18n/fr.po 2014-03-12 15:08:22 +0000 | |||
864 | +++ stock_inventory_hierarchical_location/i18n/fr.po 2014-06-11 15:04:27 +0000 | |||
865 | @@ -64,8 +64,8 @@ | |||
866 | 64 | #. module: stock_inventory_hierarchical_location | 64 | #. module: stock_inventory_hierarchical_location |
867 | 65 | #: code:addons/stock_inventory_hierarchical_location/inventory_hierarchical_location.py:41 | 65 | #: code:addons/stock_inventory_hierarchical_location/inventory_hierarchical_location.py:41 |
868 | 66 | #, python-format | 66 | #, python-format |
871 | 67 | msgid "One of the parent inventories are not open." | 67 | msgid "One of the parent inventories is not open." |
872 | 68 | msgstr "Un inventaire parent n'est pas ouvert." | 68 | msgstr "Un des inventaire parent n'est pas ouvert." |
873 | 69 | 69 | ||
874 | 70 | #. module: stock_inventory_hierarchical_location | 70 | #. module: stock_inventory_hierarchical_location |
875 | 71 | #: view:stock.inventory:0 | 71 | #: view:stock.inventory:0 |
876 | @@ -97,9 +97,9 @@ | |||
877 | 97 | #: code:addons/stock_inventory_hierarchical_location/inventory_hierarchical_location.py:58 | 97 | #: code:addons/stock_inventory_hierarchical_location/inventory_hierarchical_location.py:58 |
878 | 98 | #, python-format | 98 | #, python-format |
879 | 99 | msgid "This location is not declared on the parent inventory\n" | 99 | msgid "This location is not declared on the parent inventory\n" |
881 | 100 | "You cannot add it !" | 100 | "It cannot be added." |
882 | 101 | msgstr "Cet emplacement n'est pas déclaré dans l'inventaire parent\n" | 101 | msgstr "Cet emplacement n'est pas déclaré dans l'inventaire parent\n" |
884 | 102 | "Vous ne pouvez pas l'ajouter !" | 102 | "Vous ne pouvez pas l'ajouter." |
885 | 103 | 103 | ||
886 | 104 | #. module: stock_inventory_hierarchical_location | 104 | #. module: stock_inventory_hierarchical_location |
887 | 105 | #: code:addons/stock_inventory_hierarchical_location/inventory_hierarchical_location.py:41 | 105 | #: code:addons/stock_inventory_hierarchical_location/inventory_hierarchical_location.py:41 |
888 | 106 | 106 | ||
889 | === modified file 'stock_inventory_hierarchical_location/inventory_hierarchical_location.py' | |||
890 | --- stock_inventory_hierarchical_location/inventory_hierarchical_location.py 2014-03-12 15:08:22 +0000 | |||
891 | +++ stock_inventory_hierarchical_location/inventory_hierarchical_location.py 2014-06-11 15:04:27 +0000 | |||
892 | @@ -1,4 +1,4 @@ | |||
894 | 1 | # -*- encoding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
895 | 2 | ############################################################################## | 2 | ############################################################################## |
896 | 3 | # | 3 | # |
897 | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. |
898 | @@ -18,120 +18,74 @@ | |||
899 | 18 | # | 18 | # |
900 | 19 | ############################################################################## | 19 | ############################################################################## |
901 | 20 | 20 | ||
903 | 21 | from openerp.osv import osv | 21 | from openerp.osv import orm |
904 | 22 | from openerp.tools.translate import _ | 22 | from openerp.tools.translate import _ |
905 | 23 | 23 | ||
908 | 24 | 24 | from stock_inventory_hierarchical import HierarchicalInventoryException | |
909 | 25 | class StockInventory(osv.osv): | 25 | |
910 | 26 | # Add the date to the list of fields we must propagate to children inventories | ||
911 | 27 | from stock_inventory_hierarchical import PARENT_VALUES | ||
912 | 28 | PARENT_VALUES.append('exhaustive') | ||
913 | 29 | |||
914 | 30 | |||
915 | 31 | class HierarchicalExhInventory(orm.Model): | ||
916 | 32 | """Add hierarchical structure features to exhaustive Inventories""" | ||
917 | 26 | _inherit = 'stock.inventory' | 33 | _inherit = 'stock.inventory' |
918 | 27 | 34 | ||
919 | 28 | def __init__(self, pool, cr): | ||
920 | 29 | """Propagate the "exhaustive" field from inventories to sub-inventories""" | ||
921 | 30 | s = super(StockInventory, self) | ||
922 | 31 | s.PARENT_VALUES.append('exhaustive') | ||
923 | 32 | return s.__init__(pool, cr) | ||
924 | 33 | |||
925 | 34 | def action_open(self, cr, uid, ids, context=None): | 35 | def action_open(self, cr, uid, ids, context=None): |
926 | 35 | """Open only if all the parents are Open.""" | 36 | """Open only if all the parents are Open.""" |
927 | 36 | #XXX the dosctring used to say this but it's not implemented, normal? | ||
928 | 37 | # --> "Before opening, if locations are missing, ask the user | ||
929 | 38 | # to validate the opening without these locations." | ||
930 | 39 | for inventory in self.browse(cr, uid, ids, context=context): | 37 | for inventory in self.browse(cr, uid, ids, context=context): |
931 | 40 | while inventory.parent_id: | 38 | while inventory.parent_id: |
932 | 41 | inventory = inventory.parent_id | 39 | inventory = inventory.parent_id |
933 | 42 | if inventory.state != 'open': | 40 | if inventory.state != 'open': |
939 | 43 | raise osv.except_osv(_('Warning !'), | 41 | raise HierarchicalInventoryException( |
940 | 44 | _('One of the parent inventories are not open.')) | 42 | _('Warning'), |
941 | 45 | return super(StockInventory, self).action_open(cr, uid, ids, context=context) | 43 | _('One of the parent inventories is not open.')) |
942 | 46 | 44 | return super(HierarchicalExhInventory, self).action_open( | |
943 | 47 | def check_location(self, cr, uid, ids, location_ids, name, context=None): | 45 | cr, uid, ids, context=context) |
944 | 46 | |||
945 | 47 | # TODO v8: probably only keep the state "done" | ||
946 | 48 | def confirm_missing_locations(self, cr, uid, ids, context=None): | ||
947 | 49 | """Do something only if children state are confirm or done.""" | ||
948 | 50 | children_count = self.search( | ||
949 | 51 | cr, uid, [('parent_id', 'child_of', ids), | ||
950 | 52 | ('id', 'not in', ids), | ||
951 | 53 | ('state', 'not in', ['confirm', 'done'])], | ||
952 | 54 | context=context, count=True) | ||
953 | 55 | if children_count > 0: | ||
954 | 56 | raise HierarchicalInventoryException( | ||
955 | 57 | _('Warning'), | ||
956 | 58 | _('Some Sub-inventories are not confirmed.')) | ||
957 | 59 | return super(HierarchicalExhInventory, | ||
958 | 60 | self).confirm_missing_locations( | ||
959 | 61 | cr, uid, ids, context=context) | ||
960 | 62 | |||
961 | 63 | def onchange_location_id(self, cr, uid, ids, location_id, context=None): | ||
962 | 48 | """Check if location is a child of parent inventory location""" | 64 | """Check if location is a child of parent inventory location""" |
979 | 49 | res_location_ids = location_ids[0][2] | 65 | loc_obj = self.pool['stock.location'] |
980 | 50 | nbr_location_ids = len(res_location_ids) | 66 | for inventory in self.browse(cr, uid, ids, context=context): |
981 | 51 | for inventory in self.browse(cr, uid, ids, context=None): | 67 | if inventory.parent_id: |
982 | 52 | if inventory.parent_id.id: | 68 | allowed_location_ids = loc_obj.search( |
983 | 53 | parent_locations = self.read(cr, uid, [inventory.parent_id.id], ['location_ids']) | 69 | cr, uid, [('location_id', 'child_of', |
984 | 54 | parent_children_locations = self.pool.get('stock.location').search(cr, uid, [('location_id', 'child_of', parent_locations[0]['location_ids'])]) | 70 | inventory.parent_id.location_id.id)], |
985 | 55 | for location_id in res_location_ids: | 71 | context=context) |
986 | 56 | if location_id not in parent_children_locations: | 72 | if location_id not in allowed_location_ids: |
987 | 57 | res_location_ids.remove(location_id) | 73 | return { |
988 | 58 | res = {} | 74 | 'location_id': False, |
989 | 59 | if nbr_location_ids != len(res_location_ids): | 75 | 'warning': { |
990 | 60 | res['warning'] = {'title': _('Warning: Wrong location'), | 76 | 'title': _('Warning: Wrong location'), |
991 | 61 | 'message': _("This location is not declared on the parent inventory\n" | 77 | 'message': _("This location is not declared on " |
992 | 62 | "You cannot add it !")} | 78 | "the parent inventory\n" |
993 | 63 | res['value'] = {'location_ids': res_location_ids, } | 79 | "It cannot be added.")} |
994 | 64 | return res | 80 | } |
995 | 81 | return {} | ||
996 | 65 | 82 | ||
998 | 66 | def _fill_location_lines(self, cr, uid, inventory_id, location_ids, set_stock_zero, context=None): | 83 | def _fill_location_lines(self, cr, uid, inventory_id, location_ids, |
999 | 84 | set_stock_zero, context=None): | ||
1000 | 67 | """Add ids of children inventory into list """ | 85 | """Add ids of children inventory into list """ |
1002 | 68 | children_inventory_ids = self.search(cr, uid, [('parent_id', 'child_of', inventory_id)]) | 86 | children_inventory_ids = self.search( |
1003 | 87 | cr, uid, [('parent_id', 'child_of', inventory_id)]) | ||
1004 | 69 | context['children_inventory_ids'] = children_inventory_ids | 88 | context['children_inventory_ids'] = children_inventory_ids |
1073 | 70 | return super(StockInventory, self)._fill_location_lines(cr, uid, inventory_id, location_ids, set_stock_zero, context=context) | 89 | return super(HierarchicalExhInventory, self)._fill_location_lines( |
1074 | 71 | 90 | cr, uid, inventory_id, location_ids, set_stock_zero, | |
1075 | 72 | def open_missing_location_wizard(self, cr, uid, ids, context=None): | 91 | context=context) |
1008 | 73 | """Open wizard if inventory have children. | ||
1009 | 74 | Before, verify if all children of exhaustive inventory have at least one location.""" | ||
1010 | 75 | children_ids = self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context) | ||
1011 | 76 | for inventory in self.browse(cr, uid, children_ids, context=context): | ||
1012 | 77 | if inventory.exhaustive: | ||
1013 | 78 | if not inventory.location_ids: | ||
1014 | 79 | raise osv.except_osv(_('Warning !'), | ||
1015 | 80 | _('Location missing for inventory "%s".') % inventory.name) | ||
1016 | 81 | children_count = self.pool.get('stock.inventory').search(cr, uid, [('parent_id', 'child_of', ids)], count=True) | ||
1017 | 82 | if children_count == 1: | ||
1018 | 83 | return self.action_open(cr, uid, ids, context) | ||
1019 | 84 | else: | ||
1020 | 85 | context['active_ids'] = ids | ||
1021 | 86 | context['active_id'] = ids[0] | ||
1022 | 87 | return { | ||
1023 | 88 | 'type': 'ir.actions.act_window', | ||
1024 | 89 | 'view_type': 'form', | ||
1025 | 90 | 'view_mode': 'form', | ||
1026 | 91 | 'res_model': 'stock.inventory.missing.location', | ||
1027 | 92 | 'target': 'new', | ||
1028 | 93 | 'context': context, | ||
1029 | 94 | 'nodestroy': True, | ||
1030 | 95 | } | ||
1031 | 96 | |||
1032 | 97 | |||
1033 | 98 | # XXX: move to /wizard | ||
1034 | 99 | class StockInventoryUninventoriedLocation(osv.osv_memory): | ||
1035 | 100 | _inherit = 'stock.inventory.uninventoried.locations' | ||
1036 | 101 | |||
1037 | 102 | def inventories(self, cr, uid, inventory_parent_id): | ||
1038 | 103 | """Iterator of children inventories. | ||
1039 | 104 | return inventory_id; | ||
1040 | 105 | """ | ||
1041 | 106 | children_ids = self.pool.get('stock.inventory').search(cr, uid, [('parent_id', 'child_of', inventory_parent_id)]) | ||
1042 | 107 | for inventory_id in children_ids: | ||
1043 | 108 | yield inventory_id | ||
1044 | 109 | |||
1045 | 110 | def get_locations(self, cr, uid, inventory_id, context=None): | ||
1046 | 111 | """Get all locations through inventory tree.""" | ||
1047 | 112 | list_inventories_locations_ids = [] | ||
1048 | 113 | for i_id in self.inventories(cr, uid, inventory_id): | ||
1049 | 114 | location_ids = super(StockInventoryUninventoriedLocation, self).get_locations(cr, uid, i_id, context=context) | ||
1050 | 115 | list_inventories_locations_ids = list(set(list_inventories_locations_ids + location_ids)) | ||
1051 | 116 | return list_inventories_locations_ids | ||
1052 | 117 | |||
1053 | 118 | def get_locations_inventoried(self, cr, uid, inventory_id, location_ids, context=None): | ||
1054 | 119 | """Get all locations on inventory lines through inventory tree.""" | ||
1055 | 120 | list_all_inventoried_location_ids = [] | ||
1056 | 121 | for i_id in self.inventories(cr, uid, inventory_id): | ||
1057 | 122 | list_loc_ids = super(StockInventoryUninventoriedLocation, self).get_locations_inventoried(cr, uid, i_id, location_ids, context=context) | ||
1058 | 123 | list_all_inventoried_location_ids = list(set(list_all_inventoried_location_ids + list_loc_ids)) | ||
1059 | 124 | return list_all_inventoried_location_ids | ||
1060 | 125 | |||
1061 | 126 | def default_locations(self, cr, uid, context=None): | ||
1062 | 127 | """Do something only if children state are confirm or done.""" | ||
1063 | 128 | children_count = self.pool.get('stock.inventory').search(cr, uid, [('parent_id', 'child_of', context['active_id']), | ||
1064 | 129 | ('state', 'not in', ['confirm', 'done'])], context=context, count=True) | ||
1065 | 130 | if children_count > 1: | ||
1066 | 131 | raise osv.except_osv(_('Warning !'), _('Some Sub-inventories are not confirmed.')) | ||
1067 | 132 | return super(StockInventoryUninventoriedLocation, self).default_locations(cr, uid, context=context) | ||
1068 | 133 | |||
1069 | 134 | _defaults = { | ||
1070 | 135 | 'location_ids': default_locations, | ||
1071 | 136 | } | ||
1072 | 137 | |||
1076 | 138 | 92 | ||
1077 | === modified file 'stock_inventory_hierarchical_location/inventory_hierarchical_location_demo.xml' | |||
1078 | --- stock_inventory_hierarchical_location/inventory_hierarchical_location_demo.xml 2014-03-12 15:08:22 +0000 | |||
1079 | +++ stock_inventory_hierarchical_location/inventory_hierarchical_location_demo.xml 2014-06-11 15:04:27 +0000 | |||
1080 | @@ -3,16 +3,26 @@ | |||
1081 | 3 | <data noupdate="0"> | 3 | <data noupdate="0"> |
1082 | 4 | 4 | ||
1083 | 5 | <!-- Record inventories we can use in the tests. --> | 5 | <!-- Record inventories we can use in the tests. --> |
1085 | 6 | <!-- We need them in the demo data because test data is rolled back | 6 | <!-- We need them in the demo data because test data is rolled back |
1086 | 7 | whenever an exception is raised. --> | 7 | whenever an exception is raised. --> |
1089 | 8 | 8 | ||
1090 | 9 | <!-- Record an exhaustive inventory --> | 9 | <!-- Record a hierarchical exhaustive inventory --> |
1091 | 10 | <record id="parent_inventory_location" model="stock.inventory"> | 10 | <record id="parent_inventory_location" model="stock.inventory"> |
1093 | 11 | <field name="name">Hierarchical location exhaustive inventory</field> | 11 | <field name="name">Hierarchical exhaustive inventory</field> |
1094 | 12 | <field name="state">draft</field> | 12 | <field name="state">draft</field> |
1095 | 13 | <field name="date">2020-04-15 00:00:00</field> | 13 | <field name="date">2020-04-15 00:00:00</field> |
1098 | 14 | <field name="exhaustive">True</field> | 14 | <field name="exhaustive">True</field> |
1099 | 15 | <field name="location_ids" model="stock.location" search="[('name', '=', 'Shelf 2')]" /> | 15 | <field name="location_ids" model="stock.location" search="[('name', 'like', 'Stock')]" /> |
1100 | 16 | </record> | ||
1101 | 17 | <record id="child_1_id" model="stock.inventory"> | ||
1102 | 18 | <field name="name">Team A</field> | ||
1103 | 19 | <field name="parent_id" ref="parent_inventory_location"/> | ||
1104 | 20 | <field name="location_id" model="stock.location" search="[('name', '=', 'Shelf 1')]" /> | ||
1105 | 21 | </record> | ||
1106 | 22 | <record id="child_2_id" model="stock.inventory"> | ||
1107 | 23 | <field name="name">Team B</field> | ||
1108 | 24 | <field name="parent_id" ref="parent_inventory_location"/> | ||
1109 | 25 | <field name="location_id" model="stock.location" search="[('name', '=', 'Shelf 2')]" /> | ||
1110 | 16 | </record> | 26 | </record> |
1111 | 17 | </data> | 27 | </data> |
1112 | 18 | </openerp> | 28 | </openerp> |
1113 | 19 | 29 | ||
1114 | === modified file 'stock_inventory_hierarchical_location/inventory_hierarchical_location_view.xml' | |||
1115 | --- stock_inventory_hierarchical_location/inventory_hierarchical_location_view.xml 2014-03-12 15:08:22 +0000 | |||
1116 | +++ stock_inventory_hierarchical_location/inventory_hierarchical_location_view.xml 2014-06-11 15:04:27 +0000 | |||
1117 | @@ -5,34 +5,21 @@ | |||
1118 | 5 | <record model="ir.ui.view" id="stock_inventory_hierarchical_location_form_view"> | 5 | <record model="ir.ui.view" id="stock_inventory_hierarchical_location_form_view"> |
1119 | 6 | <field name="name">hierarchical.inventory.location.form</field> | 6 | <field name="name">hierarchical.inventory.location.form</field> |
1120 | 7 | <field name="model">stock.inventory</field> | 7 | <field name="model">stock.inventory</field> |
1121 | 8 | <field name="type">form</field> | ||
1122 | 9 | <field name="inherit_id" ref="stock.view_inventory_form" /> | 8 | <field name="inherit_id" ref="stock.view_inventory_form" /> |
1123 | 10 | <field name="arch" type="xml"> | 9 | <field name="arch" type="xml"> |
1145 | 11 | 10 | <xpath expr="/form//field[@name='exhaustive']" position="attributes"> | |
1146 | 12 | <xpath expr="//form[@string='Physical Inventory']//field[@name='exhaustive']" position="attributes"> | 11 | <attribute name="attrs">{'readonly':[('parent_id', '!=', False)]}</attribute> |
1147 | 13 | <attribute name="attrs">{'readonly':[('parent_id', '!=', False)]}</attribute> | 12 | </xpath> |
1148 | 14 | </xpath> | 13 | <xpath expr="/form//field[@name='location_id']" position="attributes"> |
1149 | 15 | 14 | <attribute name="on_change">onchange_location_id(location_id)</attribute> | |
1150 | 16 | <xpath expr="/form[@string='Physical Inventory']//page[@string='General Information']/field[@name='location_ids']" position="replace"> | 15 | </xpath> |
1151 | 17 | <field colspan="1" nolabel="1" name="location_ids" domain="[('usage','in',('view', 'internal'))]" | 16 | <xpath expr="/form//field[@name='inventory_ids']" position="attributes"> |
1152 | 18 | attrs="{'invisible':[('exhaustive','!=',True)]}" | 17 | <attribute name="context">{'default_parent_id': active_id, 'default_exhaustive': exhaustive}</attribute> |
1153 | 19 | on_change="check_location(location_ids, name)"> | 18 | </xpath> |
1133 | 20 | <tree string="Locations" editable="bottom"> | ||
1134 | 21 | <field name="name"/> | ||
1135 | 22 | </tree> | ||
1136 | 23 | </field> | ||
1137 | 24 | </xpath> | ||
1138 | 25 | |||
1139 | 26 | <!-- replace action_open button to open wizard missing locations --> | ||
1140 | 27 | <xpath expr="/form//button[@name='action_open']" position="replace"> | ||
1141 | 28 | <button name="open_missing_location_wizard" | ||
1142 | 29 | string="Open Inventory" type="object" states="draft" icon="gtk-apply"/> | ||
1143 | 30 | </xpath> | ||
1144 | 31 | |||
1154 | 32 | </field> | 19 | </field> |
1155 | 33 | </record> | 20 | </record> |
1156 | 34 | 21 | ||
1158 | 35 | <!-- Show exhaustive inventories by default --> | 22 | <!-- Show hierarchical exhaustive inventories by default --> |
1159 | 36 | <record id="stock.action_inventory_form" model="ir.actions.act_window"> | 23 | <record id="stock.action_inventory_form" model="ir.actions.act_window"> |
1160 | 37 | <field name="context">{'full':'1', 'search_default_exhaustive':1, 'search_default_main_inventories':1}</field> | 24 | <field name="context">{'full':'1', 'search_default_exhaustive':1, 'search_default_main_inventories':1}</field> |
1161 | 38 | </record> | 25 | </record> |
1162 | 39 | 26 | ||
1163 | === added directory 'stock_inventory_hierarchical_location/static' | |||
1164 | === added directory 'stock_inventory_hierarchical_location/static/src' | |||
1165 | === added directory 'stock_inventory_hierarchical_location/static/src/img' | |||
1166 | === added file 'stock_inventory_hierarchical_location/static/src/img/icon.png' | |||
1167 | 40 | Binary files stock_inventory_hierarchical_location/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and stock_inventory_hierarchical_location/static/src/img/icon.png 2014-06-11 15:04:27 +0000 differ | 27 | Binary files stock_inventory_hierarchical_location/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and stock_inventory_hierarchical_location/static/src/img/icon.png 2014-06-11 15:04:27 +0000 differ |
1168 | === modified file 'stock_inventory_hierarchical_location/test/inventory_hierarchical_location_test.yml' | |||
1169 | --- stock_inventory_hierarchical_location/test/inventory_hierarchical_location_test.yml 2014-03-12 15:08:22 +0000 | |||
1170 | +++ stock_inventory_hierarchical_location/test/inventory_hierarchical_location_test.yml 2014-06-11 15:04:27 +0000 | |||
1171 | @@ -1,31 +1,20 @@ | |||
1172 | 1 | - | 1 | - |
1174 | 2 | I will create children inventory. | 2 | Check that the exhaustive field of parent inventory has been propagated to children. |
1175 | 3 | - | 3 | - |
1180 | 4 | !python {model: stock.inventory}: | | 4 | !python {model: stock.inventory}: | |
1181 | 5 | self.child_1_id = self.create(cr, uid, {'parent_id': ref('parent_inventory_location'), | 5 | exhaustive = self.read(cr, uid, [ref("child_1_id")], ['exhaustive'])[0]['exhaustive'] |
1182 | 6 | 'inventory_ids': [], | 6 | assert exhaustive, "Exhaustive field not propagated to child inventory" |
1179 | 7 | 'name': 'Children 1 test inventory'}) | ||
1183 | 8 | 7 | ||
1184 | 9 | - | 8 | - |
1196 | 10 | I will check if exhaustive information of parent inventory has been added to children. | 9 | Check that I can't open child inventory while parent inventory is open. |
1197 | 11 | - | 10 | - |
1198 | 12 | !python {model: stock.inventory}: | | 11 | !python {model: stock.inventory}: | |
1199 | 13 | exhaustive = self.read(cr, uid, [self.child_1_id], ['exhaustive'])[0]['exhaustive'] | 12 | from stock_inventory_hierarchical import HierarchicalInventoryException |
1200 | 14 | assert exhaustive == True, "Exhaustive information not added to children inventory" | 13 | parent_state = self.read(cr, uid, [ref("parent_inventory_location")], ['state'])[0]['state'] |
1201 | 15 | 14 | assert parent_state == 'draft', "Parent inventory in state '%s'. It should be 'draft'" % parent_state | |
1191 | 16 | - | ||
1192 | 17 | I will check if i can't open children inventory while parent inventory is open. | ||
1193 | 18 | - | ||
1194 | 19 | !python {model: stock.inventory}: | | ||
1195 | 20 | from osv import orm, osv | ||
1202 | 21 | try: | 15 | try: |
1207 | 22 | self.action_open(cr, uid, [self.child_1_id]) | 16 | self.action_open(cr, uid, [ref("child_1_id")]) |
1208 | 23 | except osv.except_osv as e: | 17 | except HierarchicalInventoryException as e: |
1209 | 24 | log("Good ! The Inventory could not be opened : %s" % e) | 18 | log("Good ! The Inventory could not be opened: %s" % e) |
1210 | 25 | child_1_state = self.read(cr, uid, [self.child_1_id], ['state'])[0]['state'] | 19 | child_1_state = self.read(cr, uid, [ref("child_1_id")], ['state'])[0]['state'] |
1211 | 26 | assert child_1_state == 'draft', "Child inventory 1 have '%s' state. It should be 'draft'" % child_1_state | 20 | assert child_1_state == 'draft', "Child inventory 1 have '%s' state. It should be 'draft'" % child_1_state |
1212 | 27 | |||
1213 | 28 | |||
1214 | 29 | |||
1215 | 30 | |||
1216 | 31 | |||
1217 | 32 | \ No newline at end of file | 21 | \ No newline at end of file |
1218 | 33 | 22 | ||
1219 | === modified file 'stock_inventory_hierarchical_location/wizard/__init__.py' | |||
1220 | --- stock_inventory_hierarchical_location/wizard/__init__.py 2014-03-12 15:08:22 +0000 | |||
1221 | +++ stock_inventory_hierarchical_location/wizard/__init__.py 2014-06-11 15:04:27 +0000 | |||
1222 | @@ -1,4 +1,4 @@ | |||
1224 | 1 | # -*- encoding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
1225 | 2 | ############################################################################## | 2 | ############################################################################## |
1226 | 3 | # | 3 | # |
1227 | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. |
1228 | @@ -18,4 +18,4 @@ | |||
1229 | 18 | # | 18 | # |
1230 | 19 | ############################################################################## | 19 | ############################################################################## |
1231 | 20 | 20 | ||
1233 | 21 | import stock_inventory_missing_locations | 21 | import stock_confirm_uninventoried_location |
1234 | 22 | 22 | ||
1235 | === added file 'stock_inventory_hierarchical_location/wizard/stock_confirm_uninventoried_location.py' | |||
1236 | --- stock_inventory_hierarchical_location/wizard/stock_confirm_uninventoried_location.py 1970-01-01 00:00:00 +0000 | |||
1237 | +++ stock_inventory_hierarchical_location/wizard/stock_confirm_uninventoried_location.py 2014-06-11 15:04:27 +0000 | |||
1238 | @@ -0,0 +1,63 @@ | |||
1239 | 1 | # -*- coding: utf-8 -*- | ||
1240 | 2 | ############################################################################## | ||
1241 | 3 | # | ||
1242 | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. | ||
1243 | 5 | # | ||
1244 | 6 | # This program is free software: you can redistribute it and/or modify | ||
1245 | 7 | # it under the terms of the GNU General Public License as published by | ||
1246 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
1247 | 9 | # (at your option) any later version. | ||
1248 | 10 | # | ||
1249 | 11 | # This program is distributed in the hope that it will be useful, | ||
1250 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1251 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1252 | 14 | # GNU General Public License for more details. | ||
1253 | 15 | # | ||
1254 | 16 | # You should have received a copy of the GNU General Public License | ||
1255 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1256 | 18 | # | ||
1257 | 19 | ############################################################################## | ||
1258 | 20 | |||
1259 | 21 | from openerp.osv import orm | ||
1260 | 22 | from openerp.tools.translate import _ | ||
1261 | 23 | |||
1262 | 24 | from stock_inventory_hierarchical import HierarchicalInventoryException | ||
1263 | 25 | |||
1264 | 26 | |||
1265 | 27 | class StockInventoryUninventoriedLocation(orm.TransientModel): | ||
1266 | 28 | """Consider the lines of the sub-inventories when checking for locations""" | ||
1267 | 29 | _inherit = 'stock.inventory.uninventoried.locations' | ||
1268 | 30 | |||
1269 | 31 | def inventories(self, cr, uid, inventory_parent_id): | ||
1270 | 32 | """Iterator of children inventories. | ||
1271 | 33 | |||
1272 | 34 | @return: inventory_id | ||
1273 | 35 | """ | ||
1274 | 36 | children_ids = self.pool['stock.inventory'].search( | ||
1275 | 37 | cr, uid, [('parent_id', 'child_of', inventory_parent_id)]) | ||
1276 | 38 | for inventory_id in children_ids: | ||
1277 | 39 | yield inventory_id | ||
1278 | 40 | |||
1279 | 41 | def get_locations(self, cr, uid, inventory_id, context=None): | ||
1280 | 42 | """Get all locations through inventory tree.""" | ||
1281 | 43 | list_inventories_locations_ids = [] | ||
1282 | 44 | for i_id in self.inventories(cr, uid, inventory_id): | ||
1283 | 45 | location_ids = super( | ||
1284 | 46 | StockInventoryUninventoriedLocation, self).get_locations( | ||
1285 | 47 | cr, uid, i_id, context=context) | ||
1286 | 48 | list_inventories_locations_ids = list(set( | ||
1287 | 49 | list_inventories_locations_ids + location_ids)) | ||
1288 | 50 | return list_inventories_locations_ids | ||
1289 | 51 | |||
1290 | 52 | def get_locations_inventoried(self, cr, uid, inventory_id, location_ids, | ||
1291 | 53 | context=None): | ||
1292 | 54 | """Get all locations on inventory lines throughout inventory tree.""" | ||
1293 | 55 | list_all_inventoried_location_ids = [] | ||
1294 | 56 | for i_id in self.inventories(cr, uid, inventory_id): | ||
1295 | 57 | list_loc_ids = super( | ||
1296 | 58 | StockInventoryUninventoriedLocation, | ||
1297 | 59 | self).get_locations_inventoried( | ||
1298 | 60 | cr, uid, i_id, location_ids, context=context) | ||
1299 | 61 | list_all_inventoried_location_ids = list(set( | ||
1300 | 62 | list_all_inventoried_location_ids + list_loc_ids)) | ||
1301 | 63 | return list_all_inventoried_location_ids | ||
1302 | 0 | 64 | ||
1303 | === removed file 'stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations.py' | |||
1304 | --- stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations.py 2014-03-12 15:08:22 +0000 | |||
1305 | +++ stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations.py 1970-01-01 00:00:00 +0000 | |||
1306 | @@ -1,82 +0,0 @@ | |||
1307 | 1 | # -*- encoding: utf-8 -*- | ||
1308 | 2 | ############################################################################## | ||
1309 | 3 | # | ||
1310 | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. | ||
1311 | 5 | # | ||
1312 | 6 | # This program is free software: you can redistribute it and/or modify | ||
1313 | 7 | # it under the terms of the GNU General Public License as published by | ||
1314 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
1315 | 9 | # (at your option) any later version. | ||
1316 | 10 | # | ||
1317 | 11 | # This program is distributed in the hope that it will be useful, | ||
1318 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1319 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1320 | 14 | # GNU General Public License for more details. | ||
1321 | 15 | # | ||
1322 | 16 | # You should have received a copy of the GNU General Public License | ||
1323 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1324 | 18 | # | ||
1325 | 19 | ############################################################################## | ||
1326 | 20 | |||
1327 | 21 | from openerp.osv import osv, fields | ||
1328 | 22 | from openerp.tools.translate import _ | ||
1329 | 23 | |||
1330 | 24 | |||
1331 | 25 | class inventory_missing_location(osv.osv_memory): | ||
1332 | 26 | |||
1333 | 27 | _name = 'stock.inventory.missing.location' | ||
1334 | 28 | _description = 'Search on inventory tree for missing declared locations.' | ||
1335 | 29 | |||
1336 | 30 | _columns = { | ||
1337 | 31 | 'location_ids': fields.many2many('stock.location', | ||
1338 | 32 | 'stock_inventory_missing_location_rel', | ||
1339 | 33 | 'location_id', | ||
1340 | 34 | 'wizard_id', | ||
1341 | 35 | 'Missing location', readonly=True), | ||
1342 | 36 | } | ||
1343 | 37 | |||
1344 | 38 | def confirm_missing_locations(self, cr, uid, ids, context=None): | ||
1345 | 39 | """ Call action open method from stock.inventory """ | ||
1346 | 40 | ids = context['active_ids'] | ||
1347 | 41 | self.pool.get('stock.inventory').action_open(cr, uid, ids, context=context) | ||
1348 | 42 | return {'type': 'ir.actions.act_window_close'} | ||
1349 | 43 | |||
1350 | 44 | def inventories(self, cr, uid, inventory_parent_id): | ||
1351 | 45 | """ Iterator of children inventories. | ||
1352 | 46 | """ | ||
1353 | 47 | children_ids = self.pool.get('stock.inventory').search(cr, uid, [('parent_id', 'child_of', inventory_parent_id)]) | ||
1354 | 48 | for inventory_id in children_ids: | ||
1355 | 49 | if inventory_id == inventory_parent_id: | ||
1356 | 50 | continue # pass the parent inventory | ||
1357 | 51 | yield inventory_id | ||
1358 | 52 | |||
1359 | 53 | def get_locations_from_children(self, cr, uid, inventory_id, context=None): | ||
1360 | 54 | """ Get all locations through inventory tree. """ | ||
1361 | 55 | list_inventories_locations_ids = [] | ||
1362 | 56 | for i_id in self.inventories(cr, uid, inventory_id): | ||
1363 | 57 | location_ids = self.pool.get('stock.inventory').read(cr, uid, [i_id], ['location_ids'], context=context)[0] | ||
1364 | 58 | location_ids = self.pool.get('stock.location').search(cr, uid, [ | ||
1365 | 59 | ('location_id', 'child_of', location_ids['location_ids']), | ||
1366 | 60 | ('usage', '=', 'internal')], context=context) | ||
1367 | 61 | list_inventories_locations_ids = list(set(list_inventories_locations_ids + location_ids)) | ||
1368 | 62 | return list_inventories_locations_ids | ||
1369 | 63 | |||
1370 | 64 | def default_missing_locations(self, cr, uid, context=None): | ||
1371 | 65 | """ Initialize view with the list of missing locations on inventory tree. | ||
1372 | 66 | """ | ||
1373 | 67 | if context is None: | ||
1374 | 68 | context = {} | ||
1375 | 69 | |||
1376 | 70 | # get children locations for parent/current inventory | ||
1377 | 71 | parent_location_ids = self.pool.get('stock.inventory').read(cr, uid, [context['active_id']], ['location_ids'], context=context)[0] | ||
1378 | 72 | parent_location_ids = self.pool.get('stock.location').search(cr, uid, [ | ||
1379 | 73 | ('location_id', 'child_of', parent_location_ids['location_ids']), | ||
1380 | 74 | ('usage', '=', 'internal')], context=context) | ||
1381 | 75 | # get locations for each sub-inventory | ||
1382 | 76 | location_ids = self.get_locations_from_children(cr, uid, context['active_id']) | ||
1383 | 77 | list_missing_ids = [_id for _id in parent_location_ids if _id not in location_ids] | ||
1384 | 78 | return list_missing_ids | ||
1385 | 79 | |||
1386 | 80 | _defaults = { | ||
1387 | 81 | 'location_ids': default_missing_locations, | ||
1388 | 82 | } | ||
1389 | 83 | 0 | ||
1390 | === removed file 'stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations_view.xml' | |||
1391 | --- stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations_view.xml 2014-03-12 15:08:22 +0000 | |||
1392 | +++ stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations_view.xml 1970-01-01 00:00:00 +0000 | |||
1393 | @@ -1,43 +0,0 @@ | |||
1394 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
1395 | 2 | <openerp> | ||
1396 | 3 | <data> | ||
1397 | 4 | |||
1398 | 5 | <record id="action_view_stock_inventory_missing_location" model="ir.actions.act_window"> | ||
1399 | 6 | <field name="name">Confirm missing location</field> | ||
1400 | 7 | <field name="type">ir.actions.act_window</field> | ||
1401 | 8 | <field name="res_model">stock.inventory.missing.location</field> | ||
1402 | 9 | <field name="view_type">form</field> | ||
1403 | 10 | <field name="view_mode">form</field> | ||
1404 | 11 | <field name="target">new</field> | ||
1405 | 12 | </record> | ||
1406 | 13 | |||
1407 | 14 | <!-- The view definition is similar with stock_inventory_location/wizard/stock_confirm_uninventoried_location.xml, | ||
1408 | 15 | but the code is different. | ||
1409 | 16 | This wizard compare the locations of inventory with locations declared on parent inventory to | ||
1410 | 17 | to present to user the missing locations. --> | ||
1411 | 18 | <record id="view_confirm_missing_location" model="ir.ui.view"> | ||
1412 | 19 | <field name="name">Confirm missing location</field> | ||
1413 | 20 | <field name="model">stock.inventory.missing.location</field> | ||
1414 | 21 | <field name="type">form</field> | ||
1415 | 22 | <field name="arch" type="xml"> | ||
1416 | 23 | <form string="Confirm missing locations"> | ||
1417 | 24 | <group colspan="4" col="1"> | ||
1418 | 25 | <field name="location_ids" nolabel="1"> | ||
1419 | 26 | <tree> | ||
1420 | 27 | <field name="name"/> | ||
1421 | 28 | </tree> | ||
1422 | 29 | </field> | ||
1423 | 30 | </group> | ||
1424 | 31 | <group colspan="4" col="2"> | ||
1425 | 32 | <label string="This is the list of missing locations."/> | ||
1426 | 33 | <label string="Do you want to continue ?"/> | ||
1427 | 34 | <separator string="" colspan="4" /> | ||
1428 | 35 | <button special="cancel" string="_Cancel" icon='gtk-cancel'/> | ||
1429 | 36 | <button name="confirm_missing_locations" string="_Confirm missing locations" type="object" icon="gtk-ok"/> | ||
1430 | 37 | </group> | ||
1431 | 38 | </form> | ||
1432 | 39 | </field> | ||
1433 | 40 | </record> | ||
1434 | 41 | |||
1435 | 42 | </data> | ||
1436 | 43 | </openerp> | ||
1437 | 44 | \ No newline at end of file | 0 | \ No newline at end of file |
1438 | 45 | 1 | ||
1439 | === modified file 'stock_inventory_location/__init__.py' | |||
1440 | --- stock_inventory_location/__init__.py 2014-03-12 14:55:39 +0000 | |||
1441 | +++ stock_inventory_location/__init__.py 2014-06-11 15:04:27 +0000 | |||
1442 | @@ -20,3 +20,5 @@ | |||
1443 | 20 | 20 | ||
1444 | 21 | import stock_inventory_location | 21 | import stock_inventory_location |
1445 | 22 | import wizard | 22 | import wizard |
1446 | 23 | # Bring the main exception into the package's scope for easier reuse | ||
1447 | 24 | from .exceptions import ExhaustiveInventoryException | ||
1448 | 23 | 25 | ||
1449 | === modified file 'stock_inventory_location/__openerp__.py' | |||
1450 | --- stock_inventory_location/__openerp__.py 2014-03-12 14:55:39 +0000 | |||
1451 | +++ stock_inventory_location/__openerp__.py 2014-06-11 15:04:27 +0000 | |||
1452 | @@ -18,45 +18,60 @@ | |||
1453 | 18 | # | 18 | # |
1454 | 19 | ############################################################################## | 19 | ############################################################################## |
1455 | 20 | 20 | ||
1456 | 21 | |||
1457 | 22 | { | 21 | { |
1458 | 23 | "name": "Exhaustive Stock Inventories", | 22 | "name": "Exhaustive Stock Inventories", |
1460 | 24 | "version": "1.0", | 23 | "version": "1.1", |
1461 | 25 | "depends": ["stock"], | 24 | "depends": ["stock"], |
1462 | 26 | "author": u"Numérigraphe", | 25 | "author": u"Numérigraphe", |
1464 | 27 | "category": "Inventory", | 26 | "category": "Warehouse Management", |
1465 | 28 | "description": """ | 27 | "description": """ |
1468 | 29 | Let users choose between standard and exhaustive Inventories | 28 | Let users make exhaustive Inventories |
1469 | 30 | ============================================================ | 29 | ===================================== |
1470 | 31 | 30 | ||
1476 | 32 | Standard Physical Inventories in OpenERP only contain a generic list of products by locations, | 31 | Standard Physical Inventories in OpenERP only contain a generic list of |
1477 | 33 | which is well suited to partial Inventories and simple warehouses. | 32 | products by locations, which is well suited to partial Inventories and simple |
1478 | 34 | When the a standard Inventory is confirmed, only the products in the inventory are checked. | 33 | warehouses. When the a standard Inventory is confirmed, only the products in |
1479 | 35 | If a Product is present in the computed stock and not in the recorded Inventory, OpenERP will | 34 | the inventory are checked. If a Product is present in the computed stock and |
1480 | 36 | consider that it remains unchanged. | 35 | not in the recorded Inventory, OpenERP will consider that it remains unchanged. |
1481 | 37 | 36 | ||
1482 | 38 | But for exhaustive inventories in complex warehouses, it is not practical: | 37 | But for exhaustive inventories in complex warehouses, it is not practical: |
1484 | 39 | - you want to avoid Stock Moves in/out of these Locations while you count the goods | 38 | - you want to avoid Stock Moves to/from these Locations while counting goods |
1485 | 40 | - you must make sure all the locations you want have been counted | 39 | - you must make sure all the locations you want have been counted |
1486 | 41 | - you must make sure no other location has been counted by mistake | 40 | - you must make sure no other location has been counted by mistake |
1488 | 42 | - you want the computed stock to perfectly match the inventory when you confirm it. | 41 | - you want the computed stock to perfectly match the inventory when you |
1489 | 42 | confirm it. | ||
1490 | 43 | 43 | ||
1498 | 44 | This module lets choose whether an Physical Inventory is exhaustive or standard. | 44 | This module lets choose whether an Physical Inventory is exhaustive or |
1499 | 45 | For an exhaustive Inventory, in the state "Draft" you define the list of Locations where goods must be counted. | 45 | standard. |
1500 | 46 | - a new Inventory status ("Open") lets you indicate that the list of Locations is definitive and you are now counting the goods. | 46 | For an exhaustive Inventory: |
1501 | 47 | In that status, no Stock Moves can be recorded in/out of the Inventory's Locations. | 47 | - in the state "Draft" you define the Location where goods must be counted. |
1502 | 48 | - if some of the Inventory's Locations have not been entered in the Inventory Lines, OpenERP warns you when you confirm the Inventory. | 48 | - the new Inventory status "Open" lets you indicate that the list of Locations |
1503 | 49 | - only the Inventory's Locations can be entered in the Inventory Lines. | 49 | is final and you are now counting the goods. |
1504 | 50 | - every good that is not in the Inventory Lines is considered lost, and gets moved out of the stock when you confirm the Inventory.avec openerp | 50 | In that status, no Stock Moves can be recorded in/out of the Inventory's |
1505 | 51 | Locations. | ||
1506 | 52 | - if the Location or some of it's children have not been entered in the | ||
1507 | 53 | Inventory Lines, OpenERP warns you when you confirm the Inventory. | ||
1508 | 54 | - only the Inventory's Location or its children can be entered in the | ||
1509 | 55 | Inventory Lines. | ||
1510 | 56 | - every good that is not in the Inventory Lines is considered lost, and gets | ||
1511 | 57 | moved out of the stock when you confirm the Inventory. | ||
1512 | 51 | """, | 58 | """, |
1523 | 52 | "update_xml": [ | 59 | "data": [ |
1524 | 53 | "wizard/stock_confirm_uninventoried_location.xml", | 60 | "wizard/stock_confirm_uninventoried_location.xml", |
1525 | 54 | "stock_inventory_location_view.xml", | 61 | "stock_inventory_location_view.xml", |
1526 | 55 | "wizard/stock_fill_location_inventory_view.xml", | 62 | "wizard/stock_fill_location_inventory_view.xml", |
1527 | 56 | ], | 63 | ], |
1528 | 57 | "test": ["test/location_inventory_test.yml", | 64 | "test": [ |
1529 | 58 | "test/location_exhaustive_inventory_test.yml", | 65 | "test/inventory_standard_test.yml", |
1530 | 59 | ], | 66 | "test/inventory_exhaustive_test.yml", |
1531 | 60 | "demo": ["stock_inventory_location_demo.xml"] | 67 | "test/inventory_future_test.yml", |
1532 | 61 | 68 | ], | |
1533 | 69 | "images": [ | ||
1534 | 70 | "images/inventory_form.png", | ||
1535 | 71 | "inventory_empty_locations.png", | ||
1536 | 72 | "images/move_error.png", | ||
1537 | 73 | "images/location_locked.png", | ||
1538 | 74 | "images/future_inventory.png", | ||
1539 | 75 | ], | ||
1540 | 76 | "demo": ["stock_inventory_location_demo.xml"] | ||
1541 | 62 | } | 77 | } |
1542 | 63 | 78 | ||
1543 | === added file 'stock_inventory_location/exceptions.py' | |||
1544 | --- stock_inventory_location/exceptions.py 1970-01-01 00:00:00 +0000 | |||
1545 | +++ stock_inventory_location/exceptions.py 2014-06-11 15:04:27 +0000 | |||
1546 | @@ -0,0 +1,26 @@ | |||
1547 | 1 | # -*- coding: utf-8 -*- | ||
1548 | 2 | ############################################################################## | ||
1549 | 3 | # | ||
1550 | 4 | # This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved. | ||
1551 | 5 | # | ||
1552 | 6 | # This program is free software: you can redistribute it and/or modify | ||
1553 | 7 | # it under the terms of the GNU General Public License as published by | ||
1554 | 8 | # the Free Software Foundation, either version 3 of the License, or | ||
1555 | 9 | # (at your option) any later version. | ||
1556 | 10 | # | ||
1557 | 11 | # This program is distributed in the hope that it will be useful, | ||
1558 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1559 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1560 | 14 | # GNU General Public License for more details. | ||
1561 | 15 | # | ||
1562 | 16 | # You should have received a copy of the GNU General Public License | ||
1563 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1564 | 18 | # | ||
1565 | 19 | ############################################################################## | ||
1566 | 20 | |||
1567 | 21 | from openerp.osv import orm | ||
1568 | 22 | |||
1569 | 23 | |||
1570 | 24 | class ExhaustiveInventoryException(orm.except_orm): | ||
1571 | 25 | """The operation is not possible for an exhaustive inventory""" | ||
1572 | 26 | pass | ||
1573 | 0 | 27 | ||
1574 | === modified file 'stock_inventory_location/i18n/fr.po' | |||
1575 | --- stock_inventory_location/i18n/fr.po 2014-03-12 14:55:39 +0000 | |||
1576 | +++ stock_inventory_location/i18n/fr.po 2014-06-11 15:04:27 +0000 | |||
1577 | @@ -20,7 +20,7 @@ | |||
1578 | 20 | #: constraint:stock.move:0 | 20 | #: constraint:stock.move:0 |
1579 | 21 | #, python-format | 21 | #, python-format |
1580 | 22 | msgid "A Physical Inventory is being conducted at this location" | 22 | msgid "A Physical Inventory is being conducted at this location" |
1582 | 23 | msgstr "Un inventaire est déjà en cours à cet emplacement" | 23 | msgstr "Un inventaire est en cours à cet emplacement" |
1583 | 24 | 24 | ||
1584 | 25 | #. module: stock_inventory_location | 25 | #. module: stock_inventory_location |
1585 | 26 | #: view:stock.inventory.uninventoried.locations:0 | 26 | #: view:stock.inventory.uninventoried.locations:0 |
1586 | @@ -63,8 +63,8 @@ | |||
1587 | 63 | 63 | ||
1588 | 64 | #. module: stock_inventory_location | 64 | #. module: stock_inventory_location |
1589 | 65 | #: view:stock.inventory.uninventoried.locations:0 | 65 | #: view:stock.inventory.uninventoried.locations:0 |
1592 | 66 | msgid "Confirm uninventoried locations" | 66 | msgid "Confirm empty locations" |
1593 | 67 | msgstr "Confirmez les emplacements non-inventoriés" | 67 | msgstr "Confirmez les emplacements vides" |
1594 | 68 | 68 | ||
1595 | 69 | #. module: stock_inventory_location | 69 | #. module: stock_inventory_location |
1596 | 70 | #: model:ir.model,name:stock_inventory_location.model_stock_location | 70 | #: model:ir.model,name:stock_inventory_location.model_stock_location |
1597 | @@ -74,26 +74,26 @@ | |||
1598 | 74 | #. module: stock_inventory_location | 74 | #. module: stock_inventory_location |
1599 | 75 | #: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:54 | 75 | #: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:54 |
1600 | 76 | #, python-format | 76 | #, python-format |
1603 | 77 | msgid "Error !" | 77 | msgid "Error" |
1604 | 78 | msgstr "Erreur !" | 78 | msgstr "Erreur" |
1605 | 79 | 79 | ||
1606 | 80 | #. module: stock_inventory_location | 80 | #. module: stock_inventory_location |
1607 | 81 | #: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:75 | 81 | #: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:75 |
1608 | 82 | #, python-format | 82 | #, python-format |
1611 | 83 | msgid "Error : Empty location !" | 83 | msgid "Error: Empty location" |
1612 | 84 | msgstr "Erreur : Emplacement vide !" | 84 | msgstr "Erreur : Emplacement vide" |
1613 | 85 | 85 | ||
1614 | 86 | #. module: stock_inventory_location | 86 | #. module: stock_inventory_location |
1615 | 87 | #: code:addons/stock_inventory_location/stock_inventory_location.py:231 | 87 | #: code:addons/stock_inventory_location/stock_inventory_location.py:231 |
1616 | 88 | #: code:addons/stock_inventory_location/stock_inventory_location.py:282 | 88 | #: code:addons/stock_inventory_location/stock_inventory_location.py:282 |
1617 | 89 | #, python-format | 89 | #, python-format |
1620 | 90 | msgid "Error! Location on inventory" | 90 | msgid "Error: Location locked down" |
1621 | 91 | msgstr "Erreur! emplacement en inventaire" | 91 | msgstr "Erreur: emplacement en inventaire" |
1622 | 92 | 92 | ||
1623 | 93 | #. module: stock_inventory_location | 93 | #. module: stock_inventory_location |
1624 | 94 | #: constraint:stock.inventory:0 | 94 | #: constraint:stock.inventory:0 |
1627 | 95 | msgid "Error! You can not create recursive inventories." | 95 | msgid "Error: You can not create recursive inventories." |
1628 | 96 | msgstr "Erreur! Vous ne pouvez pas créer un inventaire récursif." | 96 | msgstr "Erreur: Vous ne pouvez pas créer un inventaire récursif." |
1629 | 97 | 97 | ||
1630 | 98 | #. module: stock_inventory_location | 98 | #. module: stock_inventory_location |
1631 | 99 | #: constraint:stock.inventory.line:0 | 99 | #: constraint:stock.inventory.line:0 |
1632 | @@ -138,12 +138,6 @@ | |||
1633 | 138 | msgstr "Emplacement manquant pour cet inventaire." | 138 | msgstr "Emplacement manquant pour cet inventaire." |
1634 | 139 | 139 | ||
1635 | 140 | #. module: stock_inventory_location | 140 | #. module: stock_inventory_location |
1636 | 141 | #: view:stock.inventory:0 | ||
1637 | 142 | #: field:stock.inventory,location_ids:0 | ||
1638 | 143 | msgid "Locations" | ||
1639 | 144 | msgstr "Emplacements" | ||
1640 | 145 | |||
1641 | 146 | #. module: stock_inventory_location | ||
1642 | 147 | #: model:ir.model,name:stock_inventory_location.model_stock_move | 141 | #: model:ir.model,name:stock_inventory_location.model_stock_move |
1643 | 148 | msgid "Mouvement de stock" | 142 | msgid "Mouvement de stock" |
1644 | 149 | msgstr "Mouvement de stock" | 143 | msgstr "Mouvement de stock" |
1645 | @@ -171,15 +165,10 @@ | |||
1646 | 171 | #. module: stock_inventory_location | 165 | #. module: stock_inventory_location |
1647 | 172 | #: code:addons/stock_inventory_location/stock_inventory_location.py:283 | 166 | #: code:addons/stock_inventory_location/stock_inventory_location.py:283 |
1648 | 173 | #, python-format | 167 | #, python-format |
1658 | 174 | msgid "One or more locations are inventoried :\n" | 168 | msgid "A Physical Inventory is being conducted at the following location(s):\n" |
1659 | 175 | "%s" | 169 | "%s" |
1660 | 176 | msgstr "Un ou plusieurs emplacements sont en inventaire :\n" | 170 | msgstr "Les emplacements suivants sont en inventaire :\n" |
1661 | 177 | "%s" | 171 | "%s" |
1653 | 178 | |||
1654 | 179 | #. module: stock_inventory_location | ||
1655 | 180 | #: constraint:stock.move:0 | ||
1656 | 181 | msgid "One or more lots are awaiting quality control and cannot be moved." | ||
1657 | 182 | msgstr "Un ou plusieurs lots sont en attente de contrôle qualité, et ne peuvent pas être déplacés." | ||
1662 | 183 | 172 | ||
1663 | 184 | #. module: stock_inventory_location | 173 | #. module: stock_inventory_location |
1664 | 185 | #: view:stock.inventory:0 | 174 | #: view:stock.inventory:0 |
1665 | @@ -198,19 +187,10 @@ | |||
1666 | 198 | 187 | ||
1667 | 199 | #. module: stock_inventory_location | 188 | #. module: stock_inventory_location |
1668 | 200 | #: view:stock.inventory.uninventoried.locations:0 | 189 | #: view:stock.inventory.uninventoried.locations:0 |
1670 | 201 | msgid "The following Stock Locations are part of the current Physical Inventory, but not Inventory Line has been recorded for them." | 190 | msgid "The following Stock Locations are part of the current Physical Inventory, but no Inventory Line has been recorded for them." |
1671 | 202 | msgstr "Les emplacements suivants font partie de l'inventaire en cours, mais aucune ligne d'inventaire les concernant n'a été enregistrée." | 191 | msgstr "Les emplacements suivants font partie de l'inventaire en cours, mais aucune ligne d'inventaire les concernant n'a été enregistrée." |
1672 | 203 | 192 | ||
1673 | 204 | #. module: stock_inventory_location | 193 | #. module: stock_inventory_location |
1674 | 205 | #: help:stock.inventory,location_ids:0 | ||
1675 | 206 | msgid "This is the list of the Stock Locations that you want to count the goods in.\n" | ||
1676 | 207 | "Only these Locations can be entered in the Inventory Lines.\n" | ||
1677 | 208 | "If some of them have not been entered in the Inventory Lines, OpenERP will warn you when you confirm the Inventory." | ||
1678 | 209 | msgstr "Ceci est la liste des emplacements dont vous voulez compter la marchandise.\n" | ||
1679 | 210 | "Seuls ces emplacements peuvent être enregistrés dans les lignes d'inventaire.\n" | ||
1680 | 211 | "Si certains ne sont enregistrés sur aucune ligne d'inventaire, OpenERP vous avertit lors de la confirmation de l'inventaire." | ||
1681 | 212 | |||
1682 | 213 | #. module: stock_inventory_location | ||
1683 | 214 | #: field:stock.inventory.uninventoried.locations,location_ids:0 | 194 | #: field:stock.inventory.uninventoried.locations,location_ids:0 |
1684 | 215 | msgid "Uninventoried location" | 195 | msgid "Uninventoried location" |
1685 | 216 | msgstr "Emplacements non inventoriés" | 196 | msgstr "Emplacements non inventoriés" |
1686 | @@ -220,8 +200,8 @@ | |||
1687 | 220 | #: code:addons/stock_inventory_location/stock_inventory_location.py:163 | 200 | #: code:addons/stock_inventory_location/stock_inventory_location.py:163 |
1688 | 221 | #: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:58 | 201 | #: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:58 |
1689 | 222 | #, python-format | 202 | #, python-format |
1692 | 223 | msgid "Warning !" | 203 | msgid "Warning" |
1693 | 224 | msgstr "Attention !" | 204 | msgstr "Attention" |
1694 | 225 | 205 | ||
1695 | 226 | #. module: stock_inventory_location | 206 | #. module: stock_inventory_location |
1696 | 227 | #: code:addons/stock_inventory_location/stock_inventory_location.py:209 | 207 | #: code:addons/stock_inventory_location/stock_inventory_location.py:209 |
1697 | @@ -232,8 +212,8 @@ | |||
1698 | 232 | #. module: stock_inventory_location | 212 | #. module: stock_inventory_location |
1699 | 233 | #: code:addons/stock_inventory_location/stock_inventory_location.py:210 | 213 | #: code:addons/stock_inventory_location/stock_inventory_location.py:210 |
1700 | 234 | #, python-format | 214 | #, python-format |
1703 | 235 | msgid "You cannot add this location to inventory line.\n" | 215 | msgid "You cannot record an Inventory Line for this Location.\n" |
1704 | 236 | "You must add this location on the locations list" | 216 | "You must first add this Location to the list of affected Locations on the Inventory form." |
1705 | 237 | msgstr "Vous ne pouvez pas ajouter cet emplacement.\n" | 217 | msgstr "Vous ne pouvez pas ajouter cet emplacement.\n" |
1706 | 238 | "Il ne fait pas partie de la liste des emplacements à inventorier" | 218 | "Il ne fait pas partie de la liste des emplacements à inventorier" |
1707 | 239 | 219 | ||
1708 | 240 | 220 | ||
1709 | === added directory 'stock_inventory_location/images' | |||
1710 | === added file 'stock_inventory_location/images/future_inventory.png' | |||
1711 | 241 | Binary files stock_inventory_location/images/future_inventory.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/future_inventory.png 2014-06-11 15:04:27 +0000 differ | 221 | Binary files stock_inventory_location/images/future_inventory.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/future_inventory.png 2014-06-11 15:04:27 +0000 differ |
1712 | === added file 'stock_inventory_location/images/inventory_empty_locations.png' | |||
1713 | 242 | Binary files stock_inventory_location/images/inventory_empty_locations.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/inventory_empty_locations.png 2014-06-11 15:04:27 +0000 differ | 222 | Binary files stock_inventory_location/images/inventory_empty_locations.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/inventory_empty_locations.png 2014-06-11 15:04:27 +0000 differ |
1714 | === added file 'stock_inventory_location/images/inventory_form.png' | |||
1715 | 243 | Binary files stock_inventory_location/images/inventory_form.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/inventory_form.png 2014-06-11 15:04:27 +0000 differ | 223 | Binary files stock_inventory_location/images/inventory_form.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/inventory_form.png 2014-06-11 15:04:27 +0000 differ |
1716 | === added file 'stock_inventory_location/images/location_locked.png' | |||
1717 | 244 | Binary files stock_inventory_location/images/location_locked.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/location_locked.png 2014-06-11 15:04:27 +0000 differ | 224 | Binary files stock_inventory_location/images/location_locked.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/location_locked.png 2014-06-11 15:04:27 +0000 differ |
1718 | === added file 'stock_inventory_location/images/move_error.png' | |||
1719 | 245 | Binary files stock_inventory_location/images/move_error.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/move_error.png 2014-06-11 15:04:27 +0000 differ | 225 | Binary files stock_inventory_location/images/move_error.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/images/move_error.png 2014-06-11 15:04:27 +0000 differ |
1720 | === added directory 'stock_inventory_location/static' | |||
1721 | === added directory 'stock_inventory_location/static/src' | |||
1722 | === added directory 'stock_inventory_location/static/src/img' | |||
1723 | === added file 'stock_inventory_location/static/src/img/icon.png' | |||
1724 | 246 | Binary files stock_inventory_location/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/static/src/img/icon.png 2014-06-11 15:04:27 +0000 differ | 226 | Binary files stock_inventory_location/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and stock_inventory_location/static/src/img/icon.png 2014-06-11 15:04:27 +0000 differ |
1725 | === modified file 'stock_inventory_location/stock_inventory_location.py' | |||
1726 | --- stock_inventory_location/stock_inventory_location.py 2014-03-12 14:55:39 +0000 | |||
1727 | +++ stock_inventory_location/stock_inventory_location.py 2014-06-11 15:04:27 +0000 | |||
1728 | @@ -18,225 +18,267 @@ | |||
1729 | 18 | # | 18 | # |
1730 | 19 | ############################################################################## | 19 | ############################################################################## |
1731 | 20 | 20 | ||
1732 | 21 | import time | ||
1733 | 21 | from collections import Iterable | 22 | from collections import Iterable |
1734 | 22 | 23 | ||
1736 | 23 | from openerp.osv import osv, orm, fields | 24 | from openerp.osv import orm, fields |
1737 | 24 | from openerp.tools.translate import _ | 25 | from openerp.tools.translate import _ |
1741 | 25 | 26 | # The next 2 imports are only needed for a feature backported from trunk-wms | |
1742 | 26 | 27 | # TODOv8! remove, feature is included upstream | |
1743 | 27 | class StockInventory(osv.osv): | 28 | from openerp.osv import osv |
1744 | 29 | from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT | ||
1745 | 30 | |||
1746 | 31 | from .exceptions import ExhaustiveInventoryException | ||
1747 | 32 | |||
1748 | 33 | |||
1749 | 34 | class StockInventory(orm.Model): | ||
1750 | 28 | """Add locations to the inventories""" | 35 | """Add locations to the inventories""" |
1751 | 29 | _inherit = 'stock.inventory' | 36 | _inherit = 'stock.inventory' |
1752 | 37 | |||
1753 | 38 | INVENTORY_STATE_SELECTION = [ | ||
1754 | 39 | ('draft', 'Draft'), | ||
1755 | 40 | ('open', 'Open'), | ||
1756 | 41 | ('done', 'Done'), | ||
1757 | 42 | ('confirm', 'Confirmed'), | ||
1758 | 43 | ('cancel', 'Cancelled') | ||
1759 | 44 | ] | ||
1760 | 45 | |||
1761 | 30 | _columns = { | 46 | _columns = { |
1786 | 31 | # XXX refactor if ever lp:~numerigraphe/openobject-addons/7.0-inventory-states is accepted upstream | 47 | # TODO v8: should we use "confirm" instead of adding "open"? |
1787 | 32 | 'state': fields.selection((('draft', 'Draft'), | 48 | 'state': fields.selection( |
1788 | 33 | ('open', 'Open'), | 49 | INVENTORY_STATE_SELECTION, 'State', readonly=True, select=True), |
1789 | 34 | ('done', 'Done'), | 50 | # TODO v8: remove this, should not be needed anymore |
1790 | 35 | ('confirm', 'Confirmed'), | 51 | # Make the inventory lines read-only in all states except "Open", |
1791 | 36 | ('cancel', 'Cancelled')), 'State', readonly=True, select=True), | 52 | # to ensure that no unwanted Location can be inserted |
1792 | 37 | # Make the inventory lines read-only in all states except "Open", to ensure that no unwanted Location can be inserted | 53 | 'inventory_line_id': fields.one2many( |
1793 | 38 | 'inventory_line_id': fields.one2many('stock.inventory.line', 'inventory_id', 'Inventory lines', readonly=True, states={'open': [('readonly', False)]}), | 54 | 'stock.inventory.line', 'inventory_id', 'Inventory lines', |
1794 | 39 | 'location_ids': fields.many2many('stock.location', 'stock_inventory_location_rel', | 55 | readonly=True, states={'open': [('readonly', False)]}), |
1795 | 40 | 'location_id', 'inventory_id', | 56 | # TODO v8: remove this, it's backported from v8 |
1796 | 41 | 'Locations', | 57 | 'location_id': fields.many2one( |
1797 | 42 | readonly=True, states={'draft': [('readonly', False)]}, | 58 | 'stock.location', 'Inventoried Location', |
1798 | 43 | help="""This is the list of the Stock Locations that you want to count the goods in. | 59 | readonly=True, states={'draft': [('readonly', False)]}), |
1799 | 44 | Only these Locations can be entered in the Inventory Lines. | 60 | 'exhaustive': fields.boolean( |
1800 | 45 | If some of them have not been entered in the Inventory Lines, OpenERP will warn you when you confirm the Inventory."""), | 61 | 'Exhaustive', readonly=True, |
1801 | 46 | 'exhaustive': fields.boolean('Exhaustive', readonly=True, states={'draft': [('readonly', False)]}, | 62 | states={'draft': [('readonly', False)]}, |
1802 | 47 | help="""Check the box if you are conducting an exhaustive Inventory. | 63 | help="Check the box if you are conducting an exhaustive " |
1803 | 48 | Leave the box unchecked if you are conducting a standard Inventory (partial inventory for example). | 64 | "Inventory.\n" |
1804 | 49 | For an exhaustive Inventory: | 65 | "Leave the box unchecked if you are conducting a standard " |
1805 | 50 | - the status "Draft" lets you define the list of Locations where goods must be counted | 66 | "Inventory (partial inventory for example).\n" |
1806 | 51 | - the status "Open" indicates that the list of Locations is definitive and you are now counting the goods. In that status, no Stock Moves can be recorded in/out of the Inventory's Locations | 67 | "For an exhaustive Inventory:\n" |
1807 | 52 | - only the Inventory's Locations can be entered in the Inventory Lines | 68 | " - the status \"Draft\" lets you define the list of " |
1808 | 53 | - if some of the Inventory's Locations have not been entered in the Inventory Lines, OpenERP warns you when you confirm the Inventory | 69 | "Locations where goods must be counted\n" |
1809 | 54 | - every good that is not in the Inventory Lines is considered lost, and gets moved out of the stock when you confirm the Inventory"""), | 70 | " - the status \"Open\" indicates that the list of Locations " |
1810 | 71 | "is definitive and you are now counting the goods. In that " | ||
1811 | 72 | "status, no Stock Moves can be recorded in/out of the " | ||
1812 | 73 | "Inventory's Locations\n" | ||
1813 | 74 | " - only the Inventory's Locations can be entered in the " | ||
1814 | 75 | "Inventory Lines\n" | ||
1815 | 76 | " - if some of the Inventory's Locations have not been " | ||
1816 | 77 | "entered in the Inventory Lines, OpenERP warns you " | ||
1817 | 78 | "when you confirm the Inventory\n" | ||
1818 | 79 | " - every good that is not in the Inventory Lines is " | ||
1819 | 80 | "considered lost, and gets moved out of the stock when you " | ||
1820 | 81 | "confirm the Inventory"), | ||
1821 | 55 | } | 82 | } |
1822 | 56 | 83 | ||
1823 | 57 | def action_open(self, cr, uid, ids, context=None): | 84 | def action_open(self, cr, uid, ids, context=None): |
1830 | 58 | """Open the inventory: open all locations, import and print inventory sheet become possible""" | 85 | """Change the state of the inventory to 'open'""" |
1825 | 59 | # verify if exhaustive inventory have locations before open inventory | ||
1826 | 60 | for inventory in self.browse(cr, uid, ids, context=None): | ||
1827 | 61 | if inventory.exhaustive: | ||
1828 | 62 | if not inventory.location_ids: | ||
1829 | 63 | raise osv.except_osv(_('Warning !'), _('Location missing for this inventory.')) | ||
1831 | 64 | return self.write(cr, uid, ids, {'state': 'open'}, context=context) | 86 | return self.write(cr, uid, ids, {'state': 'open'}, context=context) |
1832 | 65 | 87 | ||
1834 | 66 | # XXX refactor if ever lp:~numerigraphe/openobject-addons/7.0-inventory-states is accepted upstream | 88 | # TODO v8: remove this method? the feature looks already done upstream |
1835 | 89 | def action_done(self, cr, uid, ids, context=None): | ||
1836 | 90 | """ | ||
1837 | 91 | Don't allow to make an inventory with a date in the future. | ||
1838 | 92 | |||
1839 | 93 | This makes sure no stock moves will be introduced between the | ||
1840 | 94 | moment you finish the inventory and the date of the Stock Moves. | ||
1841 | 95 | Backported from trunk-wms: | ||
1842 | 96 | revid:qdp-launchpad@openerp.com-20140317090656-o7lo22tzm8yuv3r8 | ||
1843 | 97 | |||
1844 | 98 | @raise osv.except_osv: | ||
1845 | 99 | We raise this exception on purpose instead of | ||
1846 | 100 | ExhaustiveInventoryException to ensure forward-compatibility | ||
1847 | 101 | with v8. | ||
1848 | 102 | """ | ||
1849 | 103 | for inventory in self.browse(cr, uid, ids, context=None): | ||
1850 | 104 | if inventory.date > time.strftime(DEFAULT_SERVER_DATETIME_FORMAT): | ||
1851 | 105 | raise osv.except_osv( | ||
1852 | 106 | _('Error!'), | ||
1853 | 107 | _('It\'s impossible to confirm an inventory in the ' | ||
1854 | 108 | 'future. Please change the inventory date to proceed ' | ||
1855 | 109 | 'further.')) | ||
1856 | 110 | return super(StockInventory, self).action_done(cr, uid, ids, | ||
1857 | 111 | context=context) | ||
1858 | 112 | |||
1859 | 113 | # TODO: remove this in v8 | ||
1860 | 114 | def _default_location(self, cr, uid, ids, context=None): | ||
1861 | 115 | """Default stock location | ||
1862 | 116 | |||
1863 | 117 | @return: id of the stock location of the first warehouse of the | ||
1864 | 118 | default company""" | ||
1865 | 119 | location_id = False | ||
1866 | 120 | company_id = self.pool['res.company']._company_default_get( | ||
1867 | 121 | cr, uid, 'stock.warehouse', context=context) | ||
1868 | 122 | warehouse_id = self.pool['stock.warehouse'].search( | ||
1869 | 123 | cr, uid, [('company_id', '=', company_id)], limit=1) | ||
1870 | 124 | if warehouse_id: | ||
1871 | 125 | location_id = self.pool['stock.warehouse'].read( | ||
1872 | 126 | cr, uid, warehouse_id[0], ['lot_stock_id'])['lot_stock_id'][0] | ||
1873 | 127 | return location_id | ||
1874 | 128 | |||
1875 | 67 | _defaults = { | 129 | _defaults = { |
1878 | 68 | 'state': lambda *a: 'draft', | 130 | 'state': 'draft', |
1879 | 69 | 'exhaustive': lambda *a: False, | 131 | 'exhaustive': False, |
1880 | 132 | # TODO: remove this in v8 | ||
1881 | 133 | 'location_id': _default_location, | ||
1882 | 70 | } | 134 | } |
1883 | 71 | 135 | ||
1884 | 72 | def _check_location_free_from_inventories(self, cr, uid, ids): | 136 | def _check_location_free_from_inventories(self, cr, uid, ids): |
1887 | 73 | """Verify that no other Inventory is being conducted on the location (exact id, not children).""" | 137 | """ |
1888 | 74 | for inventory in self.browse(cr, uid, ids, context=None): | 138 | Verify that no other Inventory is being conducted on the same locations |
1889 | 139 | |||
1890 | 140 | Open Inventories are matched using the exact Location IDs, | ||
1891 | 141 | excluding children. | ||
1892 | 142 | """ | ||
1893 | 143 | # We don't get a context because we're called from a _constraint | ||
1894 | 144 | for inventory in self.browse(cr, uid, ids): | ||
1895 | 75 | if not inventory.exhaustive: | 145 | if not inventory.exhaustive: |
1903 | 76 | continue # always accepted on partial inventories | 146 | # never block standard inventories |
1904 | 77 | location_ids = [location.id for location in inventory.location_ids] | 147 | continue |
1905 | 78 | inv_ids = self.search(cr, uid, [('location_ids', 'in', location_ids), | 148 | if self.search(cr, uid, |
1906 | 79 | ('id', '!=', inventory.id), | 149 | [('location_id', '=', inventory.location_id.id), |
1907 | 80 | ('date', '=', inventory.date), | 150 | ('id', '!=', inventory.id), |
1908 | 81 | ('exhaustive', '=', True), ]) | 151 | ('date', '=', inventory.date), |
1909 | 82 | if inv_ids: | 152 | ('exhaustive', '=', True)]): |
1910 | 153 | # Quit as soon as one offending inventory is found | ||
1911 | 83 | return False | 154 | return False |
1912 | 84 | return True | 155 | return True |
1913 | 85 | 156 | ||
1917 | 86 | _constraints = [(_check_location_free_from_inventories, | 157 | _constraints = [ |
1918 | 87 | 'Other Physical inventories are being conducted using the same Locations.', | 158 | (_check_location_free_from_inventories, |
1919 | 88 | ['location_ids', 'date', 'exhaustive'])] | 159 | 'Other Physical inventories are being conducted using the same ' |
1920 | 160 | 'Locations.', | ||
1921 | 161 | ['location_id', 'date', 'exhaustive']) | ||
1922 | 162 | ] | ||
1923 | 89 | 163 | ||
1924 | 90 | def _get_locations_open_inventories(self, cr, uid, context=None): | 164 | def _get_locations_open_inventories(self, cr, uid, context=None): |
1930 | 91 | """Search for locations on open inventories (exhaustive inventory only), and their children """ | 165 | """IDs of location in open exhaustive inventories, with children""" |
1931 | 92 | open_inventories_ids = self.search(cr, uid, [('state', '=', 'open'), ], context=context) | 166 | inv_ids = self.search( |
1932 | 93 | location_ids = set() | 167 | cr, uid, [('state', '=', 'open'), ('exhaustive', '=', True)], |
1933 | 94 | for open_inventory in self.browse(cr, uid, open_inventories_ids, context=context): | 168 | context=context) |
1934 | 95 | location_ids.update([location.id for location in open_inventory.location_ids]) | 169 | if not inv_ids: |
1935 | 170 | # Early exit if no match found | ||
1936 | 171 | return [] | ||
1937 | 172 | # List the Locations - normally all exhaustive inventories have one | ||
1938 | 173 | location_ids = [inventory.location_id.id | ||
1939 | 174 | for inventory in self.browse(cr, uid, inv_ids, | ||
1940 | 175 | context=context)] | ||
1941 | 96 | # Extend to the children Locations | 176 | # Extend to the children Locations |
1950 | 97 | if location_ids: # XXX probably works even otherwise | 177 | return self.pool['stock.location'].search( |
1951 | 98 | location_ids = self.pool.get('stock.location').search(cr, uid, | 178 | cr, uid, |
1952 | 99 | [('location_id', 'child_of', location_ids), ('usage', '=', 'internal')], | 179 | [('location_id', 'child_of', set(location_ids)), |
1953 | 100 | context=context) | 180 | ('usage', '=', 'internal')], |
1954 | 101 | return location_ids | 181 | context=context) |
1955 | 102 | 182 | ||
1956 | 103 | def confirm_uninventoried_location_wizard(self, cr, uid, ids, context=None): | 183 | def get_missing_locations(self, cr, uid, ids, context=None): |
1957 | 104 | """ Open wizard if inventory is exhautive """ | 184 | """Compute the list of location_ids which are missing from the lines |
1958 | 185 | |||
1959 | 186 | Here, "missing" means the location is the inventory's location or one | ||
1960 | 187 | of it's children, and the inventory does not contain any line with | ||
1961 | 188 | this location.""" | ||
1962 | 189 | inventories = self.browse(cr, uid, ids, context=context) | ||
1963 | 190 | # Find the locations of the inventories | ||
1964 | 191 | inv_location_ids = [i.location_id.id for i in inventories] | ||
1965 | 192 | # Extend to the children locations | ||
1966 | 193 | inv_location_ids = set(self.pool['stock.location'].search( | ||
1967 | 194 | cr, uid, [ | ||
1968 | 195 | ('location_id', 'child_of', inv_location_ids), | ||
1969 | 196 | ('usage', '=', 'internal')], context=context)) | ||
1970 | 197 | # Find the locations already recorded in inventory lines | ||
1971 | 198 | line_locations_ids = set([l.location_id.id | ||
1972 | 199 | for l in i.inventory_line_id | ||
1973 | 200 | for i in inventories]) | ||
1974 | 201 | return list(inv_location_ids - line_locations_ids) | ||
1975 | 202 | |||
1976 | 203 | def confirm_missing_locations(self, cr, uid, ids, context=None): | ||
1977 | 204 | """Open wizard to confirm empty locations on exhaustive inventories""" | ||
1978 | 105 | for inventory in self.browse(cr, uid, ids, context=context): | 205 | for inventory in self.browse(cr, uid, ids, context=context): |
1984 | 106 | if not inventory.exhaustive: | 206 | if (self.get_missing_locations(cr, uid, ids, context=context) |
1985 | 107 | return self.action_confirm(cr, uid, ids, context=context) | 207 | and inventory.exhaustive): |
1981 | 108 | else: | ||
1982 | 109 | context['active_ids'] = ids | ||
1983 | 110 | context['active_id'] = ids[0] | ||
1986 | 111 | return { | 208 | return { |
1987 | 112 | 'type': 'ir.actions.act_window', | 209 | 'type': 'ir.actions.act_window', |
1988 | 113 | 'view_type': 'form', | 210 | 'view_type': 'form', |
1989 | 114 | 'view_mode': 'form', | 211 | 'view_mode': 'form', |
1990 | 115 | 'res_model': 'stock.inventory.uninventoried.locations', | 212 | 'res_model': 'stock.inventory.uninventoried.locations', |
1991 | 116 | 'target': 'new', | 213 | 'target': 'new', |
1993 | 117 | 'context': context, | 214 | 'context': dict(context, |
1994 | 215 | active_ids=ids, | ||
1995 | 216 | active_id=ids[0]), | ||
1996 | 118 | 'nodestroy': True, | 217 | 'nodestroy': True, |
2081 | 119 | } | 218 | } |
2082 | 120 | 219 | return self.action_confirm(cr, uid, ids, context=context) | |
2083 | 121 | # XXX : get from stock.py v6.0 patch. Waiting for integration on standard by openerp ... | 220 | |
2084 | 122 | def _fill_location_lines(self, cr, uid, inventory_id, location_ids, set_stock_zero, context=None): | 221 | |
2085 | 123 | """ To Import stock inventory according to products available in the selected locations. | 222 | class StockInventoryLine(orm.Model): |
2002 | 124 | @param self: The object pointer. | ||
2003 | 125 | @param cr: A database cursor | ||
2004 | 126 | @param uid: ID of the user currently logged in | ||
2005 | 127 | @param location_ids: the location ID or list of location IDs if we want more than one | ||
2006 | 128 | @param inventory_id: the inventory ID | ||
2007 | 129 | @param set_stock_zero: indicate if all the lines will be imported with zero quantity | ||
2008 | 130 | @param context: A standard dictionary | ||
2009 | 131 | @return: | ||
2010 | 132 | """ | ||
2011 | 133 | inventory_line_obj = self.pool.get('stock.inventory.line') | ||
2012 | 134 | move_obj = self.pool.get('stock.move') | ||
2013 | 135 | uom_obj = self.pool.get('product.uom') | ||
2014 | 136 | res = [] | ||
2015 | 137 | flag = False | ||
2016 | 138 | for location in location_ids: | ||
2017 | 139 | datas = {} | ||
2018 | 140 | move_ids = move_obj.search(cr, uid, ['|', ('location_dest_id', '=', location), | ||
2019 | 141 | ('location_id', '=', location), | ||
2020 | 142 | ('state', '=', 'done')], context=context) | ||
2021 | 143 | for move in move_obj.browse(cr, uid, move_ids, context=context): | ||
2022 | 144 | if move.location_dest_id.id == move.location_id.id: | ||
2023 | 145 | continue | ||
2024 | 146 | lot_id = move.prodlot_id.id | ||
2025 | 147 | prod_id = move.product_id.id | ||
2026 | 148 | if move.location_dest_id.id == location: | ||
2027 | 149 | qty = uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, move.product_id.uom_id.id) | ||
2028 | 150 | else: | ||
2029 | 151 | qty = -uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, move.product_id.uom_id.id) | ||
2030 | 152 | if datas.get((prod_id, lot_id)): | ||
2031 | 153 | qty = qty + datas[(prod_id, lot_id)]['product_qty'] | ||
2032 | 154 | |||
2033 | 155 | datas[(prod_id, lot_id)] = {'product_id': prod_id, | ||
2034 | 156 | 'location_id': location, | ||
2035 | 157 | # Floating point sum could introduce some tiny rounding errors. | ||
2036 | 158 | # The uom are the same on input and output to use api for rounding. | ||
2037 | 159 | 'product_qty': uom_obj._compute_qty_obj(cr, uid, move.product_id.uom_id, qty, move.product_id.uom_id), | ||
2038 | 160 | 'product_uom': move.product_id.uom_id.id, | ||
2039 | 161 | 'prod_lot_id': lot_id, | ||
2040 | 162 | 'default_code': move.product_id.default_code, | ||
2041 | 163 | 'prodlot_name': move.prodlot_id.name} | ||
2042 | 164 | if datas: | ||
2043 | 165 | flag = True | ||
2044 | 166 | res.append(datas) | ||
2045 | 167 | if not flag: | ||
2046 | 168 | raise osv.except_osv(_('Warning !'), _('No product in this location.')) | ||
2047 | 169 | |||
2048 | 170 | stock_moves = [] | ||
2049 | 171 | for stock_move in res: | ||
2050 | 172 | prod_lots = sorted(stock_move, key=lambda k: (stock_move[k]['default_code'], stock_move[k]['prodlot_name'])) | ||
2051 | 173 | for prod_lot in prod_lots: | ||
2052 | 174 | stock_move_details = stock_move.get(prod_lot) | ||
2053 | 175 | |||
2054 | 176 | if stock_move_details['product_qty'] == 0: | ||
2055 | 177 | continue # ignore product if stock equal 0 | ||
2056 | 178 | |||
2057 | 179 | stock_move_details.update({'inventory_id': inventory_id}) | ||
2058 | 180 | |||
2059 | 181 | if set_stock_zero: | ||
2060 | 182 | stock_move_details.update({'product_qty': 0}) | ||
2061 | 183 | |||
2062 | 184 | domain = [(field, '=', stock_move_details[field]) | ||
2063 | 185 | for field in ['location_id', | ||
2064 | 186 | 'product_id', | ||
2065 | 187 | 'prod_lot_id'] | ||
2066 | 188 | ] | ||
2067 | 189 | # children_inventory_ids is present if stock_inventory_hierarchical_location module has been installed | ||
2068 | 190 | inventory_ids = context.get('children_inventory_ids', False) | ||
2069 | 191 | if inventory_ids: | ||
2070 | 192 | domain.append(('inventory_id', 'child_of', inventory_ids)) | ||
2071 | 193 | else: | ||
2072 | 194 | domain.append(('inventory_id', '=', stock_move_details['inventory_id'])) | ||
2073 | 195 | |||
2074 | 196 | line_ids = inventory_line_obj.search(cr, uid, domain, context=context) | ||
2075 | 197 | if not line_ids: | ||
2076 | 198 | stock_moves.append(stock_move_details) | ||
2077 | 199 | return stock_moves | ||
2078 | 200 | |||
2079 | 201 | |||
2080 | 202 | class StockInventoryLine(osv.osv): | ||
2086 | 203 | """Only allow the Inventory's Locations""" | 223 | """Only allow the Inventory's Locations""" |
2087 | 204 | 224 | ||
2088 | 205 | _inherit = 'stock.inventory.line' | 225 | _inherit = 'stock.inventory.line' |
2089 | 206 | 226 | ||
2095 | 207 | def onchange_location_id(self, cr, uid, ids, location_ids, exhaustive, location_id, context=None): | 227 | def _default_stock_location(self, cr, uid, context=None): |
2096 | 208 | """ Raise exception if Location is not internal, or location_id not in locations list for this inventory """ | 228 | res = super(StockInventoryLine, self)._default_stock_location( |
2097 | 209 | location_ids = location_ids[0][2] | 229 | cr, uid, context=context) |
2098 | 210 | if not exhaustive or not location_ids: | 230 | if context is None or not context.get('location_id', False): |
2099 | 211 | return True # don't check if partial inventory | 231 | return res |
2100 | 232 | else: | ||
2101 | 233 | return context['location_id'] | ||
2102 | 234 | |||
2103 | 235 | _defaults = { | ||
2104 | 236 | 'location_id': _default_stock_location | ||
2105 | 237 | } | ||
2106 | 238 | |||
2107 | 239 | def onchange_location_id(self, cr, uid, ids, inventory_location_id, | ||
2108 | 240 | exhaustive, location_id, context=None): | ||
2109 | 241 | """Warn if the new is not in the location list for this inventory.""" | ||
2110 | 242 | if not exhaustive: | ||
2111 | 243 | # Don't check if partial inventory | ||
2112 | 244 | return True | ||
2113 | 212 | 245 | ||
2114 | 213 | # search children of location | 246 | # search children of location |
2123 | 214 | location_ids = self.pool.get('stock.location').search(cr, uid, | 247 | if location_id not in self.pool['stock.location'].search( |
2124 | 215 | [('location_id', 'child_of', location_ids)], context=context) | 248 | cr, uid, [('location_id', 'child_of', inventory_location_id)], |
2125 | 216 | if location_id not in location_ids: | 249 | context=context): |
2126 | 217 | return {'value': {'location_id': False}, | 250 | return { |
2127 | 218 | 'warning': {'title': _('Warning: Wrong location'), | 251 | 'value': {'location_id': False}, |
2128 | 219 | 'message': _("You cannot add this location to inventory line.\n" | 252 | 'warning': { |
2129 | 220 | "You must add this location on the locations list")} | 253 | 'title': _('Warning: Wrong location'), |
2130 | 221 | } | 254 | 'message': _( |
2131 | 255 | "You cannot record an Inventory Line for this " | ||
2132 | 256 | "Location.\n" | ||
2133 | 257 | "You must first add this Location to the list of " | ||
2134 | 258 | "affected Locations on the Inventory form.")} | ||
2135 | 259 | } | ||
2136 | 222 | return True | 260 | return True |
2137 | 223 | 261 | ||
2138 | 224 | 262 | ||
2140 | 225 | class StockLocation(osv.osv): | 263 | class StockLocation(orm.Model): |
2141 | 226 | """Refuse changes during exhaustive Inventories""" | 264 | """Refuse changes during exhaustive Inventories""" |
2142 | 227 | _inherit = 'stock.location' | 265 | _inherit = 'stock.location' |
2143 | 228 | _order = 'name' | 266 | _order = 'name' |
2144 | 229 | 267 | ||
2145 | 268 | # TODOv7: why not put this in an ORM "_constraint" instead? | ||
2146 | 230 | def _check_inventory(self, cr, uid, ids, context=None): | 269 | def _check_inventory(self, cr, uid, ids, context=None): |
2150 | 231 | """Raise an error if an exhaustive Inventory is being conducted on this Location""" | 270 | """Error if an exhaustive Inventory is being conducted here""" |
2151 | 232 | inventory_obj = self.pool.get('stock.inventory') | 271 | inv_obj = self.pool['stock.inventory'] |
2152 | 233 | location_inventory_open_ids = inventory_obj._get_locations_open_inventories(cr, uid, context=context) | 272 | location_inventory_open_ids = inv_obj._get_locations_open_inventories( |
2153 | 273 | cr, uid, context=context) | ||
2154 | 234 | if not isinstance(ids, Iterable): | 274 | if not isinstance(ids, Iterable): |
2155 | 235 | ids = [ids] | 275 | ids = [ids] |
2160 | 236 | for id in ids: | 276 | for inv_id in ids: |
2161 | 237 | if id in location_inventory_open_ids: | 277 | if inv_id in location_inventory_open_ids: |
2162 | 238 | raise osv.except_osv(_('Error! Location on inventory'), | 278 | raise ExhaustiveInventoryException( |
2163 | 239 | _('A Physical Inventory is being conducted at this location')) | 279 | _('Error: Location locked down'), |
2164 | 280 | _('A Physical Inventory is being conducted at this ' | ||
2165 | 281 | 'location')) | ||
2166 | 240 | return True | 282 | return True |
2167 | 241 | 283 | ||
2168 | 242 | def write(self, cr, uid, ids, vals, context=None): | 284 | def write(self, cr, uid, ids, vals, context=None): |
2169 | @@ -245,16 +287,19 @@ | |||
2170 | 245 | if not isinstance(ids, Iterable): | 287 | if not isinstance(ids, Iterable): |
2171 | 246 | ids = [ids] | 288 | ids = [ids] |
2172 | 247 | ids_to_check = ids | 289 | ids_to_check = ids |
2175 | 248 | # If we are changing the parent, there must be no inventory must conducted there either | 290 | # If changing the parent, no inventory must conducted there either |
2176 | 249 | if vals.get('location_id'): | 291 | if vals.get('location_id'): |
2177 | 250 | ids_to_check.append(vals['location_id']) | 292 | ids_to_check.append(vals['location_id']) |
2178 | 251 | self._check_inventory(cr, uid, ids_to_check, context=context) | 293 | self._check_inventory(cr, uid, ids_to_check, context=context) |
2180 | 252 | return super(StockLocation, self).write(cr, uid, ids, vals, context=context) | 294 | return super(StockLocation, self).write(cr, uid, ids, vals, |
2181 | 295 | context=context) | ||
2182 | 253 | 296 | ||
2183 | 254 | def create(self, cr, uid, vals, context=None): | 297 | def create(self, cr, uid, vals, context=None): |
2184 | 255 | """Refuse create if an inventory is being conducted at the parent""" | 298 | """Refuse create if an inventory is being conducted at the parent""" |
2187 | 256 | self._check_inventory(cr, uid, vals.get('location_id'), context=context) | 299 | self._check_inventory(cr, uid, vals.get('location_id'), |
2188 | 257 | return super(StockLocation, self).create(cr, uid, vals, context=context) | 300 | context=context) |
2189 | 301 | return super(StockLocation, self).create(cr, uid, vals, | ||
2190 | 302 | context=context) | ||
2191 | 258 | 303 | ||
2192 | 259 | def unlink(self, cr, uid, ids, context=None): | 304 | def unlink(self, cr, uid, ids, context=None): |
2193 | 260 | """Refuse unlink if an inventory is being conducted""" | 305 | """Refuse unlink if an inventory is being conducted""" |
2194 | @@ -262,34 +307,45 @@ | |||
2195 | 262 | return super(StockLocation, self).unlink(cr, uid, ids, context=context) | 307 | return super(StockLocation, self).unlink(cr, uid, ids, context=context) |
2196 | 263 | 308 | ||
2197 | 264 | 309 | ||
2199 | 265 | class StockMove(osv.osv): | 310 | class StockMove(orm.Model): |
2200 | 266 | """Refuse Moves during exhaustive Inventories""" | 311 | """Refuse Moves during exhaustive Inventories""" |
2201 | 267 | 312 | ||
2202 | 268 | _inherit = 'stock.move' | 313 | _inherit = 'stock.move' |
2203 | 269 | 314 | ||
2204 | 315 | # TODOv7: adapt this to match trunk-wms | ||
2205 | 270 | def _check_open_inventory_location(self, cr, uid, ids, context=None): | 316 | def _check_open_inventory_location(self, cr, uid, ids, context=None): |
2208 | 271 | """ Check if location is not in opened inventory | 317 | """ |
2209 | 272 | Don't check on partial inventory (checkbox "Exhaustive" not checked). | 318 | Check that the locations are not locked by an open inventory |
2210 | 319 | |||
2211 | 320 | Standard inventories are not checked. | ||
2212 | 321 | |||
2213 | 322 | @raise ExhaustiveInventoryException: an error is raised if locations | ||
2214 | 323 | are locked, instead of returning False, in order to pass an | ||
2215 | 324 | extensive error message back to users. | ||
2216 | 273 | """ | 325 | """ |
2217 | 274 | message = "" | 326 | message = "" |
2222 | 275 | inventory_obj = self.pool.get('stock.inventory') | 327 | inv_obj = self.pool['stock.inventory'] |
2223 | 276 | location_inventory_open_ids = inventory_obj._get_locations_open_inventories(cr, uid, context=context) | 328 | locked_location_ids = inv_obj._get_locations_open_inventories( |
2224 | 277 | if not location_inventory_open_ids: | 329 | cr, uid, context=context) |
2225 | 278 | return True # Nothing to verify | 330 | if not locked_location_ids: |
2226 | 331 | # Nothing to verify | ||
2227 | 332 | return True | ||
2228 | 279 | for move in self.browse(cr, uid, ids, context=context): | 333 | for move in self.browse(cr, uid, ids, context=context): |
2229 | 280 | if (move.location_id.usage != 'inventory' | 334 | if (move.location_id.usage != 'inventory' |
2231 | 281 | and move.location_dest_id.id in location_inventory_open_ids): | 335 | and move.location_dest_id.id in locked_location_ids): |
2232 | 282 | message += " - %s\n" % (move.location_dest_id.name) | 336 | message += " - %s\n" % (move.location_dest_id.name) |
2233 | 283 | |||
2234 | 284 | if (move.location_dest_id.usage != 'inventory' | 337 | if (move.location_dest_id.usage != 'inventory' |
2236 | 285 | and move.location_id.id in location_inventory_open_ids): | 338 | and move.location_id.id in locked_location_ids): |
2237 | 286 | message += " - %s\n" % (move.location_id.name) | 339 | message += " - %s\n" % (move.location_id.name) |
2238 | 287 | if message: | 340 | if message: |
2241 | 288 | raise osv.except_osv(_('Error! Location on inventory'), | 341 | raise ExhaustiveInventoryException( |
2242 | 289 | _('One or more locations are inventoried :\n%s') % message) | 342 | _('Error: Location locked down'), |
2243 | 343 | _('A Physical Inventory is being conducted at the following ' | ||
2244 | 344 | 'location(s):\n%s') % message) | ||
2245 | 290 | return True | 345 | return True |
2246 | 291 | 346 | ||
2247 | 292 | _constraints = [ | 347 | _constraints = [ |
2251 | 293 | (_check_open_inventory_location, | 348 | (_check_open_inventory_location, |
2252 | 294 | "A Physical Inventory is being conducted at this location", ['location_id', 'location_dest_id']), | 349 | "A Physical Inventory is being conducted at this location", |
2253 | 295 | ] | 350 | ['location_id', 'location_dest_id']), |
2254 | 351 | ] | ||
2255 | 296 | 352 | ||
2256 | === modified file 'stock_inventory_location/stock_inventory_location_demo.xml' | |||
2257 | --- stock_inventory_location/stock_inventory_location_demo.xml 2014-03-12 14:55:39 +0000 | |||
2258 | +++ stock_inventory_location/stock_inventory_location_demo.xml 2014-06-11 15:04:27 +0000 | |||
2259 | @@ -1,25 +1,26 @@ | |||
2260 | 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2261 | 2 | <openerp> | 2 | <openerp> |
2262 | 3 | <data noupdate="0"> | 3 | <data noupdate="0"> |
2263 | 4 | <!-- Record a non exhaustive inventory --> | ||
2264 | 5 | <record id="inventory_standard" model="stock.inventory"> | ||
2265 | 6 | <field name="name">Standard inventory</field> | ||
2266 | 7 | <field name="state">draft</field> | ||
2267 | 8 | </record> | ||
2268 | 4 | 9 | ||
2269 | 5 | <!-- Record inventories we can use in the tests. --> | ||
2270 | 6 | <!-- We need them in the demo data because test data is rolled back | ||
2271 | 7 | whenever an exception is raised. --> | ||
2272 | 8 | |||
2273 | 9 | <!-- Record an non exhaustive inventory --> | ||
2274 | 10 | <record id="stock_inventory_location_0" model="stock.inventory"> | ||
2275 | 11 | <field name="name">Location test inventory</field> | ||
2276 | 12 | <field name="state">draft</field> | ||
2277 | 13 | <field name="date">2020-03-01 00:00:00</field> | ||
2278 | 14 | </record> | ||
2279 | 15 | |||
2280 | 16 | <!-- Record an exhaustive inventory --> | 10 | <!-- Record an exhaustive inventory --> |
2287 | 17 | <record id="stock_inventory_location_1" model="stock.inventory"> | 11 | <record id="inventory_exhaustive" model="stock.inventory"> |
2288 | 18 | <field name="name">Location test exhaustive inventory</field> | 12 | <field name="name">Exhaustive inventory</field> |
2289 | 19 | <field name="state">draft</field> | 13 | <field name="state">draft</field> |
2290 | 20 | <field name="date">2020-03-15 00:00:00</field> | 14 | <field name="exhaustive">True</field> |
2291 | 21 | <field name="exhaustive">True</field> | 15 | <field name="location_id" model="stock.location" search="[('name', '=', 'Shelf 2')]" /> |
2292 | 22 | <field name="location_ids" model="stock.location" search="[('name', '=', 'Shelf 2')]" /> | 16 | </record> |
2293 | 17 | |||
2294 | 18 | <!-- Record an inventory dated in the future --> | ||
2295 | 19 | <!-- TODOv8: remove this entry, only useful for a test already in trunk-wms --> | ||
2296 | 20 | <record id="inventory_future" model="stock.inventory"> | ||
2297 | 21 | <field name="name">Inventory in the future</field> | ||
2298 | 22 | <field name="state">draft</field> | ||
2299 | 23 | <field name="date">2020-03-01 00:00:00</field> | ||
2300 | 23 | </record> | 24 | </record> |
2301 | 24 | </data> | 25 | </data> |
2302 | 25 | </openerp> | 26 | </openerp> |
2303 | 26 | 27 | ||
2304 | === modified file 'stock_inventory_location/stock_inventory_location_view.xml' | |||
2305 | --- stock_inventory_location/stock_inventory_location_view.xml 2014-03-12 14:55:39 +0000 | |||
2306 | +++ stock_inventory_location/stock_inventory_location_view.xml 2014-06-11 15:04:27 +0000 | |||
2307 | @@ -1,59 +1,59 @@ | |||
2308 | 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2309 | 2 | <openerp> | 2 | <openerp> |
2310 | 3 | <data> | 3 | <data> |
2312 | 4 | 4 | ||
2313 | 5 | <record model="ir.ui.view" id="stock_inventory_location_form_view"> | 5 | <record model="ir.ui.view" id="stock_inventory_location_form_view"> |
2314 | 6 | <field name="name">stock.inventory.location.form</field> | 6 | <field name="name">stock.inventory.location.form</field> |
2315 | 7 | <field name="model">stock.inventory</field> | 7 | <field name="model">stock.inventory</field> |
2316 | 8 | <field name="inherit_id" ref="stock.view_inventory_form"/> | 8 | <field name="inherit_id" ref="stock.view_inventory_form"/> |
2317 | 9 | <field name="priority" eval="10"/> | 9 | <field name="priority" eval="10"/> |
2318 | 10 | <field name="arch" type="xml"> | 10 | <field name="arch" type="xml"> |
2321 | 11 | <!-- Add type of inventory : partial or complete. --> | 11 | <!-- Show the state 'done' in the statusbar --> |
2322 | 12 | <xpath expr="/form//field[@name='date']" position="after"> | 12 | <xpath expr="/form//field[@name='state']" position="attributes"> |
2323 | 13 | <attribute name="statusbar_visible">draft,open,confirm</attribute> | ||
2324 | 14 | </xpath> | ||
2325 | 15 | |||
2326 | 16 | <!-- TODO v8 place "exhaustive" next to "location_id" --> | ||
2327 | 17 | <!-- Add type of inventory: standard or exhaustive. --> | ||
2328 | 18 | <xpath expr="/form//field[@name='name']" position="after"> | ||
2329 | 13 | <field name="exhaustive"/> | 19 | <field name="exhaustive"/> |
2362 | 14 | </xpath> | 20 | <field name="location_id" groups="stock.group_locations" |
2363 | 15 | 21 | domain="[('usage','in',('view', 'internal'))]" | |
2364 | 16 | <!-- Add the list of Locations on exhaustive inventories --> | 22 | attrs="{'invisible':[('exhaustive','!=',True)], 'required':[('exhaustive','=',True)]}"/> |
2365 | 17 | <xpath expr="/form//field[@name='inventory_line_id']" position="before"> | 23 | </xpath> |
2366 | 18 | <!-- Add the locations list for inventory --> | 24 | |
2367 | 19 | <field colspan="1" nolabel="1" name="location_ids" domain="[('usage','in',('view', 'internal'))]" attrs="{'invisible':[('exhaustive','!=',True)]}"> | 25 | <!-- Enable Fill Inventory button when state is open --> |
2368 | 20 | <tree string="Locations" editable="bottom"> | 26 | <xpath expr="//button[@string='Fill Inventory']" position="attributes"> |
2369 | 21 | <field name="name"/> | 27 | <attribute name="states">open</attribute> |
2370 | 22 | </tree> | 28 | <attribute name="context">{'default_exhaustive': exhaustive}</attribute> |
2371 | 23 | </field> | 29 | </xpath> |
2372 | 24 | </xpath> | 30 | |
2373 | 25 | 31 | <!-- Control locations added by user on inventory line --> | |
2374 | 26 | <!-- Add Fill Inventory button when state is open --> | 32 | <xpath expr="/form//field[@name='inventory_line_id']" |
2375 | 27 | <xpath expr="//button[@string='Fill Inventory']" position="attributes"> | 33 | position="attributes"> |
2376 | 28 | <attribute name="states">draft,open,confirm</attribute> | 34 | <attribute name="context">{'location_id': location_id}</attribute> |
2377 | 29 | </xpath> | 35 | </xpath> |
2378 | 30 | 36 | <xpath expr="/form//field[@name='inventory_line_id']/tree//field[@name='location_id']" | |
2379 | 31 | <!-- Reduce the colspan of the lines to make room for the Locations--> | 37 | position="attributes"> |
2380 | 32 | <xpath expr="/form//field[@name='inventory_line_id']" position="attributes"> | 38 | <attribute name="on_change">onchange_location_id(parent.location_id, parent.exhaustive, location_id)</attribute> |
2381 | 33 | <attribute name="colspan">3</attribute> | 39 | </xpath> |
2382 | 34 | </xpath> | 40 | <xpath expr="/form//field[@name='inventory_line_id']/form//field[@name='location_id']" |
2383 | 35 | 41 | position="attributes"> | |
2384 | 36 | <!-- Control locations added by user on inventory line --> | 42 | <attribute name="on_change">onchange_location_id(parent.location_id, parent.exhaustive, location_id)</attribute> |
2385 | 37 | <xpath expr="/form//field[@name='inventory_line_id']/tree//field[@name='location_id']" position="attributes"> | 43 | </xpath> |
2386 | 38 | <attribute name="on_change">onchange_location_id(parent.location_ids, parent.exhaustive, location_id)</attribute> | 44 | |
2355 | 39 | </xpath> | ||
2356 | 40 | <xpath expr="/form//field[@name='inventory_line_id']/form//field[@name='location_id']" position="attributes"> | ||
2357 | 41 | <attribute name="on_change">onchange_location_id(parent.location_ids, parent.exhaustive, location_id)</attribute> | ||
2358 | 42 | </xpath> | ||
2359 | 43 | |||
2360 | 44 | <!-- #XXX change the attributes instead and add the button --> | ||
2361 | 45 | <!-- #XXX enlarge the group's colspan? --> | ||
2387 | 46 | <!-- Add button to open an inventory. Call wizard on confirm inventory --> | 45 | <!-- Add button to open an inventory. Call wizard on confirm inventory --> |
2398 | 47 | <xpath expr="/form//button[@name='action_cancel_inventory']" position="replace"> | 46 | <xpath expr="/form//button[@name='action_cancel_inventory']" position="before"> |
2399 | 48 | <button name="action_cancel_inventory" states="draft,open,confirm,done" string="Cancel Inventory" type="object" icon="gtk-cancel"/> | 47 | <button name="action_open" states="draft" string="Open Inventory" type="object" class="oe_highlight" groups="stock.group_stock_user"/> |
2400 | 49 | <button name="action_open" states="draft" string="Open Inventory" type="object" icon="gtk-go-forward"/> | 48 | </xpath> |
2401 | 50 | </xpath> | 49 | <!-- Show the "cancel" button in state "open" --> |
2402 | 51 | 50 | <xpath expr="/form//button[@name='action_cancel_inventory']" position="attributes"> | |
2403 | 52 | <!-- replace action_confirm button --> | 51 | <attribute name="states">draft,open,confirm,done</attribute> |
2404 | 53 | <!-- #XXX change the attributes instead --> | 52 | </xpath> |
2405 | 54 | <xpath expr="/form//button[@name='action_confirm']" position="replace"> | 53 | <!-- hijack the "confirm" button --> |
2406 | 55 | <button name="confirm_uninventoried_location_wizard" | 54 | <xpath expr="/form//button[@name='action_confirm']" position="attributes"> |
2407 | 56 | string="Confirm Inventory" type="object" states="open" icon="gtk-apply"/> | 55 | <attribute name="states">open</attribute> |
2408 | 56 | <attribute name="name">confirm_missing_locations</attribute> | ||
2409 | 57 | </xpath> | 57 | </xpath> |
2410 | 58 | </field> | 58 | </field> |
2411 | 59 | </record> | 59 | </record> |
2412 | @@ -62,16 +62,16 @@ | |||
2413 | 62 | <record model="ir.ui.view" id="view_inventory_complete_filter"> | 62 | <record model="ir.ui.view" id="view_inventory_complete_filter"> |
2414 | 63 | <field name="name">complete.inventory.filter</field> | 63 | <field name="name">complete.inventory.filter</field> |
2415 | 64 | <field name="model">stock.inventory</field> | 64 | <field name="model">stock.inventory</field> |
2416 | 65 | <field name="type">search</field> | ||
2417 | 66 | <field name="inherit_id" ref="stock.view_inventory_filter"/> | 65 | <field name="inherit_id" ref="stock.view_inventory_filter"/> |
2418 | 67 | <field name="arch" type="xml"> | 66 | <field name="arch" type="xml"> |
2419 | 68 | <xpath expr="//field[@name='name']" position="before"> | 67 | <xpath expr="//field[@name='name']" position="before"> |
2421 | 69 | <filter icon="terp-check" name="exhaustive" string="Exhaustive" domain="[('exhaustive', '=', True)]" help="Only select inventories that have no parents." /> | 68 | <filter icon="terp-check" name="exhaustive" string="Exhaustive" domain="[('exhaustive', '=', True)]" |
2422 | 69 | help="Only select exhaustive Inventories." /> | ||
2423 | 70 | <separator orientation="vertical"/> | 70 | <separator orientation="vertical"/> |
2424 | 71 | </xpath> | 71 | </xpath> |
2425 | 72 | </field> | 72 | </field> |
2426 | 73 | </record> | 73 | </record> |
2428 | 74 | 74 | ||
2429 | 75 | <!-- Show exhaustive inventories by default --> | 75 | <!-- Show exhaustive inventories by default --> |
2430 | 76 | <record id="stock.action_inventory_form" model="ir.actions.act_window"> | 76 | <record id="stock.action_inventory_form" model="ir.actions.act_window"> |
2431 | 77 | <field name="context">{'full':'1', 'search_default_exhaustive':1}</field> | 77 | <field name="context">{'full':'1', 'search_default_exhaustive':1}</field> |
2432 | 78 | 78 | ||
2433 | === renamed file 'stock_inventory_location/test/location_exhaustive_inventory_test.yml' => 'stock_inventory_location/test/inventory_exhaustive_test.yml' | |||
2434 | --- stock_inventory_location/test/location_exhaustive_inventory_test.yml 2014-03-12 14:55:39 +0000 | |||
2435 | +++ stock_inventory_location/test/inventory_exhaustive_test.yml 2014-06-11 15:04:27 +0000 | |||
2436 | @@ -3,99 +3,114 @@ | |||
2437 | 3 | I will call open_action method and check if state of inventories are 'open'. | 3 | I will call open_action method and check if state of inventories are 'open'. |
2438 | 4 | - | 4 | - |
2439 | 5 | !python {model: stock.inventory}: | | 5 | !python {model: stock.inventory}: | |
2450 | 6 | from osv import orm, osv | 6 | self.action_open(cr, uid, [ref('inventory_exhaustive')]) |
2451 | 7 | self.action_open(cr, uid, [ref('stock_inventory_location_1')]) | 7 | inventory_state = self.read(cr, uid, [ref('inventory_exhaustive')], ['state'])[0]['state'] |
2452 | 8 | inventory_state = self.read(cr, uid, [ref('stock_inventory_location_1')], ['state'])[0]['state'] | 8 | assert inventory_state == 'open', "Inventory in state '%s'. It should be 'open'" % inventory_state |
2453 | 9 | assert inventory_state == 'open', "Parent inventory have '%s' state. It should be 'open'" % inventory_state | 9 | - |
2454 | 10 | 10 | I create a wizard record for stock_confirm_uninventoried_location to verify that it contains the uninventoried locations | |
2455 | 11 | - | 11 | - |
2456 | 12 | In order, i add products to exhaustive inventory. | 12 | !python {model: stock.inventory.uninventoried.locations}: | |
2457 | 13 | Don't add mou(product.product_product_25) and keya (product.product_product_24) products. | 13 | ctx = dict(context, active_ids=[ref('inventory_exhaustive')]) |
2458 | 14 | Adding pc1. | 14 | wizard_id = self.create(cr, uid, {}, context=ctx) |
2459 | 15 | - | 15 | wizard = self.browse(cr, uid, wizard_id, context=ctx) |
2460 | 16 | assert len(wizard.location_ids) > 0 , "The wizard does not contain any lines." | ||
2461 | 17 | - | ||
2462 | 18 | I add products to exhaustive inventory. | ||
2463 | 19 | Adding 17” LCD Monitor. | ||
2464 | 20 | - | ||
2465 | 16 | !record {model: stock.inventory.line, id: lines_inventory_location_pc1}: | 21 | !record {model: stock.inventory.line, id: lines_inventory_location_pc1}: |
2467 | 17 | product_id: product.product_product_10 | 22 | product_id: product.product_product_7 |
2468 | 18 | product_uom: product.product_uom_unit | 23 | product_uom: product.product_uom_unit |
2469 | 19 | company_id: base.main_company | 24 | company_id: base.main_company |
2471 | 20 | inventory_id: stock_inventory_location_1 | 25 | inventory_id: inventory_exhaustive |
2472 | 21 | product_qty: 18.0 | 26 | product_qty: 18.0 |
2473 | 22 | location_id: stock.stock_location_14 | 27 | location_id: stock.stock_location_14 |
2474 | 23 | 28 | ||
2475 | 24 | - | 29 | - |
2478 | 25 | Adding pc3. | 30 | Adding USB Keyboard, QWERTY. |
2479 | 26 | - | 31 | - |
2480 | 27 | !record {model: stock.inventory.line, id: lines_inventory_location_pc3}: | 32 | !record {model: stock.inventory.line, id: lines_inventory_location_pc3}: |
2482 | 28 | product_id: product.product_product_pc3 | 33 | product_id: product.product_product_8 |
2483 | 29 | product_uom: product.product_uom_unit | 34 | product_uom: product.product_uom_unit |
2484 | 30 | company_id: base.main_company | 35 | company_id: base.main_company |
2486 | 31 | inventory_id: stock_inventory_location_1 | 36 | inventory_id: inventory_exhaustive |
2487 | 32 | product_qty: 5.0 | 37 | product_qty: 5.0 |
2489 | 33 | location_id: stock.stock_location_14 | 38 | location_id: stock.stock_location_14 |
2490 | 34 | 39 | ||
2491 | 35 | - | 40 | - |
2492 | 36 | I will call the function _get_locations_open_inventories and check the result. | 41 | I will call the function _get_locations_open_inventories and check the result. |
2494 | 37 | The function will return only the location_ids of the exhaustive inventory. | 42 | The function will return only the location_id of the exhaustive inventory. |
2495 | 38 | - | 43 | - |
2496 | 39 | !python {model: stock.inventory}: | | 44 | !python {model: stock.inventory}: | |
2503 | 40 | from osv import orm, osv | 45 | locations = self._get_locations_open_inventories(cr, uid) |
2504 | 41 | locations = self._get_locations_open_inventories(cr, uid) | 46 | assert len(locations) == 1, "Function return wrong results: %s" % locations |
2505 | 42 | assert len(locations) == 1, "Function return wrong results : %s" % locations | 47 | assert locations[0] == ref('stock.stock_location_14'), "Function '_get_locations_open_inventories' return wrong location_id. Should be '%s': '%s'" % (stock.stock_location_14, locations[0]) |
2506 | 43 | assert locations[0] == ref('stock.stock_location_14'), "Function '_get_locations_open_inventories' return wrong location_id. Should be '%s' : '%s'" % (stock.stock_location_14, locations[0]) | 48 | - |
2501 | 44 | |||
2502 | 45 | - | ||
2507 | 46 | I will call the function onchange_location_id. | 49 | I will call the function onchange_location_id. |
2509 | 47 | The function must to return true in the first case, and return a warning dictionnary in the second test. | 50 | The function must return True in the first case, and return a warning dictionnary in the second test. |
2510 | 48 | - | 51 | - |
2511 | 49 | !python {model: stock.inventory.line}: | | 52 | !python {model: stock.inventory.line}: | |
2512 | 50 | from osv import orm, osv | ||
2513 | 51 | res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_14')])], True, ref('stock.stock_location_14')) | 53 | res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_14')])], True, ref('stock.stock_location_14')) |
2515 | 52 | assert res == True, "Exhaustive : The function 'onchange_location_id' should return True and return '%s'" % res | 54 | assert res == True, "Exhaustive: The function 'onchange_location_id' should return True and return '%s'" % res |
2516 | 53 | res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_14')])], True, ref('stock.stock_location_components')) | 55 | res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_14')])], True, ref('stock.stock_location_components')) |
2518 | 54 | assert res.get('warning', False) != False , "Function 'onchange_location_id' : Warning not raise. ('%s)" % res | 56 | assert res.get('warning', False) != False , "Function 'onchange_location_id': Warning not raise. ('%s)" % res |
2519 | 55 | 57 | ||
2520 | 56 | - | 58 | - |
2538 | 57 | I will call _fill_location_lines to simulate confirmation for stock_confirm_uninventoried_location, | 59 | I create a wizard record for stock_confirm_uninventoried_location and validate it |
2539 | 58 | and create stock_moves | 60 | - |
2540 | 59 | - | 61 | !python {model: stock.inventory.uninventoried.locations}: | |
2541 | 60 | !python {model: stock.inventory}: | | 62 | ctx = dict(context, active_ids=[ref('inventory_exhaustive')]) |
2542 | 61 | from osv import orm, osv | 63 | wizard_id = self.create(cr, uid, {}, context=ctx) |
2543 | 62 | ctx={'location': [ref('stock.stock_location_14')]} | 64 | wizard = self.browse(cr, uid, wizard_id, context=ctx) |
2544 | 63 | lines = self._fill_location_lines(cr, uid, ref('stock_inventory_location_1'), [ref('stock.stock_location_14')], True, context=ctx) | 65 | assert len(wizard.location_ids) == 0 , "The wizard should not contain any lines but contains %s." % wizard.location_ids |
2545 | 64 | for line in lines: | 66 | self.confirm_uninventoried_locations(cr, uid, wizard_id, context=ctx) |
2546 | 65 | self.pool.get('stock.inventory.line').create(cr, uid, line, context=context) | 67 | - |
2547 | 66 | 68 | Stock moves are not allowed in the locations during the inventory. | |
2548 | 67 | - | 69 | - |
2549 | 68 | I will confirm exhaustive inventory | 70 | !python {model: stock.move}: | |
2550 | 69 | - | 71 | # TODOv8: remove this test, this is already part of trunk-wms |
2551 | 70 | !python {model: stock.inventory}: | | 72 | from stock_inventory_location import ExhaustiveInventoryException |
2552 | 71 | from osv import orm, osv | 73 | try: |
2553 | 72 | self.action_confirm(cr, uid, [ref('stock_inventory_location_1')]) | 74 | self.create( |
2554 | 73 | inventory_state = self.read(cr, uid, [ref('stock_inventory_location_1')], ['state'])[0]['state'] | 75 | cr,uid, { |
2555 | 76 | 'name': 'Bad move', | ||
2556 | 77 | 'location_id': ref('stock.stock_location_14'), | ||
2557 | 78 | 'location_dest_id': ref('stock.stock_location_3'), | ||
2558 | 79 | 'product_id': ref('product.product_product_8'), | ||
2559 | 80 | 'product_uom': ref('product.product_uom_unit'), | ||
2560 | 81 | 'date_expected': '2020-01-01 00:00:00' | ||
2561 | 82 | }) | ||
2562 | 83 | except ExhaustiveInventoryException as e: | ||
2563 | 84 | log("Good! The Stock Move was refused: %s" % e) | ||
2564 | 85 | - | ||
2565 | 86 | I will confirm the exhaustive inventory | ||
2566 | 87 | - | ||
2567 | 88 | !python {model: stock.inventory}: | | ||
2568 | 89 | self.action_confirm(cr, uid, [ref('inventory_exhaustive')]) | ||
2569 | 90 | inventory_state = self.read(cr, uid, [ref('inventory_exhaustive')], ['state'])[0]['state'] | ||
2570 | 74 | assert inventory_state == 'confirm', "Exhaustive inventory have '%s' state. It should be 'confirm'" % inventory_state | 91 | assert inventory_state == 'confirm', "Exhaustive inventory have '%s' state. It should be 'confirm'" % inventory_state |
2572 | 75 | 92 | ||
2573 | 76 | - | 93 | - |
2575 | 77 | I will validate exhaustive inventory | 94 | I will validate the exhaustive inventory |
2576 | 78 | - | 95 | - |
2577 | 79 | !python {model: stock.inventory}: | | 96 | !python {model: stock.inventory}: | |
2581 | 80 | from osv import orm, osv | 97 | self.action_done(cr, uid, [ref('inventory_exhaustive')]) |
2582 | 81 | self.action_done(cr, uid, [ref('stock_inventory_location_1')]) | 98 | inventory_state = self.read(cr, uid, [ref('inventory_exhaustive')], ['state'])[0]['state'] |
2580 | 82 | inventory_state = self.read(cr, uid, [ref('stock_inventory_location_1')], ['state'])[0]['state'] | ||
2583 | 83 | assert inventory_state == 'done', "Exhaustive inventory have '%s' state. It should be 'done'" % inventory_state | 99 | assert inventory_state == 'done', "Exhaustive inventory have '%s' state. It should be 'done'" % inventory_state |
2585 | 84 | 100 | ||
2586 | 85 | - | 101 | - |
2587 | 86 | I will verify the quantity for each products. | 102 | I will verify the quantity for each products. |
2589 | 87 | - | 103 | - |
2590 | 88 | !python {model: product.product}: | | 104 | !python {model: product.product}: | |
2598 | 89 | from osv import orm, osv | 105 | ctx = dict(context, location=[ref('stock.stock_location_14')]) |
2599 | 90 | ctx={'location': [ref('stock.stock_location_14')], 'to_date': '2020-12-31 23:59:59'} | 106 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_7')], ['qty_available'], context=ctx)[0]['qty_available'] |
2600 | 91 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_10')], ['qty_available'], context=ctx)[0]['qty_available'] | 107 | assert prod_qty_avail == 18.0, "The stock of PC1 was not set to 18.0: %s" % prod_qty_avail |
2601 | 92 | assert prod_qty_avail == 18.0, "The stock of PC1 was not set to 18.0 : %s" % prod_qty_avail | 108 | |
2602 | 93 | 109 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_8')], ['qty_available'], context=ctx)[0]['qty_available'] | |
2603 | 94 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_pc3')], ['qty_available'], context=ctx)[0]['qty_available'] | 110 | assert prod_qty_avail == 5.0, "The stock of PC3 was not set to 5.0: %s" % prod_qty_avail |
2597 | 95 | assert prod_qty_avail == 5.0, "The stock of PC3 was not set to 5.0 : %s" % prod_qty_avail | ||
2604 | 96 | 111 | ||
2605 | 97 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_24')], ['qty_available'], context=ctx)[0]['qty_available'] | 112 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_24')], ['qty_available'], context=ctx)[0]['qty_available'] |
2607 | 98 | assert prod_qty_avail == 0.0, "The stock of KEYA was not set to 0 : %s" % prod_qty_avail | 113 | assert prod_qty_avail == 0.0, "The stock of KEYA was not set to 0: %s" % prod_qty_avail |
2608 | 99 | 114 | ||
2609 | 100 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_25')], ['qty_available'], context=ctx)[0]['qty_available'] | 115 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_25')], ['qty_available'], context=ctx)[0]['qty_available'] |
2611 | 101 | assert prod_qty_avail == 0.0, "The stock of MOU was not set to 0 : %s" % prod_qty_avail | 116 | assert prod_qty_avail == 0.0, "The stock of MOU was not set to 0: %s" % prod_qty_avail |
2612 | 102 | 117 | ||
2613 | === added file 'stock_inventory_location/test/inventory_future_test.yml' | |||
2614 | --- stock_inventory_location/test/inventory_future_test.yml 1970-01-01 00:00:00 +0000 | |||
2615 | +++ stock_inventory_location/test/inventory_future_test.yml 2014-06-11 15:04:27 +0000 | |||
2616 | @@ -0,0 +1,13 @@ | |||
2617 | 1 | - | ||
2618 | 2 | Check that an inventory with a date in the future cannot be opened. | ||
2619 | 3 | - | ||
2620 | 4 | !python {model: stock.inventory}: | | ||
2621 | 5 | # TODO v8: maybe this is already part of the new WMS | ||
2622 | 6 | from osv.osv import except_osv | ||
2623 | 7 | self.action_open(cr, uid, [ref('inventory_future')]) | ||
2624 | 8 | try: | ||
2625 | 9 | self.action_done(cr, uid, [ref('inventory_future')]) | ||
2626 | 10 | except except_osv as e: | ||
2627 | 11 | log("Good! The Inventory could not be opened: %s" % e) | ||
2628 | 12 | inventory_state = self.read(cr, uid, [ref('inventory_future')], ['state'])[0]['state'] | ||
2629 | 13 | assert inventory_state != 'done', "Future inventory is done." | ||
2630 | 0 | 14 | ||
2631 | === renamed file 'stock_inventory_location/test/location_inventory_test.yml' => 'stock_inventory_location/test/inventory_standard_test.yml' | |||
2632 | --- stock_inventory_location/test/location_inventory_test.yml 2014-03-12 14:55:39 +0000 | |||
2633 | +++ stock_inventory_location/test/inventory_standard_test.yml 2014-06-11 15:04:27 +0000 | |||
2634 | @@ -3,61 +3,57 @@ | |||
2635 | 3 | I will call open_action method and check if state of inventories are 'open'. | 3 | I will call open_action method and check if state of inventories are 'open'. |
2636 | 4 | - | 4 | - |
2637 | 5 | !python {model: stock.inventory}: | | 5 | !python {model: stock.inventory}: | |
2643 | 6 | from osv import orm, osv | 6 | self.action_open(cr, uid, [ref('inventory_standard')]) |
2644 | 7 | self.action_open(cr, uid, [ref('stock_inventory_location_0')]) | 7 | inventory_state = self.read(cr, uid, [ref('inventory_standard')], ['state'])[0]['state'] |
2645 | 8 | inventory_state = self.read(cr, uid, [ref('stock_inventory_location_0')], ['state'])[0]['state'] | 8 | assert inventory_state == 'open', "Partial inventory have '%s' state. It should be 'open'" % inventory_state |
2646 | 9 | assert inventory_state == 'open', "Partial inventory have '%s' state. It should be 'open'" % inventory_state | 9 | |
2642 | 10 | |||
2647 | 11 | - | 10 | - |
2648 | 12 | In order, I add products to inventory. | 11 | In order, I add products to inventory. |
2650 | 13 | Adding cpu1. | 12 | Adding Azerty Keyboard. |
2651 | 14 | - | 13 | - |
2654 | 15 | !record {model: stock.inventory.line, id: lines_inventory_location_cpu1}: | 14 | !record {model: stock.inventory.line, id: lines_inventory_location_kbaz}: |
2655 | 16 | product_id: product.product_product_cpu1 | 15 | product_id: product.product_product_9 |
2656 | 17 | product_uom: product.product_uom_unit | 16 | product_uom: product.product_uom_unit |
2657 | 18 | company_id: base.main_company | 17 | company_id: base.main_company |
2659 | 19 | inventory_id: stock_inventory_location_0 | 18 | inventory_id: inventory_standard |
2660 | 20 | product_qty: 18.0 | 19 | product_qty: 18.0 |
2661 | 21 | location_id: stock.stock_location_components | 20 | location_id: stock.stock_location_components |
2662 | 22 | 21 | ||
2663 | 23 | - | 22 | - |
2665 | 24 | Adding cpu3. | 23 | Adding Optical Mouse. |
2666 | 25 | - | 24 | - |
2669 | 26 | !record {model: stock.inventory.line, id: lines_inventory_location_cpu3}: | 25 | !record {model: stock.inventory.line, id: lines_inventory_location_optm}: |
2670 | 27 | product_id: product.product_product_cpu3 | 26 | product_id: product.product_product_10 |
2671 | 28 | product_uom: product.product_uom_unit | 27 | product_uom: product.product_uom_unit |
2672 | 29 | company_id: base.main_company | 28 | company_id: base.main_company |
2674 | 30 | inventory_id: stock_inventory_location_0 | 29 | inventory_id: inventory_standard |
2675 | 31 | product_qty: 12.0 | 30 | product_qty: 12.0 |
2676 | 32 | location_id: stock.stock_location_components | 31 | location_id: stock.stock_location_components |
2677 | 33 | 32 | ||
2678 | 34 | - | 33 | - |
2680 | 35 | Adding fan. | 34 | Adding Multimedia Speakers. |
2681 | 36 | - | 35 | - |
2684 | 37 | !record {model: stock.inventory.line, id: lines_inventory_location_fan}: | 36 | !record {model: stock.inventory.line, id: lines_inventory_location_grca}: |
2685 | 38 | product_id: product.product_product_fan | 37 | product_id: product.product_template_31 |
2686 | 39 | product_uom: product.product_uom_unit | 38 | product_uom: product.product_uom_unit |
2687 | 40 | company_id: base.main_company | 39 | company_id: base.main_company |
2689 | 41 | inventory_id: stock_inventory_location_0 | 40 | inventory_id: inventory_standard |
2690 | 42 | product_qty: 32.0 | 41 | product_qty: 32.0 |
2691 | 43 | location_id: stock.stock_location_components | 42 | location_id: stock.stock_location_components |
2692 | 44 | 43 | ||
2693 | 45 | - | 44 | - |
2694 | 46 | I will call the function _get_locations_open_inventories and check the result. | 45 | I will call the function _get_locations_open_inventories and check the result. |
2696 | 47 | The function will return no locations. | 46 | The function will return no locations because it's not an exhaustive inventory. |
2697 | 48 | - | 47 | - |
2698 | 49 | !python {model: stock.inventory}: | | 48 | !python {model: stock.inventory}: | |
2703 | 50 | from osv import orm, osv | 49 | locations = self._get_locations_open_inventories(cr, uid) |
2704 | 51 | locations = self._get_locations_open_inventories(cr, uid) | 50 | assert len(locations) == 0, "Function return wrong results: %s" % locations |
2705 | 52 | assert len(locations) == 0, "Function return wrong results : %s" % locations | 51 | |
2702 | 53 | |||
2706 | 54 | - | 52 | - |
2707 | 55 | I will call the function onchange_location_id. | 53 | I will call the function onchange_location_id. |
2709 | 56 | The function must to return true in all test case. | 54 | The function must to return true in all test case. |
2710 | 57 | - | 55 | - |
2711 | 58 | !python {model: stock.inventory.line}: | | 56 | !python {model: stock.inventory.line}: | |
2712 | 59 | from osv import orm, osv | ||
2713 | 60 | pass | ||
2714 | 61 | res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_components')])], False, ref('stock.stock_location_components')) | 57 | res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_components')])], False, ref('stock.stock_location_components')) |
2715 | 62 | assert res == True, "The function 'onchange_location_id' should return True and return '%s'" % res | 58 | assert res == True, "The function 'onchange_location_id' should return True and return '%s'" % res |
2716 | 63 | res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_components')])], False, ref('stock.stock_location_14')) | 59 | res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_components')])], False, ref('stock.stock_location_14')) |
2717 | @@ -68,42 +64,37 @@ | |||
2718 | 68 | The function must return True in all test cases. | 64 | The function must return True in all test cases. |
2719 | 69 | - | 65 | - |
2720 | 70 | !python {model: stock.location}: | | 66 | !python {model: stock.location}: | |
2721 | 71 | from osv import orm, osv | ||
2722 | 72 | res = self._check_inventory(cr, uid, ref('stock.stock_location_components')) | 67 | res = self._check_inventory(cr, uid, ref('stock.stock_location_components')) |
2723 | 73 | assert res == True, "The function '_check_inventory' should return True and return '%s'" % res | 68 | assert res == True, "The function '_check_inventory' should return True and return '%s'" % res |
2724 | 74 | res = self._check_inventory(cr, uid, ref('stock.stock_location_14')) | 69 | res = self._check_inventory(cr, uid, ref('stock.stock_location_14')) |
2725 | 75 | assert res == True, "The function '_check_inventory' should return True and return '%s'" % res | 70 | assert res == True, "The function '_check_inventory' should return True and return '%s'" % res |
2730 | 76 | 71 | ||
2731 | 77 | - | 72 | - |
2732 | 78 | I will confirm inventory. | 73 | I will confirm inventory. |
2733 | 79 | - | 74 | - |
2734 | 80 | !python {model: stock.inventory}: | | 75 | !python {model: stock.inventory}: | |
2738 | 81 | from osv import orm, osv | 76 | self.action_confirm(cr, uid, [ref('inventory_standard')]) |
2739 | 82 | self.action_confirm(cr, uid, [ref('stock_inventory_location_0')]) | 77 | inventory_state = self.read(cr, uid, [ref('inventory_standard')], ['state'])[0]['state'] |
2737 | 83 | inventory_state = self.read(cr, uid, [ref('stock_inventory_location_0')], ['state'])[0]['state'] | ||
2740 | 84 | assert inventory_state == 'confirm', "Partial inventory have '%s' state. It should be 'confirm'" % inventory_state | 78 | assert inventory_state == 'confirm', "Partial inventory have '%s' state. It should be 'confirm'" % inventory_state |
2741 | 85 | 79 | ||
2742 | 86 | - | 80 | - |
2743 | 87 | I will validate inventory | 81 | I will validate inventory |
2744 | 88 | - | 82 | - |
2745 | 89 | !python {model: stock.inventory}: | | 83 | !python {model: stock.inventory}: | |
2751 | 90 | from osv import orm, osv | 84 | self.action_done(cr, uid, [ref('inventory_standard')]) |
2752 | 91 | self.action_done(cr, uid, [ref('stock_inventory_location_0')]) | 85 | inventory_state = self.read(cr, uid, [ref('inventory_standard')], ['state'])[0]['state'] |
2753 | 92 | inventory_state = self.read(cr, uid, [ref('stock_inventory_location_0')], ['state'])[0]['state'] | 86 | assert inventory_state == 'done', "Partial inventory have '%s' state. It should be 'done'" % inventory_state |
2754 | 93 | assert inventory_state == 'done', "Partial inventory have '%s' state. It should be 'done'" % inventory_state | 87 | |
2750 | 94 | |||
2755 | 95 | - | 88 | - |
2756 | 96 | I will verify the quantity for each products. | 89 | I will verify the quantity for each products. |
2758 | 97 | - | 90 | - |
2759 | 98 | !python {model: product.product}: | | 91 | !python {model: product.product}: | |
2760 | 99 | from osv import orm, osv | ||
2761 | 100 | ctx={'location': [ref('stock.stock_location_components')], 'to_date': '2020-12-31 23:59:59'} | ||
2762 | 101 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_cpu1')], ['qty_available'], context=ctx)[0]['qty_available'] | ||
2763 | 102 | assert prod_qty_avail == 18.0, "The stock of CPU1 was not set to 18.0 : %s" % prod_qty_avail | ||
2764 | 103 | |||
2765 | 104 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_cpu3')], ['qty_available'], context=ctx)[0]['qty_available'] | ||
2766 | 105 | assert prod_qty_avail == 12.0, "The stock of CPU3 was not set to 12.0 : %s" % prod_qty_avail | ||
2767 | 106 | |||
2768 | 107 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_fan')], ['qty_available'], context=ctx)[0]['qty_available'] | ||
2769 | 108 | assert prod_qty_avail == 32.0, "The stock of FAN was not set to 32.0 : %s" % prod_qty_avail | ||
2770 | 109 | |||
2771 | 110 | \ No newline at end of file | 92 | \ No newline at end of file |
2772 | 93 | ctx={'location': [ref('stock.stock_location_components')]} | ||
2773 | 94 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_9')], ['qty_available'], context=ctx)[0]['qty_available'] | ||
2774 | 95 | assert prod_qty_avail == 18.0, "The stock of CPU1 was not set to 18.0: %s" % prod_qty_avail | ||
2775 | 96 | |||
2776 | 97 | prod_qty_avail = self.read(cr, uid, [ref('product.product_product_10')], ['qty_available'], context=ctx)[0]['qty_available'] | ||
2777 | 98 | assert prod_qty_avail == 12.0, "The stock of CPU3 was not set to 12.0: %s" % prod_qty_avail | ||
2778 | 99 | |||
2779 | 100 | prod_qty_avail = self.read(cr, uid, [ref('product.product_template_31')], ['qty_available'], context=ctx)[0]['qty_available'] | ||
2780 | 101 | assert prod_qty_avail == 32.0, "The stock of FAN was not set to 32.0: %s" % prod_qty_avail | ||
2781 | 111 | 102 | ||
2782 | === modified file 'stock_inventory_location/wizard/stock_confirm_uninventoried_location.py' | |||
2783 | --- stock_inventory_location/wizard/stock_confirm_uninventoried_location.py 2014-03-12 14:55:39 +0000 | |||
2784 | +++ stock_inventory_location/wizard/stock_confirm_uninventoried_location.py 2014-06-11 15:04:27 +0000 | |||
2785 | @@ -18,78 +18,45 @@ | |||
2786 | 18 | # | 18 | # |
2787 | 19 | ############################################################################## | 19 | ############################################################################## |
2788 | 20 | 20 | ||
2794 | 21 | from openerp.osv import fields, osv | 21 | from openerp.osv import fields, orm |
2795 | 22 | from openerp.tools.translate import _ | 22 | |
2796 | 23 | 23 | ||
2797 | 24 | 24 | class stock_inventory_uninventoried_location(orm.TransientModel): | |
2793 | 25 | class stock_inventory_uninventoried_location(osv.osv_memory): | ||
2798 | 26 | _name = 'stock.inventory.uninventoried.locations' | 25 | _name = 'stock.inventory.uninventoried.locations' |
2799 | 27 | _description = 'Confirm the uninventoried Locations.' | 26 | _description = 'Confirm the uninventoried Locations.' |
2800 | 28 | 27 | ||
2801 | 29 | _columns = { | 28 | _columns = { |
2823 | 30 | 'location_ids': fields.many2many('stock.location', | 29 | 'location_ids': fields.many2many( |
2824 | 31 | 'stock_inventory_uninventoried_location_rel', | 30 | 'stock.location', |
2825 | 32 | 'location_id', | 31 | 'stock_inventory_uninventoried_location_rel', |
2826 | 33 | 'wizard_id', | 32 | 'location_id', 'wizard_id', |
2827 | 34 | 'Uninventoried location', readonly=True), | 33 | 'Uninventoried location', readonly=True), |
2828 | 35 | } | 34 | } |
2808 | 36 | |||
2809 | 37 | def get_locations(self, cr, uid, inventory_id, context=None): | ||
2810 | 38 | """ Get all locations from inventory. """ | ||
2811 | 39 | location_ids = self.pool.get('stock.inventory').read(cr, uid, [inventory_id], ['location_ids'], context=context)[0] | ||
2812 | 40 | return self.pool.get('stock.location').search(cr, uid, [ | ||
2813 | 41 | ('location_id', 'child_of', location_ids['location_ids']), | ||
2814 | 42 | ('usage', '=', 'internal')], context=context) | ||
2815 | 43 | |||
2816 | 44 | def get_locations_inventoried(self, cr, uid, inventory_id, location_ids, context=None): | ||
2817 | 45 | """ Get all locations on inventory lines. """ | ||
2818 | 46 | inventory_line_obj = self.pool.get('stock.inventory.line') | ||
2819 | 47 | inventory_line_ids = inventory_line_obj.search(cr, uid, [('location_id', 'in', location_ids), | ||
2820 | 48 | ('inventory_id', '=', inventory_id)], context=context) | ||
2821 | 49 | inventory_line_locations_ids = inventory_line_obj.read(cr, uid, inventory_line_ids, ['location_id'], context=context) | ||
2822 | 50 | return list(set([_id['location_id'][0] for _id in inventory_line_locations_ids])) | ||
2829 | 51 | 35 | ||
2830 | 52 | def default_locations(self, cr, uid, context=None): | 36 | def default_locations(self, cr, uid, context=None): |
2839 | 53 | """ Initialize view with the list of uninventoried locations. | 37 | """Initialize view with the list of uninventoried locations.""" |
2840 | 54 | Search for children of the location if exists. | 38 | return self.pool['stock.inventory'].get_missing_locations( |
2841 | 55 | """ | 39 | cr, uid, context['active_ids'], context=context) |
2834 | 56 | if context is None: | ||
2835 | 57 | context = {} | ||
2836 | 58 | location_ids = self.get_locations(cr, uid, context['active_id']) | ||
2837 | 59 | inventory_line_locations_ids = self.get_locations_inventoried(cr, uid, context['active_id'], location_ids) | ||
2838 | 60 | return [_id for _id in location_ids if _id not in inventory_line_locations_ids] | ||
2842 | 61 | 40 | ||
2843 | 62 | _defaults = { | 41 | _defaults = { |
2844 | 63 | 'location_ids': default_locations, | 42 | 'location_ids': default_locations, |
2846 | 64 | } | 43 | } |
2847 | 65 | 44 | ||
2848 | 66 | def confirm_uninventoried_locations(self, cr, uid, ids, context=None): | 45 | def confirm_uninventoried_locations(self, cr, uid, ids, context=None): |
2850 | 67 | """ Call action confirm method from stock.inventory """ | 46 | """Add the missing inventory lines with qty=0 and confirm inventory""" |
2851 | 68 | inventory_ids = context['active_ids'] | 47 | inventory_ids = context['active_ids'] |
2858 | 69 | # call the wizard to add lines for uninventoried locations with zero quantity | 48 | inventory_obj = self.pool['stock.inventory'] |
2859 | 70 | inventory_obj = self.pool.get('stock.inventory') | 49 | wizard_obj = self.pool['stock.fill.inventory'] |
2860 | 71 | if not isinstance(inventory_ids, list): | 50 | for inventory in inventory_obj.browse(cr, uid, inventory_ids, |
2861 | 72 | inventory_ids = [inventory_ids] | 51 | context=context): |
2856 | 73 | |||
2857 | 74 | for inventory in inventory_obj.browse(cr, uid, inventory_ids, context=context): | ||
2862 | 75 | if inventory.exhaustive: | 52 | if inventory.exhaustive: |
2878 | 76 | location_ids = self.get_locations(cr, uid, inventory.id, context=context) | 53 | # silently run the import wizard with qty=0 |
2879 | 77 | # get stock inventory lines | 54 | wizard_id = wizard_obj.create( |
2880 | 78 | lines = [] | 55 | cr, uid, {'location_id': inventory.location_id.id, |
2881 | 79 | try: | 56 | 'recursive': True, |
2882 | 80 | # create inventory lines with zero qty | 57 | 'set_stock_zero': True}, context=context) |
2883 | 81 | lines = inventory_obj._fill_location_lines(cr, uid, | 58 | wizard_obj.fill_inventory(cr, uid, [wizard_id], |
2884 | 82 | inventory.id, | 59 | context=context) |
2870 | 83 | location_ids, | ||
2871 | 84 | True, | ||
2872 | 85 | context=context) | ||
2873 | 86 | except osv.except_osv as e: | ||
2874 | 87 | pass | ||
2875 | 88 | |||
2876 | 89 | for line in lines: | ||
2877 | 90 | self.pool.get('stock.inventory.line').create(cr, uid, line, context=context) | ||
2885 | 91 | 60 | ||
2886 | 92 | inventory_obj.action_confirm(cr, uid, inventory_ids, context=context) | 61 | inventory_obj.action_confirm(cr, uid, inventory_ids, context=context) |
2887 | 93 | return {'type': 'ir.actions.act_window_close'} | 62 | return {'type': 'ir.actions.act_window_close'} |
2888 | 94 | |||
2889 | 95 | |||
2890 | 96 | 63 | ||
2891 | === modified file 'stock_inventory_location/wizard/stock_confirm_uninventoried_location.xml' | |||
2892 | --- stock_inventory_location/wizard/stock_confirm_uninventoried_location.xml 2014-03-12 14:55:39 +0000 | |||
2893 | +++ stock_inventory_location/wizard/stock_confirm_uninventoried_location.xml 2014-06-11 15:04:27 +0000 | |||
2894 | @@ -1,33 +1,33 @@ | |||
2895 | 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2896 | 2 | <openerp> | 2 | <openerp> |
2897 | 3 | <data> | 3 | <data> |
2900 | 4 | <!-- The view definition is similar with stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations_view.xml, | 4 | <!-- The view definition is similar with stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations_view.xml, |
2901 | 5 | but the code is different. | 5 | but the code is different. |
2902 | 6 | This wizard compare declared locations with locations on inventory lines to present the uninventoried (empty) locations to user. --> | 6 | This wizard compare declared locations with locations on inventory lines to present the uninventoried (empty) locations to user. --> |
2903 | 7 | <record id="view_confirm_uninventoried_location" model="ir.ui.view"> | 7 | <record id="view_confirm_uninventoried_location" model="ir.ui.view"> |
2904 | 8 | <field name="name">stock.inventory.uninventoried.locations.form</field> | 8 | <field name="name">stock.inventory.uninventoried.locations.form</field> |
2905 | 9 | <field name="model">stock.inventory.uninventoried.locations</field> | 9 | <field name="model">stock.inventory.uninventoried.locations</field> |
2906 | 10 | <field name="type">form</field> | ||
2907 | 11 | <field name="arch" type="xml"> | 10 | <field name="arch" type="xml"> |
2909 | 12 | <form string="Confirm uninventoried locations"> | 11 | <form string="Confirm empty locations" version="7.0"> |
2910 | 13 | <group colspan="4" col="1"> | 12 | <group colspan="4" col="1"> |
2912 | 14 | <label string="The following Stock Locations are part of the current Physical Inventory, but not Inventory Line has been recorded for them."/> | 13 | <separator string="The following Locations are empty"/> |
2913 | 14 | <label string="The following Stock Locations are part of the current Physical Inventory, but no Inventory Line has been recorded for them."/> | ||
2914 | 15 | <label string="It could either mean that the Locations are empty, or that the Inventory is not yet complete."/> | ||
2915 | 16 | <label string="If you confirm the Inventory, these Locations will be considered empty and their content will be purged."/> | ||
2916 | 15 | <field name="location_ids" nolabel="1"> | 17 | <field name="location_ids" nolabel="1"> |
2917 | 16 | <tree> | 18 | <tree> |
2918 | 17 | <field name="name"/> | 19 | <field name="name"/> |
2919 | 18 | </tree> | 20 | </tree> |
2920 | 19 | </field> | 21 | </field> |
2921 | 20 | <label string="It could either mean that the Locations are empty, or that the Inventory is not yet complete."/> | ||
2922 | 21 | <label string="If you confirm the Inventory, these Locations will be considered empty and their content will be purged."/> | ||
2923 | 22 | <separator string=""/> | 22 | <separator string=""/> |
2924 | 23 | </group> | 23 | </group> |
2929 | 24 | <group colspan="4" col="2"> | 24 | <footer> |
2930 | 25 | <button special="cancel" string="Cancel" icon="gtk-cancel" default_focus="1" /> | 25 | <button name="confirm_uninventoried_locations" string="Purge contents and confirm Inventory" type="object" class="oe_highlight"/> |
2931 | 26 | <button name="confirm_uninventoried_locations" string="Purge contents and confirm Inventory" type="object" icon="gtk-ok"/> | 26 | or |
2932 | 27 | </group> | 27 | <button string="Cancel" class="oe_link" special="cancel" default_focus="1"/> |
2933 | 28 | </footer> | ||
2934 | 28 | </form> | 29 | </form> |
2935 | 29 | </field> | 30 | </field> |
2936 | 30 | </record> | 31 | </record> |
2937 | 31 | |||
2938 | 32 | </data> | 32 | </data> |
2939 | 33 | </openerp> | 33 | </openerp> |
2940 | 34 | \ No newline at end of file | 34 | \ No newline at end of file |
2941 | 35 | 35 | ||
2942 | === modified file 'stock_inventory_location/wizard/stock_fill_location_inventory.py' | |||
2943 | --- stock_inventory_location/wizard/stock_fill_location_inventory.py 2014-03-12 14:55:39 +0000 | |||
2944 | +++ stock_inventory_location/wizard/stock_fill_location_inventory.py 2014-06-11 15:04:27 +0000 | |||
2945 | @@ -18,80 +18,30 @@ | |||
2946 | 18 | # | 18 | # |
2947 | 19 | ############################################################################## | 19 | ############################################################################## |
2948 | 20 | 20 | ||
2955 | 21 | from openerp.osv import fields, osv | 21 | from openerp.osv import fields, orm |
2956 | 22 | from openerp.tools.translate import _ | 22 | |
2957 | 23 | from collections import OrderedDict | 23 | |
2958 | 24 | 24 | class FillInventoryWizard(orm.TransientModel): | |
2959 | 25 | 25 | """Add a field that lets the client make the location read-only""" | |
2954 | 26 | class stock_fill_location_inventory(osv.osv_memory): | ||
2960 | 27 | _inherit = 'stock.fill.inventory' | 26 | _inherit = 'stock.fill.inventory' |
2961 | 28 | 27 | ||
2962 | 29 | _columns = { | 28 | _columns = { |
3031 | 30 | 'location_id': fields.many2one('stock.location', 'Location'), | 29 | 'exhaustive': fields.boolean('Exhaustive', readonly=True) |
3032 | 31 | #'exhaustive': fields.boolean('stock.inventory', 'Type'), | 30 | } |
3033 | 32 | 'exhaustive': fields.boolean('stock.inventory'), | 31 | |
3034 | 33 | } | 32 | def default_get(self, cr, uid, fields, context=None): |
3035 | 34 | 33 | """Get 'location_id' and 'exhaustive' from the inventory""" | |
3036 | 35 | def get_inventory_type(self, cr, uid, context=None): | 34 | if context is None: |
3037 | 36 | if context.get('active_id', False): | 35 | context = {} |
3038 | 37 | inventory_obj = self.pool.get('stock.inventory') | 36 | inv_id = context.get('active_id') |
3039 | 38 | exhaustive = inventory_obj.read(cr, uid, [context.get('active_id')], ['exhaustive'], context=context)[0]['exhaustive'] | 37 | |
3040 | 39 | return exhaustive | 38 | res = super(FillInventoryWizard, self).default_get( |
3041 | 40 | return False | 39 | cr, uid, fields, context=context) |
3042 | 41 | 40 | if (context.get('active_model') == 'stock.inventory' | |
3043 | 42 | _defaults = { | 41 | and inv_id |
3044 | 43 | 'exhaustive': get_inventory_type, | 42 | and 'location_id' in fields): |
3045 | 44 | } | 43 | inventory = self.pool['stock.inventory'].browse( |
3046 | 45 | 44 | cr, uid, context['active_id'], context=context) | |
3047 | 46 | def view_init(self, cr, uid, fields_list, context=None): | 45 | res.update({'location_id': inventory.location_id.id, |
3048 | 47 | """ inherit from original to add multiple selection of location | 46 | 'exhaustive': inventory.exhaustive}) |
3049 | 48 | and exclude from location list the locations already choosen by another inventory """ | 47 | return res |
2982 | 49 | if context is None: | ||
2983 | 50 | context = {} | ||
2984 | 51 | |||
2985 | 52 | inventory_obj = self.pool.get('stock.inventory') | ||
2986 | 53 | inventory_state = inventory_obj.read(cr, uid, [context.get('active_id')], ['state'], context=context)[0] | ||
2987 | 54 | if inventory_state['state'] != 'open': | ||
2988 | 55 | raise osv.except_osv(_('Error !'), | ||
2989 | 56 | _('the inventory must be in "Open" state.')) | ||
2990 | 57 | |||
2991 | 58 | nb_inventory = inventory_obj.search(cr, uid, [('id', '=', context.get('active_id'))], count=True, context=context) | ||
2992 | 59 | if nb_inventory == 0: | ||
2993 | 60 | raise osv.except_osv(_('Warning !'), | ||
2994 | 61 | _('No locations found for the inventory.')) | ||
2995 | 62 | |||
2996 | 63 | return super(stock_fill_location_inventory, self).view_init(cr, uid, fields_list, context=context) | ||
2997 | 64 | |||
2998 | 65 | def fill_inventory(self, cr, uid, ids, context=None): | ||
2999 | 66 | """ Fill the inventory only with open locations on the inventory. | ||
3000 | 67 | """ | ||
3001 | 68 | if context is None: | ||
3002 | 69 | context = {} | ||
3003 | 70 | |||
3004 | 71 | fill_inventory = self.browse(cr, uid, ids[0], context=context) | ||
3005 | 72 | if not fill_inventory.exhaustive: | ||
3006 | 73 | return super(stock_fill_location_inventory, self).fill_inventory(cr, uid, ids, context=context) # call standard wizard | ||
3007 | 74 | |||
3008 | 75 | location_ids = self.pool.get('stock.inventory').read(cr, uid, [context.get('active_id')], ['location_ids'])[0] | ||
3009 | 76 | |||
3010 | 77 | if not location_ids['location_ids']: | ||
3011 | 78 | raise osv.except_osv(_('Error : Empty location !'), _('No location to import.\nYou must add a location on the locations list.')) | ||
3012 | 79 | |||
3013 | 80 | if fill_inventory.recursive: | ||
3014 | 81 | location_ids = self.pool.get('stock.location').search(cr, uid, [('location_id', 'child_of', location_ids['location_ids']), | ||
3015 | 82 | ('usage', '=', 'internal')], context=context) | ||
3016 | 83 | else: | ||
3017 | 84 | location_ids = location_ids['location_ids'] | ||
3018 | 85 | |||
3019 | 86 | location_ids = list(OrderedDict.fromkeys(location_ids)) | ||
3020 | 87 | |||
3021 | 88 | lines = self.pool.get('stock.inventory')._fill_location_lines(cr, uid, | ||
3022 | 89 | context['active_ids'][0], | ||
3023 | 90 | location_ids, | ||
3024 | 91 | fill_inventory.set_stock_zero, | ||
3025 | 92 | context=context) | ||
3026 | 93 | |||
3027 | 94 | inventory_lines_obj = self.pool.get('stock.inventory.line') | ||
3028 | 95 | for line in lines: | ||
3029 | 96 | inventory_lines_obj.create(cr, uid, line, context=context) | ||
3030 | 97 | return {'type': 'ir.actions.act_window_close'} | ||
3050 | 98 | 48 | ||
3051 | === modified file 'stock_inventory_location/wizard/stock_fill_location_inventory_view.xml' | |||
3052 | --- stock_inventory_location/wizard/stock_fill_location_inventory_view.xml 2014-03-12 14:55:39 +0000 | |||
3053 | +++ stock_inventory_location/wizard/stock_fill_location_inventory_view.xml 2014-06-11 15:04:27 +0000 | |||
3054 | @@ -10,7 +10,7 @@ | |||
3055 | 10 | <field name="exhaustive" invisible="1" /> | 10 | <field name="exhaustive" invisible="1" /> |
3056 | 11 | </xpath> | 11 | </xpath> |
3057 | 12 | <xpath expr="//field[@name='location_id']" position="attributes"> | 12 | <xpath expr="//field[@name='location_id']" position="attributes"> |
3059 | 13 | <attribute name="attrs">{'invisible':[('exhaustive','=',True)]}</attribute> | 13 | <attribute name="attrs">{'readonly':[('exhaustive','=',True)]}</attribute> |
3060 | 14 | </xpath> | 14 | </xpath> |
3061 | 15 | </field> | 15 | </field> |
3062 | 16 | </record> | 16 | </record> |