~serpent-consulting-services/openerp-usa/fix-shipping_api_ups_cc

« back to all changes in this revision

Viewing changes to stock_multilocation_picking/stock_multi_location.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
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>)
7
 
#
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.
12
 
#
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.
17
 
#
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/>
20
 
#
21
 
##############################################################################
22
 
 
23
 
from osv import fields, osv
24
 
 
25
 
class stock_multi_location(osv.osv):
26
 
 
27
 
    def _calc_imm_use_stock(self, cr, uid, ids, name, args, context=None):
28
 
        res = {}
29
 
        if context is None:
30
 
            context = {}
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
38
 
        return res
39
 
  
40
 
    def _calc_bom_stock_value(self, cr, uid, ids, name, args, context=None):
41
 
        return 0.0
42
 
 
43
 
    def _calc_stock(self, cr, uid, ids, name, args, context=None):
44
 
        res = {}
45
 
        if context is None:
46
 
            context = {}
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]
52
 
        return res
53
 
 
54
 
    def onchange_packge_no(self, cr, uid, ids, line_ids, evaluation_order, context=None):
55
 
        ret = {}
56
 
        if evaluation_order:
57
 
            ret['evaluation_order'] = evaluation_order
58
 
        else:
59
 
            for line in line_ids:
60
 
                if evaluation_order < line[2]['evaluation_order']:
61
 
                     evaluation_order = line[2]['evaluation_order']
62
 
            evaluation_order += 1
63
 
            ret['evaluation_order'] = evaluation_order
64
 
        return {'value': ret}
65
 
 
66
 
    def _find_multi_loc(self, cr, uid, ids, context=None):
67
 
        result_locations = {}
68
 
        result_products = {}
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)
77
 
 
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':
81
 
                return 'secondary'
82
 
        return 'primary'
83
 
 
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)])
87
 
        if shop:
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
90
 
        return False
91
 
 
92
 
    _name = "stock.multi.location"
93
 
    _rec_name='location_name'
94
 
    _order = 'evaluation_order'
95
 
    _columns = {
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.', 
104
 
                                         select=1),
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,
108
 
            store = {
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),
111
 
                },
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,
114
 
            store = {
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)
128
 
        }
129
 
    _defaults = {
130
 
        'location_active': True,
131
 
        'storage_type': get_storage_type,
132
 
        'warehouse': _get_shop_id
133
 
        }
134
 
 
135
 
stock_multi_location()
136
 
 
137
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'