2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2008-09-07 23:24:39 +00:00
##############################################################################
2010-06-15 08:14:32 +00:00
#
2009-10-14 11:15:34 +00:00
# OpenERP, Open Source Management Solution
2010-01-12 09:18:39 +00:00
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
2008-09-07 23:24:39 +00:00
#
2008-11-03 19:18:56 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 11:15:34 +00:00
# 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.
2008-09-07 23:24:39 +00:00
#
2008-11-03 19:18:56 +00:00
# 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
2009-10-14 11:15:34 +00:00
# GNU Affero General Public License for more details.
2008-09-07 23:24:39 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2010-06-15 08:14:32 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-09-07 23:24:39 +00:00
#
##############################################################################
2012-12-06 14:56:32 +00:00
from openerp . osv import fields , osv
2008-09-07 23:24:39 +00:00
class stock_location_path ( osv . osv ) :
_name = " stock.location.path "
2010-10-11 21:57:06 +00:00
_description = " Pushed Flows "
2008-09-07 23:24:39 +00:00
_columns = {
' name ' : fields . char ( ' Operation ' , size = 64 ) ,
2010-05-28 09:55:05 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' ) ,
2008-09-07 23:24:39 +00:00
' product_id ' : fields . many2one ( ' product.product ' , ' Products ' , ondelete = ' cascade ' , select = 1 ) ,
2010-06-15 08:14:32 +00:00
' journal_id ' : fields . many2one ( ' stock.journal ' , ' Journal ' ) ,
2010-10-11 21:57:06 +00:00
' location_from_id ' : fields . many2one ( ' stock.location ' , ' Source Location ' , ondelete = ' cascade ' , select = 1 , required = True ) ,
' location_dest_id ' : fields . many2one ( ' stock.location ' , ' Destination Location ' , ondelete = ' cascade ' , select = 1 , required = True ) ,
2008-09-07 23:24:39 +00:00
' delay ' : fields . integer ( ' Delay (days) ' , help = " Number of days to do this transition " ) ,
2010-06-10 13:00:36 +00:00
' invoice_state ' : fields . selection ( [
( " invoiced " , " Invoiced " ) ,
( " 2binvoiced " , " To Be Invoiced " ) ,
2010-10-28 07:20:11 +00:00
( " none " , " Not Applicable " ) ] , " Invoice Status " ,
2010-06-10 13:00:36 +00:00
required = True , ) ,
2010-10-11 21:57:06 +00:00
' picking_type ' : fields . selection ( [ ( ' out ' , ' Sending Goods ' ) , ( ' in ' , ' Getting Goods ' ) , ( ' internal ' , ' Internal ' ) ] , ' Shipping Type ' , required = True , select = True , help = " Depending on the company, choose whatever you want to receive or send products " ) ,
2008-09-07 23:24:39 +00:00
' auto ' : fields . selection (
[ ( ' auto ' , ' Automatic Move ' ) , ( ' manual ' , ' Manual Operation ' ) , ( ' transparent ' , ' Automatic No Step Added ' ) ] ,
' Automatic Move ' ,
required = True , select = 1 ,
help = " This is used to define paths the product has to follow within the location tree. \n " \
" The ' Automatic Move ' value will create a stock move after the current one that will be " \
" validated automatically. With ' Manual Operation ' , the stock move has to be validated " \
" by a worker. With ' Automatic No Step Added ' , the location is replaced in the original move. "
) ,
}
_defaults = {
2010-11-27 20:16:16 +00:00
' auto ' : ' auto ' ,
' delay ' : 1 ,
' invoice_state ' : ' none ' ,
' picking_type ' : ' internal ' ,
2008-09-07 23:24:39 +00:00
}
stock_location_path ( )
2010-05-28 09:55:05 +00:00
class product_pulled_flow ( osv . osv ) :
_name = ' product.pulled.flow '
2010-06-13 21:16:36 +00:00
_description = " Pulled Flows "
2010-05-28 09:55:05 +00:00
_columns = {
' name ' : fields . char ( ' Name ' , size = 64 , required = True , help = " This field will fill the packing Origin and the name of its moves " ) ,
' cancel_cascade ' : fields . boolean ( ' Cancel Cascade ' , help = " Allow you to cancel moves related to the product pull flow " ) ,
2010-12-16 16:37:31 +00:00
' location_id ' : fields . many2one ( ' stock.location ' , ' Destination Location ' , required = True , help = " Is the destination location that needs supplying " ) ,
' location_src_id ' : fields . many2one ( ' stock.location ' , ' Source Location ' , help = " Location used by Destination Location to supply " ) ,
2010-06-15 08:14:32 +00:00
' journal_id ' : fields . many2one ( ' stock.journal ' , ' Journal ' ) ,
2010-05-28 09:55:05 +00:00
' procure_method ' : fields . selection ( [ ( ' make_to_stock ' , ' Make to Stock ' ) , ( ' make_to_order ' , ' Make to Order ' ) ] , ' Procure Method ' , required = True , help = " ' Make to Stock ' : When needed, take from the stock or wait until re-supplying. ' Make to Order ' : When needed, purchase or produce for the procurement request. " ) ,
' type_proc ' : fields . selection ( [ ( ' produce ' , ' Produce ' ) , ( ' buy ' , ' Buy ' ) , ( ' move ' , ' Move ' ) ] , ' Type of Procurement ' , required = True ) ,
2012-07-13 10:17:51 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' , help = " Is used to know to which company the pickings and moves belong. " ) ,
2012-03-21 12:07:42 +00:00
' partner_address_id ' : fields . many2one ( ' res.partner ' , ' Partner Address ' ) ,
2010-10-11 21:57:06 +00:00
' picking_type ' : fields . selection ( [ ( ' out ' , ' Sending Goods ' ) , ( ' in ' , ' Getting Goods ' ) , ( ' internal ' , ' Internal ' ) ] , ' Shipping Type ' , required = True , select = True , help = " Depending on the company, choose whatever you want to receive or send products " ) ,
2010-05-28 09:55:05 +00:00
' product_id ' : fields . many2one ( ' product.product ' , ' Product ' ) ,
2010-06-10 13:00:36 +00:00
' invoice_state ' : fields . selection ( [
( " invoiced " , " Invoiced " ) ,
( " 2binvoiced " , " To Be Invoiced " ) ,
2010-10-28 07:20:11 +00:00
( " none " , " Not Applicable " ) ] , " Invoice Status " ,
2010-06-10 13:00:36 +00:00
required = True , ) ,
2010-05-28 09:55:05 +00:00
}
_defaults = {
2010-06-21 10:44:15 +00:00
' cancel_cascade ' : False ,
' procure_method ' : ' make_to_stock ' ,
' type_proc ' : ' move ' ,
' picking_type ' : ' out ' ,
' invoice_state ' : ' none ' ,
' company_id ' : lambda self , cr , uid , c : self . pool . get ( ' res.company ' ) . _company_default_get ( cr , uid , ' product.pulled.flow ' , context = c ) ,
2010-05-28 09:55:05 +00:00
}
product_pulled_flow ( )
2008-09-07 23:24:39 +00:00
class product_product ( osv . osv ) :
_inherit = ' product.product '
_columns = {
2010-06-21 10:44:15 +00:00
' flow_pull_ids ' : fields . one2many ( ' product.pulled.flow ' , ' product_id ' , ' Pulled Flows ' ) ,
2008-09-07 23:24:39 +00:00
' path_ids ' : fields . one2many ( ' stock.location.path ' , ' product_id ' ,
2010-05-28 09:55:05 +00:00
' Pushed Flow ' ,
2008-09-07 23:24:39 +00:00
help = " These rules set the right path of the product in the " \
" whole location tree. " )
}
product_product ( )
2010-05-28 09:55:05 +00:00
class stock_move ( osv . osv ) :
_inherit = ' stock.move '
_columns = {
' cancel_cascade ' : fields . boolean ( ' Cancel Cascade ' , help = ' If checked, when this move is cancelled, cancel the linked move too ' )
}
2010-11-22 10:37:53 +00:00
def action_cancel ( self , cr , uid , ids , context = None ) :
2010-05-28 09:55:05 +00:00
for m in self . browse ( cr , uid , ids , context = context ) :
if m . cancel_cascade and m . move_dest_id :
self . action_cancel ( cr , uid , [ m . move_dest_id . id ] , context = context )
res = super ( stock_move , self ) . action_cancel ( cr , uid , ids , context )
return res
2012-12-09 10:55:27 +00:00
def _prepare_chained_picking ( self , cr , uid , picking_name , picking , picking_type , moves_todo , context = None ) :
res = super ( stock_move , self ) . _prepare_chained_picking ( cr , uid , picking_name , picking , picking_type , moves_todo , context = context )
res . update ( { ' invoice_state ' : moves_todo [ 0 ] [ 1 ] [ 6 ] or ' none ' } )
return res
2010-05-28 09:55:05 +00:00
stock_move ( )
2008-09-07 23:24:39 +00:00
class stock_location ( osv . osv ) :
_inherit = ' stock.location '
2010-11-22 10:37:53 +00:00
def chained_location_get ( self , cr , uid , location , partner = None , product = None , context = None ) :
2008-09-07 23:24:39 +00:00
if product :
for path in product . path_ids :
if path . location_from_id . id == location . id :
2012-12-09 10:55:27 +00:00
return path . location_dest_id , path . auto , path . delay , path . journal_id and path . journal_id . id or False , path . company_id and path . company_id . id or False , path . picking_type , path . invoice_state
2008-09-18 14:14:19 +00:00
return super ( stock_location , self ) . chained_location_get ( cr , uid , location , partner , product , context )
2008-09-07 23:24:39 +00:00
stock_location ( )
2009-03-06 22:18:24 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: