[ADD]wizard to configure a new wh in settings + change on data in stock_multi_wh

bzr revid: csn@openerp.com-20130909153255-wnhc2vxlcvidk4kh
This commit is contained in:
Cedric Snauwaert 2013-09-09 17:32:55 +02:00
parent 15dd2573d5
commit b84b805a36
8 changed files with 339 additions and 101 deletions

View File

@ -243,5 +243,20 @@ watch your stock valuation, and track production lots upstream and downstream (b
<field name="number_next">1</field>
<field name="number_increment">1</field>
</record>
<!--
Add Warehouse to picking_type
-->
<record id="picking_type_in" model="stock.picking.type">
<field name="warehouse_id" ref="warehouse0"/>
</record>
<record id="picking_type_out" model="stock.picking.type">
<field name="warehouse_id" ref="warehouse0"/>
</record>
<record id="picking_type_internal" model="stock.picking.type">
<field name="warehouse_id" ref="warehouse0"/>
</record>
</data>
</openerp>

View File

@ -19,4 +19,6 @@
#
##############################################################################
import wizard
import stock_location

View File

@ -96,10 +96,12 @@ You can use the demo data as follow:
'author': 'OpenERP SA',
'images': ['images/pulled_flow.jpeg','images/pushed_flow.jpeg'],
'depends': ['procurement','stock'],
'data': ['stock_location_view.xml',
'data': ['wizard/configure_wh_view.xml',
'stock_location_view.xml',
'stock_location_data.xml',
'security/stock_location_security.xml',
'security/ir.model.access.csv'],
'security/ir.model.access.csv',
'res_config_view.xml'],
'demo': [
'stock_location_demo_cpu1.xml',
'stock_location_demo_cpu3.yml',

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_stock_location_config_settings" model="ir.ui.view">
<field name="name">stock settings</field>
<field name="model">stock.config.settings</field>
<field name="inherit_id" ref="stock.view_stock_config_settings"/>
<field name="arch" type="xml">
<separator string="Location &amp; Warehouse" position="before">
<button name="%(action_view_stock_configure_wh)d" string="Configure a new warehouse" type="action"/>
</separator>
</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1 @@
import configure_wh

View File

@ -0,0 +1,183 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
class stock_configure_wh(osv.osv_memory):
_name = "stock.configure.wh"
_description = "Configure New WH"
_columns = {
'name': fields.char('Warehouse Name', required=True),
'address_id': fields.many2one('res.partner', 'Warehouse Address'),
'internal_stock_loc_id': fields.many2one('stock.location', 'Internal Stock Location', required=True),
'input_stock_loc_id': fields.many2one('stock.location', 'Input Location', required=True),
'output_stock_loc_id': fields.many2one('stock.location', 'Output Location', required=True),
'crossdock': fields.boolean('Crossdock', help='Whether this warehouse uses generally crossdock operations or not'),
'packing': fields.boolean('Packing', help='Whether we make packing in that warehouse while making outgoing shipments or not'),
'packing_loc_id': fields.many2one('stock.location', 'Packing Zone Location')
}
def onchange_crossdock(self, cr, uid, ids, crossdock=False, context=None):
if crossdock:
return {'value': {'packing': False, 'packing_loc_id': False}}
return True
def onchange_packing(self, cr, uid, ids, packing=False, stock_loc=False, context=None):
if packing:
return {'value': {'packing_loc_id': stock_loc}}
return True
def configure_wh(self, cr, uid, ids, context=None):
""" To Import stock inventory according to products available in the selected locations.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: the ID or list of IDs if we want more than one
@param context: A standard dictionary
@return:
"""
if context is None:
context = {}
route_obj = self.pool.get('stock.location.route')
pull_obj = self.pool.get('procurement.rule')
inventory_obj = self.pool.get('stock.inventory')
if ids and len(ids):
ids = ids[0]
obj = self.browse(cr, uid, ids, context=context)
data_obj = self.pool.get('ir.model.data')
wh_stock_loc = obj.internal_stock_loc_id.id
wh_input_stock_loc = obj.input_stock_loc_id.id
wh_output_stock_loc = obj.output_stock_loc_id.id
customer_loc = data_obj.get_object_reference(cr, uid, 'stock', 'stock_location_customers')[1]
supplier_loc = data_obj.get_object_reference(cr, uid, 'stock', 'stock_location_suppliers')[1]
#create route
new_route_id = False
route_data = {
'name': obj.name+': Ship',
'warehouse_selectable': True,
'product_selectable': False,
}
if wh_stock_loc != wh_output_stock_loc:
if obj.packing:
route_data['name'] = obj.name+': Pick + Pack + Ship'
else:
route_data['name'] = obj.name+': Pick + Ship'
new_route_id = route_obj.create(cr, uid, vals=route_data, context=context)
#create wh
wh_data = {
'name': obj.name,
'address_id': obj.address_id and obj.address_id.id or False,
'lot_stock_id': wh_stock_loc,
'route_id': new_route_id,
}
wh_obj = self.pool.get('stock.warehouse')
new_wh_id = wh_obj.create(cr, uid, vals=wh_data, context=context)
#create in, out, internal picking types for wh
#First create new sequence
seq_obj = self.pool.get('ir.sequence')
in_seq_id = seq_obj.create(cr, uid, values={'name': 'Picking in', 'prefix': 'IN', 'padding': 5}, context=context)
out_seq_id = seq_obj.create(cr, uid, values={'name': 'Picking out', 'prefix': 'OUT', 'padding': 5}, context=context)
internal_seq_id = seq_obj.create(cr, uid, values={'name': 'Picking internal', 'prefix': 'INT', 'padding': 5}, context=context)
#then create picking_type
picking_obj = self.pool.get('stock.picking.type')
in_picking_id = picking_obj.create(cr, uid, vals={'name': 'Receptions', 'warehouse_id': new_wh_id, 'code_id': 'incoming', 'sequence_id': in_seq_id, 'default_location_src_id': supplier_loc, 'default_location_dest_id': wh_stock_loc}, context=context)
out_picking_id = picking_obj.create(cr, uid, vals={'name': 'Delivery Orders', 'warehouse_id': new_wh_id, 'code_id': 'outgoing', 'sequence_id': out_seq_id, 'default_location_src_id': wh_stock_loc, 'default_location_dest_id': customer_loc}, context=context)
internal_picking_id = picking_obj.create(cr, uid, vals={'name': 'Internal Transfers', 'warehouse_id': new_wh_id, 'code_id': 'internal', 'sequence_id': internal_seq_id, 'default_location_src_id': wh_stock_loc, 'default_location_dest_id': wh_stock_loc, 'pack': obj.packing}, context=context)
#add pull rules to default route
#ship pull rules
pull_data = {
'name': obj.name+': Stock -> customer',
'location_src_id': wh_stock_loc,
'location_id': customer_loc,
'propagate': True,
'route_id': new_route_id,
'action': 'move',
'picking_type_id': internal_picking_id,
'procure_method': 'make_to_stock'
}
#ship rules
if wh_stock_loc == wh_output_stock_loc:
pull_obj.create(cr, uid, vals=pull_data, context=context)
#pick-pack-ship rules
elif obj.packing:
#if packing zone is the same as output or stock, only create one pull rule, otherwise, create two
if obj.packing_loc_id.id == wh_stock_loc:
pull_data.update({
'name': obj.name + ' Stock -> Output',
'location_id': wh_output_stock_loc,
})
pull_obj.create(cr, uid, vals=pull_data, context=context)
else:
pull_data.update({
'name': obj.name+' Stock -> Pack',
'location_id': obj.packing_loc_id.id,
})
pull_obj.create(cr, uid, vals=pull_data, context=context)
pull_data.update({
'name': obj.name+' Pack -> Output',
'location_src_id': obj.packing_loc_id.id,
'location_id': wh_output_stock_loc,
'picking_type_id': internal_picking_id,
'procure_method': 'make_to_order',
})
pull_obj.create(cr, uid, vals=pull_data, context=context)
pull_data.update({
'name': obj.name+' Output -> Customer',
'location_src_id': wh_output_stock_loc,
'location_id': customer_loc,
'picking_type_id': out_picking_id,
'procure_method': 'make_to_order',
})
pull_obj.create(cr, uid, vals=pull_data, context=context)
#pick-ship rules
else:
pull_data.update({
'name': obj.name + ' Stock -> Output',
'location_id': wh_output_stock_loc,
})
pull_obj.create(cr, uid, vals=pull_data, context=context)
pull_data.update({
'name': obj.name+' Output -> Customer',
'location_src_id': wh_output_stock_loc,
'location_id': customer_loc,
'picking_type_id': out_picking_id,
'procure_method': 'make_to_order',
})
pull_obj.create(cr, uid, vals=pull_data, context=context)
return {'type': 'ir.actions.act_window_close'}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="stock_configure_wh" model="ir.ui.view">
<field name="name">Configure Warehouse</field>
<field name="model">stock.configure.wh</field>
<field name="arch" type="xml">
<form string="Configure Warehouse" version="7.0">
<sheet>
<separator string="Warehouse Informations"/>
<group>
<group>
<field name="name"/>
<field name="address_id"/>
</group>
<group>
<field name="crossdock" on_change="onchange_crossdock(crossdock)"/>
<field name="packing" attrs="{'invisible': [('crossdock', '=', True)]}" on_change="onchange_packing(packing, internal_stock_loc_id)"/>
</group>
</group>
<separator string="Warehouse locations"/>
<group>
<field name="internal_stock_loc_id"/>
<field name="input_stock_loc_id"/>
<field name="output_stock_loc_id"/>
<field name="packing_loc_id" attrs="{'invisible': [('packing', '=', False)], 'required': [('packing', '=', True)]}"/>
</group>
<footer>
<button name="configure_wh" string="Configure Warehouse" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</sheet>
</form>
</field>
</record>
<record id="action_view_stock_configure_wh" model="ir.actions.act_window">
<field name="name">Configure Warehouse</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">stock.configure.wh</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="stock_configure_wh"/>
<field name="target">new</field>
</record>
</data>
</openerp>

View File

@ -19,43 +19,43 @@
-
Create Location structure of Warehouse Panama Santiago District
-
!record {model: stock.location, id: location_panama_santiago}:
!record {model: stock.location, id: location_wh1}:
name: Panama Santiago District Warehouse
location_id: location_panama
-
Input
-
!record {model: stock.location, id: location_panama_santiago_input}:
!record {model: stock.location, id: location_wh1_input}:
name: Input
location_id: location_panama_santiago
location_id: location_wh1
-
Output
-
!record {model: stock.location, id: location_panama_santiago_output}:
!record {model: stock.location, id: location_wh1_output}:
name: Output
location_id: location_panama_santiago
location_id: location_wh1
-
Stock
-
!record {model: stock.location, id: location_panama_santiago_stock}:
!record {model: stock.location, id: location_wh1_stock}:
name: Stock
location_id: location_panama_santiago
location_id: location_wh1
-
!record {model: stock.location, id: location_panama_santiago_stock_area1}:
!record {model: stock.location, id: location_wh1_stock_area1}:
name: Area1
location_id: location_panama_santiago_stock
location_id: location_wh1_stock
-
!record {model: stock.location, id: location_panama_santiago_stock_area1_bin1}:
!record {model: stock.location, id: location_wh1_stock_area1_bin1}:
name: Bin1
location_id: location_panama_santiago_stock_area1
location_id: location_wh1_stock_area1
-
Create warehouse Panama Santiago District
-
!record {model: stock.warehouse, id: wh_panama_santiago}:
!record {model: stock.warehouse, id: wh_wh1}:
name: Panama Santiago District Warehouse
lot_stock_id: location_panama_santiago
lot_stock_id: location_wh1
-
Create picking type in for this warehouse
-
@ -63,8 +63,8 @@
name: Reception
code_id: incoming
sequence_id: stock.seq_picking_type_in
warehouse_id: wh_panama_santiago
default_location_dest_id: location_panama_santiago_input
warehouse_id: wh_wh1
default_location_dest_id: location_wh1_input
-
Create picking type out for this warehouse
-
@ -72,8 +72,8 @@
name: Deliveries
code_id: outgoing
sequence_id: stock.seq_picking_type_out
warehouse_id: wh_panama_santiago
default_location_src_id: location_panama_santiago_output
warehouse_id: wh_wh1
default_location_src_id: location_wh1_output
-
Create picking type internal for this warehouse
-
@ -81,44 +81,44 @@
name: Internal
code_id: internal
sequence_id: stock.seq_picking_type_internal
warehouse_id: wh_panama_santiago
default_location_src_id: location_panama_santiago_stock
default_location_dest_id: location_panama_santiago_stock
warehouse_id: wh_wh1
default_location_src_id: location_wh1_stock
default_location_dest_id: location_wh1_stock
-
Create Location structure of Warehouse Panama Main
-
!record {model: stock.location, id: location_panama_main}:
!record {model: stock.location, id: location_wh2}:
name: Panama Main Warehouse
location_id: location_panama
-
Input
-
!record {model: stock.location, id: location_panama_main_input}:
!record {model: stock.location, id: location_wh2_input}:
name: Input
location_id: location_panama_main
location_id: location_wh2
-
Output
-
!record {model: stock.location, id: location_panama_main_output}:
!record {model: stock.location, id: location_wh2_output}:
name: Output
location_id: location_panama_main
location_id: location_wh2
-
Stock
-
!record {model: stock.location, id: location_panama_main_stock}:
!record {model: stock.location, id: location_wh2_stock}:
name: Stock
location_id: location_panama_main
location_id: location_wh2
-
!record {model: stock.location, id: location_panama_main_stock_area2}:
!record {model: stock.location, id: location_wh2_stock_area2}:
name: Area2
location_id: location_panama_main_stock
location_id: location_wh2_stock
-
Create warehouse Panama main
-
!record {model: stock.warehouse, id: wh_panama_main}:
!record {model: stock.warehouse, id: wh_wh2}:
name: Panama Main Warehouse
lot_stock_id: location_panama_main
lot_stock_id: location_wh2
-
Create picking type in for warehouse panama main
-
@ -126,8 +126,8 @@
name: Reception
code_id: incoming
sequence_id: stock.seq_picking_type_in
warehouse_id: wh_panama_main
default_location_dest_id: location_panama_main_input
warehouse_id: wh_wh2
default_location_dest_id: location_wh2_input
-
Create picking type out for warehouse panama main
-
@ -135,8 +135,8 @@
name: Deliveries
code_id: outgoing
sequence_id: stock.seq_picking_type_out
warehouse_id: wh_panama_main
default_location_src_id: location_panama_main_output
warehouse_id: wh_wh2
default_location_src_id: location_wh2_output
-
Create picking type internal for warehouse panama main
-
@ -144,58 +144,27 @@
name: Internal
code_id: internal
sequence_id: stock.seq_picking_type_internal
warehouse_id: wh_panama_main
default_location_src_id: location_panama_main_stock
default_location_dest_id: location_panama_main_stock
warehouse_id: wh_wh2
default_location_src_id: location_wh2_stock
default_location_dest_id: location_wh2_stock
-
Create Location structure of Warehouse Dubai
-
!record {model: stock.location, id: location_panama_main}:
name: Panama Main Warehouse
location_id: location_panama
-
Create United Arab Emirates in Location structure
-
!record {model: stock.location, id: location_uae}:
name: United Arab Emirates
location_id: stock.stock_location_locations
-
Create Location structure of Dubai Warehouse
-
!record {model: stock.location, id: location_dubai}:
name: Dubai Warehouse
location_id: location_uae
child_ids:
- name: Input
- name: Output
- name: Stock
child_ids:
- name: Area3
-
Create Dubai warehouse
-
!record {model: stock.warehouse, id: wh_dubai}:
name: Dubai Warehouse
lot_stock_id: location_dubai
-
Create Ship Route for main panama warehouse
-
!record {model: stock.location.route, id: route_wh_panama_main_ship}:
!record {model: stock.location.route, id: route_wh_wh2_ship}:
name: Ship main panama
warehouse_selectable: True
product_selectable: False
pull_ids:
- invoice_state: none
location_id: location_panama_main_output
location_src_id: location_panama_main_stock
location_id: location_wh2_output
location_src_id: location_wh2_stock
name: Panama Main Stock -> Panama Main Output
procure_method: make_to_stock
picking_type_id: picking_type_main_internal
action: move
- invoice_state: none
location_id: stock.stock_location_customers
location_src_id: location_panama_main_output
location_src_id: location_wh2_output
name: Panama Main Output -> Customer
picking_type_id: picking_type_main_out
procure_method: make_to_order
@ -203,21 +172,21 @@
-
Create Ship Route for panama santiago warehouse
-
!record {model: stock.location.route, id: route_wh_panama_santiago_ship}:
!record {model: stock.location.route, id: route_wh_wh1_ship}:
name: Ship panama santiago
warehouse_selectable: True
product_selectable: False
pull_ids:
- invoice_state: none
location_id: location_panama_santiago_output
location_src_id: location_panama_santiago_stock
location_id: location_wh1_output
location_src_id: location_wh1_stock
name: Santiago Stock -> Santiago Output
procure_method: make_to_stock
picking_type_id: picking_type_santiago_internal
action: move
- invoice_state: none
location_id: stock.stock_location_customers
location_src_id: location_panama_santiago_output
location_src_id: location_wh1_output
name: Santiago Output -> Customer
picking_type_id: picking_type_santiago_out
procure_method: make_to_order
@ -226,8 +195,8 @@
Add routes to warehouses
-
!python {model: stock.warehouse}: |
self.write(cr, uid, [ref('wh_panama_main')], {'route_id': ref('route_wh_panama_main_ship')}, context=context)
self.write(cr, uid, [ref('wh_panama_santiago')], {'route_id': ref('route_wh_panama_santiago_ship')}, context=context)
self.write(cr, uid, [ref('wh_wh2')], {'route_id': ref('route_wh_wh2_ship'), 'lot_stock_id': ref('location_wh2_stock')}, context=context)
self.write(cr, uid, [ref('wh_wh1')], {'route_id': ref('route_wh_wh1_ship'), 'lot_stock_id': ref('location_wh1_stock')}, context=context)
-
Create Products
-
@ -339,7 +308,7 @@
-
!record {model: stock.inventory, id: inventory_stock1}:
name: Inventory Stock 1
location_id: location_panama_santiago_stock
location_id: location_wh1_stock
-
I create the wizard to confirm the inventory
-
@ -358,14 +327,14 @@
inventory_id: inventory_stock1
product_id: product_A
product_qty: 6
location_id: location_panama_santiago_stock
location_id: location_wh1_stock
-
!record {model: stock.inventory.line, id: inventory_stock1line_productB}:
inventory_id: inventory_stock1
product_id: product_B
product_qty: 12
location_id: location_panama_santiago_stock
location_id: location_wh1_stock
-
I confirm Stock1 inventory
-
@ -376,7 +345,7 @@
-
!record {model: stock.inventory, id: inventory_stock2}:
name: Inventory Stock 2
location_id: location_panama_main_stock
location_id: location_wh2_stock
-
I fill Stock2 inventory
-
@ -390,21 +359,21 @@
inventory_id: inventory_stock2
product_id: product_A
product_qty: 8
location_id: location_panama_main_stock
location_id: location_wh2_stock
-
!record {model: stock.inventory.line, id: inventory_stock2line_productB}:
inventory_id: inventory_stock2
product_id: product_B
product_qty: 120
location_id: location_panama_main_stock
location_id: location_wh2_stock
-
!record {model: stock.inventory.line, id: inventory_stock2line_productC_1}:
inventory_id: inventory_stock2
product_id: product_C
product_qty: 5
location_id: location_panama_main_stock
location_id: location_wh2_stock
prod_lot_id: lot003
-
@ -412,7 +381,7 @@
inventory_id: inventory_stock2
product_id: product_C
product_qty: 15
location_id: location_panama_main_stock
location_id: location_wh2_stock
prod_lot_id: lot004
-
I confirm Stock2 inventory
@ -424,7 +393,7 @@
-
!record {model: stock.inventory, id: inventory_stock1_area1}:
name: Inventory Stock1 area 1
location_id: location_panama_santiago_stock_area1
location_id: location_wh1_stock_area1
-
I fill Area1 inventory
-
@ -438,14 +407,14 @@
inventory_id: inventory_stock1_area1
product_id: product_D
product_qty: 4
location_id: location_panama_santiago_stock_area1
location_id: location_wh1_stock_area1
-
!record {model: stock.inventory.line, id: inventory_stock1line_productD_2}:
inventory_id: inventory_stock1_area1
product_id: product_D
product_qty: 5
location_id: location_panama_santiago_stock_area1
location_id: location_wh1_stock_area1
-
I confirm Area1 inventory
-
@ -456,7 +425,7 @@
-
!record {model: stock.inventory, id: inventory_stock2_area2}:
name: Inventory Stock2 area 2
location_id: location_panama_main_stock_area2
location_id: location_wh2_stock_area2
-
I fill Area2 inventory
-
@ -470,14 +439,14 @@
inventory_id: inventory_stock2_area2
product_id: product_D
product_qty: 2
location_id: location_panama_main_stock_area2
location_id: location_wh2_stock_area2
-
!record {model: stock.inventory.line, id: inventory_stock2line_productD_2}:
inventory_id: inventory_stock2_area2
product_id: product_D
product_qty: 3
location_id: location_panama_main_stock_area2
location_id: location_wh2_stock_area2
-
I confirm Area2 inventory
-
@ -489,7 +458,7 @@
-
!record {model: stock.inventory, id: inventory_stock1_area1_bin1}:
name: Inventory Stock1 area1 bin 1
location_id: location_panama_santiago_stock_area1_bin1
location_id: location_wh1_stock_area1_bin1
-
I fill Bin1 inventory
-
@ -503,7 +472,7 @@
inventory_id: inventory_stock1_area1_bin1
product_id: product_C
product_qty: 3
location_id: location_panama_santiago_stock_area1_bin1
location_id: location_wh1_stock_area1_bin1
prod_lot_id: lot001
-
@ -511,7 +480,7 @@
inventory_id: inventory_stock1_area1_bin1
product_id: product_C
product_qty: 14
location_id: location_panama_santiago_stock_area1_bin1
location_id: location_wh1_stock_area1_bin1
prod_lot_id: lot002
-
I confirm Bin1 inventory
@ -523,7 +492,7 @@
-
!record {model: sale.order, id: so1}:
partner_id: customer_1
warehouse_id: wh_panama_main
warehouse_id: wh_wh2
order_line:
- product_id: product_A
product_uom_qty: 7
@ -537,7 +506,7 @@
-
!record {model: sale.order, id: so2}:
partner_id: customer_1
warehouse_id: wh_panama_main
warehouse_id: wh_wh2
order_line:
- product_id: product_E
product_uom_qty: 5
@ -551,7 +520,7 @@
-
!record {model: sale.order, id: so3}:
partner_id: customer_2
warehouse_id: wh_panama_santiago
warehouse_id: wh_wh1
order_line:
- product_id: product_A
product_uom_qty: 5