Files
tryton/location.py
T

209 lines
7.7 KiB
Python
Raw Normal View History

2008-06-23 21:01:22 +02:00
#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
2008-04-08 14:27:53 +02:00
"Wharehouse"
from trytond.osv import fields, OSV
2008-06-05 01:00:26 +02:00
from trytond.wizard import Wizard, WizardOSV
2008-07-11 23:20:17 +02:00
import datetime
2008-04-08 14:27:53 +02:00
STATES = {
2008-04-24 00:49:17 +02:00
'readonly': "not active",
}
2008-04-08 14:27:53 +02:00
class Location(OSV):
"Stock Location"
_name = 'stock.location'
_description = __doc__
name = fields.Char("Name", size=None, required=True, states=STATES)
code = fields.Char("Code", size=None, states=STATES, select=1)
active = fields.Boolean('Active', select=1)
2008-05-21 18:14:52 +02:00
address = fields.Many2One("relationship.address", "Address",
2008-07-23 20:33:17 +02:00
states={
'invisible': "type != 'warehouse'",
'readonly': "not active",
})
type = fields.Selection([
('supplier', 'Supplier'),
('customer', 'Customer'),
2008-05-14 11:45:08 +02:00
('lost_found', 'Lost and Found'),
('warehouse', 'Warehouse'),
('storage', 'Storage'),
('production', 'Production'),
], 'Location type', states=STATES)
parent = fields.Many2One("stock.location", "Parent", select=1,
left="left", right="right")
left = fields.Integer('Left', required=True)
right = fields.Integer('Right', required=True)
2008-06-11 20:18:37 +02:00
childs = fields.One2Many("stock.location", "parent", "Childs")
2008-04-24 00:49:17 +02:00
input_location = fields.Many2One(
2008-07-23 20:33:17 +02:00
"stock.location", "Input", states={
'invisible': "type != 'warehouse'",
'readonly': "not active",
'required': "type == 'warehouse'",
},
domain="[('type','=','storage'), ('parent', 'child_of', [active_id])]")
2008-04-24 00:49:17 +02:00
output_location = fields.Many2One(
2008-07-23 20:33:17 +02:00
"stock.location", "Output", states={
'invisible': "type != 'warehouse'",
'readonly': "not active",
'required': "type == 'warehouse'",
},
domain="[('type','=','storage'), ('parent', 'child_of', [active_id])]")
2008-04-24 00:49:17 +02:00
storage_location = fields.Many2One(
2008-07-23 20:33:17 +02:00
"stock.location", "Storage", states={
'invisible': "type != 'warehouse'",
'readonly': "not active",
'required': "type == 'warehouse'",
},
domain="[('type','=','storage'), ('parent', 'child_of', [active_id])]")
2008-06-11 20:18:37 +02:00
quantity = fields.Function('get_quantity', type='float', string='Quantity')
2008-06-05 01:00:26 +02:00
forecast_quantity = fields.Function('get_quantity', type='float',
2008-06-11 20:18:37 +02:00
string='Forecast Quantity')
2008-04-08 14:27:53 +02:00
2008-04-22 17:49:50 +02:00
def __init__(self):
super(Location, self).__init__()
self._order.insert(0, ('name', 'ASC'))
2008-04-08 14:27:53 +02:00
def default_active(self, cursor, user, context=None):
return True
def default_left(self, cursor, user, context=None):
return 0
def default_right(self, cursor, user, context=None):
return 0
2008-04-24 00:49:17 +02:00
def default_type(self, cursor, user, context=None):
return 'storage'
2008-04-24 00:49:17 +02:00
2008-07-23 20:37:32 +02:00
def check_xml_record(self, cursor, user, ids, values, context=None):
return True
2008-04-08 14:27:53 +02:00
def name_search(self, cursor, user, name, args=None, operator='ilike',
2008-04-23 16:59:39 +02:00
context=None, limit=None):
2008-04-08 14:27:53 +02:00
if not args:
args=[]
2008-04-17 02:31:55 +02:00
ids = self.search(
cursor, user, [('code', '=', name)] + args, limit=limit,
context=context)
2008-04-08 14:27:53 +02:00
if not ids:
2008-04-17 02:31:55 +02:00
ids = self.search(
cursor, user, [('name', operator, name)] + args, limit=limit,
context=context)
2008-04-08 14:27:53 +02:00
result = self.name_get(cursor, user, ids, context)
return result
def get_quantity(self, cursor, user, ids, name, arg, context=None):
product_obj = self.pool.get('product.product')
if (not context) or (not context.get('product')):
return dict([(i,0) for i in ids])
if name != 'forecast_quantity' and context.get('stock_date_end'):
if context['stock_date_end'] != datetime.date.today():
2008-07-11 23:20:17 +02:00
context = context.copy()
del context['stock_date_end']
pbl = product_obj.products_by_location(cursor, user, location_ids=ids,
product_ids=[context['product']], with_childs=True, skip_zero=False,
context=context).iteritems()
return dict( [(loc,qty) for (loc,prod), qty in pbl] )
2008-05-20 17:38:43 +02:00
def view_header_get(self, cursor, user, value, view_type='form',
context=None):
product_obj = self.pool.get('product.product')
uom_obj = self.pool.get('product.uom')
if context is None:
context = {}
if context.get('product'):
product_name = product_obj.name_get(cursor, user, context['product'],
context=context)[0][1]
product = product_obj.browse(cursor, user, context['product'],
context=context)
uom_name = uom_obj.name_get(cursor, user, product.default_uom.id,
context=context)[0][1]
return value + ': ' + product_name + ' (' + uom_name + ')'
return False
2008-04-08 14:27:53 +02:00
Location()
2008-05-21 18:14:52 +02:00
class Party(OSV):
_name = 'relationship.party'
supplier_location = fields.Property(type='many2one',
relation='stock.location', string='Supplier Location',
group_name='Stock Properties', view_load=True,
domain=[('type', '=', 'supplier')],
help='The default source location ' \
2008-05-21 18:14:52 +02:00
'when receiving products from the party.')
customer_location = fields.Property(type='many2one',
relation='stock.location', string='Customer Location',
group_name='Stock Properties', view_load=True,
domain=[('type', '=', 'customer')],
help='The default destination location ' \
2008-05-21 18:14:52 +02:00
'when sending products to the party.')
2008-05-21 18:14:52 +02:00
Party()
2008-06-05 01:00:26 +02:00
2008-07-11 23:20:17 +02:00
class ChooseStockDateInit(WizardOSV):
_name = 'stock.location_stock_date.init'
2008-10-06 12:11:57 +02:00
_description = "Compute stock quantities"
2008-06-05 01:00:26 +02:00
forecast_date = fields.Date(
2008-10-06 12:11:57 +02:00
'At Date', help='Allow to compute expected '\
2008-06-05 01:00:26 +02:00
'stock quantities for this date.\n'\
'* An empty value is an infinite date in the future.\n'\
'* A date in the past will provide historical values.')
2008-10-06 12:11:57 +02:00
def default_forecast_date(self, cursor, user, context=None):
return datetime.date.today()
2008-07-11 23:20:17 +02:00
ChooseStockDateInit()
2008-06-05 01:00:26 +02:00
class OpenProduct(Wizard):
'Open Products'
_name = 'stock.product.open'
states = {
'init': {
'result': {
'type': 'form',
2008-07-11 23:20:17 +02:00
'object': 'stock.location_stock_date.init',
2008-06-05 01:00:26 +02:00
'state': [
2008-06-06 22:50:40 +02:00
('end', 'Cancel', 'tryton-cancel'),
('open', 'Open', 'tryton-ok', True),
2008-06-05 01:00:26 +02:00
],
},
},
'open': {
'result': {
'type': 'action',
'action': '_action_open_product',
'state': 'end',
},
},
}
def _action_open_product(self, cursor, user, data, context=None):
model_data_obj = self.pool.get('ir.model.data')
act_window_obj = self.pool.get('ir.action.act_window')
model_data_ids = model_data_obj.search(cursor, user, [
('fs_id', '=', 'act_product_by_location'),
('module', '=', 'stock'),
('inherit', '=', False),
2008-06-05 01:00:26 +02:00
], limit=1, context=context)
model_data = model_data_obj.browse(cursor, user, model_data_ids[0],
context=context)
res = act_window_obj.read(cursor, user, model_data.db_id, context=context)
2008-07-11 23:20:17 +02:00
if context == None: context = {}
context['locations'] = data['ids']
2008-06-05 01:00:26 +02:00
if data['form']['forecast_date']:
context['stock_date_end'] = data['form']['forecast_date']
else:
context['stock_date_end'] = datetime.date.max
2008-06-05 01:00:26 +02:00
res['context'] = str(context)
return res
OpenProduct()