Merge lp:~acsone-openerp/stock-logistic-warehouse/7.0-inventory-hierarchical-location-generate-inventory-lga into lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-hierarchical

Proposed by Laetitia Gangloff (Acsone)
Status: Merged
Merged at revision: 44
Proposed branch: lp:~acsone-openerp/stock-logistic-warehouse/7.0-inventory-hierarchical-location-generate-inventory-lga
Merge into: lp:~numerigraphe-team/stock-logistic-warehouse/7.0-inventory-hierarchical
Diff against target: 206 lines (+178/-0)
4 files modified
stock_inventory_hierarchical_location/__openerp__.py (+1/-0)
stock_inventory_hierarchical_location/wizard/__init__.py (+1/-0)
stock_inventory_hierarchical_location/wizard/generate_inventory.py (+134/-0)
stock_inventory_hierarchical_location/wizard/generate_inventory_view.xml (+42/-0)
To merge this branch: bzr merge lp:~acsone-openerp/stock-logistic-warehouse/7.0-inventory-hierarchical-location-generate-inventory-lga
Reviewer Review Type Date Requested Status
Loïc Bellier - Numérigraphe testing, code review Approve
Review via email: mp+223712@code.launchpad.net

Description of the change

Hello,

I add a wizard to easily create inventory and sub-inventory.

To post a comment you must log in.
43. By Laetitia Gangloff (Acsone)

generate_inventory: prefix to the created inventories / include internal location

Revision history for this message
Laetitia Gangloff (Acsone) (laetitia-gangloff) wrote :

Following Loïc idea:
- I add the possibility to choose a prefix for the inventory name. This prefix will concatenate with the location name.
- I add the possibility to include internal location.

44. By Laetitia Gangloff (Acsone)

generate_inventory : rename include internal in only view and adapt code following the change

Revision history for this message
Laetitia Gangloff (Acsone) (laetitia-gangloff) wrote :

Following some comments of Loïc:
- I change the possibility to include internal location by the possibility to use only view !

Sorry, for the mistake and thank you to Loïc for his help.

Revision history for this message
Loïc Bellier - Numérigraphe (lb-b) wrote :

Work perfectly ! Thanks.

