~acsone-openerp/stock-logistic-warehouse/7.0-inventory-hierarchical-location-generate-inventory-lga

« back to all changes in this revision

Viewing changes to stock_inventory_hierarchical_location/wizard/generate_inventory.py

  • Committer: Laetitia Gangloff
  • Date: 2014-06-20 13:46:03 UTC
  • Revision ID: laetitia.gangloff@acsone.eu-20140620134603-glr9oss93ezz58g4
generate_inventory : rename include internal in only view and adapt code following the change

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"),
48
48
    }
49
49
 
50
50
    def _default_location(self, cr, uid, ids, context=None):
64
64
 
65
65
    _defaults = {
66
66
        'location_id': _default_location,
67
 
        'level': 1
 
67
        'level': 1,
 
68
        'only_view': True,
68
69
    }
69
70
 
70
71
    _sql_constraints = [
71
72
        ('level', 'CHECK (level>0)', 'Level must be positive!'),
72
73
    ]
73
74
 
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'))
 
80
            if only_view:
 
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)
115
116
 
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)
119
120
 
120
121
        mod_obj = self.pool['ir.model.data']
121
122
        result = mod_obj.get_object_reference(cr, uid, 'stock', 'view_inventory_form')