1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
6
# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>
21
##############################################################################
23
from osv import fields, osv
25
class stock_multi_location(osv.osv):
27
def _calc_imm_use_stock(self, cr, uid, ids, name, args, context=None):
31
for multi_location in self.pool.get('stock.multi.location').browse(cr, uid, ids, context=context):
32
context['location'] = multi_location.location_name.id
33
field_names = ['qty_available', 'virtual_available', 'outgoing_qty']
34
stock_data = multi_location.product_id._product_available(field_names, context=context)
35
if multi_location.product_id.id in stock_data:
36
result = stock_data[multi_location.product_id.id]['qty_available'] - abs(stock_data[multi_location.product_id.id]['outgoing_qty'])
37
res[multi_location.id] = result
40
def _calc_bom_stock_value(self, cr, uid, ids, name, args, context=None):
43
def _calc_stock(self, cr, uid, ids, name, args, context=None):
47
for multi_location in self.pool.get('stock.multi.location').browse(cr, uid, ids, context=context):
48
context['location'] = multi_location.location_name.id
49
stock_data = multi_location.product_id._product_available(field_names=['qty_available', 'virtual_available'], context=context)
50
if multi_location.product_id.id in stock_data:
51
res[multi_location.id] = stock_data[multi_location.product_id.id]
54
def onchange_packge_no(self, cr, uid, ids, line_ids, evaluation_order, context=None):
57
ret['evaluation_order'] = evaluation_order
60
if evaluation_order < line[2]['evaluation_order']:
61
evaluation_order = line[2]['evaluation_order']
63
ret['evaluation_order'] = evaluation_order
66
def _find_multi_loc(self, cr, uid, ids, context=None):
69
multi_loc_obj = self.pool.get('stock.multi.location')
70
for move in self.pool.get('stock.move').browse(cr, uid, ids, context=context):
71
result_locations[move.location_id.id] = True
72
result_locations[move.location_dest_id.id] = True
73
result_products[move.product_id.id] = True
74
locations = result_locations.keys()
75
products = result_products.keys()
76
return multi_loc_obj.search(cr, uid, [('location_name', 'in', locations),('product_id', 'in', products) ], context=context)
78
def get_storage_type(self, cr, uid, context=None):
79
for line in context.get('muli_location', []):
80
if line[2]['storage_type'] == 'primary':
84
def _get_shop_id(self, cr, uid, ids, context=None):
85
company_id = self.pool.get('res.users')._get_company(cr, uid, context=context)
86
shop = self.pool.get('sale.shop').search(cr, uid, [('company_id', '=', company_id)])
88
shop_obj = self.pool.get('sale.shop').browse(cr, uid, shop[0], context=context)
89
return shop_obj.warehouse_id and shop_obj.warehouse_id.id
92
_name = "stock.multi.location"
93
_rec_name='location_name'
94
_order = 'evaluation_order'
96
'evaluation_order': fields.integer('Eval Order', size=10, help='The order in which individual locations are evaluated for picking purposes.'),
97
'storage_type': fields.selection([
98
('primary','Primary'),
99
('secondary','Secondary'),
100
('overstock','Overstock')
101
], 'Storage Type', help='Storage type of the location. Options are: Primary, Secondary, Overstock ', select=1),
102
'warehouse': fields.many2one('stock.warehouse', 'Warehouse', help='This is the name of the warehouse. '),
103
'location_name': fields.many2one('stock.location', 'Location Name', required=True, help='This is the location where the product is located.',
105
'location_type': fields.related('location_name', 'usage', type='char', size=16, string='Location type', store=True,
106
help="This is the type associated with the Location Name.", readonly=True),
107
'qty_available': fields.function(_calc_stock, multi="stock", method=True,
109
'stock.multi.location': (lambda self, cr, uid, ids, c={}: ids, ['product_id', 'location_name'], 10),
110
'stock.move': (_find_multi_loc, ['product_id', 'location_id', 'location_dest_id', 'product_qty', 'state'], 10),
112
type='float', string='Real Stock', help='This is the real stock for each specific location.'),
113
'virtual_available': fields.function(_calc_stock, multi="stock", method=True,
115
'stock.multi.location': (lambda self, cr, uid, ids, c={}: ids, ['product_id', 'location_name'], 10),
116
'stock.move': (_find_multi_loc, ['product_id', 'location_id', 'location_dest_id', 'product_qty', 'state'], 10),
117
},type='float', string='Virtual Stock', help='This is the virtual Stock for each specific location.'),
118
'immediately_usable_stock': fields.function(_calc_imm_use_stock, method=True, type='float', string='Immediately Usable Stock',
119
help='This is the immediately usable stock by location.'),
120
'bom_stock_value': fields.function(_calc_bom_stock_value, method=True,type='float', string='BoM Stock Value',
121
help='This is the calculated BoM Stock available by location '),
122
'product_uom': fields.many2one('product.uom', 'Product UoM', help='This is the Products UoM taken from the Product record.'),
123
'min_level': fields.integer('Min Level', size=64,help='This shows the minimum level of inventory held in this location.' ),
124
'target_level': fields.integer('Target Level', size=64, help='This is the target Maximum level of Inventory held in this location.'),
125
'qty_multiple': fields.integer('Qty Multiple', size=64, help='This is the minimum qty to replenish the inventory with.'),
126
'location_active': fields.boolean('Active', help='This indicates whether the replenish rules are active for this product’s location.'),
127
'product_id': fields.many2one('product.product', 'Product', required=True, select=1)
130
'location_active': True,
131
'storage_type': get_storage_type,
132
'warehouse': _get_shop_id
135
stock_multi_location()
137
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'