diff --git a/__init__.py b/__init__.py index 6c38892eb5..05eb28e042 100644 --- a/__init__.py +++ b/__init__.py @@ -24,7 +24,6 @@ # ############################################################################## -from warehouse import * from location import * from packing import * from move import * diff --git a/__tryton__.py b/__tryton__.py index 1f3677d261..0aab44efd4 100644 --- a/__tryton__.py +++ b/__tryton__.py @@ -10,7 +10,6 @@ 'partner', 'product' ], 'xml': [ - 'warehouse.xml', 'location.xml', 'move.xml', 'packing.xml', diff --git a/location.py b/location.py index b2cfe0ce94..74f3fa1eae 100644 --- a/location.py +++ b/location.py @@ -2,9 +2,12 @@ from trytond.osv import fields, OSV STATES = { - 'readonly': "active == False", + 'readonly': "not active", +} +STATES_WH = { + 'readonly': "(not active) or type != 'warehouse'", + 'required': "type == 'warehouse' and active", } - class Location(OSV): "Stock Location" _name = 'stock.location' @@ -13,13 +16,26 @@ class Location(OSV): name = fields.Char("Name", size=64, required=True, states=STATES,) code = fields.Char("Code", size=32, states=STATES, select=True,) active = fields.Boolean('Active', select=True) - usage = fields.Selection([('supplier', 'Supplier'), + address = fields.Many2One("partner.address", "Address", states=STATES_WH,) + type = fields.Selection([('supplier', 'Supplier'), ('customer', 'Customer'), ('inventory', 'Inventory'), ('procurement', 'Procurement'), + ('warehouse', 'Warehouse'), + ('storage', 'Storage'), ('production', 'Production')], 'Location type', states=STATES,) - warehouse = fields.Many2One("stock.warehouse", "Warehouse", select="1") + parent = fields.Many2One("stock.location", "Parent", select="1") + childs = fields.One2Many("stock.location", "parent", "Childs",) + input_location = fields.Many2One( + "stock.location", "Input", states=STATES_WH, + domain="[('type','=','storage')]",) + output_location = fields.Many2One( + "stock.location", "Output", states=STATES_WH, + domain="[('type','=','storage')]",) + storage_location = fields.Many2One( + "stock.location", "Storage", states=STATES_WH, + domain="[('type','=','storage')]") # TODO: champ calcule vers product (retournant les product dispo) # + context qui passe la location courante et permet de calculer @@ -28,6 +44,9 @@ class Location(OSV): def default_active(self, cursor, user, context=None): return True + def default_type(self, cursor, user, context=None): + return 'storage' + def name_search(self, cursor, user, name, args=None, operator='ilike', context=None, limit=80): if not args: @@ -107,12 +126,3 @@ class Location(OSV): Location() - -class Warehouse(OSV): - _name = "stock.warehouse" - _inherit = "stock.warehouse" - input_location = fields.Many2One("stock.location", "Input location", required=True,) - output_location = fields.Many2One("stock.location", "Output location", required=True,) - store_location = fields.Many2One("stock.location", "Default store location", required=True,) - -Warehouse() diff --git a/location.xml b/location.xml index d1ce23cad2..084b48f497 100644 --- a/location.xml +++ b/location.xml @@ -1,6 +1,7 @@ + stock.location form @@ -11,17 +12,21 @@ diff --git a/move.py b/move.py index 10c4045762..8b7e75063b 100644 --- a/move.py +++ b/move.py @@ -20,12 +20,12 @@ class Move(OSV): quantity = fields.Float( "Quantity", digits=(12, 6), required=True, states=STATES,) - from_location =fields.Many2One( + from_location = fields.Many2One( "stock.location", "From Location", select=True, required=True, - states=STATES,) + states=STATES, domain="[('type', '!=', 'warehouse')]",) to_location = fields.Many2One( "stock.location", "To Location", select=True, required=True, - states=STATES,) + states=STATES,domain="[('type', '!=', 'warehouse')]",) incoming_packing_in = fields.Many2One( "stock.packing.in", "Supplier Packing", states=STATES, select=True) inventory_packing_in = fields.Many2One( @@ -95,59 +95,47 @@ class Move(OSV): return True def default_to_location(self, cursor, user, context=None): - if context and context.get('wh_incoming'): - warehouse = self.pool.get('stock.warehouse').browse( - cursor, user, context['wh_incoming'], context=context) - return warehouse.input_location.id - if context and context.get('wh_inv_out'): - warehouse = self.pool.get('stock.warehouse').browse( - cursor, user, context['wh_inv_out'], context=context) - return warehouse.output_location.id - if context and context.get('wh_inv_in'): - warehouse = self.pool.get('stock.warehouse').browse( - cursor, user, context['wh_inv_in'], context=context) - return warehouse.store_location.id - return False + if context and context.get('warehouse') and context.get('type'): + wh_location = self.pool.get('stock.location').browse( + cursor, user, context['warehouse'], context=context) + field = {'inventory_in': 'storage_location', + 'inventory_out': 'output_location', + 'incoming': 'input_location',}.get(context['type']) + return field and wh_location[field].id or False def default_from_location(self, cursor, user, context=None): - if context and context.get('wh_inv_in'): - warehouse = self.pool.get('stock.warehouse').browse( - cursor, user, context['wh_inv_in'], context=context) - return warehouse.input_location.id - if context and context.get('wh_outgoing'): - warehouse = self.pool.get('stock.warehouse').browse( - cursor, user, context['wh_outgoing'], context=context) - return warehouse.output_location.id - if context and context.get('wh_inv_out'): - warehouse = self.pool.get('stock.warehouse').browse( - cursor, user, context['wh_inv_out'], context=context) - return warehouse.store_location.id - return False + if context and context.get('warehouse') and context.get('type'): + wh_location = self.pool.get('stock.location').browse( + cursor, user, context['warehouse'], context=context) + field = {'inventory_in': 'input_location', + 'inventory_out': 'storage_location', + 'outgoing': 'output_location',}.get(context['type']) + return field and wh_location[field].id or False def default_state(self, cursor, user, context=None): - if not context: return 'draft' - if 'pack_incoming_state' in context: - if context['pack_incoming_state'] == 'waiting': - return 'waiting' - if context['pack_incoming_state'] in ('received', 'done'): - return 'done' - if 'pack_inv_in_state' in context: - if context['pack_inv_in_state'] == 'received': - return 'waiting' - if context['pack_inv_in_state'] == 'done': - return 'done' - if 'pack_outgoing_state' in context: - if context['pack_outgoing_state'] in \ - ('waiting', 'assigned', 'ready'): - return 'waiting' - if context['pack_outgoing_state'] in 'done': - return 'done' - if 'pack_inv_out_state' in context: - if context['pack_inv_out_state'] == 'assigned': - return 'waiting' - if context['pack_inv_out_state'] == 'ready': - return 'done' - +#TODO +# if not context: return 'draft' +# if 'pack_incoming_state' in context: +# if context['pack_incoming_state'] == 'waiting': +# return 'waiting' +# if context['pack_incoming_state'] in ('received', 'done'): +# return 'done' +# if 'pack_inv_in_state' in context: +# if context['pack_inv_in_state'] == 'received': +# return 'waiting' +# if context['pack_inv_in_state'] == 'done': +# return 'done' +# if 'pack_outgoing_state' in context: +# if context['pack_outgoing_state'] in \ +# ('waiting', 'assigned', 'ready'): +# return 'waiting' +# if context['pack_outgoing_state'] in 'done': +# return 'done' +# if 'pack_inv_out_state' in context: +# if context['pack_inv_out_state'] == 'assigned': +# return 'waiting' +# if context['pack_inv_out_state'] == 'ready': +# return 'done' return 'draft' def on_change_product(self, cursor, user, ids, value, context=None): @@ -217,7 +205,7 @@ class CreatePacking(Wizard): move_obj = self.pool.get('stock.move') packing_obj = self.pool.get('stock.packing.in') - warehouse_obj = self.pool.get('stock.warehouse') + location_obj = self.pool.get('stock.location') moves = move_obj.browse(cursor, user, data['ids'], context=context) # Collect moves by incoming location @@ -237,25 +225,26 @@ class CreatePacking(Wizard): moves_by_location[location].append(move.id) # Fetch warehouse for these locations - warehouse_ids = warehouse_obj.search( + wh_location_ids = location_obj.search( cursor, user, [('input_location', 'in', - [l for l in moves_by_location])]) - warehouses = warehouse_obj.browse( + [l for l in moves_by_location]), + ('usage','=','warehouse')]) + wh_locations = location_obj.browse( cursor, user, warehouse_ids, context=context) - loc2wh = dict([( wh.input_location.id, wh.id) for wh in warehouses]) + loc2wh = dict([( whl.input_location.id, whl.id) for whl in wh_locations]) packing_ids = [] for location, move_ids in moves_by_location.iteritems(): - wh = loc2wh.get(location) - if not wh: + whl = loc2wh.get(location) + if not whl: raise ExceptWizard( 'UserError', 'Moves must have a final destination '\ 'who is an input location of a wharehouse.') pid = packing_obj.create( cursor, user, - {'incoming_moves': [('set',move_ids)], 'warehouse': wh}, + {'incoming_moves': [('set',move_ids)], 'warehouse': whl}, context=context) packing_ids.append(pid) diff --git a/packing.py b/packing.py index 8ac040e532..b00909b296 100644 --- a/packing.py +++ b/packing.py @@ -17,21 +17,21 @@ class PackingIn(OSV): effective_date =fields.DateTime('Effective Date', readonly=True) planned_date = fields.DateTime('Planned Date', readonly=True) warehouse = fields.Many2One( - 'stock.warehouse',"Warehouse", required=True, states=STATES,) + 'stock.location',"Warehouse", required=True, states=STATES, + domain="[('type', '=', 'warehouse')]",) incoming_moves = fields.One2Many( 'stock.move', 'incoming_packing_in', 'Incoming Moves', states={'readonly':"state in ('received','done')",}, - context="{'wh_incoming': warehouse, 'pack_incoming_state': state}") + context="{'warehouse': warehouse, 'packing_state': state, 'type':'incoming'}") inventory_moves = fields.One2Many( 'stock.move', 'inventory_packing_in', 'Inventory Moves', states={'readonly':"state in ('draft','waiting')",}, - context="{'wh_inv_in': warehouse, 'pack_inv_in_state': state}") + context="{'warehouse': warehouse, 'packing_state': state, 'type':'inventory_in'}") code = fields.Char("Code", size=None, select=1, readonly=True,) state = fields.Selection( [('draft','Draft'),('done','Done'),('cancel','Cancel'), ('waiting','Waiting'),('received','Received')], 'State', readonly=True) - def __init__(self): super(PackingIn, self).__init__() self._rpc_allowed += [ @@ -142,15 +142,16 @@ class PackingOut(OSV): effective_date =fields.DateTime('Effective Date', readonly=True) planned_date = fields.DateTime('Planned Date', readonly=True) warehouse = fields.Many2One( - 'stock.warehouse',"Warehouse", required=True, states=STATES,) + 'stock.location',"Warehouse", required=True, states=STATES, + domain="[('type', '=', 'warehouse')]",) outgoing_moves = fields.One2Many( 'stock.move', 'outgoing_packing_out', 'Outgoing Moves', states=STATES, - context="{'wh_outgoing': warehouse, 'pack_outgoing_state': state}") + context="{'warehouse': warehouse, 'packing_state': state, 'type':'outgoing',}") inventory_moves = fields.One2Many( 'stock.move', 'inventory_packing_out', 'Inventory Moves', states={'readonly':"state not in ('assigned')",}, - context="{'wh_inv_out': warehouse, 'pack_inv_out_state': state}") + context="{'warehouse': warehouse, 'packing_state': state, 'type':'inventory_out',}") code = fields.Char("Code", size=None, select=1, readonly=True,) state = fields.Selection( [('draft','Draft'),('done','Done'),('cancel','Cancel'), diff --git a/warehouse.py b/warehouse.py deleted file mode 100644 index 841c2553ff..0000000000 --- a/warehouse.py +++ /dev/null @@ -1,23 +0,0 @@ -"Wharehouse" -from trytond.osv import fields, OSV - -STATES = { - 'readonly': "active == False", -} - - -class Warehouse(OSV): - "Warehouse" - _name = 'stock.warehouse' - _order = 'name' - _description = __doc__ - name = fields.Char("Name", size=64, required=True, select=True) - address = fields.Many2One("partner.address", "Address") - locations = fields.One2Many( - "stock.location", "warehouse", "Storage locations",) - active = fields.Boolean('Active', select=True) - - def default_active(self, cursor, user, context=None): - return True - -Warehouse() diff --git a/warehouse.xml b/warehouse.xml deleted file mode 100644 index efd9969ade..0000000000 --- a/warehouse.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - stock.warehouse - form - - - - - stock.warehouse - tree - - - - - - ]]> - - - - Warehouses - stock.warehouse - form - - - - - - - - - - - - - - - - - Stock administration - - - - - - - - - - - - - - - - - - - - - - - -