review: Approve (testing, code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'stock_inventory_hierarchical_location/__openerp__.py'
2--- stock_inventory_hierarchical_location/__openerp__.py 2014-06-12 18:19:17 +0000
3+++ stock_inventory_hierarchical_location/__openerp__.py 2014-06-20 13:46:20 +0000
4@@ -42,6 +42,7 @@
5 """,
6 "data": [
7 "inventory_hierarchical_location_view.xml",
8+ "wizard/generate_inventory_view.xml",
9 ],
10 "test": ["tests/inventory_hierarchical_location_test.yml"],
11 "demo": ["inventory_hierarchical_location_demo.xml"],
12
13=== modified file 'stock_inventory_hierarchical_location/wizard/__init__.py'
14--- stock_inventory_hierarchical_location/wizard/__init__.py 2014-06-12 18:19:17 +0000
15+++ stock_inventory_hierarchical_location/wizard/__init__.py 2014-06-20 13:46:20 +0000
16@@ -19,3 +19,4 @@
17 ##############################################################################
18
19 from . import stock_fill_location_inventory
20+from . import generate_inventory
21
22=== added file 'stock_inventory_hierarchical_location/wizard/generate_inventory.py'
23--- stock_inventory_hierarchical_location/wizard/generate_inventory.py 1970-01-01 00:00:00 +0000
24+++ stock_inventory_hierarchical_location/wizard/generate_inventory.py 2014-06-20 13:46:20 +0000
25@@ -0,0 +1,134 @@
26+# -*- coding: utf-8 -*-
27+#
28+#
29+# Authors: Laetitia Gangloff
30+# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
31+# All Rights Reserved
32+#
33+# WARNING: This program as such is intended to be used by professional
34+# programmers who take the whole responsibility of assessing all potential
35+# consequences resulting from its eventual inadequacies and bugs.
36+# End users who are looking for a ready-to-use solution with commercial
37+# guarantees and support are strongly advised to contact a Free Software
38+# Service Company.
39+#
40+# This program is free software: you can redistribute it and/or modify
41+# it under the terms of the GNU Affero General Public License as
42+# published by the Free Software Foundation, either version 3 of the
43+# License, or (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 Affero General Public License for more details.
49+#
50+# You should have received a copy of the GNU Affero General Public License
51+# along with this program. If not, see <http://www.gnu.org/licenses/>.
52+#
53+#
54+
55+from openerp.osv import fields, orm
56+from openerp.tools.translate import _
57+
58+
59+class GenerateInventoryWizard(orm.TransientModel):
60+ """ This wizard generate an inventory and all related sub-inventories for the specified location and level
61+ Example: location = Stock / level = 1 => 1 inventory on Stock (similar to create)
62+ location = Stock / level = 2 => 1 inventory on Stock, 1 sub-inventory on Shelf1, 1 sub-inventory on Shelf2
63+ """
64+
65+ _name = "stock.generate.inventory"
66+ _description = "Generate Inventory"
67+
68+ _columns = {
69+ 'prefix_inv_name': fields.char('Inventory prefix', help="Optional prefix for all created inventory"),
70+ 'location_id': fields.many2one('stock.location', 'Location', required=True),
71+ 'level': fields.integer("Level", help="number of level between inventory on location_id and sub-inventory"),
72+ 'only_view': fields.boolean('Only view', help="If set, only inventory on view location can be created"),
73+ }
74+
75+ def _default_location(self, cr, uid, ids, context=None):
76+ """Default stock location
77+
78+ @return: id of the stock location of the first warehouse of the
79+ default company"""
80+ location_id = False
81+ company_id = self.pool['res.company']._company_default_get(
82+ cr, uid, 'stock.warehouse', context=context)
83+ warehouse_id = self.pool['stock.warehouse'].search(
84+ cr, uid, [('company_id', '=', company_id)], limit=1)
85+ if warehouse_id:
86+ location_id = self.pool['stock.warehouse'].read(
87+ cr, uid, warehouse_id[0], ['lot_stock_id'])['lot_stock_id'][0]
88+ return location_id
89+
90+ _defaults = {
91+ 'location_id': _default_location,
92+ 'level': 1,
93+ 'only_view': True,
94+ }
95+
96+ _sql_constraints = [
97+ ('level', 'CHECK (level>0)', 'Level must be positive!'),
98+ ]
99+
100+ def _create_subinventory(self, cr, uid, inventory_ids, prefix_inv_name, only_view, context):
101+ new_inventory_ids = []
102+ for inventory_id in inventory_ids:
103+ location_id = self.pool['stock.inventory'].read(cr, uid, inventory_id, ['location_id'], context=context)['location_id'][0]
104+ domain = [('location_id', '=', location_id)]
105+ if only_view:
106+ domain.append(('usage', '=', 'view'))
107+ location_ids = self.pool['stock.location'].search(cr, uid, domain, context=context)
108+ for location_id in location_ids:
109+ location_name = self.pool['stock.location'].read(cr, uid, location_id, ['name'], context=context)['name']
110+ new_inventory_ids.append(self.pool['stock.inventory'].create(cr, uid, {'name': prefix_inv_name + location_name,
111+ 'exhaustive': True,
112+ 'location_id': location_id,
113+ 'parent_id': inventory_id}, context=context))
114+ return new_inventory_ids
115+
116+ def generate_inventory(self, cr, uid, ids, context=None):
117+ """ Generate inventory and sub-inventories for specified location and level
118+
119+ @param self: The object pointer.
120+ @param cr: A database cursor
121+ @param uid: ID of the user currently logged in
122+ @param ids: the ID or list of IDs if we want more than one
123+ @param context: A standard dictionary
124+ @return:
125+ """
126+ if context is None:
127+ context = {}
128+
129+ if ids and len(ids):
130+ ids = ids[0]
131+ else:
132+ return {'type': 'ir.actions.act_window_close'}
133+ generate_inventory = self.browse(cr, uid, ids, context=context)
134+ # create first level inventory
135+ prefix_inv_name = generate_inventory.prefix_inv_name or ''
136+ location_id = generate_inventory.location_id.id
137+ only_view = generate_inventory.only_view
138+ parent_inventory_id = self.pool['stock.inventory'].create(cr, uid, {'name': prefix_inv_name + generate_inventory.location_id.name,
139+ 'exhaustive': True,
140+ 'location_id': location_id}, context=context)
141+
142+ inventory_ids = [parent_inventory_id]
143+ for i in range(1, generate_inventory.level):
144+ inventory_ids = self._create_subinventory(cr, uid, inventory_ids, prefix_inv_name, only_view, context)
145+
146+ mod_obj = self.pool['ir.model.data']
147+ result = mod_obj.get_object_reference(cr, uid, 'stock', 'view_inventory_form')
148+ view_id = result and result[1] or False
149+ return {'name': _('Inventory generated'),
150+ 'view_mode': 'form',
151+ 'view_type': 'form',
152+ 'res_model': 'stock.inventory',
153+ 'type': 'ir.actions.act_window',
154+ 'view_id': view_id,
155+ 'res_id': int(parent_inventory_id),
156+ }
157+
158+
159+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
160
161=== added file 'stock_inventory_hierarchical_location/wizard/generate_inventory_view.xml'
162--- stock_inventory_hierarchical_location/wizard/generate_inventory_view.xml 1970-01-01 00:00:00 +0000
163+++ stock_inventory_hierarchical_location/wizard/generate_inventory_view.xml 2014-06-20 13:46:20 +0000
164@@ -0,0 +1,42 @@
165+<?xml version="1.0" encoding="utf-8"?>
166+<openerp>
167+ <data>
168+ <record id="view_stock_generate_inventory" model="ir.ui.view">
169+ <field name="name">Generate Inventory</field>
170+ <field name="model">stock.generate.inventory</field>
171+ <field name="arch" type="xml">
172+ <form string="Generate Inventory" version="7.0">
173+ <separator string="Generate inventory"/>
174+ <group>
175+ <field name="prefix_inv_name"/>
176+ <field name="location_id"/>
177+ <field name="only_view"/>
178+ <field name="level"/>
179+ </group>
180+ <footer>
181+ <button name="generate_inventory" string="Generate Inventory" type="object" class="oe_highlight"/>
182+ or
183+ <button string="Cancel" class="oe_link" special="cancel" />
184+ </footer>
185+ </form>
186+ </field>
187+ </record>
188+
189+ <record id="action_view_stock_generate_inventory" model="ir.actions.act_window">
190+ <field name="name">Generate Inventory</field>
191+ <field name="type">ir.actions.act_window</field>
192+ <field name="res_model">stock.generate.inventory</field>
193+ <field name="view_type">form</field>
194+ <field name="view_mode">form</field>
195+ <field name="view_id" ref="view_stock_generate_inventory"/>
196+ <field name="target">new</field>
197+ </record>
198+
199+ <menuitem action="action_view_stock_generate_inventory"
200+ id="menu_action_stock_generate_inventory_form"
201+ parent="stock.menu_stock_inventory_control"
202+ sequence="20"
203+ groups="stock.group_locations"/>
204+
205+ </data>
206+</openerp>

Subscribers

People subscribed via source and target branches