2010-05-28 09:55:05 +00:00
##############################################################################
2012-03-30 08:11:36 +00:00
#
2010-05-28 09:55:05 +00:00
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 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
2012-03-30 08:11:36 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2010-05-28 09:55:05 +00:00
#
##############################################################################
2013-06-27 14:46:29 +00:00
from openerp . osv import osv , fields
2012-12-06 14:56:32 +00:00
from openerp . tools . translate import _
2010-05-28 09:55:05 +00:00
2010-05-28 12:37:09 +00:00
class procurement_order ( osv . osv ) :
_inherit = ' procurement.order '
2013-06-27 14:46:29 +00:00
2010-05-28 09:55:05 +00:00
def check_buy ( self , cr , uid , ids , context = None ) :
2010-11-22 10:37:53 +00:00
for procurement in self . browse ( cr , uid , ids , context = context ) :
2010-05-28 09:55:05 +00:00
for line in procurement . product_id . flow_pull_ids :
if line . location_id == procurement . location_id :
return line . type_proc == ' buy '
2010-05-28 12:37:09 +00:00
return super ( procurement_order , self ) . check_buy ( cr , uid , ids )
2010-05-28 09:55:05 +00:00
def check_produce ( self , cr , uid , ids , context = None ) :
2010-11-22 10:37:53 +00:00
for procurement in self . browse ( cr , uid , ids , context = context ) :
2010-05-28 09:55:05 +00:00
for line in procurement . product_id . flow_pull_ids :
if line . location_id == procurement . location_id :
return line . type_proc == ' produce '
2010-05-28 12:37:09 +00:00
return super ( procurement_order , self ) . check_produce ( cr , uid , ids )
2010-05-28 09:55:05 +00:00
def check_move ( self , cr , uid , ids , context = None ) :
2010-11-22 10:37:53 +00:00
for procurement in self . browse ( cr , uid , ids , context = context ) :
2010-05-28 09:55:05 +00:00
for line in procurement . product_id . flow_pull_ids :
if line . location_id == procurement . location_id :
return ( line . type_proc == ' move ' ) and ( line . location_src_id )
return False
2012-03-05 18:40:03 +00:00
def action_move_create ( self , cr , uid , ids , context = None ) :
2010-05-28 09:55:05 +00:00
move_obj = self . pool . get ( ' stock.move ' )
for proc in proc_obj . browse ( cr , uid , ids , context = context ) :
line = None
for line in proc . product_id . flow_pull_ids :
2010-10-13 21:59:50 +00:00
if line . location_id == proc . location_id :
2010-05-28 09:55:05 +00:00
break
2012-07-27 06:55:57 +00:00
assert line , ' Line cannot be False if we are on this state of the workflow '
2010-05-28 09:55:05 +00:00
origin = ( proc . origin or proc . name or ' ' ) . split ( ' : ' ) [ 0 ] + ' : ' + line . name
2010-10-13 21:59:50 +00:00
move_id = move_obj . create ( cr , uid , {
2010-05-28 09:55:05 +00:00
' name ' : line . name ,
2010-06-21 09:04:28 +00:00
' company_id ' : line . company_id and line . company_id . id or False ,
2010-05-28 09:55:05 +00:00
' product_id ' : proc . product_id . id ,
2010-09-21 12:50:29 +00:00
' date ' : proc . date_planned ,
2010-05-28 09:55:05 +00:00
' product_qty ' : proc . product_qty ,
' product_uom ' : proc . product_uom . id ,
' product_uos_qty ' : ( proc . product_uos and proc . product_uos_qty ) \
or proc . product_qty ,
' product_uos ' : ( proc . product_uos and proc . product_uos . id ) \
or proc . product_uom . id ,
2012-03-30 08:11:36 +00:00
' partner_id ' : line . partner_address_id . id ,
2010-05-28 09:55:05 +00:00
' location_id ' : line . location_src_id . id ,
' location_dest_id ' : line . location_id . id ,
' move_dest_id ' : proc . move_id and proc . move_id . id or False , # to verif, about history ?
' tracking_id ' : False ,
' cancel_cascade ' : line . cancel_cascade ,
2013-06-27 14:46:29 +00:00
' group_id ' : proc . group_id . id ,
2010-05-28 09:55:05 +00:00
' state ' : ' confirmed ' ,
2010-10-13 21:59:50 +00:00
' note ' : _ ( ' Move for pulled procurement coming from original location %s , pull rule %s , via original Procurement %s (# %d ) ' ) % ( proc . location_id . name , line . name , proc . name , proc . id ) ,
2010-05-28 09:55:05 +00:00
} )
2013-06-29 22:17:03 +00:00
move_obj . button_confirm ( cr , uid , [ move_id ] , context = context )
2010-05-28 09:55:05 +00:00
return False