2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2008-09-16 11:19:45 +00:00
##############################################################################
2010-05-17 13:34:31 +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-16 11:19:45 +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-16 11:19:45 +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-16 11:19:45 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2010-05-17 13:34:31 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-09-16 11:19:45 +00:00
#
##############################################################################
2012-12-06 14:56:32 +00:00
from openerp . osv import fields , osv
from openerp . tools . translate import _
2008-09-16 11:19:45 +00:00
2009-04-03 08:08:58 +00:00
WARNING_MESSAGE = [
( ' no-message ' , ' No Message ' ) ,
( ' warning ' , ' Warning ' ) ,
( ' block ' , ' Blocking Message ' )
]
2009-10-28 15:09:40 +00:00
WARNING_HELP = _ ( ' Selecting the " Warning " option will notify user with the message, Selecting " Blocking Message " will throw an exception with the message and block the flow. The Message has to be written in the next field. ' )
2009-04-03 08:08:58 +00:00
2008-09-16 11:19:45 +00:00
class res_partner ( osv . osv ) :
_inherit = ' res.partner '
_columns = {
2012-12-21 16:48:08 +00:00
' sale_warn ' : fields . selection ( WARNING_MESSAGE , ' Sales Order ' , help = WARNING_HELP , required = True ) ,
' sale_warn_msg ' : fields . text ( ' Message for Sales Order ' ) ,
2011-02-24 16:35:00 +00:00
' purchase_warn ' : fields . selection ( WARNING_MESSAGE , ' Purchase Order ' , help = WARNING_HELP , required = True ) ,
2008-10-27 05:59:28 +00:00
' purchase_warn_msg ' : fields . text ( ' Message for Purchase Order ' ) ,
2011-02-24 16:35:00 +00:00
' picking_warn ' : fields . selection ( WARNING_MESSAGE , ' Stock Picking ' , help = WARNING_HELP , required = True ) ,
2008-10-27 05:59:28 +00:00
' picking_warn_msg ' : fields . text ( ' Message for Stock Picking ' ) ,
2011-02-24 16:35:00 +00:00
' invoice_warn ' : fields . selection ( WARNING_MESSAGE , ' Invoice ' , help = WARNING_HELP , required = True ) ,
2008-10-27 05:59:28 +00:00
' invoice_warn_msg ' : fields . text ( ' Message for Invoice ' ) ,
2008-09-20 19:06:25 +00:00
}
2009-04-03 08:08:58 +00:00
_defaults = {
2011-02-24 16:35:00 +00:00
' sale_warn ' : ' no-message ' ,
' purchase_warn ' : ' no-message ' ,
' picking_warn ' : ' no-message ' ,
' invoice_warn ' : ' no-message ' ,
2009-04-03 08:08:58 +00:00
}
2010-05-17 13:34:31 +00:00
2008-09-16 11:19:45 +00:00
class sale_order ( osv . osv ) :
_inherit = ' sale.order '
2012-11-26 14:21:42 +00:00
def onchange_partner_id ( self , cr , uid , ids , part , context = None ) :
2008-09-16 11:19:45 +00:00
if not part :
2012-03-21 12:31:00 +00:00
return { ' value ' : { ' partner_invoice_id ' : False , ' partner_shipping_id ' : False , ' payment_term ' : False } }
2008-09-16 11:19:45 +00:00
warning = { }
2009-04-03 08:08:58 +00:00
title = False
message = False
2012-11-26 14:21:42 +00:00
partner = self . pool . get ( ' res.partner ' ) . browse ( cr , uid , part , context = context )
2009-04-03 08:08:58 +00:00
if partner . sale_warn != ' no-message ' :
2009-10-28 15:09:40 +00:00
title = _ ( " Warning for %s " ) % partner . name
message = partner . sale_warn_msg
2009-04-03 08:08:58 +00:00
warning = {
2009-10-28 15:09:40 +00:00
' title ' : title ,
' message ' : message ,
2009-04-03 08:08:58 +00:00
}
2014-05-07 10:25:50 +00:00
if partner . sale_warn == ' block ' :
return { ' value ' : { ' partner_id ' : False } , ' warning ' : warning }
2009-04-03 08:08:58 +00:00
2012-11-26 14:21:42 +00:00
result = super ( sale_order , self ) . onchange_partner_id ( cr , uid , ids , part , context = context )
2010-05-17 13:34:31 +00:00
2008-09-18 14:14:19 +00:00
if result . get ( ' warning ' , False ) :
2009-04-03 08:08:58 +00:00
warning [ ' title ' ] = title and title + ' & ' + result [ ' warning ' ] [ ' title ' ] or result [ ' warning ' ] [ ' title ' ]
warning [ ' message ' ] = message and message + ' ' + result [ ' warning ' ] [ ' message ' ] or result [ ' warning ' ] [ ' message ' ]
2010-05-17 13:34:31 +00:00
2014-10-16 13:12:52 +00:00
if warning :
result [ ' warning ' ] = warning
return result
2008-09-16 11:19:45 +00:00
class purchase_order ( osv . osv ) :
_inherit = ' purchase.order '
2014-07-04 02:58:15 +00:00
def onchange_partner_id ( self , cr , uid , ids , part , context = None ) :
2008-09-16 11:19:45 +00:00
if not part :
return { ' value ' : { ' partner_address_id ' : False } }
warning = { }
2009-10-28 15:09:40 +00:00
title = False
message = False
2014-07-04 02:58:15 +00:00
partner = self . pool . get ( ' res.partner ' ) . browse ( cr , uid , part , context = context )
2009-04-03 08:08:58 +00:00
if partner . purchase_warn != ' no-message ' :
2009-10-28 15:09:40 +00:00
title = _ ( " Warning for %s " ) % partner . name
message = partner . purchase_warn_msg
2009-04-03 08:08:58 +00:00
warning = {
2009-10-28 15:09:40 +00:00
' title ' : title ,
' message ' : message
2009-04-03 08:08:58 +00:00
}
2014-05-07 10:25:50 +00:00
if partner . purchase_warn == ' block ' :
return { ' value ' : { ' partner_id ' : False } , ' warning ' : warning }
2014-07-04 02:58:15 +00:00
result = super ( purchase_order , self ) . onchange_partner_id ( cr , uid , ids , part , context = context )
2010-05-17 13:34:31 +00:00
2009-10-28 15:09:40 +00:00
if result . get ( ' warning ' , False ) :
warning [ ' title ' ] = title and title + ' & ' + result [ ' warning ' ] [ ' title ' ] or result [ ' warning ' ] [ ' title ' ]
warning [ ' message ' ] = message and message + ' ' + result [ ' warning ' ] [ ' message ' ] or result [ ' warning ' ] [ ' message ' ]
2010-05-17 13:34:31 +00:00
2014-10-16 13:12:52 +00:00
if warning :
result [ ' warning ' ] = warning
return result
2010-05-17 13:34:31 +00:00
2008-09-16 11:19:45 +00:00
class account_invoice ( osv . osv ) :
_inherit = ' account.invoice '
def onchange_partner_id ( self , cr , uid , ids , type , partner_id ,
2014-07-04 03:45:33 +00:00
date_invoice = False , payment_term = False ,
partner_bank_id = False , company_id = False ,
context = None ) :
2008-09-16 11:19:45 +00:00
if not partner_id :
return { ' value ' : {
' account_id ' : False ,
' payment_term ' : False ,
}
}
warning = { }
2009-10-28 15:09:40 +00:00
title = False
message = False
2014-07-04 03:45:33 +00:00
partner = self . pool . get ( ' res.partner ' ) . browse ( cr , uid , partner_id , context = context )
2009-04-03 08:08:58 +00:00
if partner . invoice_warn != ' no-message ' :
2009-10-28 15:09:40 +00:00
title = _ ( " Warning for %s " ) % partner . name
message = partner . invoice_warn_msg
2009-04-03 08:08:58 +00:00
warning = {
2009-10-28 15:09:40 +00:00
' title ' : title ,
' message ' : message
2009-04-03 08:08:58 +00:00
}
2014-05-07 10:25:50 +00:00
if partner . invoice_warn == ' block ' :
return { ' value ' : { ' partner_id ' : False } , ' warning ' : warning }
2008-09-16 11:19:45 +00:00
result = super ( account_invoice , self ) . onchange_partner_id ( cr , uid , ids , type , partner_id ,
2012-11-28 06:53:18 +00:00
date_invoice = date_invoice , payment_term = payment_term ,
2014-07-04 03:45:33 +00:00
partner_bank_id = partner_bank_id , company_id = company_id , context = context )
2010-05-17 13:34:31 +00:00
2009-10-28 15:09:40 +00:00
if result . get ( ' warning ' , False ) :
warning [ ' title ' ] = title and title + ' & ' + result [ ' warning ' ] [ ' title ' ] or result [ ' warning ' ] [ ' title ' ]
warning [ ' message ' ] = message and message + ' ' + result [ ' warning ' ] [ ' message ' ] or result [ ' warning ' ] [ ' message ' ]
2010-05-17 13:34:31 +00:00
2014-10-16 13:12:52 +00:00
if warning :
result [ ' warning ' ] = warning
return result
2010-05-17 13:34:31 +00:00
2008-09-16 11:19:45 +00:00
2013-07-25 14:43:35 +00:00
class stock_picking ( osv . osv ) :
_inherit = ' stock.picking '
2012-09-18 12:22:36 +00:00
2012-11-06 09:31:33 +00:00
def onchange_partner_in ( self , cr , uid , ids , partner_id = None , context = None ) :
2012-09-18 12:22:36 +00:00
if not partner_id :
return { }
partner = self . pool . get ( ' res.partner ' ) . browse ( cr , uid , partner_id , context = context )
warning = { }
title = False
message = False
if partner . picking_warn != ' no-message ' :
title = _ ( " Warning for %s " ) % partner . name
message = partner . picking_warn_msg
warning = {
' title ' : title ,
' message ' : message
}
2014-05-07 10:25:50 +00:00
if partner . picking_warn == ' block ' :
return { ' value ' : { ' partner_id ' : False } , ' warning ' : warning }
2015-03-02 11:08:43 +00:00
result = { ' value ' : { } }
2012-09-18 12:22:36 +00:00
2014-10-16 13:12:52 +00:00
if warning :
result [ ' warning ' ] = warning
return result
2012-09-18 12:22:36 +00:00
2008-09-16 11:19:45 +00:00
class product_product ( osv . osv ) :
2014-05-27 07:42:52 +00:00
_inherit = ' product.template '
2008-09-16 11:19:45 +00:00
_columns = {
2012-12-21 16:48:08 +00:00
' sale_line_warn ' : fields . selection ( WARNING_MESSAGE , ' Sales Order Line ' , help = WARNING_HELP , required = True ) ,
' sale_line_warn_msg ' : fields . text ( ' Message for Sales Order Line ' ) ,
2011-02-24 16:35:00 +00:00
' purchase_line_warn ' : fields . selection ( WARNING_MESSAGE , ' Purchase Order Line ' , help = WARNING_HELP , required = True ) ,
2008-10-25 10:11:07 +00:00
' purchase_line_warn_msg ' : fields . text ( ' Message for Purchase Order Line ' ) ,
2008-11-05 08:35:51 +00:00
}
2010-05-17 13:34:31 +00:00
2009-04-03 08:08:58 +00:00
_defaults = {
2011-02-24 16:35:00 +00:00
' sale_line_warn ' : ' no-message ' ,
' purchase_line_warn ' : ' no-message ' ,
2009-04-03 08:08:58 +00:00
}
2010-05-17 13:34:31 +00:00
2008-09-16 11:19:45 +00:00
class sale_order_line ( osv . osv ) :
_inherit = ' sale.order.line '
2013-10-23 08:57:58 +00:00
def product_id_change_with_wh ( self , cr , uid , ids , pricelist , product , qty = 0 ,
2008-09-16 11:19:45 +00:00
uom = False , qty_uos = 0 , uos = False , name = ' ' , partner_id = False ,
2009-01-24 01:55:45 +00:00
lang = False , update_tax = True , date_order = False , packaging = False ,
2013-10-22 15:29:58 +00:00
fiscal_position = False , flag = False , warehouse_id = False , context = None ) :
2008-09-16 11:19:45 +00:00
warning = { }
if not product :
return { ' value ' : { ' th_weight ' : 0 , ' product_packaging ' : False ,
' product_uos_qty ' : qty } , ' domain ' : { ' product_uom ' : [ ] ,
' product_uos ' : [ ] } }
2010-05-17 13:34:31 +00:00
product_obj = self . pool . get ( ' product.product ' )
2008-09-16 11:19:45 +00:00
product_info = product_obj . browse ( cr , uid , product )
2009-04-03 08:23:23 +00:00
title = False
message = False
2010-05-17 13:34:31 +00:00
2009-04-03 08:23:23 +00:00
if product_info . sale_line_warn != ' no-message ' :
2009-10-28 15:09:40 +00:00
title = _ ( " Warning for %s " ) % product_info . name
2009-04-03 08:23:23 +00:00
message = product_info . sale_line_warn_msg
warning [ ' title ' ] = title
warning [ ' message ' ] = message
2014-05-07 10:25:50 +00:00
if product_info . sale_line_warn == ' block ' :
return { ' value ' : { ' product_id ' : False } , ' warning ' : warning }
2010-05-17 13:34:31 +00:00
2013-10-23 08:57:58 +00:00
result = super ( sale_order_line , self ) . product_id_change_with_wh ( cr , uid , ids , pricelist , product , qty ,
2008-09-20 11:54:38 +00:00
uom , qty_uos , uos , name , partner_id ,
2013-10-22 15:29:58 +00:00
lang , update_tax , date_order , packaging , fiscal_position , flag , warehouse_id = warehouse_id , context = context )
2009-04-03 08:23:23 +00:00
2008-09-18 14:14:19 +00:00
if result . get ( ' warning ' , False ) :
2009-10-28 15:09:40 +00:00
warning [ ' title ' ] = title and title + ' & ' + result [ ' warning ' ] [ ' title ' ] or result [ ' warning ' ] [ ' title ' ]
2009-04-03 08:23:23 +00:00
warning [ ' message ' ] = message and message + ' \n \n ' + result [ ' warning ' ] [ ' message ' ] or result [ ' warning ' ] [ ' message ' ]
2010-05-17 13:34:31 +00:00
2014-10-16 13:12:52 +00:00
if warning :
result [ ' warning ' ] = warning
return result
2010-05-17 13:34:31 +00:00
2008-09-16 11:19:45 +00:00
class purchase_order_line ( osv . osv ) :
_inherit = ' purchase.order.line '
2012-09-18 12:22:36 +00:00
def onchange_product_id ( self , cr , uid , ids , pricelist , product , qty , uom ,
partner_id , date_order = False , fiscal_position_id = False , date_planned = False ,
2015-02-17 10:10:10 +00:00
name = False , price_unit = False , state = ' draft ' , context = None ) :
2008-09-16 11:19:45 +00:00
warning = { }
if not product :
2015-02-16 14:07:21 +00:00
return { ' value ' : { ' price_unit ' : price_unit or 0.0 , ' name ' : name or ' ' , ' product_uom ' : uom or False } , ' domain ' : { ' product_uom ' : [ ] } }
2010-05-17 13:34:31 +00:00
product_obj = self . pool . get ( ' product.product ' )
2008-09-16 11:19:45 +00:00
product_info = product_obj . browse ( cr , uid , product )
2009-04-03 08:23:23 +00:00
title = False
message = False
2010-05-17 13:34:31 +00:00
2009-04-03 08:23:23 +00:00
if product_info . purchase_line_warn != ' no-message ' :
2009-10-28 15:09:40 +00:00
title = _ ( " Warning for %s " ) % product_info . name
2009-04-03 08:23:23 +00:00
message = product_info . purchase_line_warn_msg
warning [ ' title ' ] = title
warning [ ' message ' ] = message
2014-05-07 10:25:50 +00:00
if product_info . purchase_line_warn == ' block ' :
return { ' value ' : { ' product_id ' : False } , ' warning ' : warning }
2010-05-17 13:34:31 +00:00
2012-09-18 12:22:36 +00:00
result = super ( purchase_order_line , self ) . onchange_product_id ( cr , uid , ids , pricelist , product , qty , uom ,
2013-09-17 08:05:15 +00:00
partner_id , date_order = date_order , fiscal_position_id = fiscal_position_id , date_planned = date_planned , name = name , price_unit = price_unit , state = state , context = context )
2009-04-03 08:23:23 +00:00
2008-09-20 11:54:38 +00:00
if result . get ( ' warning ' , False ) :
2009-10-28 15:09:40 +00:00
warning [ ' title ' ] = title and title + ' & ' + result [ ' warning ' ] [ ' title ' ] or result [ ' warning ' ] [ ' title ' ]
2009-04-03 08:23:23 +00:00
warning [ ' message ' ] = message and message + ' \n \n ' + result [ ' warning ' ] [ ' message ' ] or result [ ' warning ' ] [ ' message ' ]
2010-05-17 13:34:31 +00:00
2014-10-16 13:12:52 +00:00
if warning :
result [ ' warning ' ] = warning
return result
2010-05-17 13:34:31 +00:00
2008-09-16 11:19:45 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: