~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to procurement_cycle/procurement.py

UF-73: [MERGE] Merge with unifield-wm branch

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 TeMPO Consulting, MSF 
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import osv, fields
 
23
 
 
24
import time
 
25
from tools.translate import _
 
26
 
 
27
class stock_frequence(osv.osv):
 
28
    _name = 'stock.frequence'
 
29
    _inherit = 'stock.frequence'
 
30
    
 
31
    def choose_frequency(self, cr, uid, ids, context={}):
 
32
        '''
 
33
        Adds the support of order cycles on choose frequency method
 
34
        '''
 
35
        if isinstance(ids, (int, long)):
 
36
            ids = [ids]
 
37
            
 
38
        if not context.get('res_ok', False) and 'active_id' in context and 'active_model' in context and \
 
39
            context.get('active_model') == 'stock.warehouse.order.cycle':
 
40
            self.pool.get('stock.warehouse.order.cycle').write(cr, uid, [context.get('active_id')], {'frequence_id': ids[0]})
 
41
            
 
42
        return super(stock_frequence, self).choose_frequency(cr, uid, ids, context=context)
 
43
    
 
44
stock_frequence()
 
45
 
 
46
class stock_warehouse_order_cycle(osv.osv):
 
47
    _name = 'stock.warehouse.order.cycle'
 
48
    _description = 'Order Cycle'
 
49
    
 
50
    _columns = {
 
51
        'name': fields.char(size=64, string='Name', required=True),
 
52
        'category_id': fields.many2one('product.category', string='Category'),
 
53
        'product_id': fields.many2one('product.product', string='Specific product'),
 
54
        'warehouse_id': fields.many2one('stock.warehouse', string='Warehouse', required=True),
 
55
        'location_id': fields.many2one('stock.location', string='Location'),
 
56
        'frequence_id': fields.many2one('stock.frequence', string='Frequence'),
 
57
        'next_date': fields.related('frequence_id', 'next_date', string='Next scheduled date', readonly=True, type='date'),
 
58
        'product_ids': fields.many2many('product.product', 'order_cycle_product_rel', 'order_cycle_id', 'product_id', string="Products"),
 
59
        'company_id': fields.many2one('res.company','Company',required=True),
 
60
        'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the automatic supply without removing it."),
 
61
        # Parameters for quantity calculation
 
62
        'leadtime': fields.integer(string='Delivery lead time to consider'),
 
63
        'order_coverage': fields.integer(string='Order coverage'),
 
64
        'safety_stock_time': fields.integer(string='Safety stock in time'),
 
65
        'safety_stock': fields.integer(string='Safety stock (quantity'),
 
66
        'past_consumption': fields.boolean(string='Past monthly consumtion'),
 
67
        'reviewed_consumption': fields.boolean(string='Reviewed monthly consumtion'),
 
68
        'manual_consumption': fields.boolean(string='Manual monthly consumtion'),
 
69
    }
 
70
    
 
71
    _defaults = {
 
72
        'past_consumption': lambda *a: 1,
 
73
        'active': lambda *a: 1,
 
74
        'name': lambda x,y,z,c: x.pool.get('ir.sequence').get(y,z,'stock.order.cycle') or '',
 
75
        'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.order.cycle', context=c)
 
76
    }
 
77
    
 
78
    def choose_change_frequence(self, cr, uid, ids, context={}):
 
79
        '''
 
80
        Open a wizard to define a frequency for the order cycle
 
81
        or open a wizard to modify the frequency if frequency already exists
 
82
        '''
 
83
        if isinstance(ids, (int, long)):
 
84
            ids = [ids]
 
85
            
 
86
        frequence_id = False
 
87
        res_id = False
 
88
        res_ok = False
 
89
            
 
90
        for proc in self.browse(cr, uid, ids):
 
91
            res_id = proc.id
 
92
            if proc.frequence_id and proc.frequence_id.id:
 
93
                frequence_id = proc.frequence_id.id
 
94
                res_ok = True
 
95
            
 
96
        context.update({'active_id': res_id, 
 
97
                        'active_model': 'stock.warehouse.order.cycle',
 
98
                        'res_ok': res_ok})
 
99
            
 
100
        return {'type': 'ir.actions.act_window',
 
101
                'target': 'new',
 
102
                'res_model': 'stock.frequence',
 
103
                'view_type': 'form',
 
104
                'view_model': 'form',
 
105
                'context': context,
 
106
                'res_id': frequence_id}
 
107
    
 
108
    def onchange_warehouse_id(self, cr, uid, ids, warehouse_id, context=None):
 
109
        """ Finds location id for changed warehouse.
 
110
        @param warehouse_id: Changed id of warehouse.
 
111
        @return: Dictionary of values.
 
112
        """
 
113
        if warehouse_id:
 
114
            w = self.pool.get('stock.warehouse').browse(cr, uid, warehouse_id, context=context)
 
115
            v = {'location_id': w.lot_stock_id.id}
 
116
            return {'value': v}
 
117
        return {}
 
118
    
 
119
    def copy(self, cr, uid, id, default=None, context=None):
 
120
        if not default:
 
121
            default = {}
 
122
        default.update({
 
123
            'name': self.pool.get('ir.sequence').get(cr, uid, 'stock.order.cycle') or '',
 
124
        })
 
125
        return super(stock_warehouse_order_cycle, self).copy(cr, uid, id, default, context=context)
 
126
    
 
127
stock_warehouse_order_cycle()
 
128
 
 
129
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'