44
44
'prefix_inv_name': fields.char('Inventory prefix', help="Optional prefix for all created inventory"),
45
45
'location_id': fields.many2one('stock.location', 'Location', required=True),
46
46
'level': fields.integer("Level", help="number of level between inventory on location_id and sub-inventory"),
47
'include_internal': fields.boolean('Include internal', help="If set, inventory on internal location can be created")
47
'only_view': fields.boolean('Only view', help="If set, only inventory on view location can be created"),
50
50
def _default_location(self, cr, uid, ids, context=None):
66
66
'location_id': _default_location,
70
71
_sql_constraints = [
71
72
('level', 'CHECK (level>0)', 'Level must be positive!'),
74
def _create_subinventory(self, cr, uid, inventory_ids, prefix_inv_name, include_internal, context):
75
def _create_subinventory(self, cr, uid, inventory_ids, prefix_inv_name, only_view, context):
75
76
new_inventory_ids = []
76
77
for inventory_id in inventory_ids:
77
78
location_id = self.pool['stock.inventory'].read(cr, uid, inventory_id, ['location_id'], context=context)['location_id'][0]
78
79
domain = [('location_id', '=', location_id)]
79
if not include_internal:
80
domain.append(('usage', '!=', 'internal'))
81
domain.append(('usage', '=', 'view'))
81
82
location_ids = self.pool['stock.location'].search(cr, uid, domain, context=context)
82
83
for location_id in location_ids:
83
84
location_name = self.pool['stock.location'].read(cr, uid, location_id, ['name'], context=context)['name']
108
109
# create first level inventory
109
110
prefix_inv_name = generate_inventory.prefix_inv_name or ''
110
111
location_id = generate_inventory.location_id.id
111
include_internal = generate_inventory.include_internal
112
only_view = generate_inventory.only_view
112
113
parent_inventory_id = self.pool['stock.inventory'].create(cr, uid, {'name': prefix_inv_name + generate_inventory.location_id.name,
113
114
'exhaustive': True,
114
115
'location_id': location_id}, context=context)
116
117
inventory_ids = [parent_inventory_id]
117
118
for i in range(1, generate_inventory.level):
118
inventory_ids = self._create_subinventory(cr, uid, inventory_ids, prefix_inv_name, include_internal, context)
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']
121
122
result = mod_obj.get_object_reference(cr, uid, 'stock', 'view_inventory_form')