[MOV] stock: stock_location

Location models and views are moved in their own file. Impacted:

 - stock.location
 - stock.location.route
 - stock.location.path

This commit only moves files. No change is done.
This commit is contained in:
Thibault Delavallée
2016-04-29 12:18:43 +02:00
parent cb486d7eb6
commit f37cabe36d
6 changed files with 593 additions and 585 deletions
+1
View File
@@ -75,6 +75,7 @@ Dashboard / Reports for Inventory Management will include:
'stock_view.xml',
'views/stock_picking_views.xml',
'views/stock_quant_views.xml',
'views/stock_location_views.xml',
'views/procurement_views.xml',
'views/stock_warehouse_views.xml',
'views/stock_move_views.xml',
+1
View File
@@ -9,6 +9,7 @@ import res_company
import res_partner
import stock_config_settings
import stock_inventory
import stock_location
import stock_move
import stock_pack_operation
import stock_picking
+301
View File
@@ -0,0 +1,301 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime
from dateutil import relativedelta
from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
#----------------------------------------------------------
# Stock Location
#----------------------------------------------------------
class stock_location(osv.osv):
_name = "stock.location"
_description = "Inventory Locations"
_parent_name = "location_id"
_parent_store = True
_parent_order = 'name'
_order = 'parent_left'
_rec_name = 'complete_name'
def _complete_name(self, cr, uid, ids, name, args, context=None):
""" Forms complete name of location from parent location to child location.
@return: Dictionary of values
"""
res = {}
for m in self.browse(cr, uid, ids, context=context):
res[m.id] = m.name
parent = m.location_id
while parent:
res[m.id] = parent.name + '/' + res[m.id]
parent = parent.location_id
return res
def _get_sublocations(self, cr, uid, ids, context=None):
""" return all sublocations of the given stock locations (included) """
if context is None:
context = {}
context_with_inactive = context.copy()
context_with_inactive['active_test'] = False
return self.search(cr, uid, [('id', 'child_of', ids)], context=context_with_inactive)
def name_get(self, cr, uid, ids, context=None):
res = []
for location in self.browse(cr, uid, ids, context=context):
sub_location = location
name = location.name
while sub_location.location_id and sub_location.usage != 'view':
sub_location = sub_location.location_id
name = sub_location.name + '/' + name
res.append((location.id, name))
return res
_columns = {
'name': fields.char('Location Name', required=True, translate=True),
'active': fields.boolean('Active', help="By unchecking the active field, you may hide a location without deleting it."),
'usage': fields.selection([
('supplier', 'Vendor Location'),
('view', 'View'),
('internal', 'Internal Location'),
('customer', 'Customer Location'),
('inventory', 'Inventory Loss'),
('procurement', 'Procurement'),
('production', 'Production'),
('transit', 'Transit Location')],
'Location Type', required=True,
help="""* Vendor Location: Virtual location representing the source location for products coming from your vendors
\n* View: Virtual location used to create a hierarchical structures for your warehouse, aggregating its child locations ; can't directly contain products
\n* Internal Location: Physical locations inside your own warehouses,
\n* Customer Location: Virtual location representing the destination location for products sent to your customers
\n* Inventory Loss: Virtual location serving as counterpart for inventory operations used to correct stock levels (Physical inventories)
\n* Procurement: Virtual location serving as temporary counterpart for procurement operations when the source (vendor or production) is not known yet. This location should be empty when the procurement scheduler has finished running.
\n* Production: Virtual counterpart location for production operations: this location consumes the raw material and produces finished products
\n* Transit Location: Counterpart location that should be used in inter-companies or inter-warehouses operations
""", select=True),
'complete_name': fields.function(_complete_name, type='char', string="Full Location Name",
store={'stock.location': (_get_sublocations, ['name', 'location_id', 'active'], 10)}),
'location_id': fields.many2one('stock.location', 'Parent Location', select=True, ondelete='cascade',
help="The parent location that includes this location. Example : The 'Dispatch Zone' is the 'Gate 1' parent location."),
'child_ids': fields.one2many('stock.location', 'location_id', 'Contains'),
'partner_id': fields.many2one('res.partner', 'Owner', help="Owner of the location if not internal"),
'comment': fields.text('Additional Information'),
'posx': fields.integer('Corridor (X)', help="Optional localization details, for information purpose only"),
'posy': fields.integer('Shelves (Y)', help="Optional localization details, for information purpose only"),
'posz': fields.integer('Height (Z)', help="Optional localization details, for information purpose only"),
'parent_left': fields.integer('Left Parent', select=1),
'parent_right': fields.integer('Right Parent', select=1),
'company_id': fields.many2one('res.company', 'Company', select=1, help='Let this field empty if this location is shared between companies'),
'scrap_location': fields.boolean('Is a Scrap Location?', help='Check this box to allow using this location to put scrapped/damaged goods.'),
'return_location': fields.boolean('Is a Return Location?', help='Check this box to allow using this location as a return location.'),
'removal_strategy_id': fields.many2one('product.removal', 'Removal Strategy', help="Defines the default method used for suggesting the exact location (shelf) where to take the products from, which lot etc. for this location. This method can be enforced at the product category level, and a fallback is made on the parent locations if none is set here."),
'putaway_strategy_id': fields.many2one('product.putaway', 'Put Away Strategy', help="Defines the default method used for suggesting the exact location (shelf) where to store the products. This method can be enforced at the product category level, and a fallback is made on the parent locations if none is set here."),
'barcode': fields.char('Barcode', copy=False, oldname='loc_barcode'),
}
_defaults = {
'active': True,
'usage': 'internal',
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.location', context=c),
'posx': 0,
'posy': 0,
'posz': 0,
'scrap_location': False,
}
_sql_constraints = [('barcode_company_uniq', 'unique (barcode,company_id)', 'The barcode for a location must be unique per company !')]
def default_get(self, cr, uid, fields, context=None):
res = super(stock_location, self).default_get(cr, uid, fields, context=context)
if 'barcode' in fields and 'barcode' not in res and res.get('complete_name'):
res['barcode'] = res['complete_name']
return res
def get_putaway_strategy(self, cr, uid, ids, product, context=None):
''' Returns the location where the product has to be put, if any compliant putaway strategy is found. Otherwise returns None.'''
location = self.browse(cr, uid, ids[0], context=context)
putaway_obj = self.pool.get('product.putaway')
loc = location
while loc:
if loc.putaway_strategy_id:
res = putaway_obj.putaway_apply(cr, uid, loc.putaway_strategy_id, product, context=context)
if res:
return res
loc = loc.location_id
def get_warehouse(self, cr, uid, ids, context=None):
"""
Returns warehouse id of warehouse that contains location
:param location: browse record (stock.location)
"""
location = self.browse(cr, uid, ids[0], context=context)
wh_obj = self.pool.get("stock.warehouse")
whs = wh_obj.search(cr, uid, [('view_location_id.parent_left', '<=', location.parent_left),
('view_location_id.parent_right', '>=', location.parent_left)], context=context)
return whs and whs[0] or False
#----------------------------------------------------------
# Routes
#----------------------------------------------------------
class stock_location_route(osv.osv):
_name = 'stock.location.route'
_description = "Inventory Routes"
_order = 'sequence'
_columns = {
'name': fields.char('Route Name', required=True, translate=True),
'sequence': fields.integer('Sequence'),
'pull_ids': fields.one2many('procurement.rule', 'route_id', 'Procurement Rules', copy=True),
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the route without removing it."),
'push_ids': fields.one2many('stock.location.path', 'route_id', 'Push Rules', copy=True),
'product_selectable': fields.boolean('Applicable on Product', help="When checked, the route will be selectable in the Inventory tab of the Product form. It will take priority over the Warehouse route. "),
'product_categ_selectable': fields.boolean('Applicable on Product Category', help="When checked, the route will be selectable on the Product Category. It will take priority over the Warehouse route. "),
'warehouse_selectable': fields.boolean('Applicable on Warehouse', help="When a warehouse is selected for this route, this route should be seen as the default route when products pass through this warehouse. This behaviour can be overridden by the routes on the Product/Product Categories or by the Preferred Routes on the Procurement"),
'supplied_wh_id': fields.many2one('stock.warehouse', 'Supplied Warehouse'),
'supplier_wh_id': fields.many2one('stock.warehouse', 'Supplying Warehouse'),
'company_id': fields.many2one('res.company', 'Company', select=1, help='Leave this field empty if this route is shared between all companies'),
#Reverse many2many fields:
'product_ids': fields.many2many('product.template', 'stock_route_product', 'route_id', 'product_id', 'Products'),
'categ_ids': fields.many2many('product.category', 'stock_location_route_categ', 'route_id', 'categ_id', 'Product Categories'),
'warehouse_ids': fields.many2many('stock.warehouse', 'stock_route_warehouse', 'route_id', 'warehouse_id', 'Warehouses'),
}
_defaults = {
'sequence': lambda self, cr, uid, ctx: 0,
'active': True,
'product_selectable': True,
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.location.route', context=c),
}
def write(self, cr, uid, ids, vals, context=None):
'''when a route is deactivated, deactivate also its pull and push rules'''
if isinstance(ids, (int, long)):
ids = [ids]
res = super(stock_location_route, self).write(cr, uid, ids, vals, context=context)
if 'active' in vals:
push_ids = []
pull_ids = []
for route in self.browse(cr, uid, ids, context=context):
if route.push_ids:
push_ids += [r.id for r in route.push_ids if r.active != vals['active']]
if route.pull_ids:
pull_ids += [r.id for r in route.pull_ids if r.active != vals['active']]
if push_ids:
self.pool.get('stock.location.path').write(cr, uid, push_ids, {'active': vals['active']}, context=context)
if pull_ids:
self.pool.get('procurement.rule').write(cr, uid, pull_ids, {'active': vals['active']}, context=context)
return res
def view_product_ids(self, cr, uid, ids, context=None):
return {
'name': _('Products'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'product.template',
'type': 'ir.actions.act_window',
'domain': [('route_ids', 'in', ids[0])],
}
def view_categ_ids(self, cr, uid, ids, context=None):
return {
'name': _('Product Categories'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'product.category',
'type': 'ir.actions.act_window',
'domain': [('route_ids', 'in', ids[0])],
}
class stock_location_path(osv.osv):
_name = "stock.location.path"
_description = "Pushed Flows"
_order = "name"
def _get_rules(self, cr, uid, ids, context=None):
res = []
for route in self.browse(cr, uid, ids, context=context):
res += [x.id for x in route.push_ids]
return res
_columns = {
'name': fields.char('Operation Name', required=True),
'company_id': fields.many2one('res.company', 'Company'),
'route_id': fields.many2one('stock.location.route', 'Route'),
'location_from_id': fields.many2one('stock.location', 'Source Location', ondelete='cascade', select=1, required=True,
help="This rule can be applied when a move is confirmed that has this location as destination location"),
'location_dest_id': fields.many2one('stock.location', 'Destination Location', ondelete='cascade', select=1, required=True,
help="The new location where the goods need to go"),
'delay': fields.integer('Delay (days)', help="Number of days needed to transfer the goods"),
'picking_type_id': fields.many2one('stock.picking.type', 'Picking Type', required=True,
help="This is the picking type that will be put on the stock moves"),
'auto': fields.selection(
[('manual','Manual Operation'),('transparent','Automatic No Step Added')],
'Automatic Move',
required=True, select=1,
help="The 'Manual Operation' value will create a stock move after the current one. " \
"With 'Automatic No Step Added', the location is replaced in the original move."
),
'propagate': fields.boolean('Propagate cancel and split', help='If checked, when the previous move is cancelled or split, the move generated by this move will too'),
'active': fields.boolean('Active'),
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse'),
'route_sequence': fields.related('route_id', 'sequence', string='Route Sequence',
store={
'stock.location.route': (_get_rules, ['sequence'], 10),
'stock.location.path': (lambda self, cr, uid, ids, c={}: ids, ['route_id'], 10),
}),
'sequence': fields.integer('Sequence'),
}
_defaults = {
'auto': 'manual',
'delay': 0,
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'procurement.order', context=c),
'propagate': True,
'active': True,
}
def _prepare_push_apply(self, cr, uid, ids, move, context=None):
rule = self.browse(cr, uid, ids[0], context=context)
newdate = (datetime.strptime(move.date_expected, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta.relativedelta(days=rule.delay or 0)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
return {
'origin': move.origin or move.picking_id.name or "/",
'location_id': move.location_dest_id.id,
'location_dest_id': rule.location_dest_id.id,
'date': newdate,
'company_id': rule.company_id and rule.company_id.id or False,
'date_expected': newdate,
'picking_id': False,
'picking_type_id': rule.picking_type_id and rule.picking_type_id.id or False,
'propagate': rule.propagate,
'push_rule_id': rule.id,
'warehouse_id': rule.warehouse_id and rule.warehouse_id.id or False,
}
def _apply(self, cr, uid, ids, move, context=None):
rule = self.browse(cr, uid, ids[0], context=context)
move_obj = self.pool.get('stock.move')
newdate = (datetime.strptime(move.date_expected, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta.relativedelta(days=rule.delay or 0)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
if rule.auto == 'transparent':
old_dest_location = move.location_dest_id.id
move_obj.write(cr, uid, [move.id], {
'date': newdate,
'date_expected': newdate,
'location_dest_id': rule.location_dest_id.id
})
#avoid looping if a push rule is not well configured
if rule.location_dest_id.id != old_dest_location:
#call again push_apply to see if a next step is defined
move._push_apply()
else:
vals = self._prepare_push_apply(cr, uid, [rule.id], move, context=context)
move_id = move_obj.copy(cr, uid, move.id, vals, context=context)
move_obj.write(cr, uid, [move.id], {
'move_dest_id': move_id,
})
move_obj.action_confirm(cr, uid, [move_id], context=None)
-295
View File
@@ -33,209 +33,6 @@ class stock_incoterms(osv.osv):
'active': True,
}
#----------------------------------------------------------
# Stock Location
#----------------------------------------------------------
class stock_location(osv.osv):
_name = "stock.location"
_description = "Inventory Locations"
_parent_name = "location_id"
_parent_store = True
_parent_order = 'name'
_order = 'parent_left'
_rec_name = 'complete_name'
def _complete_name(self, cr, uid, ids, name, args, context=None):
""" Forms complete name of location from parent location to child location.
@return: Dictionary of values
"""
res = {}
for m in self.browse(cr, uid, ids, context=context):
res[m.id] = m.name
parent = m.location_id
while parent:
res[m.id] = parent.name + '/' + res[m.id]
parent = parent.location_id
return res
def _get_sublocations(self, cr, uid, ids, context=None):
""" return all sublocations of the given stock locations (included) """
if context is None:
context = {}
context_with_inactive = context.copy()
context_with_inactive['active_test'] = False
return self.search(cr, uid, [('id', 'child_of', ids)], context=context_with_inactive)
def name_get(self, cr, uid, ids, context=None):
res = []
for location in self.browse(cr, uid, ids, context=context):
sub_location = location
name = location.name
while sub_location.location_id and sub_location.usage != 'view':
sub_location = sub_location.location_id
name = sub_location.name + '/' + name
res.append((location.id, name))
return res
_columns = {
'name': fields.char('Location Name', required=True, translate=True),
'active': fields.boolean('Active', help="By unchecking the active field, you may hide a location without deleting it."),
'usage': fields.selection([
('supplier', 'Vendor Location'),
('view', 'View'),
('internal', 'Internal Location'),
('customer', 'Customer Location'),
('inventory', 'Inventory Loss'),
('procurement', 'Procurement'),
('production', 'Production'),
('transit', 'Transit Location')],
'Location Type', required=True,
help="""* Vendor Location: Virtual location representing the source location for products coming from your vendors
\n* View: Virtual location used to create a hierarchical structures for your warehouse, aggregating its child locations ; can't directly contain products
\n* Internal Location: Physical locations inside your own warehouses,
\n* Customer Location: Virtual location representing the destination location for products sent to your customers
\n* Inventory Loss: Virtual location serving as counterpart for inventory operations used to correct stock levels (Physical inventories)
\n* Procurement: Virtual location serving as temporary counterpart for procurement operations when the source (vendor or production) is not known yet. This location should be empty when the procurement scheduler has finished running.
\n* Production: Virtual counterpart location for production operations: this location consumes the raw material and produces finished products
\n* Transit Location: Counterpart location that should be used in inter-companies or inter-warehouses operations
""", select=True),
'complete_name': fields.function(_complete_name, type='char', string="Full Location Name",
store={'stock.location': (_get_sublocations, ['name', 'location_id', 'active'], 10)}),
'location_id': fields.many2one('stock.location', 'Parent Location', select=True, ondelete='cascade',
help="The parent location that includes this location. Example : The 'Dispatch Zone' is the 'Gate 1' parent location."),
'child_ids': fields.one2many('stock.location', 'location_id', 'Contains'),
'partner_id': fields.many2one('res.partner', 'Owner', help="Owner of the location if not internal"),
'comment': fields.text('Additional Information'),
'posx': fields.integer('Corridor (X)', help="Optional localization details, for information purpose only"),
'posy': fields.integer('Shelves (Y)', help="Optional localization details, for information purpose only"),
'posz': fields.integer('Height (Z)', help="Optional localization details, for information purpose only"),
'parent_left': fields.integer('Left Parent', select=1),
'parent_right': fields.integer('Right Parent', select=1),
'company_id': fields.many2one('res.company', 'Company', select=1, help='Let this field empty if this location is shared between companies'),
'scrap_location': fields.boolean('Is a Scrap Location?', help='Check this box to allow using this location to put scrapped/damaged goods.'),
'return_location': fields.boolean('Is a Return Location?', help='Check this box to allow using this location as a return location.'),
'removal_strategy_id': fields.many2one('product.removal', 'Removal Strategy', help="Defines the default method used for suggesting the exact location (shelf) where to take the products from, which lot etc. for this location. This method can be enforced at the product category level, and a fallback is made on the parent locations if none is set here."),
'putaway_strategy_id': fields.many2one('product.putaway', 'Put Away Strategy', help="Defines the default method used for suggesting the exact location (shelf) where to store the products. This method can be enforced at the product category level, and a fallback is made on the parent locations if none is set here."),
'barcode': fields.char('Barcode', copy=False, oldname='loc_barcode'),
}
_defaults = {
'active': True,
'usage': 'internal',
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.location', context=c),
'posx': 0,
'posy': 0,
'posz': 0,
'scrap_location': False,
}
_sql_constraints = [('barcode_company_uniq', 'unique (barcode,company_id)', 'The barcode for a location must be unique per company !')]
def default_get(self, cr, uid, fields, context=None):
res = super(stock_location, self).default_get(cr, uid, fields, context=context)
if 'barcode' in fields and 'barcode' not in res and res.get('complete_name'):
res['barcode'] = res['complete_name']
return res
def get_putaway_strategy(self, cr, uid, ids, product, context=None):
''' Returns the location where the product has to be put, if any compliant putaway strategy is found. Otherwise returns None.'''
location = self.browse(cr, uid, ids[0], context=context)
putaway_obj = self.pool.get('product.putaway')
loc = location
while loc:
if loc.putaway_strategy_id:
res = putaway_obj.putaway_apply(cr, uid, loc.putaway_strategy_id, product, context=context)
if res:
return res
loc = loc.location_id
def get_warehouse(self, cr, uid, ids, context=None):
"""
Returns warehouse id of warehouse that contains location
:param location: browse record (stock.location)
"""
location = self.browse(cr, uid, ids[0], context=context)
wh_obj = self.pool.get("stock.warehouse")
whs = wh_obj.search(cr, uid, [('view_location_id.parent_left', '<=', location.parent_left),
('view_location_id.parent_right', '>=', location.parent_left)], context=context)
return whs and whs[0] or False
#----------------------------------------------------------
# Routes
#----------------------------------------------------------
class stock_location_route(osv.osv):
_name = 'stock.location.route'
_description = "Inventory Routes"
_order = 'sequence'
_columns = {
'name': fields.char('Route Name', required=True, translate=True),
'sequence': fields.integer('Sequence'),
'pull_ids': fields.one2many('procurement.rule', 'route_id', 'Procurement Rules', copy=True),
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the route without removing it."),
'push_ids': fields.one2many('stock.location.path', 'route_id', 'Push Rules', copy=True),
'product_selectable': fields.boolean('Applicable on Product', help="When checked, the route will be selectable in the Inventory tab of the Product form. It will take priority over the Warehouse route. "),
'product_categ_selectable': fields.boolean('Applicable on Product Category', help="When checked, the route will be selectable on the Product Category. It will take priority over the Warehouse route. "),
'warehouse_selectable': fields.boolean('Applicable on Warehouse', help="When a warehouse is selected for this route, this route should be seen as the default route when products pass through this warehouse. This behaviour can be overridden by the routes on the Product/Product Categories or by the Preferred Routes on the Procurement"),
'supplied_wh_id': fields.many2one('stock.warehouse', 'Supplied Warehouse'),
'supplier_wh_id': fields.many2one('stock.warehouse', 'Supplying Warehouse'),
'company_id': fields.many2one('res.company', 'Company', select=1, help='Leave this field empty if this route is shared between all companies'),
#Reverse many2many fields:
'product_ids': fields.many2many('product.template', 'stock_route_product', 'route_id', 'product_id', 'Products'),
'categ_ids': fields.many2many('product.category', 'stock_location_route_categ', 'route_id', 'categ_id', 'Product Categories'),
'warehouse_ids': fields.many2many('stock.warehouse', 'stock_route_warehouse', 'route_id', 'warehouse_id', 'Warehouses'),
}
_defaults = {
'sequence': lambda self, cr, uid, ctx: 0,
'active': True,
'product_selectable': True,
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.location.route', context=c),
}
def write(self, cr, uid, ids, vals, context=None):
'''when a route is deactivated, deactivate also its pull and push rules'''
if isinstance(ids, (int, long)):
ids = [ids]
res = super(stock_location_route, self).write(cr, uid, ids, vals, context=context)
if 'active' in vals:
push_ids = []
pull_ids = []
for route in self.browse(cr, uid, ids, context=context):
if route.push_ids:
push_ids += [r.id for r in route.push_ids if r.active != vals['active']]
if route.pull_ids:
pull_ids += [r.id for r in route.pull_ids if r.active != vals['active']]
if push_ids:
self.pool.get('stock.location.path').write(cr, uid, push_ids, {'active': vals['active']}, context=context)
if pull_ids:
self.pool.get('procurement.rule').write(cr, uid, pull_ids, {'active': vals['active']}, context=context)
return res
def view_product_ids(self, cr, uid, ids, context=None):
return {
'name': _('Products'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'product.template',
'type': 'ir.actions.act_window',
'domain': [('route_ids', 'in', ids[0])],
}
def view_categ_ids(self, cr, uid, ids, context=None):
return {
'name': _('Product Categories'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'product.category',
'type': 'ir.actions.act_window',
'domain': [('route_ids', 'in', ids[0])],
}
class stock_production_lot(osv.osv):
_name = 'stock.production.lot'
@@ -281,95 +78,3 @@ class stock_production_lot(osv.osv):
'type': 'ir.actions.act_window',
}
return False
# WHERE IS ORDERPOINT ?
#----------------------------------------------------------
# Stock Warehouse
#----------------------------------------------------------
class stock_location_path(osv.osv):
_name = "stock.location.path"
_description = "Pushed Flows"
_order = "name"
def _get_rules(self, cr, uid, ids, context=None):
res = []
for route in self.browse(cr, uid, ids, context=context):
res += [x.id for x in route.push_ids]
return res
_columns = {
'name': fields.char('Operation Name', required=True),
'company_id': fields.many2one('res.company', 'Company'),
'route_id': fields.many2one('stock.location.route', 'Route'),
'location_from_id': fields.many2one('stock.location', 'Source Location', ondelete='cascade', select=1, required=True,
help="This rule can be applied when a move is confirmed that has this location as destination location"),
'location_dest_id': fields.many2one('stock.location', 'Destination Location', ondelete='cascade', select=1, required=True,
help="The new location where the goods need to go"),
'delay': fields.integer('Delay (days)', help="Number of days needed to transfer the goods"),
'picking_type_id': fields.many2one('stock.picking.type', 'Picking Type', required=True,
help="This is the picking type that will be put on the stock moves"),
'auto': fields.selection(
[('manual','Manual Operation'),('transparent','Automatic No Step Added')],
'Automatic Move',
required=True, select=1,
help="The 'Manual Operation' value will create a stock move after the current one. " \
"With 'Automatic No Step Added', the location is replaced in the original move."
),
'propagate': fields.boolean('Propagate cancel and split', help='If checked, when the previous move is cancelled or split, the move generated by this move will too'),
'active': fields.boolean('Active'),
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse'),
'route_sequence': fields.related('route_id', 'sequence', string='Route Sequence',
store={
'stock.location.route': (_get_rules, ['sequence'], 10),
'stock.location.path': (lambda self, cr, uid, ids, c={}: ids, ['route_id'], 10),
}),
'sequence': fields.integer('Sequence'),
}
_defaults = {
'auto': 'manual',
'delay': 0,
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'procurement.order', context=c),
'propagate': True,
'active': True,
}
def _prepare_push_apply(self, cr, uid, ids, move, context=None):
rule = self.browse(cr, uid, ids[0], context=context)
newdate = (datetime.strptime(move.date_expected, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta.relativedelta(days=rule.delay or 0)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
return {
'origin': move.origin or move.picking_id.name or "/",
'location_id': move.location_dest_id.id,
'location_dest_id': rule.location_dest_id.id,
'date': newdate,
'company_id': rule.company_id and rule.company_id.id or False,
'date_expected': newdate,
'picking_id': False,
'picking_type_id': rule.picking_type_id and rule.picking_type_id.id or False,
'propagate': rule.propagate,
'push_rule_id': rule.id,
'warehouse_id': rule.warehouse_id and rule.warehouse_id.id or False,
}
def _apply(self, cr, uid, ids, move, context=None):
rule = self.browse(cr, uid, ids[0], context=context)
move_obj = self.pool.get('stock.move')
newdate = (datetime.strptime(move.date_expected, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta.relativedelta(days=rule.delay or 0)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
if rule.auto == 'transparent':
old_dest_location = move.location_dest_id.id
move_obj.write(cr, uid, [move.id], {
'date': newdate,
'date_expected': newdate,
'location_dest_id': rule.location_dest_id.id
})
#avoid looping if a push rule is not well configured
if rule.location_dest_id.id != old_dest_location:
#call again push_apply to see if a next step is defined
move._push_apply()
else:
vals = self._prepare_push_apply(cr, uid, [rule.id], move, context=context)
move_id = move_obj.copy(cr, uid, move.id, vals, context=context)
move_obj.write(cr, uid, [move.id], {
'move_dest_id': move_id,
})
move_obj.action_confirm(cr, uid, [move_id], context=None)
-290
View File
@@ -84,190 +84,6 @@
parent="menu_stock_inventory_control" groups="stock.group_production_lot"
sequence="101"/>
#
# Lot composition (history)
#
<act_window
context="{'location': active_id, 'search_default_real_stock_available': 1, 'search_default_virtual_stock_available': 1,
'search_default_virtual_stock_negative': 1, 'search_default_real_stock_negative': 1}"
id="act_product_location_open"
name="Products"
res_model="product.product"
src_model="stock.location"/>
<record id="view_location_form" model="ir.ui.view">
<field name="name">stock.location.form</field>
<field name="model">stock.location</field>
<field name="arch" type="xml">
<form string="Stock Location">
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
</button>
<button string="Current Stock"
class="oe_stat_button"
icon="fa-building-o" name="%(location_open_quants)d" type="action"
context="{'search_default_internal_loc': 1}"/>
<button string="Products"
class="oe_stat_button"
icon="fa-filter" name="%(act_product_location_open)d" type="action"
context="{'location_id': active_id}"
/>
</div>
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
<label for="location_id" class="oe_edit_only"/>
<h2><field name="location_id"/></h2>
<group>
<group string="Additional Information">
<field name="usage"/>
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="scrap_location"/>
<field name="return_location"/>
</group>
<group string="Localization" name="localization">
<field name="posx"/>
<field name="posy"/>
<field name="posz"/>
<field name="barcode"/>
</group>
<group string="Logistics" groups="stock.group_adv_location">
<field name="removal_strategy_id" options="{'no_create': True}"/>
<field name="putaway_strategy_id"/>
</group>
</group>
<field name="comment" placeholder="External note..."/>
</form>
</field>
</record>
<record id="view_location_search" model="ir.ui.view">
<field name="name">stock.location.search</field>
<field name="model">stock.location</field>
<field name="arch" type="xml">
<search string="Stock Locations">
<field name="name" string="Stock Locations"/>
<filter name="in_location" string="Internal" domain="[('usage', '=', 'internal')]" help="Internal Locations"/>
<filter name="customer" string="Customer" domain="[('usage', '=', 'customer')]" help="Customer Locations"/>
<filter name="supplier" string="Vendor" domain="[('usage', '=', 'supplier')]" help="Vendor Locations"/>
<field name="location_id" string="Parent Location"/>
<separator/>
<filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
</search>
</field>
</record>
<record id="view_location_tree2" model="ir.ui.view">
<field name="name">stock.location.tree</field>
<field name="model">stock.location</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<tree string="Stock Location" decoration-info="usage=='view'" decoration-danger="usage=='internal'">
<field name="active" invisible="1"/>
<field name="complete_name"/>
<field name="usage"/>
<field name="company_id" groups="base.group_multi_company"/>
</tree>
</field>
</record>
<record id="stock_location_path_filter" model="ir.ui.view">
<field name="name">stock.location.path.select</field>
<field name="model">stock.location.path</field>
<field name="arch" type="xml">
<search string="Search Stock Location Paths">
<filter string="Global" name="route_false" domain="[('route_id','=',False)]" help="If the route is global"/>
<separator/>
<filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
</search>
</field>
</record>
<record id="stock_location_path_tree" model="ir.ui.view">
<field name="name">stock.location.path.tree</field>
<field name="model">stock.location.path</field>
<field name="arch" type="xml">
<tree string="Location Paths">
<field name="location_from_id" />
<field name="location_dest_id" />
<field name="name" />
<field name="active" invisible="1"/>
</tree>
</field>
</record>
<record id="stock_location_path_form" model="ir.ui.view">
<field name="name">stock.location.path.form</field>
<field name="model">stock.location.path</field>
<field name="arch" type="xml">
<form string="Location Paths">
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive" groups="stock.group_adv_location">
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
</button>
</div>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
</div>
<group>
<group>
<field name="sequence"/>
</group>
</group>
<group>
<group string="Locations">
<field name="location_from_id"/>
<field name="location_dest_id"/>
</group>
<group string="Details">
<field name="auto"/>
<field name="picking_type_id"/>
<field name="company_id" groups="base.group_multi_company" />
<label for="delay" string="Delay"/>
<div>
<field name="delay" class="oe_inline"/>days
</div>
</group>
</group>
</form>
</field>
</record>
<record id="action_location_form" model="ir.actions.act_window">
<field name="name">Locations</field>
<field name="res_model">stock.location</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_location_tree2"/>
<field name="search_view_id" ref="view_location_search"/>
<field name="context">{'search_default_in_location':1}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to add a location.
</p><p>
Define your locations to reflect your warehouse structure and
organization. Odoo is able to manage physical locations
(warehouses, shelves, bin, etc), partner locations (customers,
vendors) and virtual locations which are the counterpart of
the stock operations like the manufacturing orders
consumptions, inventories, etc.
</p><p>
Every stock operation in Odoo moves the products from one
location to another one. For instance, if you receive products
from a vendor, Odoo will move products from the Vendor
location to the Stock location. Each report can be performed on
physical, partner or virtual locations.
</p>
</field>
</record>
<menuitem action="action_location_form" id="menu_action_location_form"
groups="stock.group_stock_multi_locations"
parent="menu_warehouse_config" sequence="2"/>
<!--
Stock picking
Defaults and Internal Pickings
@@ -321,111 +137,5 @@
</record>
<menuitem action="action_incoterms_tree" id="menu_action_incoterm_open" parent="menu_warehouse_config" sequence="5" groups="base.group_no_one"/>
<record model="ir.actions.act_window" id="stolocpath">
<field name="context">{'search_default_route_false':1}</field>
<field name="name">Push Rules</field>
<field name="res_model">stock.location.path</field>
</record>
<menuitem id="menu_stock_location_path" name="Global Push Rules" parent="stock.menu_routes_config" action="stolocpath" groups="base.group_no_one" sequence="4"/>
<!--Routes-->
<record id="stock_location_route_tree" model="ir.ui.view">
<field name="name">stock.location.route.tree</field>
<field name="model">stock.location.route</field>
<field name="arch" type="xml">
<tree string="Routes">
<field name="sequence" widget="handle" />
<field name="name"/>
<field name="active" invisible="1"/>
</tree>
</field>
</record>
<record id="stock_location_route_form_view" model="ir.ui.view">
<field name="name">stock.location.route.form</field>
<field name="model">stock.location.route</field>
<field eval="7" name="priority" />
<field name="arch" type="xml">
<form string="Route">
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive" groups="stock.group_adv_location">
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
</button>
</div>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
</div>
<group>
<group>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
</group>
<group>
<field name="sequence" string="Sequence" groups="base.group_no_one"/>
</group>
</group>
<separator string="Applicable On"/>
<p class="oe_grey">Select the places where this route can be selected</p>
<group>
<group>
<button name="view_categ_ids" for="product_categ_selectable" type="object" string="Product Categories" class="oe_link"/>
<div>
<field name="product_categ_selectable" class="oe_inline"/>
</div>
<button name="view_product_ids" for="product_selectable" type="object" string="Products" class="oe_link"/>
<div>
<field name="product_selectable" class="oe_inline"/>
</div>
</group>
<group>
<field name="warehouse_selectable" string="Warehouses"/>
<field name="warehouse_ids" widget="many2many_tags" nolabel="1"
attrs="{'readonly': [('warehouse_selectable', '=', False)]}"/>
</group>
</group>
<group string="Push Rules" colspan="4" >
<field name="push_ids" colspan="4" nolabel="1"/>
</group>
<group string="Procurement Rules" colspan="4" >
<field name="pull_ids" colspan="4" nolabel="1"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="stock_location_route_view_search" model="ir.ui.view">
<field name="name">stock.location.route.search</field>
<field name="model">stock.location.route</field>
<field name="arch" type="xml">
<search string="Route">
<filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
</search>
</field>
</record>
<record id="action_routes_form" model="ir.actions.act_window">
<field name="name">Routes</field>
<field name="res_model">stock.location.route</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="stock_location_route_tree" />
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to add a route.
</p>
<p>You can define here the main routes that run through
your warehouses and that define the flows of your products. These
routes can be assigned to a product, a product category or be fixed
on procurement or sales order. </p>
</field>
</record>
<menuitem action="action_routes_form" id="menu_stock_routes"
parent="stock.menu_routes_config" sequence="1" />
</data>
</openerp>
+290
View File
@@ -0,0 +1,290 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<act_window
context="{'location': active_id, 'search_default_real_stock_available': 1, 'search_default_virtual_stock_available': 1,
'search_default_virtual_stock_negative': 1, 'search_default_real_stock_negative': 1}"
id="act_product_location_open"
name="Products"
res_model="product.product"
src_model="stock.location"/>
<record id="view_location_form" model="ir.ui.view">
<field name="name">stock.location.form</field>
<field name="model">stock.location</field>
<field name="arch" type="xml">
<form string="Stock Location">
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
</button>
<button string="Current Stock"
class="oe_stat_button"
icon="fa-building-o" name="%(location_open_quants)d" type="action"
context="{'search_default_internal_loc': 1}"/>
<button string="Products"
class="oe_stat_button"
icon="fa-filter" name="%(act_product_location_open)d" type="action"
context="{'location_id': active_id}"
/>
</div>
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
<label for="location_id" class="oe_edit_only"/>
<h2><field name="location_id"/></h2>
<group>
<group string="Additional Information">
<field name="usage"/>
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="scrap_location"/>
<field name="return_location"/>
</group>
<group string="Localization" name="localization">
<field name="posx"/>
<field name="posy"/>
<field name="posz"/>
<field name="barcode"/>
</group>
<group string="Logistics" groups="stock.group_adv_location">
<field name="removal_strategy_id" options="{'no_create': True}"/>
<field name="putaway_strategy_id"/>
</group>
</group>
<field name="comment" placeholder="External note..."/>
</form>
</field>
</record>
<record id="view_location_search" model="ir.ui.view">
<field name="name">stock.location.search</field>
<field name="model">stock.location</field>
<field name="arch" type="xml">
<search string="Stock Locations">
<field name="name" string="Stock Locations"/>
<filter name="in_location" string="Internal" domain="[('usage', '=', 'internal')]" help="Internal Locations"/>
<filter name="customer" string="Customer" domain="[('usage', '=', 'customer')]" help="Customer Locations"/>
<filter name="supplier" string="Vendor" domain="[('usage', '=', 'supplier')]" help="Vendor Locations"/>
<field name="location_id" string="Parent Location"/>
<separator/>
<filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
</search>
</field>
</record>
<record id="view_location_tree2" model="ir.ui.view">
<field name="name">stock.location.tree</field>
<field name="model">stock.location</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<tree string="Stock Location" decoration-info="usage=='view'" decoration-danger="usage=='internal'">
<field name="active" invisible="1"/>
<field name="complete_name"/>
<field name="usage"/>
<field name="company_id" groups="base.group_multi_company"/>
</tree>
</field>
</record>
<record id="action_location_form" model="ir.actions.act_window">
<field name="name">Locations</field>
<field name="res_model">stock.location</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_location_tree2"/>
<field name="search_view_id" ref="view_location_search"/>
<field name="context">{'search_default_in_location':1}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to add a location.
</p><p>
Define your locations to reflect your warehouse structure and
organization. Odoo is able to manage physical locations
(warehouses, shelves, bin, etc), partner locations (customers,
vendors) and virtual locations which are the counterpart of
the stock operations like the manufacturing orders
consumptions, inventories, etc.
</p><p>
Every stock operation in Odoo moves the products from one
location to another one. For instance, if you receive products
from a vendor, Odoo will move products from the Vendor
location to the Stock location. Each report can be performed on
physical, partner or virtual locations.
</p>
</field>
</record>
<menuitem action="action_location_form" id="menu_action_location_form"
groups="stock.group_stock_multi_locations"
parent="menu_warehouse_config" sequence="2"/>
<record id="stock_location_path_filter" model="ir.ui.view">
<field name="name">stock.location.path.select</field>
<field name="model">stock.location.path</field>
<field name="arch" type="xml">
<search string="Search Stock Location Paths">
<filter string="Global" name="route_false" domain="[('route_id','=',False)]" help="If the route is global"/>
<separator/>
<filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
</search>
</field>
</record>
<record id="stock_location_path_tree" model="ir.ui.view">
<field name="name">stock.location.path.tree</field>
<field name="model">stock.location.path</field>
<field name="arch" type="xml">
<tree string="Location Paths">
<field name="location_from_id" />
<field name="location_dest_id" />
<field name="name" />
<field name="active" invisible="1"/>
</tree>
</field>
</record>
<record id="stock_location_path_form" model="ir.ui.view">
<field name="name">stock.location.path.form</field>
<field name="model">stock.location.path</field>
<field name="arch" type="xml">
<form string="Location Paths">
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive" groups="stock.group_adv_location">
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
</button>
</div>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
</div>
<group>
<group>
<field name="sequence"/>
</group>
</group>
<group>
<group string="Locations">
<field name="location_from_id"/>
<field name="location_dest_id"/>
</group>
<group string="Details">
<field name="auto"/>
<field name="picking_type_id"/>
<field name="company_id" groups="base.group_multi_company" />
<label for="delay" string="Delay"/>
<div>
<field name="delay" class="oe_inline"/>days
</div>
</group>
</group>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="stolocpath">
<field name="context">{'search_default_route_false':1}</field>
<field name="name">Push Rules</field>
<field name="res_model">stock.location.path</field>
</record>
<menuitem id="menu_stock_location_path" name="Global Push Rules" parent="stock.menu_routes_config" action="stolocpath" groups="base.group_no_one" sequence="4"/>
<!--Routes-->
<record id="stock_location_route_tree" model="ir.ui.view">
<field name="name">stock.location.route.tree</field>
<field name="model">stock.location.route</field>
<field name="arch" type="xml">
<tree string="Routes">
<field name="sequence" widget="handle" />
<field name="name"/>
<field name="active" invisible="1"/>
</tree>
</field>
</record>
<record id="stock_location_route_form_view" model="ir.ui.view">
<field name="name">stock.location.route.form</field>
<field name="model">stock.location.route</field>
<field eval="7" name="priority" />
<field name="arch" type="xml">
<form string="Route">
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive" groups="stock.group_adv_location">
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
</button>
</div>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
</div>
<group>
<group>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
</group>
<group>
<field name="sequence" string="Sequence" groups="base.group_no_one"/>
</group>
</group>
<separator string="Applicable On"/>
<p class="oe_grey">Select the places where this route can be selected</p>
<group>
<group>
<button name="view_categ_ids" for="product_categ_selectable" type="object" string="Product Categories" class="oe_link"/>
<div>
<field name="product_categ_selectable" class="oe_inline"/>
</div>
<button name="view_product_ids" for="product_selectable" type="object" string="Products" class="oe_link"/>
<div>
<field name="product_selectable" class="oe_inline"/>
</div>
</group>
<group>
<field name="warehouse_selectable" string="Warehouses"/>
<field name="warehouse_ids" widget="many2many_tags" nolabel="1"
attrs="{'readonly': [('warehouse_selectable', '=', False)]}"/>
</group>
</group>
<group string="Push Rules" colspan="4" >
<field name="push_ids" colspan="4" nolabel="1"/>
</group>
<group string="Procurement Rules" colspan="4" >
<field name="pull_ids" colspan="4" nolabel="1"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="stock_location_route_view_search" model="ir.ui.view">
<field name="name">stock.location.route.search</field>
<field name="model">stock.location.route</field>
<field name="arch" type="xml">
<search string="Route">
<filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
</search>
</field>
</record>
<record id="action_routes_form" model="ir.actions.act_window">
<field name="name">Routes</field>
<field name="res_model">stock.location.route</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="stock_location_route_tree" />
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to add a route.
</p>
<p>You can define here the main routes that run through
your warehouses and that define the flows of your products. These
routes can be assigned to a product, a product category or be fixed
on procurement or sales order. </p>
</field>
</record>
<menuitem action="action_routes_form" id="menu_stock_routes"
parent="stock.menu_routes_config" sequence="1" />
</odoo>