1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
from osv import fields,osv
24
from tools.translate import _
27
('no-message','No Message'),
28
('warning','Warning'),
29
('block','Blocking Message')
32
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.')
34
class res_partner(osv.osv):
35
_inherit = 'res.partner'
37
'sale_warn' : fields.selection(WARNING_MESSAGE, 'Sale Order', help=WARNING_HELP, required=True),
38
'sale_warn_msg' : fields.text('Message for Sale Order'),
39
'purchase_warn' : fields.selection(WARNING_MESSAGE, 'Purchase Order', help=WARNING_HELP, required=True),
40
'purchase_warn_msg' : fields.text('Message for Purchase Order'),
41
'picking_warn' : fields.selection(WARNING_MESSAGE, 'Stock Picking', help=WARNING_HELP, required=True),
42
'picking_warn_msg' : fields.text('Message for Stock Picking'),
43
'invoice_warn' : fields.selection(WARNING_MESSAGE, 'Invoice', help=WARNING_HELP, required=True),
44
'invoice_warn_msg' : fields.text('Message for Invoice'),
47
'sale_warn' : 'no-message',
48
'purchase_warn' : 'no-message',
49
'picking_warn' : 'no-message',
50
'invoice_warn' : 'no-message',
56
class sale_order(osv.osv):
57
_inherit = 'sale.order'
58
def onchange_partner_id(self, cr, uid, ids, part):
60
return {'value':{'partner_invoice_id': False, 'partner_shipping_id':False, 'partner_order_id':False, 'payment_term' : False}}
64
partner = self.pool.get('res.partner').browse(cr, uid, part)
65
if partner.sale_warn != 'no-message':
66
if partner.sale_warn == 'block':
67
raise osv.except_osv(_('Alert for %s !') % (partner.name), partner.sale_warn_msg)
68
title = _("Warning for %s") % partner.name
69
message = partner.sale_warn_msg
75
result = super(sale_order, self).onchange_partner_id(cr, uid, ids, part)
77
if result.get('warning',False):
78
warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
79
warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
81
return {'value': result.get('value',{}), 'warning':warning}
85
class purchase_order(osv.osv):
86
_inherit = 'purchase.order'
87
def onchange_partner_id(self, cr, uid, ids, part):
89
return {'value':{'partner_address_id': False}}
93
partner = self.pool.get('res.partner').browse(cr, uid, part)
94
if partner.purchase_warn != 'no-message':
95
if partner.purchase_warn == 'block':
96
raise osv.except_osv(_('Alert for %s !') % (partner.name), partner.purchase_warn_msg)
97
title = _("Warning for %s") % partner.name
98
message = partner.purchase_warn_msg
103
result = super(purchase_order, self).onchange_partner_id(cr, uid, ids, part)
105
if result.get('warning',False):
106
warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
107
warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
109
return {'value': result.get('value',{}), 'warning':warning}
114
class account_invoice(osv.osv):
115
_inherit = 'account.invoice'
116
def onchange_partner_id(self, cr, uid, ids, type, partner_id,
117
date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
120
'address_contact_id': False ,
121
'address_invoice_id': False,
123
'payment_term': False,
129
partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
130
if partner.invoice_warn != 'no-message':
131
if partner.invoice_warn == 'block':
132
raise osv.except_osv(_('Alert for %s !') % (partner.name), partner.invoice_warn_msg)
134
title = _("Warning for %s") % partner.name
135
message = partner.invoice_warn_msg
140
result = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id,
141
date_invoice=False, payment_term=False, partner_bank_id=False)
143
if result.get('warning',False):
144
warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
145
warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
147
return {'value': result.get('value',{}), 'warning':warning}
151
class stock_picking(osv.osv):
152
_inherit = 'stock.picking'
154
def onchange_partner_in(self, cr, uid, context, partner_id=None):
157
partner = self.pool.get('res.partner.address').browse(cr, uid, [partner_id])[0].partner_id
161
if partner.picking_warn != 'no-message':
162
if partner.picking_warn == 'block':
163
raise osv.except_osv(_('Alert for %s !') % (partner.name), partner.picking_warn_msg)
164
title = _("Warning for %s") % partner.name
165
message = partner.picking_warn_msg
170
result = super(stock_picking, self).onchange_partner_in(cr, uid, context, partner_id)
171
if result.get('warning',False):
172
warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
173
warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
175
return {'value': result.get('value',{}), 'warning':warning}
179
class product_product(osv.osv):
180
_inherit = 'product.product'
182
'sale_line_warn' : fields.selection(WARNING_MESSAGE,'Sale Order Line', help=WARNING_HELP, required=True),
183
'sale_line_warn_msg' : fields.text('Message for Sale Order Line'),
184
'purchase_line_warn' : fields.selection(WARNING_MESSAGE,'Purchase Order Line', help=WARNING_HELP, required=True),
185
'purchase_line_warn_msg' : fields.text('Message for Purchase Order Line'),
189
'sale_line_warn' : 'no-message',
190
'purchase_line_warn' : 'no-message',
195
class sale_order_line(osv.osv):
196
_inherit = 'sale.order.line'
197
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
198
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
199
lang=False, update_tax=True, date_order=False, packaging=False,
200
fiscal_position=False, flag=False, context=None):
203
return {'value': {'th_weight' : 0, 'product_packaging': False,
204
'product_uos_qty': qty}, 'domain': {'product_uom': [],
206
product_obj = self.pool.get('product.product')
207
product_info = product_obj.browse(cr, uid, product)
211
if product_info.sale_line_warn != 'no-message':
212
if product_info.sale_line_warn == 'block':
213
raise osv.except_osv(_('Alert for %s !') % (product_info.name), product_info.sale_line_warn_msg)
214
title = _("Warning for %s") % product_info.name
215
message = product_info.sale_line_warn_msg
216
warning['title'] = title
217
warning['message'] = message
219
result = super(sale_order_line, self).product_id_change( cr, uid, ids, pricelist, product, qty,
220
uom, qty_uos, uos, name, partner_id,
221
lang, update_tax, date_order, packaging, fiscal_position, flag, context=context)
223
if result.get('warning',False):
224
warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']
225
warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message']
227
return {'value': result.get('value',{}), 'warning':warning}
231
class purchase_order_line(osv.osv):
232
_inherit = 'purchase.order.line'
233
def product_id_change(self,cr, uid, ids, pricelist, product, qty, uom,
234
partner_id, date_order=False, fiscal_position=False, date_planned=False,
235
name=False, price_unit=False, notes=False, context=None):
238
return {'value': {'price_unit': 0.0, 'name':'','notes':'', 'product_uom' : False}, 'domain':{'product_uom':[]}}
239
product_obj = self.pool.get('product.product')
240
product_info = product_obj.browse(cr, uid, product)
244
if product_info.purchase_line_warn != 'no-message':
245
if product_info.purchase_line_warn == 'block':
246
raise osv.except_osv(_('Alert for %s !') % (product_info.name), product_info.purchase_line_warn_msg)
247
title = _("Warning for %s") % product_info.name
248
message = product_info.purchase_line_warn_msg
249
warning['title'] = title
250
warning['message'] = message
252
result = super(purchase_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty, uom,
253
partner_id, date_order, fiscal_position)
255
if result.get('warning',False):
256
warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']
257
warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message']
259
return {'value': result.get('value',{}), 'warning':warning}
261
purchase_order_line()
264
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: