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
=== modified file 'stock_inventory_hierarchical_location/__openerp__.py'
--- stock_inventory_hierarchical_location/__openerp__.py 2014-06-12 18:19:17 +0000
+++ stock_inventory_hierarchical_location/__openerp__.py 2014-06-20 13:46:20 +0000
@@ -42,6 +42,7 @@
42 """,42 """,
43 "data": [43 "data": [
44 "inventory_hierarchical_location_view.xml",44 "inventory_hierarchical_location_view.xml",
45 "wizard/generate_inventory_view.xml",
45 ],46 ],
46 "test": ["tests/inventory_hierarchical_location_test.yml"],47 "test": ["tests/inventory_hierarchical_location_test.yml"],
47 "demo": ["inventory_hierarchical_location_demo.xml"],48 "demo": ["inventory_hierarchical_location_demo.xml"],
4849
=== modified file 'stock_inventory_hierarchical_location/wizard/__init__.py'
--- stock_inventory_hierarchical_location/wizard/__init__.py 2014-06-12 18:19:17 +0000
+++ stock_inventory_hierarchical_location/wizard/__init__.py 2014-06-20 13:46:20 +0000
@@ -19,3 +19,4 @@
19##############################################################################19##############################################################################
2020
21from . import stock_fill_location_inventory21from . import stock_fill_location_inventory
22from . import generate_inventory
2223
=== added file 'stock_inventory_hierarchical_location/wizard/generate_inventory.py'
--- stock_inventory_hierarchical_location/wizard/generate_inventory.py 1970-01-01 00:00:00 +0000
+++ stock_inventory_hierarchical_location/wizard/generate_inventory.py 2014-06-20 13:46:20 +0000
@@ -0,0 +1,134 @@
1# -*- coding: utf-8 -*-
2#
3#
4# Authors: Laetitia Gangloff
5# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
6# All Rights Reserved
7#
8# WARNING: This program as such is intended to be used by professional
9# programmers who take the whole responsibility of assessing all potential
10# consequences resulting from its eventual inadequacies and bugs.
11# End users who are looking for a ready-to-use solution with commercial
12# guarantees and support are strongly advised to contact a Free Software
13# Service Company.
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU Affero General Public License as
17# published by the Free Software Foundation, either version 3 of the
18# License, or (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU Affero General Public License for more details.
24#
25# You should have received a copy of the GNU Affero General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
27#
28#
29
30from openerp.osv import fields, orm
31from openerp.tools.translate import _
32
33
34class GenerateInventoryWizard(orm.TransientModel):
35 """ This wizard generate an inventory and all related sub-inventories for the specified location and level
36 Example: location = Stock / level = 1 => 1 inventory on Stock (similar to create)
37 location = Stock / level = 2 => 1 inventory on Stock, 1 sub-inventory on Shelf1, 1 sub-inventory on Shelf2
38 """
39
40 _name = "stock.generate.inventory"
41 _description = "Generate Inventory"
42
43 _columns = {
44 'prefix_inv_name': fields.char('Inventory prefix', help="Optional prefix for all created inventory"),
45 'location_id': fields.many2one('stock.location', 'Location', required=True),
46 'level': fields.integer("Level", help="number of level between inventory on location_id and sub-inventory"),
47 'only_view': fields.boolean('Only view', help="If set, only inventory on view location can be created"),
48 }
49
50 def _default_location(self, cr, uid, ids, context=None):
51 """Default stock location
52
53 @return: id of the stock location of the first warehouse of the
54 default company"""
55 location_id = False
56 company_id = self.pool['res.company']._company_default_get(
57 cr, uid, 'stock.warehouse', context=context)
58 warehouse_id = self.pool['stock.warehouse'].search(
59 cr, uid, [('company_id', '=', company_id)], limit=1)
60 if warehouse_id:
61 location_id = self.pool['stock.warehouse'].read(
62 cr, uid, warehouse_id[0], ['lot_stock_id'])['lot_stock_id'][0]
63 return location_id
64
65 _defaults = {
66 'location_id': _default_location,
67 'level': 1,
68 'only_view': True,
69 }
70
71 _sql_constraints = [
72 ('level', 'CHECK (level>0)', 'Level must be positive!'),
73 ]
74
75 def _create_subinventory(self, cr, uid, inventory_ids, prefix_inv_name, only_view, context):
76 new_inventory_ids = []
77 for inventory_id in inventory_ids:
78 location_id = self.pool['stock.inventory'].read(cr, uid, inventory_id, ['location_id'], context=context)['location_id'][0]
79 domain = [('location_id', '=', location_id)]
80 if only_view:
81 domain.append(('usage', '=', 'view'))
82 location_ids = self.pool['stock.location'].search(cr, uid, domain, context=context)
83 for location_id in location_ids:
84 location_name = self.pool['stock.location'].read(cr, uid, location_id, ['name'], context=context)['name']
85 new_inventory_ids.append(self.pool['stock.inventory'].create(cr, uid, {'name': prefix_inv_name + location_name,
86 'exhaustive': True,
87 'location_id': location_id,
88 'parent_id': inventory_id}, context=context))
89 return new_inventory_ids
90
91 def generate_inventory(self, cr, uid, ids, context=None):
92 """ Generate inventory and sub-inventories for specified location and level
93
94 @param self: The object pointer.
95 @param cr: A database cursor
96 @param uid: ID of the user currently logged in
97 @param ids: the ID or list of IDs if we want more than one
98 @param context: A standard dictionary
99 @return:
100 """
101 if context is None:
102 context = {}
103
104 if ids and len(ids):
105 ids = ids[0]
106 else:
107 return {'type': 'ir.actions.act_window_close'}
108 generate_inventory = self.browse(cr, uid, ids, context=context)
109 # create first level inventory
110 prefix_inv_name = generate_inventory.prefix_inv_name or ''
111 location_id = generate_inventory.location_id.id
112 only_view = generate_inventory.only_view
113 parent_inventory_id = self.pool['stock.inventory'].create(cr, uid, {'name': prefix_inv_name + generate_inventory.location_id.name,
114 'exhaustive': True,
115 'location_id': location_id}, context=context)
116
117 inventory_ids = [parent_inventory_id]
118 for i in range(1, generate_inventory.level):
119 inventory_ids = self._create_subinventory(cr, uid, inventory_ids, prefix_inv_name, only_view, context)
120
121 mod_obj = self.pool['ir.model.data']
122 result = mod_obj.get_object_reference(cr, uid, 'stock', 'view_inventory_form')
123 view_id = result and result[1] or False
124 return {'name': _('Inventory generated'),
125 'view_mode': 'form',
126 'view_type': 'form',
127 'res_model': 'stock.inventory',
128 'type': 'ir.actions.act_window',
129 'view_id': view_id,
130 'res_id': int(parent_inventory_id),
131 }
132
133
134# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
0135
=== added file 'stock_inventory_hierarchical_location/wizard/generate_inventory_view.xml'
--- stock_inventory_hierarchical_location/wizard/generate_inventory_view.xml 1970-01-01 00:00:00 +0000
+++ stock_inventory_hierarchical_location/wizard/generate_inventory_view.xml 2014-06-20 13:46:20 +0000
@@ -0,0 +1,42 @@
1<?xml version="1.0" encoding="utf-8"?>
2<openerp>
3 <data>
4 <record id="view_stock_generate_inventory" model="ir.ui.view">
5 <field name="name">Generate Inventory</field>
6 <field name="model">stock.generate.inventory</field>
7 <field name="arch" type="xml">
8 <form string="Generate Inventory" version="7.0">
9 <separator string="Generate inventory"/>
10 <group>
11 <field name="prefix_inv_name"/>
12 <field name="location_id"/>
13 <field name="only_view"/>
14 <field name="level"/>
15 </group>
16 <footer>
17 <button name="generate_inventory" string="Generate Inventory" type="object" class="oe_highlight"/>
18 or
19 <button string="Cancel" class="oe_link" special="cancel" />
20 </footer>
21 </form>
22 </field>
23 </record>
24
25 <record id="action_view_stock_generate_inventory" model="ir.actions.act_window">
26 <field name="name">Generate Inventory</field>
27 <field name="type">ir.actions.act_window</field>
28 <field name="res_model">stock.generate.inventory</field>
29 <field name="view_type">form</field>
30 <field name="view_mode">form</field>
31 <field name="view_id" ref="view_stock_generate_inventory"/>
32 <field name="target">new</field>
33 </record>
34
35 <menuitem action="action_view_stock_generate_inventory"
36 id="menu_action_stock_generate_inventory_form"
37 parent="stock.menu_stock_inventory_control"
38 sequence="20"
39 groups="stock.group_locations"/>
40
41 </data>
42</openerp>

Subscribers

People subscribed via source and target branches