Merge lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-location into lp:stock-logistic-warehouse

Proposed by Loïc Bellier - Numérigraphe
Status: Superseded
Proposed branch: lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-location
Merge into: lp:stock-logistic-warehouse
Diff against target: 1345 lines (+1249/-0)
15 files modified
stock_inventory_location/__init__.py (+24/-0)
stock_inventory_location/__openerp__.py (+77/-0)
stock_inventory_location/exceptions.py (+26/-0)
stock_inventory_location/i18n/fr.po (+241/-0)
stock_inventory_location/stock_inventory_location.py (+351/-0)
stock_inventory_location/stock_inventory_location_demo.xml (+26/-0)
stock_inventory_location/stock_inventory_location_view.xml (+81/-0)
stock_inventory_location/test/inventory_exhaustive_test.yml (+128/-0)
stock_inventory_location/test/inventory_future_test.yml (+13/-0)
stock_inventory_location/test/inventory_standard_test.yml (+100/-0)
stock_inventory_location/wizard/__init__.py (+22/-0)
stock_inventory_location/wizard/stock_confirm_uninventoried_location.py (+62/-0)
stock_inventory_location/wizard/stock_confirm_uninventoried_location.xml (+33/-0)
stock_inventory_location/wizard/stock_fill_location_inventory.py (+47/-0)
stock_inventory_location/wizard/stock_fill_location_inventory_view.xml (+18/-0)
To merge this branch: bzr merge lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-location
Reviewer Review Type Date Requested Status
Lionel Sausin - Initiatives/Numérigraphe (community) Needs Resubmitting
Alexandre Fayolle - camptocamp code review, test Needs Fixing
Review via email: mp+210630@code.launchpad.net

This proposal has been superseded by a proposal from 2014-06-20.

Description of the change

This proposal feature obsoletes Tiny's "stock_alternative_inventory", and
implements exhaustive inventory in a much more practical way.

It lets you explicitly state which locations are being inventoried, and makes
sure the stock levels exactly reflect the physical inventory for those
locations.

It also checks that all locations been entered in the inventory lines,
and no other locations.

Finally it will block Stock Moves during the inventory, to keep
warehouse workers from changing the stock while the inventory is not
finished.

To post a comment you must log in.
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

Hello,

Thanks for this contribution, the functionality is great and I'd love to see it in OCA. And thanks for including tests.

A few minor changes are needed to bring the module to the coding standards

* use orm.Model / orm.TransientModel as base classes instead of osv.osv and osv.osv_memory
* model column default values: in OpenERP 7.0, not need to use a lambda for a constant value, just use the constant

Additionally:

