1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO Consulting, MSF
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.
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.
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/>.
20
##############################################################################
22
from osv import osv, fields
25
from tools.translate import _
27
class stock_frequence(osv.osv):
28
_name = 'stock.frequence'
29
_inherit = 'stock.frequence'
31
def choose_frequency(self, cr, uid, ids, context={}):
33
Adds the support of order cycles on choose frequency method
35
if isinstance(ids, (int, long)):
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]})
42
return super(stock_frequence, self).choose_frequency(cr, uid, ids, context=context)
46
class stock_warehouse_order_cycle(osv.osv):
47
_name = 'stock.warehouse.order.cycle'
48
_description = 'Order Cycle'
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'),
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)
78
def choose_change_frequence(self, cr, uid, ids, context={}):
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
83
if isinstance(ids, (int, long)):
90
for proc in self.browse(cr, uid, ids):
92
if proc.frequence_id and proc.frequence_id.id:
93
frequence_id = proc.frequence_id.id
96
context.update({'active_id': res_id,
97
'active_model': 'stock.warehouse.order.cycle',
100
return {'type': 'ir.actions.act_window',
102
'res_model': 'stock.frequence',
104
'view_model': 'form',
106
'res_id': frequence_id}
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.
114
w = self.pool.get('stock.warehouse').browse(cr, uid, warehouse_id, context=context)
115
v = {'location_id': w.lot_stock_id.id}
119
def copy(self, cr, uid, id, default=None, context=None):
123
'name': self.pool.get('ir.sequence').get(cr, uid, 'stock.order.cycle') or '',
125
return super(stock_warehouse_order_cycle, self).copy(cr, uid, id, default, context=context)
127
stock_warehouse_order_cycle()
129
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'