* in __openerp__.py, I think you should use 'Warehouse Management' for the category (i.e. the same one as the official 'stock' addon
* no space before '!' in english (I'd remove the exclamation marks in exception messages altogether, that the UI job to display an icon)
* in confirm_uninventoried_location_wizard: you should add a 'if context is None: context = {}' at the beginning.
* in confirm_uninventoried_locations: you are ignoring an osv_except exception. Could you add a comment in the code explaining why this is safe? If this is about the "No product in this location" warning raised in the reimplementation of _fill_location_lines, then I think a check that we are ignoring the correct exception should be added. You could for instance subclass except_osv and raise + ignore the subclass. Otherwise I think the code may hide things we do not want to hide (or even fail because of an except_osv

review: Needs Fixing (code review, test)
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Recent developments in trunk-wms implement some features of this proposal but the implementation is different.
I suggest we refactor this proposal and the following patches, to make it easy to port the module to v8 later on.
- Add locations as many2one instead of one2many
  http://bazaar.launchpad.net/~openerp-dev/openobject-addons/trunk-wms/revision/9596
- forbid inventories in the future
  http://bazaar.launchpad.net/~openerp-dev/openobject-addons/trunk-wms/revision/9598

review: Needs Resubmitting
36. By Loïc Bellier - Numérigraphe

[REF] update coding style for v7

37. By Loïc Bellier - Numérigraphe

[FIX]: Fix product on yaml test.

38. By Numérigraphe

[MERGE] only allow one location per inventory to make it easier to migrate to v8 when the time comes. code & views cleaned up.

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Loïc and I are still working on this proposal. Good progress was made: we re-aligned the features with v8 in mind, and improved the code style and the views.
Acsone joined in and we're still making tests, and i hope Loïc can make a new proposal in the coming days.

39. By Numérigraphe

[FIX] test and add a test for the refactored function

40. By Numérigraphe

[FIX] wrong nesting in list comprehension

41. By Laetitia Gangloff (Acsone)

[FIX] read inventories as superuser to allow the control on locations even when the user has no permission on inventories. Courtesy of ACSONE.

42. By Laetitia Gangloff (Acsone)

[FIX] don't mutate the data received by the method, it causes an infinite recursion. Fix provided by ACSONE.

43. By Laetitia Gangloff (Acsone)

[FIX] missing test files from the previous fixes by ASCONE

44. By Laetitia Gangloff (Acsone)

[FIX] exhaustive was not passed to the wizard when emptying the locations that were not in the inventory

45. By Numérigraphe

[REF] remove TODO

46. By Laetitia Gangloff (Acsone)

[FIX] missing import

47. By Numérigraphe

[IMP] French translation

Unmerged revisions

47. By Numérigraphe

[IMP] French translation

46. By Laetitia Gangloff (Acsone)

[FIX] missing import

45. By Numérigraphe

[REF] remove TODO

44. By Laetitia Gangloff (Acsone)

[FIX] exhaustive was not passed to the wizard when emptying the locations that were not in the inventory

43. By Laetitia Gangloff (Acsone)

[FIX] missing test files from the previous fixes by ASCONE

42. By Laetitia Gangloff (Acsone)

[FIX] don't mutate the data received by the method, it causes an infinite recursion. Fix provided by ACSONE.

41. By Laetitia Gangloff (Acsone)

[FIX] read inventories as superuser to allow the control on locations even when the user has no permission on inventories. Courtesy of ACSONE.

40. By Numérigraphe

[FIX] wrong nesting in list comprehension

39. By Numérigraphe

[FIX] test and add a test for the refactored function

38. By Numérigraphe

[MERGE] only allow one location per inventory to make it easier to migrate to v8 when the time comes. code & views cleaned up.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'stock_inventory_location'
2=== added file 'stock_inventory_location/__init__.py'
3--- stock_inventory_location/__init__.py 1970-01-01 00:00:00 +0000
4+++ stock_inventory_location/__init__.py 2014-06-12 16:47:03 +0000
5@@ -0,0 +1,24 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved.
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU General Public License as published by
13+# the Free Software Foundation, either version 3 of the License, or
14+# (at your option) any later version.
15+#
16+# This program is distributed in the hope that it will be useful,
17+# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+# GNU General Public License for more details.
20+#
21+# You should have received a copy of the GNU General Public License
22+# along with this program. If not, see <http://www.gnu.org/licenses/>.
23+#
24+##############################################################################
25+
26+import stock_inventory_location
27+import wizard
28+# Bring the main exception into the package's scope for easier reuse
29+from .exceptions import ExhaustiveInventoryException
30
31=== added file 'stock_inventory_location/__openerp__.py'
32--- stock_inventory_location/__openerp__.py 1970-01-01 00:00:00 +0000
33+++ stock_inventory_location/__openerp__.py 2014-06-12 16:47:03 +0000
34@@ -0,0 +1,77 @@
35+# -*- coding: utf-8 -*-
36+##############################################################################
37+#
38+# This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved.
39+#
40+# This program is free software: you can redistribute it and/or modify
41+# it under the terms of the GNU General Public License as published by
42+# the Free Software Foundation, either version 3 of the License, or
43+# (at your option) any later version.
44+#
45+# This program is distributed in the hope that it will be useful,
46+# but WITHOUT ANY WARRANTY; without even the implied warranty of
47+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48+# GNU General Public License for more details.
49+#
50+# You should have received a copy of the GNU General Public License
51+# along with this program. If not, see <http://www.gnu.org/licenses/>.
52+#
53+##############################################################################
54+
55+{
56+ "name": "Exhaustive Stock Inventories",
57+ "version": "1.1",
58+ "depends": ["stock"],
59+ "author": u"Numérigraphe",
60+ "category": "Warehouse Management",
61+ "description": """
62+Let users make exhaustive Inventories
63+=====================================
64+
65+Standard Physical Inventories in OpenERP only contain a generic list of
66+products by locations, which is well suited to partial Inventories and simple
67+warehouses. When the a standard Inventory is confirmed, only the products in
68+the inventory are checked. If a Product is present in the computed stock and
69+not in the recorded Inventory, OpenERP will consider that it remains unchanged.
70+
71+But for exhaustive inventories in complex warehouses, it is not practical:
72+ - you want to avoid Stock Moves to/from these Locations while counting goods
73+ - you must make sure all the locations you want have been counted
74+ - you must make sure no other location has been counted by mistake
75+ - you want the computed stock to perfectly match the inventory when you
76+ confirm it.
77+
78+This module lets choose whether an Physical Inventory is exhaustive or
79+standard.
80+For an exhaustive Inventory:
81+ - in the state "Draft" you define the Location where goods must be counted.
82+ - the new Inventory status "Open" lets you indicate that the list of Locations
83+ is final and you are now counting the goods.
84+ In that status, no Stock Moves can be recorded in/out of the Inventory's
85+ Locations.
86+ - if the Location or some of it's children have not been entered in the
87+ Inventory Lines, OpenERP warns you when you confirm the Inventory.
88+ - only the Inventory's Location or its children can be entered in the
89+ Inventory Lines.
90+ - every good that is not in the Inventory Lines is considered lost, and gets
91+ moved out of the stock when you confirm the Inventory.
92+""",
93+ "data": [
94+ "wizard/stock_confirm_uninventoried_location.xml",
95+ "stock_inventory_location_view.xml",
96+ "wizard/stock_fill_location_inventory_view.xml",
97+ ],
98+ "test": [
99+ "test/inventory_standard_test.yml",
100+ "test/inventory_exhaustive_test.yml",
101+ "test/inventory_future_test.yml",
102+ ],
103+ "images": [
104+ "images/inventory_form.png",
105+ "inventory_empty_locations.png",
106+ "images/move_error.png",
107+ "images/location_locked.png",
108+ "images/future_inventory.png",
109+ ],
110+ "demo": ["stock_inventory_location_demo.xml"]
111+}
112
113=== added file 'stock_inventory_location/exceptions.py'
114--- stock_inventory_location/exceptions.py 1970-01-01 00:00:00 +0000
115+++ stock_inventory_location/exceptions.py 2014-06-12 16:47:03 +0000
116@@ -0,0 +1,26 @@
117+# -*- coding: utf-8 -*-
118+##############################################################################
119+#
120+# This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved.
121+#
122+# This program is free software: you can redistribute it and/or modify
123+# it under the terms of the GNU General Public License as published by
124+# the Free Software Foundation, either version 3 of the License, or
125+# (at your option) any later version.
126+#
127+# This program is distributed in the hope that it will be useful,
128+# but WITHOUT ANY WARRANTY; without even the implied warranty of
129+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130+# GNU General Public License for more details.
131+#
132+# You should have received a copy of the GNU General Public License
133+# along with this program. If not, see <http://www.gnu.org/licenses/>.
134+#
135+##############################################################################
136+
137+from openerp.osv import orm
138+
139+
140+class ExhaustiveInventoryException(orm.except_orm):
141+ """The operation is not possible for an exhaustive inventory"""
142+ pass
143
144=== added directory 'stock_inventory_location/i18n'
145=== added file 'stock_inventory_location/i18n/fr.po'
146--- stock_inventory_location/i18n/fr.po 1970-01-01 00:00:00 +0000
147+++ stock_inventory_location/i18n/fr.po 2014-06-12 16:47:03 +0000
148@@ -0,0 +1,241 @@
149+# Translation of OpenERP Server.
150+# This file contains the translation of the following modules:
151+# * stock_inventory_location
152+#
153+msgid ""
154+msgstr ""
155+"Project-Id-Version: OpenERP Server 6.0.4\n"
156+"Report-Msgid-Bugs-To: support@openerp.com\n"
157+"POT-Creation-Date: 2013-09-25 13:58+0000\n"
158+"PO-Revision-Date: 2013-09-25 13:58+0000\n"
159+"Last-Translator: <>\n"
160+"Language-Team: \n"
161+"MIME-Version: 1.0\n"
162+"Content-Type: text/plain; charset=UTF-8\n"
163+"Content-Transfer-Encoding: \n"
164+"Plural-Forms: \n"
165+
166+#. module: stock_inventory_location
167+#: code:addons/stock_inventory_location/stock_inventory_location.py:232
168+#: constraint:stock.move:0
169+#, python-format
170+msgid "A Physical Inventory is being conducted at this location"
171+msgstr "Un inventaire est en cours à cet emplacement"
172+
173+#. module: stock_inventory_location
174+#: view:stock.inventory.uninventoried.locations:0
175+msgid "Cancel"
176+msgstr "Annuler"
177+
178+#. module: stock_inventory_location
179+#: view:stock.inventory:0
180+msgid "Cancel Inventory"
181+msgstr "Annuler l'inventaire"
182+
183+#. module: stock_inventory_location
184+#: help:stock.inventory,exhaustive:0
185+msgid "Check the box if you are conducting an exhaustive Inventory.\n"
186+"Leave the box unchecked if you are conducting a standard Inventory (partial inventory for example).\n"
187+"For an exhaustive Inventory:\n"
188+" - the status \"Draft\" lets you define the list of Locations where goods must be counted\n"
189+" - 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\n"
190+" - only the Inventory's Locations can be entered in the Inventory Lines\n"
191+" - if some of the Inventory's Locations have not been entered in the Inventory Lines, OpenERP warns you when you confirm the Inventory\n"
192+" - every good that is not in the Inventory Lines is considered lost, and gets moved out of the stock when you confirm the Inventory"
193+msgstr "Cochez la case si vous effectuez un inventaire exhaustif.\n"
194+"Laissez la case non-dochée si vous effectuez un inventaire standard (par exmple un inventaire partiel).\n"
195+"Pour les inventaires exhaustifs :\n"
196+" - le statut \"Brouillon\" permet d'indiquer la liste des emplacements dont la marchandise doit être comptée\n"
197+" - le statut \"Ouvert\" indiqueque la liste des emplacements est définitive, et que le comptage est en cours. Dans ce statut, aucun mouvement de stock ne peut être enregistré depuis/vers les emplacements de l'inventaire\n"
198+" - seuls les emplacements de l'inventaire peuvent être saisis dans les lignes d'inventaire\n"
199+" - si certains emplacements sont absent des lignes d'inventaire, OpenERP vous en avertit lors de la confirmation de l'inventaire\n"
200+" - toutes les marchandises qui ne sont pas dans les lignes d'inventaire sont considérées comme perdues, et sont supprimées lors de la confirmation de l'inventaire"
201+
202+#. module: stock_inventory_location
203+#: view:stock.inventory:0
204+msgid "Confirm Inventory"
205+msgstr "Confirmer l'inventaire"
206+
207+#. module: stock_inventory_location
208+#: model:ir.model,name:stock_inventory_location.model_stock_inventory_uninventoried_locations
209+msgid "Confirm the uninventoried Locations."
210+msgstr "Confirmer les emplacements non inventoriés."
211+
212+#. module: stock_inventory_location
213+#: view:stock.inventory.uninventoried.locations:0
214+msgid "Confirm empty locations"
215+msgstr "Confirmez les emplacements vides"
216+
217+#. module: stock_inventory_location
218+#: model:ir.model,name:stock_inventory_location.model_stock_location
219+msgid "Emplacement"
220+msgstr "Emplacement"
221+
222+#. module: stock_inventory_location
223+#: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:54
224+#, python-format
225+msgid "Error"
226+msgstr "Erreur"
227+
228+#. module: stock_inventory_location
229+#: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:75
230+#, python-format
231+msgid "Error: Empty location"
232+msgstr "Erreur : Emplacement vide"
233+
234+#. module: stock_inventory_location
235+#: code:addons/stock_inventory_location/stock_inventory_location.py:231
236+#: code:addons/stock_inventory_location/stock_inventory_location.py:282
237+#, python-format
238+msgid "Error: Location locked down"
239+msgstr "Erreur: emplacement en inventaire"
240+
241+#. module: stock_inventory_location
242+#: constraint:stock.inventory:0
243+msgid "Error: You can not create recursive inventories."
244+msgstr "Erreur: Vous ne pouvez pas créer un inventaire récursif."
245+
246+#. module: stock_inventory_location
247+#: constraint:stock.inventory.line:0
248+msgid "Error: duplicates lines"
249+msgstr "Erreur: lignes en double"
250+
251+#. module: stock_inventory_location
252+#: view:stock.inventory:0
253+#: field:stock.inventory,exhaustive:0
254+msgid "Exhaustive"
255+msgstr "Exhaustif"
256+
257+#. module: stock_inventory_location
258+#: model:ir.model,name:stock_inventory_location.model_stock_inventory
259+msgid "Gestion des stocks"
260+msgstr "Gestion des stocks"
261+
262+#. module: stock_inventory_location
263+#: view:stock.inventory.uninventoried.locations:0
264+msgid "If you confirm the Inventory, these Locations will be considered empty and their content will be purged."
265+msgstr "Si vous confirmez l'inventaire, ces emplacements seront considérés comme vides et leur contenu sera supprimé."
266+
267+#. module: stock_inventory_location
268+#: model:ir.model,name:stock_inventory_location.model_stock_fill_inventory
269+msgid "Importer un inventaire"
270+msgstr "Importer un inventaire"
271+
272+#. module: stock_inventory_location
273+#: view:stock.inventory.uninventoried.locations:0
274+msgid "It could either mean that the Locations are empty, or that the Inventory is not yet complete."
275+msgstr "Cela peut vouloir dire soit que l'inventaire n'est pas terminé, soit que ces emplacements sont effectivement vides."
276+
277+#. module: stock_inventory_location
278+#: model:ir.model,name:stock_inventory_location.model_stock_inventory_line
279+msgid "Ligne d'inventaire"
280+msgstr "Ligne d'inventaire"
281+
282+#. module: stock_inventory_location
283+#: code:addons/stock_inventory_location/stock_inventory_location.py:59
284+#, python-format
285+msgid "Location missing for this inventory."
286+msgstr "Emplacement manquant pour cet inventaire."
287+
288+#. module: stock_inventory_location
289+#: model:ir.model,name:stock_inventory_location.model_stock_move
290+msgid "Mouvement de stock"
291+msgstr "Mouvement de stock"
292+
293+#. module: stock_inventory_location
294+#: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:75
295+#, python-format
296+msgid "No location to import.\n"
297+"You must add a location on the locations list."
298+msgstr "Pas d'emplacement à importer.\n"
299+"Vous devez ajouter un emplacement dans la liste des emplacements."
300+
301+#. module: stock_inventory_location
302+#: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:58
303+#, python-format
304+msgid "No locations found for the inventory."
305+msgstr "Pas d'emplacement trouvé pour cet inventaire."
306+
307+#. module: stock_inventory_location
308+#: code:addons/stock_inventory_location/stock_inventory_location.py:163
309+#, python-format
310+msgid "No product in this location."
311+msgstr "Pas de produit à cet emplacement."
312+
313+#. module: stock_inventory_location
314+#: code:addons/stock_inventory_location/stock_inventory_location.py:283
315+#, python-format
316+msgid "A Physical Inventory is being conducted at the following location(s):\n"
317+"%s"
318+msgstr "Les emplacements suivants sont en inventaire :\n"
319+"%s"
320+
321+#. module: stock_inventory_location
322+#: view:stock.inventory:0
323+msgid "Open Inventory"
324+msgstr "Ouvrir l'inventaire"
325+
326+#. module: stock_inventory_location
327+#: constraint:stock.inventory:0
328+msgid "Other Physical inventories are being conducted using the same Locations."
329+msgstr "Erreur: certains emplacements sont déjà dans un autre inventaire."
330+
331+#. module: stock_inventory_location
332+#: view:stock.inventory.uninventoried.locations:0
333+msgid "Purge contents and confirm Inventory"
334+msgstr "Supprimer le contenu et confirmer l'inventaire"
335+
336+#. module: stock_inventory_location
337+#: view:stock.inventory.uninventoried.locations:0
338+msgid "The following Stock Locations are part of the current Physical Inventory, but no Inventory Line has been recorded for them."
339+msgstr "Les emplacements suivants font partie de l'inventaire en cours, mais aucune ligne d'inventaire les concernant n'a été enregistrée."
340+
341+#. module: stock_inventory_location
342+#: field:stock.inventory.uninventoried.locations,location_ids:0
343+msgid "Uninventoried location"
344+msgstr "Emplacements non inventoriés"
345+
346+#. module: stock_inventory_location
347+#: code:addons/stock_inventory_location/stock_inventory_location.py:59
348+#: code:addons/stock_inventory_location/stock_inventory_location.py:163
349+#: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:58
350+#, python-format
351+msgid "Warning"
352+msgstr "Attention"
353+
354+#. module: stock_inventory_location
355+#: code:addons/stock_inventory_location/stock_inventory_location.py:209
356+#, python-format
357+msgid "Warning: Wrong location"
358+msgstr "Attention: emplacement incorrect"
359+
360+#. module: stock_inventory_location
361+#: code:addons/stock_inventory_location/stock_inventory_location.py:210
362+#, python-format
363+msgid "You cannot record an Inventory Line for this Location.\n"
364+"You must first add this Location to the list of affected Locations on the Inventory form."
365+msgstr "Vous ne pouvez pas ajouter cet emplacement.\n"
366+"Il ne fait pas partie de la liste des emplacements à inventorier"
367+
368+#. module: stock_inventory_location
369+#: constraint:stock.move:0
370+msgid "You must assign a production lot for this product"
371+msgstr "Vous devez affecter un lot de fabrication à ce produit."
372+
373+#. module: stock_inventory_location
374+#: constraint:stock.inventory.line:0
375+msgid "You must not create same inventory line Product, Location, Lot on the same date"
376+msgstr "Vous ne pouvez pas créer plusieurs lignes d'inventaires pour le même produit, lot, emplacement à la même date"
377+
378+#. module: stock_inventory_location
379+#: constraint:stock.move:0
380+msgid "You try to assign a lot which is not from the same product"
381+msgstr "Vous essayez d'affecter un lot qui n'est pas pour ce produit."
382+
383+
384+#. module: stock_inventory_location
385+#: code:addons/stock_inventory_location/wizard/stock_fill_location_inventory.py:54
386+#, python-format
387+msgid "the inventory must be in \"Open\" state."
388+msgstr "l'inventaire doit etre \"Ouvert\"."
389+
390
391=== added directory 'stock_inventory_location/images'
392=== added file 'stock_inventory_location/images/future_inventory.png'
393Binary 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-12 16:47:03 +0000 differ
394=== added file 'stock_inventory_location/images/inventory_empty_locations.png'
395Binary 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-12 16:47:03 +0000 differ
396=== added file 'stock_inventory_location/images/inventory_form.png'
397Binary 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-12 16:47:03 +0000 differ
398=== added file 'stock_inventory_location/images/location_locked.png'
399Binary 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-12 16:47:03 +0000 differ
400=== added file 'stock_inventory_location/images/move_error.png'
401Binary 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-12 16:47:03 +0000 differ
402=== added directory 'stock_inventory_location/static'
403=== added directory 'stock_inventory_location/static/src'
404=== added directory 'stock_inventory_location/static/src/img'
405=== added file 'stock_inventory_location/static/src/img/icon.png'
406Binary 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-12 16:47:03 +0000 differ
407=== added file 'stock_inventory_location/stock_inventory_location.py'
408--- stock_inventory_location/stock_inventory_location.py 1970-01-01 00:00:00 +0000
409+++ stock_inventory_location/stock_inventory_location.py 2014-06-12 16:47:03 +0000
410@@ -0,0 +1,351 @@
411+# -*- coding: utf-8 -*-
412+##############################################################################
413+#
414+# This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved.
415+#
416+# This program is free software: you can redistribute it and/or modify
417+# it under the terms of the GNU General Public License as published by
418+# the Free Software Foundation, either version 3 of the License, or
419+# (at your option) any later version.
420+#
421+# This program is distributed in the hope that it will be useful,
422+# but WITHOUT ANY WARRANTY; without even the implied warranty of
423+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
424+# GNU General Public License for more details.
425+#
426+# You should have received a copy of the GNU General Public License
427+# along with this program. If not, see <http://www.gnu.org/licenses/>.
428+#
429+##############################################################################
430+
431+import time
432+from collections import Iterable
433+
434+from openerp.osv import orm, fields
435+from openerp.tools.translate import _
436+# The next 2 imports are only needed for a feature backported from trunk-wms
437+# TODOv8! remove, feature is included upstream
438+from openerp.osv import osv
439+from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
440+
441+from .exceptions import ExhaustiveInventoryException
442+
443+
444+class StockInventory(orm.Model):
445+ """Add locations to the inventories"""
446+ _inherit = 'stock.inventory'
447+
448+ INVENTORY_STATE_SELECTION = [
449+ ('draft', 'Draft'),
450+ ('open', 'Open'),
451+ ('done', 'Done'),
452+ ('confirm', 'Confirmed'),
453+ ('cancel', 'Cancelled')
454+ ]
455+
456+ _columns = {
457+ # TODO v8: should we use "confirm" instead of adding "open"?
458+ 'state': fields.selection(
459+ INVENTORY_STATE_SELECTION, 'State', readonly=True, select=True),
460+ # TODO v8: remove this, should not be needed anymore
461+ # Make the inventory lines read-only in all states except "Open",
462+ # to ensure that no unwanted Location can be inserted
463+ 'inventory_line_id': fields.one2many(
464+ 'stock.inventory.line', 'inventory_id', 'Inventory lines',
465+ readonly=True, states={'open': [('readonly', False)]}),
466+ # TODO v8: remove this, it's backported from v8
467+ 'location_id': fields.many2one(
468+ 'stock.location', 'Inventoried Location',
469+ readonly=True, states={'draft': [('readonly', False)]}),
470+ 'exhaustive': fields.boolean(
471+ 'Exhaustive', readonly=True,
472+ states={'draft': [('readonly', False)]},
473+ help="Check the box if you are conducting an exhaustive "
474+ "Inventory.\n"
475+ "Leave the box unchecked if you are conducting a standard "
476+ "Inventory (partial inventory for example).\n"
477+ "For an exhaustive Inventory:\n"
478+ " - the status \"Draft\" lets you define the list of "
479+ "Locations where goods must be counted\n"
480+ " - the status \"Open\" indicates that the list of Locations "
481+ "is definitive and you are now counting the goods. In that "
482+ "status, no Stock Moves can be recorded in/out of the "
483+ "Inventory's Locations\n"
484+ " - only the Inventory's Locations can be entered in the "
485+ "Inventory Lines\n"
486+ " - if some of the Inventory's Locations have not been "
487+ "entered in the Inventory Lines, OpenERP warns you "
488+ "when you confirm the Inventory\n"
489+ " - every good that is not in the Inventory Lines is "
490+ "considered lost, and gets moved out of the stock when you "
491+ "confirm the Inventory"),
492+ }
493+
494+ def action_open(self, cr, uid, ids, context=None):
495+ """Change the state of the inventory to 'open'"""
496+ return self.write(cr, uid, ids, {'state': 'open'}, context=context)
497+
498+ # TODO v8: remove this method? the feature looks already done upstream
499+ def action_done(self, cr, uid, ids, context=None):
500+ """
501+ Don't allow to make an inventory with a date in the future.
502+
503+ This makes sure no stock moves will be introduced between the
504+ moment you finish the inventory and the date of the Stock Moves.
505+ Backported from trunk-wms:
506+ revid:qdp-launchpad@openerp.com-20140317090656-o7lo22tzm8yuv3r8
507+
508+ @raise osv.except_osv:
509+ We raise this exception on purpose instead of
510+ ExhaustiveInventoryException to ensure forward-compatibility
511+ with v8.
512+ """
513+ for inventory in self.browse(cr, uid, ids, context=None):
514+ if inventory.date > time.strftime(DEFAULT_SERVER_DATETIME_FORMAT):
515+ raise osv.except_osv(
516+ _('Error!'),
517+ _('It\'s impossible to confirm an inventory in the '
518+ 'future. Please change the inventory date to proceed '
519+ 'further.'))
520+ return super(StockInventory, self).action_done(cr, uid, ids,
521+ context=context)
522+
523+ # TODO: remove this in v8
524+ def _default_location(self, cr, uid, ids, context=None):
525+ """Default stock location
526+
527+ @return: id of the stock location of the first warehouse of the
528+ default company"""
529+ location_id = False
530+ company_id = self.pool['res.company']._company_default_get(
531+ cr, uid, 'stock.warehouse', context=context)
532+ warehouse_id = self.pool['stock.warehouse'].search(
533+ cr, uid, [('company_id', '=', company_id)], limit=1)
534+ if warehouse_id:
535+ location_id = self.pool['stock.warehouse'].read(
536+ cr, uid, warehouse_id[0], ['lot_stock_id'])['lot_stock_id'][0]
537+ return location_id
538+
539+ _defaults = {
540+ 'state': 'draft',
541+ 'exhaustive': False,
542+ # TODO: remove this in v8
543+ 'location_id': _default_location,
544+ }
545+
546+ def _check_location_free_from_inventories(self, cr, uid, ids):
547+ """
548+ Verify that no other Inventory is being conducted on the same locations
549+
550+ Open Inventories are matched using the exact Location IDs,
551+ excluding children.
552+ """
553+ # We don't get a context because we're called from a _constraint
554+ for inventory in self.browse(cr, uid, ids):
555+ if not inventory.exhaustive:
556+ # never block standard inventories
557+ continue
558+ if self.search(cr, uid,
559+ [('location_id', '=', inventory.location_id.id),
560+ ('id', '!=', inventory.id),
561+ ('date', '=', inventory.date),
562+ ('exhaustive', '=', True)]):
563+ # Quit as soon as one offending inventory is found
564+ return False
565+ return True
566+
567+ _constraints = [
568+ (_check_location_free_from_inventories,
569+ 'Other Physical inventories are being conducted using the same '
570+ 'Locations.',
571+ ['location_id', 'date', 'exhaustive'])
572+ ]
573+
574+ def _get_locations_open_inventories(self, cr, uid, context=None):
575+ """IDs of location in open exhaustive inventories, with children"""
576+ inv_ids = self.search(
577+ cr, uid, [('state', '=', 'open'), ('exhaustive', '=', True)],
578+ context=context)
579+ if not inv_ids:
580+ # Early exit if no match found
581+ return []
582+ # List the Locations - normally all exhaustive inventories have one
583+ location_ids = [inventory.location_id.id
584+ for inventory in self.browse(cr, uid, inv_ids,
585+ context=context)]
586+ # Extend to the children Locations
587+ return self.pool['stock.location'].search(
588+ cr, uid,
589+ [('location_id', 'child_of', set(location_ids)),
590+ ('usage', '=', 'internal')],
591+ context=context)
592+
593+ def get_missing_locations(self, cr, uid, ids, context=None):
594+ """Compute the list of location_ids which are missing from the lines
595+
596+ Here, "missing" means the location is the inventory's location or one
597+ of it's children, and the inventory does not contain any line with
598+ this location."""
599+ inventories = self.browse(cr, uid, ids, context=context)
600+ # Find the locations of the inventories
601+ inv_location_ids = [i.location_id.id for i in inventories]
602+ # Extend to the children locations
603+ inv_location_ids = set(self.pool['stock.location'].search(
604+ cr, uid, [
605+ ('location_id', 'child_of', inv_location_ids),
606+ ('usage', '=', 'internal')], context=context))
607+ # Find the locations already recorded in inventory lines
608+ line_locations_ids = set([l.location_id.id
609+ for i in inventories
610+ for l in i.inventory_line_id])
611+ return list(inv_location_ids - line_locations_ids)
612+
613+ def confirm_missing_locations(self, cr, uid, ids, context=None):
614+ """Open wizard to confirm empty locations on exhaustive inventories"""
615+ for inventory in self.browse(cr, uid, ids, context=context):
616+ if (self.get_missing_locations(cr, uid, ids, context=context)
617+ and inventory.exhaustive):
618+ return {
619+ 'type': 'ir.actions.act_window',
620+ 'view_type': 'form',
621+ 'view_mode': 'form',
622+ 'res_model': 'stock.inventory.uninventoried.locations',
623+ 'target': 'new',
624+ 'context': dict(context,
625+ active_ids=ids,
626+ active_id=ids[0]),
627+ 'nodestroy': True,
628+ }
629+ return self.action_confirm(cr, uid, ids, context=context)
630+
631+
632+class StockInventoryLine(orm.Model):
633+ """Only allow the Inventory's Locations"""
634+
635+ _inherit = 'stock.inventory.line'
636+
637+ def _default_stock_location(self, cr, uid, context=None):
638+ res = super(StockInventoryLine, self)._default_stock_location(
639+ cr, uid, context=context)
640+ if context is None or not context.get('location_id', False):
641+ return res
642+ else:
643+ return context['location_id']
644+
645+ _defaults = {
646+ 'location_id': _default_stock_location
647+ }
648+
649+ def onchange_location_id(self, cr, uid, ids, inventory_location_id,
650+ exhaustive, location_id, context=None):
651+ """Warn if the new is not in the location list for this inventory."""
652+ if not exhaustive:
653+ # Don't check if partial inventory
654+ return True
655+
656+ # search children of location
657+ if location_id not in self.pool['stock.location'].search(
658+ cr, uid, [('location_id', 'child_of', inventory_location_id)],
659+ context=context):
660+ return {
661+ 'value': {'location_id': False},
662+ 'warning': {
663+ 'title': _('Warning: Wrong location'),
664+ 'message': _(
665+ "You cannot record an Inventory Line for this "
666+ "Location.\n"
667+ "You must first add this Location to the list of "
668+ "affected Locations on the Inventory form.")}
669+ }
670+ return True
671+
672+
673+class StockLocation(orm.Model):
674+ """Refuse changes during exhaustive Inventories"""
675+ _inherit = 'stock.location'
676+ _order = 'name'
677+
678+ # TODOv7: why not put this in an ORM "_constraint" instead?
679+ def _check_inventory(self, cr, uid, ids, context=None):
680+ """Error if an exhaustive Inventory is being conducted here"""
681+ inv_obj = self.pool['stock.inventory']
682+ location_inventory_open_ids = inv_obj._get_locations_open_inventories(
683+ cr, uid, context=context)
684+ if not isinstance(ids, Iterable):
685+ ids = [ids]
686+ for inv_id in ids:
687+ if inv_id in location_inventory_open_ids:
688+ raise ExhaustiveInventoryException(
689+ _('Error: Location locked down'),
690+ _('A Physical Inventory is being conducted at this '
691+ 'location'))
692+ return True
693+
694+ def write(self, cr, uid, ids, vals, context=None):
695+ """Refuse write if an inventory is being conducted"""
696+ self._check_inventory(cr, uid, ids, context=context)
697+ if not isinstance(ids, Iterable):
698+ ids = [ids]
699+ ids_to_check = ids
700+ # If changing the parent, no inventory must conducted there either
701+ if vals.get('location_id'):
702+ ids_to_check.append(vals['location_id'])
703+ self._check_inventory(cr, uid, ids_to_check, context=context)
704+ return super(StockLocation, self).write(cr, uid, ids, vals,
705+ context=context)
706+
707+ def create(self, cr, uid, vals, context=None):
708+ """Refuse create if an inventory is being conducted at the parent"""
709+ self._check_inventory(cr, uid, vals.get('location_id'),
710+ context=context)
711+ return super(StockLocation, self).create(cr, uid, vals,
712+ context=context)
713+
714+ def unlink(self, cr, uid, ids, context=None):
715+ """Refuse unlink if an inventory is being conducted"""
716+ self._check_inventory(cr, uid, ids, context=context)
717+ return super(StockLocation, self).unlink(cr, uid, ids, context=context)
718+
719+
720+class StockMove(orm.Model):
721+ """Refuse Moves during exhaustive Inventories"""
722+
723+ _inherit = 'stock.move'
724+
725+ # TODOv7: adapt this to match trunk-wms
726+ def _check_open_inventory_location(self, cr, uid, ids, context=None):
727+ """
728+ Check that the locations are not locked by an open inventory
729+
730+ Standard inventories are not checked.
731+
732+ @raise ExhaustiveInventoryException: an error is raised if locations
733+ are locked, instead of returning False, in order to pass an
734+ extensive error message back to users.
735+ """
736+ message = ""
737+ inv_obj = self.pool['stock.inventory']
738+ locked_location_ids = inv_obj._get_locations_open_inventories(
739+ cr, uid, context=context)
740+ if not locked_location_ids:
741+ # Nothing to verify
742+ return True
743+ for move in self.browse(cr, uid, ids, context=context):
744+ if (move.location_id.usage != 'inventory'
745+ and move.location_dest_id.id in locked_location_ids):
746+ message += " - %s\n" % (move.location_dest_id.name)
747+ if (move.location_dest_id.usage != 'inventory'
748+ and move.location_id.id in locked_location_ids):
749+ message += " - %s\n" % (move.location_id.name)
750+ if message:
751+ raise ExhaustiveInventoryException(
752+ _('Error: Location locked down'),
753+ _('A Physical Inventory is being conducted at the following '
754+ 'location(s):\n%s') % message)
755+ return True
756+
757+ _constraints = [
758+ (_check_open_inventory_location,
759+ "A Physical Inventory is being conducted at this location",
760+ ['location_id', 'location_dest_id']),
761+ ]
762
763=== added file 'stock_inventory_location/stock_inventory_location_demo.xml'
764--- stock_inventory_location/stock_inventory_location_demo.xml 1970-01-01 00:00:00 +0000
765+++ stock_inventory_location/stock_inventory_location_demo.xml 2014-06-12 16:47:03 +0000
766@@ -0,0 +1,26 @@
767+<?xml version="1.0" encoding="utf-8"?>
768+<openerp>
769+ <data noupdate="0">
770+ <!-- Record a non exhaustive inventory -->
771+ <record id="inventory_standard" model="stock.inventory">
772+ <field name="name">Standard inventory</field>
773+ <field name="state">draft</field>
774+ </record>
775+
776+ <!-- Record an exhaustive inventory -->
777+ <record id="inventory_exhaustive" model="stock.inventory">
778+ <field name="name">Exhaustive inventory</field>
779+ <field name="state">draft</field>
780+ <field name="exhaustive">True</field>
781+ <field name="location_id" model="stock.location" search="[('name', '=', 'Shelf 2')]" />
782+ </record>
783+
784+ <!-- Record an inventory dated in the future -->
785+ <!-- TODOv8: remove this entry, only useful for a test already in trunk-wms -->
786+ <record id="inventory_future" model="stock.inventory">
787+ <field name="name">Inventory in the future</field>
788+ <field name="state">draft</field>
789+ <field name="date">2020-03-01 00:00:00</field>
790+ </record>
791+ </data>
792+</openerp>
793
794=== added file 'stock_inventory_location/stock_inventory_location_view.xml'
795--- stock_inventory_location/stock_inventory_location_view.xml 1970-01-01 00:00:00 +0000
796+++ stock_inventory_location/stock_inventory_location_view.xml 2014-06-12 16:47:03 +0000
797@@ -0,0 +1,81 @@
798+<?xml version="1.0" encoding="utf-8"?>
799+<openerp>
800+ <data>
801+
802+ <record model="ir.ui.view" id="stock_inventory_location_form_view">
803+ <field name="name">stock.inventory.location.form</field>
804+ <field name="model">stock.inventory</field>
805+ <field name="inherit_id" ref="stock.view_inventory_form"/>
806+ <field name="priority" eval="10"/>
807+ <field name="arch" type="xml">
808+ <!-- Show the state 'done' in the statusbar -->
809+ <xpath expr="/form//field[@name='state']" position="attributes">
810+ <attribute name="statusbar_visible">draft,open,confirm</attribute>
811+ </xpath>
812+
813+ <!-- TODO v8 place "exhaustive" next to "location_id" -->
814+ <!-- Add type of inventory: standard or exhaustive. -->
815+ <xpath expr="/form//field[@name='name']" position="after">
816+ <field name="exhaustive"/>
817+ <field name="location_id" groups="stock.group_locations"
818+ domain="[('usage','in',('view', 'internal'))]"
819+ attrs="{'invisible':[('exhaustive','!=',True)], 'required':[('exhaustive','=',True)]}"/>
820+ </xpath>
821+
822+ <!-- Enable Fill Inventory button when state is open -->
823+ <xpath expr="//button[@string='Fill Inventory']" position="attributes">
824+ <attribute name="states">open</attribute>
825+ <attribute name="context">{'default_exhaustive': exhaustive}</attribute>
826+ </xpath>
827+
828+ <!-- Control locations added by user on inventory line -->
829+ <xpath expr="/form//field[@name='inventory_line_id']"
830+ position="attributes">
831+ <attribute name="context">{'location_id': location_id}</attribute>
832+ </xpath>
833+ <xpath expr="/form//field[@name='inventory_line_id']/tree//field[@name='location_id']"
834+ position="attributes">
835+ <attribute name="on_change">onchange_location_id(parent.location_id, parent.exhaustive, location_id)</attribute>
836+ </xpath>
837+ <xpath expr="/form//field[@name='inventory_line_id']/form//field[@name='location_id']"
838+ position="attributes">
839+ <attribute name="on_change">onchange_location_id(parent.location_id, parent.exhaustive, location_id)</attribute>
840+ </xpath>
841+
842+ <!-- Add button to open an inventory. Call wizard on confirm inventory -->
843+ <xpath expr="/form//button[@name='action_cancel_inventory']" position="before">
844+ <button name="action_open" states="draft" string="Open Inventory" type="object" class="oe_highlight" groups="stock.group_stock_user"/>
845+ </xpath>
846+ <!-- Show the "cancel" button in state "open" -->
847+ <xpath expr="/form//button[@name='action_cancel_inventory']" position="attributes">
848+ <attribute name="states">draft,open,confirm,done</attribute>
849+ </xpath>
850+ <!-- hijack the "confirm" button -->
851+ <xpath expr="/form//button[@name='action_confirm']" position="attributes">
852+ <attribute name="states">open</attribute>
853+ <attribute name="name">confirm_missing_locations</attribute>
854+ </xpath>
855+ </field>
856+ </record>
857+
858+ <!-- Add filter for complete or partial inventory -->
859+ <record model="ir.ui.view" id="view_inventory_complete_filter">
860+ <field name="name">complete.inventory.filter</field>
861+ <field name="model">stock.inventory</field>
862+ <field name="inherit_id" ref="stock.view_inventory_filter"/>
863+ <field name="arch" type="xml">
864+ <xpath expr="//field[@name='name']" position="before">
865+ <filter icon="terp-check" name="exhaustive" string="Exhaustive" domain="[('exhaustive', '=', True)]"
866+ help="Only select exhaustive Inventories." />
867+ <separator orientation="vertical"/>
868+ </xpath>
869+ </field>
870+ </record>
871+
872+ <!-- Show exhaustive inventories by default -->
873+ <record id="stock.action_inventory_form" model="ir.actions.act_window">
874+ <field name="context">{'full':'1', 'search_default_exhaustive':1}</field>
875+ </record>
876+
877+ </data>
878+</openerp>
879\ No newline at end of file
880
881=== added directory 'stock_inventory_location/test'
882=== added file 'stock_inventory_location/test/inventory_exhaustive_test.yml'
883--- stock_inventory_location/test/inventory_exhaustive_test.yml 1970-01-01 00:00:00 +0000
884+++ stock_inventory_location/test/inventory_exhaustive_test.yml 2014-06-12 16:47:03 +0000
885@@ -0,0 +1,128 @@
886+-
887+ This file will test an exhaustive inventory.
888+ I will call open_action method and check if state of inventories are 'open'.
889+-
890+ !python {model: stock.inventory}: |
891+ self.action_open(cr, uid, [ref('inventory_exhaustive')])
892+ inventory_state = self.read(cr, uid, [ref('inventory_exhaustive')], ['state'])[0]['state']
893+ assert inventory_state == 'open', "Inventory in state '%s'. It should be 'open'" % inventory_state
894+-
895+ I will check that the function get_missing_locations return some locations.
896+-
897+ !python {model: stock.inventory}: |
898+ missing_loc_ids = self.get_missing_locations(cr, uid, [ref('inventory_exhaustive')], context=context)
899+ assert len(missing_loc_ids), "get_missing_locations did not return any ID."
900+-
901+ I create a wizard record for stock_confirm_uninventoried_location to verify that it contains the uninventoried locations
902+-
903+ !python {model: stock.inventory.uninventoried.locations}: |
904+ ctx = dict(context, active_ids=[ref('inventory_exhaustive')])
905+ wizard_id = self.create(cr, uid, {}, context=ctx)
906+ wizard = self.browse(cr, uid, wizard_id, context=ctx)
907+ assert len(wizard.location_ids) > 0 , "The wizard does not contain any lines."
908+-
909+ I add products to exhaustive inventory.
910+ Adding 17” LCD Monitor.
911+-
912+ !record {model: stock.inventory.line, id: lines_inventory_location_pc1}:
913+ product_id: product.product_product_7
914+ product_uom: product.product_uom_unit
915+ company_id: base.main_company
916+ inventory_id: inventory_exhaustive
917+ product_qty: 18.0
918+ location_id: stock.stock_location_14
919+
920+-
921+ Adding USB Keyboard, QWERTY.
922+-
923+ !record {model: stock.inventory.line, id: lines_inventory_location_pc3}:
924+ product_id: product.product_product_8
925+ product_uom: product.product_uom_unit
926+ company_id: base.main_company
927+ inventory_id: inventory_exhaustive
928+ product_qty: 5.0
929+ location_id: stock.stock_location_14
930+
931+-
932+ I will call the function _get_locations_open_inventories and check the result.
933+ The function will return only the location_id of the exhaustive inventory.
934+-
935+ !python {model: stock.inventory}: |
936+ locations = self._get_locations_open_inventories(cr, uid)
937+ assert len(locations) == 1, "Function return wrong results: %s" % locations
938+ 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])
939+-
940+ I will call the function onchange_location_id.
941+ The function must return True in the first case, and return a warning dictionnary in the second test.
942+-
943+ !python {model: stock.inventory.line}: |
944+ res = self.onchange_location_id(cr, uid, [], ref('stock.stock_location_14'), True, ref('stock.stock_location_14'))
945+ assert res == True, "Exhaustive: The function 'onchange_location_id' should return True and return '%s'" % res
946+ res = self.onchange_location_id(cr, uid, [], ref('stock.stock_location_14'), True, ref('stock.stock_location_components'))
947+ assert res.get('warning', False) != False , "Function 'onchange_location_id': Warning not raise. ('%s)" % res
948+
949+-
950+ I will check that the function get_missing_locations does not return any locations.
951+-
952+ !python {model: stock.inventory}: |
953+ missing_loc_ids = self.get_missing_locations(cr, uid, [ref('inventory_exhaustive')], context=context)
954+ assert not missing_loc_ids, "get_missing_locations should not return IDs but returned %s" % missing_loc_ids
955+-
956+ I create a wizard record for stock_confirm_uninventoried_location and validate it
957+-
958+ !python {model: stock.inventory.uninventoried.locations}: |
959+ ctx = dict(context, active_ids=[ref('inventory_exhaustive')])
960+ wizard_id = self.create(cr, uid, {}, context=ctx)
961+ wizard = self.browse(cr, uid, wizard_id, context=ctx)
962+ assert len(wizard.location_ids) == 0 , "The wizard should not contain any lines but contains %s." % wizard.location_ids
963+ self.confirm_uninventoried_locations(cr, uid, wizard_id, context=ctx)
964+-
965+ Stock moves are not allowed in the locations during the inventory.
966+-
967+ !python {model: stock.move}: |
968+ # TODOv8: remove this test, this is already part of trunk-wms
969+ from stock_inventory_location import ExhaustiveInventoryException
970+ try:
971+ self.create(
972+ cr,uid, {
973+ 'name': 'Bad move',
974+ 'location_id': ref('stock.stock_location_14'),
975+ 'location_dest_id': ref('stock.stock_location_3'),
976+ 'product_id': ref('product.product_product_8'),
977+ 'product_uom': ref('product.product_uom_unit'),
978+ 'date_expected': '2020-01-01 00:00:00'
979+ })
980+ except ExhaustiveInventoryException as e:
981+ log("Good! The Stock Move was refused: %s" % e)
982+-
983+ I will confirm the exhaustive inventory
984+-
985+ !python {model: stock.inventory}: |
986+ self.action_confirm(cr, uid, [ref('inventory_exhaustive')])
987+ inventory_state = self.read(cr, uid, [ref('inventory_exhaustive')], ['state'])[0]['state']
988+ assert inventory_state == 'confirm', "Exhaustive inventory is in state '%s'. It should be 'confirm'" % inventory_state
989+
990+-
991+ I will validate the exhaustive inventory
992+-
993+ !python {model: stock.inventory}: |
994+ self.action_done(cr, uid, [ref('inventory_exhaustive')])
995+ inventory_state = self.read(cr, uid, [ref('inventory_exhaustive')], ['state'])[0]['state']
996+ assert inventory_state == 'done', "Exhaustive inventory is in state '%s'. It should be 'done'" % inventory_state
997+
998+-
999+ I will verify the quantity for each products.
1000+-
1001+ !python {model: product.product}: |
1002+ ctx = dict(context, location=[ref('stock.stock_location_14')])
1003+ prod_qty_avail = self.read(cr, uid, [ref('product.product_product_7')], ['qty_available'], context=ctx)[0]['qty_available']
1004+ assert prod_qty_avail == 18.0, "The stock of PC1 was not set to 18.0: %s" % prod_qty_avail
1005+
1006+ prod_qty_avail = self.read(cr, uid, [ref('product.product_product_8')], ['qty_available'], context=ctx)[0]['qty_available']
1007+ assert prod_qty_avail == 5.0, "The stock of PC3 was not set to 5.0: %s" % prod_qty_avail
1008+
1009+ prod_qty_avail = self.read(cr, uid, [ref('product.product_product_24')], ['qty_available'], context=ctx)[0]['qty_available']
1010+ assert prod_qty_avail == 0.0, "The stock of KEYA was not set to 0: %s" % prod_qty_avail
1011+
1012+ prod_qty_avail = self.read(cr, uid, [ref('product.product_product_25')], ['qty_available'], context=ctx)[0]['qty_available']
1013+ assert prod_qty_avail == 0.0, "The stock of MOU was not set to 0: %s" % prod_qty_avail
1014
1015=== added file 'stock_inventory_location/test/inventory_future_test.yml'
1016--- stock_inventory_location/test/inventory_future_test.yml 1970-01-01 00:00:00 +0000
1017+++ stock_inventory_location/test/inventory_future_test.yml 2014-06-12 16:47:03 +0000
1018@@ -0,0 +1,13 @@
1019+-
1020+ Check that an inventory with a date in the future cannot be opened.
1021+-
1022+ !python {model: stock.inventory}: |
1023+ # TODO v8: maybe this is already part of the new WMS
1024+ from osv.osv import except_osv
1025+ self.action_open(cr, uid, [ref('inventory_future')])
1026+ try:
1027+ self.action_done(cr, uid, [ref('inventory_future')])
1028+ except except_osv as e:
1029+ log("Good! The Inventory could not be opened: %s" % e)
1030+ inventory_state = self.read(cr, uid, [ref('inventory_future')], ['state'])[0]['state']
1031+ assert inventory_state != 'done', "Future inventory is done."
1032
1033=== added file 'stock_inventory_location/test/inventory_standard_test.yml'
1034--- stock_inventory_location/test/inventory_standard_test.yml 1970-01-01 00:00:00 +0000
1035+++ stock_inventory_location/test/inventory_standard_test.yml 2014-06-12 16:47:03 +0000
1036@@ -0,0 +1,100 @@
1037+-
1038+ This file will test a non exhaustive inventory.
1039+ I will call open_action method and check if state of inventories are 'open'.
1040+-
1041+ !python {model: stock.inventory}: |
1042+ self.action_open(cr, uid, [ref('inventory_standard')])
1043+ inventory_state = self.read(cr, uid, [ref('inventory_standard')], ['state'])[0]['state']
1044+ assert inventory_state == 'open', "Partial inventory have '%s' state. It should be 'open'" % inventory_state
1045+
1046+-
1047+ In order, I add products to inventory.
1048+ Adding Azerty Keyboard.
1049+-
1050+ !record {model: stock.inventory.line, id: lines_inventory_location_kbaz}:
1051+ product_id: product.product_product_9
1052+ product_uom: product.product_uom_unit
1053+ company_id: base.main_company
1054+ inventory_id: inventory_standard
1055+ product_qty: 18.0
1056+ location_id: stock.stock_location_components
1057+
1058+-
1059+ Adding Optical Mouse.
1060+-
1061+ !record {model: stock.inventory.line, id: lines_inventory_location_optm}:
1062+ product_id: product.product_product_10
1063+ product_uom: product.product_uom_unit
1064+ company_id: base.main_company
1065+ inventory_id: inventory_standard
1066+ product_qty: 12.0
1067+ location_id: stock.stock_location_components
1068+
1069+-
1070+ Adding Multimedia Speakers.
1071+-
1072+ !record {model: stock.inventory.line, id: lines_inventory_location_grca}:
1073+ product_id: product.product_template_31
1074+ product_uom: product.product_uom_unit
1075+ company_id: base.main_company
1076+ inventory_id: inventory_standard
1077+ product_qty: 32.0
1078+ location_id: stock.stock_location_components
1079+
1080+-
1081+ I will call the function _get_locations_open_inventories and check the result.
1082+ The function will return no locations because it's not an exhaustive inventory.
1083+-
1084+ !python {model: stock.inventory}: |
1085+ locations = self._get_locations_open_inventories(cr, uid)
1086+ assert len(locations) == 0, "Function return wrong results: %s" % locations
1087+
1088+-
1089+ I will call the function onchange_location_id.
1090+ The function must to return true in all test case.
1091+-
1092+ !python {model: stock.inventory.line}: |
1093+ res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_components')])], False, ref('stock.stock_location_components'))
1094+ assert res == True, "The function 'onchange_location_id' should return True and return '%s'" % res
1095+ res = self.onchange_location_id(cr, uid, [], [(6,0,[ref('stock.stock_location_components')])], False, ref('stock.stock_location_14'))
1096+ assert res == True, "The function 'onchange_location_id' should return True and return '%s'" % res
1097+
1098+-
1099+ I will call the function _check_inventory.
1100+ The function must return True in all test cases.
1101+-
1102+ !python {model: stock.location}: |
1103+ res = self._check_inventory(cr, uid, ref('stock.stock_location_components'))
1104+ assert res == True, "The function '_check_inventory' should return True and return '%s'" % res
1105+ res = self._check_inventory(cr, uid, ref('stock.stock_location_14'))
1106+ assert res == True, "The function '_check_inventory' should return True and return '%s'" % res
1107+
1108+-
1109+ I will confirm inventory.
1110+-
1111+ !python {model: stock.inventory}: |
1112+ self.action_confirm(cr, uid, [ref('inventory_standard')])
1113+ inventory_state = self.read(cr, uid, [ref('inventory_standard')], ['state'])[0]['state']
1114+ assert inventory_state == 'confirm', "Partial inventory have '%s' state. It should be 'confirm'" % inventory_state
1115+
1116+-
1117+ I will validate inventory
1118+-
1119+ !python {model: stock.inventory}: |
1120+ self.action_done(cr, uid, [ref('inventory_standard')])
1121+ inventory_state = self.read(cr, uid, [ref('inventory_standard')], ['state'])[0]['state']
1122+ assert inventory_state == 'done', "Partial inventory have '%s' state. It should be 'done'" % inventory_state
1123+
1124+-
1125+ I will verify the quantity for each products.
1126+-
1127+ !python {model: product.product}: |
1128+ ctx={'location': [ref('stock.stock_location_components')]}
1129+ prod_qty_avail = self.read(cr, uid, [ref('product.product_product_9')], ['qty_available'], context=ctx)[0]['qty_available']
1130+ assert prod_qty_avail == 18.0, "The stock of CPU1 was not set to 18.0: %s" % prod_qty_avail
1131+
1132+ prod_qty_avail = self.read(cr, uid, [ref('product.product_product_10')], ['qty_available'], context=ctx)[0]['qty_available']
1133+ assert prod_qty_avail == 12.0, "The stock of CPU3 was not set to 12.0: %s" % prod_qty_avail
1134+
1135+ prod_qty_avail = self.read(cr, uid, [ref('product.product_template_31')], ['qty_available'], context=ctx)[0]['qty_available']
1136+ assert prod_qty_avail == 32.0, "The stock of FAN was not set to 32.0: %s" % prod_qty_avail
1137
1138=== added directory 'stock_inventory_location/wizard'
1139=== added file 'stock_inventory_location/wizard/__init__.py'
1140--- stock_inventory_location/wizard/__init__.py 1970-01-01 00:00:00 +0000
1141+++ stock_inventory_location/wizard/__init__.py 2014-06-12 16:47:03 +0000
1142@@ -0,0 +1,22 @@
1143+# -*- coding: utf-8 -*-1
1144+##############################################################################
1145+#
1146+# This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved.
1147+#
1148+# This program is free software: you can redistribute it and/or modify
1149+# it under the terms of the GNU General Public License as published by
1150+# the Free Software Foundation, either version 3 of the License, or
1151+# (at your option) any later version.
1152+#
1153+# This program is distributed in the hope that it will be useful,
1154+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1155+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1156+# GNU General Public License for more details.
1157+#
1158+# You should have received a copy of the GNU General Public License
1159+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1160+#
1161+##############################################################################
1162+
1163+import stock_fill_location_inventory
1164+import stock_confirm_uninventoried_location
1165
1166=== added file 'stock_inventory_location/wizard/stock_confirm_uninventoried_location.py'
1167--- stock_inventory_location/wizard/stock_confirm_uninventoried_location.py 1970-01-01 00:00:00 +0000
1168+++ stock_inventory_location/wizard/stock_confirm_uninventoried_location.py 2014-06-12 16:47:03 +0000
1169@@ -0,0 +1,62 @@
1170+# -*- encoding: utf-8 -*-
1171+##############################################################################
1172+#
1173+# This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved.
1174+#
1175+# This program is free software: you can redistribute it and/or modify
1176+# it under the terms of the GNU General Public License as published by
1177+# the Free Software Foundation, either version 3 of the License, or
1178+# (at your option) any later version.
1179+#
1180+# This program is distributed in the hope that it will be useful,
1181+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1182+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1183+# GNU General Public License for more details.
1184+#
1185+# You should have received a copy of the GNU General Public License
1186+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1187+#
1188+##############################################################################
1189+
1190+from openerp.osv import fields, orm
1191+
1192+
1193+class stock_inventory_uninventoried_location(orm.TransientModel):
1194+ _name = 'stock.inventory.uninventoried.locations'
1195+ _description = 'Confirm the uninventoried Locations.'
1196+
1197+ _columns = {
1198+ 'location_ids': fields.many2many(
1199+ 'stock.location',
1200+ 'stock_inventory_uninventoried_location_rel',
1201+ 'location_id', 'wizard_id',
1202+ 'Uninventoried location', readonly=True),
1203+ }
1204+
1205+ def default_locations(self, cr, uid, context=None):
1206+ """Initialize view with the list of uninventoried locations."""
1207+ return self.pool['stock.inventory'].get_missing_locations(
1208+ cr, uid, context['active_ids'], context=context)
1209+
1210+ _defaults = {
1211+ 'location_ids': default_locations,
1212+ }
1213+
1214+ def confirm_uninventoried_locations(self, cr, uid, ids, context=None):
1215+ """Add the missing inventory lines with qty=0 and confirm inventory"""
1216+ inventory_ids = context['active_ids']
1217+ inventory_obj = self.pool['stock.inventory']
1218+ wizard_obj = self.pool['stock.fill.inventory']
1219+ for inventory in inventory_obj.browse(cr, uid, inventory_ids,
1220+ context=context):
1221+ if inventory.exhaustive:
1222+ # silently run the import wizard with qty=0
1223+ wizard_id = wizard_obj.create(
1224+ cr, uid, {'location_id': inventory.location_id.id,
1225+ 'recursive': True,
1226+ 'set_stock_zero': True}, context=context)
1227+ wizard_obj.fill_inventory(cr, uid, [wizard_id],
1228+ context=context)
1229+
1230+ inventory_obj.action_confirm(cr, uid, inventory_ids, context=context)
1231+ return {'type': 'ir.actions.act_window_close'}
1232
1233=== added file 'stock_inventory_location/wizard/stock_confirm_uninventoried_location.xml'
1234--- stock_inventory_location/wizard/stock_confirm_uninventoried_location.xml 1970-01-01 00:00:00 +0000
1235+++ stock_inventory_location/wizard/stock_confirm_uninventoried_location.xml 2014-06-12 16:47:03 +0000
1236@@ -0,0 +1,33 @@
1237+<?xml version="1.0" encoding="utf-8"?>
1238+<openerp>
1239+ <data>
1240+ <!-- The view definition is similar with stock_inventory_hierarchical_location/wizard/stock_inventory_missing_locations_view.xml,
1241+ but the code is different.
1242+ This wizard compare declared locations with locations on inventory lines to present the uninventoried (empty) locations to user. -->
1243+ <record id="view_confirm_uninventoried_location" model="ir.ui.view">
1244+ <field name="name">stock.inventory.uninventoried.locations.form</field>
1245+ <field name="model">stock.inventory.uninventoried.locations</field>
1246+ <field name="arch" type="xml">
1247+ <form string="Confirm empty locations" version="7.0">
1248+ <group colspan="4" col="1">
1249+ <separator string="The following Locations are empty"/>
1250+ <label string="The following Stock Locations are part of the current Physical Inventory, but no Inventory Line has been recorded for them."/>
1251+ <label string="It could either mean that the Locations are empty, or that the Inventory is not yet complete."/>
1252+ <label string="If you confirm the Inventory, these Locations will be considered empty and their content will be purged."/>
1253+ <field name="location_ids" nolabel="1">
1254+ <tree>
1255+ <field name="name"/>
1256+ </tree>
1257+ </field>
1258+ <separator string=""/>
1259+ </group>
1260+ <footer>
1261+ <button name="confirm_uninventoried_locations" string="Purge contents and confirm Inventory" type="object" class="oe_highlight"/>
1262+ or
1263+ <button string="Cancel" class="oe_link" special="cancel" default_focus="1"/>
1264+ </footer>
1265+ </form>
1266+ </field>
1267+ </record>
1268+ </data>
1269+</openerp>
1270\ No newline at end of file
1271
1272=== added file 'stock_inventory_location/wizard/stock_fill_location_inventory.py'
1273--- stock_inventory_location/wizard/stock_fill_location_inventory.py 1970-01-01 00:00:00 +0000
1274+++ stock_inventory_location/wizard/stock_fill_location_inventory.py 2014-06-12 16:47:03 +0000
1275@@ -0,0 +1,47 @@
1276+# -*- coding: utf-8 -*-
1277+##############################################################################
1278+#
1279+# This module is copyright (C) 2013 Numérigraphe SARL. All Rights Reserved.
1280+#
1281+# This program is free software: you can redistribute it and/or modify
1282+# it under the terms of the GNU General Public License as published by
1283+# the Free Software Foundation, either version 3 of the License, or
1284+# (at your option) any later version.
1285+#
1286+# This program is distributed in the hope that it will be useful,
1287+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1288+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1289+# GNU General Public License for more details.
1290+#
1291+# You should have received a copy of the GNU General Public License
1292+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1293+#
1294+##############################################################################
1295+
1296+from openerp.osv import fields, orm
1297+
1298+
1299+class FillInventoryWizard(orm.TransientModel):
1300+ """Add a field that lets the client make the location read-only"""
1301+ _inherit = 'stock.fill.inventory'
1302+
1303+ _columns = {
1304+ 'exhaustive': fields.boolean('Exhaustive', readonly=True)
1305+ }
1306+
1307+ def default_get(self, cr, uid, fields, context=None):
1308+ """Get 'location_id' and 'exhaustive' from the inventory"""
1309+ if context is None:
1310+ context = {}
1311+ inv_id = context.get('active_id')
1312+
1313+ res = super(FillInventoryWizard, self).default_get(
1314+ cr, uid, fields, context=context)
1315+ if (context.get('active_model') == 'stock.inventory'
1316+ and inv_id
1317+ and 'location_id' in fields):
1318+ inventory = self.pool['stock.inventory'].browse(
1319+ cr, uid, context['active_id'], context=context)
1320+ res.update({'location_id': inventory.location_id.id,
1321+ 'exhaustive': inventory.exhaustive})
1322+ return res
1323
1324=== added file 'stock_inventory_location/wizard/stock_fill_location_inventory_view.xml'
1325--- stock_inventory_location/wizard/stock_fill_location_inventory_view.xml 1970-01-01 00:00:00 +0000
1326+++ stock_inventory_location/wizard/stock_fill_location_inventory_view.xml 2014-06-12 16:47:03 +0000
1327@@ -0,0 +1,18 @@
1328+<?xml version="1.0" encoding="utf-8"?>
1329+<openerp>
1330+ <data>
1331+ <record id="view_stock_fill_inventory_location" model="ir.ui.view">
1332+ <field name="name">Import Inventory</field>
1333+ <field name="model">stock.fill.inventory</field>
1334+ <field name="inherit_id" ref="stock.view_stock_fill_inventory" />
1335+ <field name="arch" type="xml">
1336+ <xpath expr="//field[@name='location_id']" position="after">
1337+ <field name="exhaustive" invisible="1" />
1338+ </xpath>
1339+ <xpath expr="//field[@name='location_id']" position="attributes">
1340+ <attribute name="attrs">{'readonly':[('exhaustive','=',True)]}</attribute>
1341+ </xpath>
1342+ </field>
1343+ </record>
1344+ </data>
1345+</openerp>