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, '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):
121 'payment_term': False,
127 partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
128 if partner.invoice_warn != 'no-message':
129 if partner.invoice_warn == 'block':
130 raise osv.except_osv(_('Alert for %s !') % (partner.name), partner.invoice_warn_msg)
132 title = _("Warning for %s") % partner.name
133 message = partner.invoice_warn_msg
138 result = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id,
139 date_invoice=False, payment_term=False, partner_bank_id=False)
141 if result.get('warning',False):
142 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
143 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
145 return {'value': result.get('value',{}), 'warning':warning}
149 class stock_picking(osv.osv):
150 _inherit = 'stock.picking'
152 def onchange_partner_in(self, cr, uid, context, partner_id=None):
155 partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
159 if partner.picking_warn != 'no-message':
160 if partner.picking_warn == 'block':
161 raise osv.except_osv(_('Alert for %s !') % (partner.name), partner.picking_warn_msg)
162 title = _("Warning for %s") % partner.name
163 message = partner.picking_warn_msg
168 result = super(stock_picking, self).onchange_partner_in(cr, uid, context, partner_id)
169 if result.get('warning',False):
170 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
171 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
173 return {'value': result.get('value',{}), 'warning':warning}
177 class product_product(osv.osv):
178 _inherit = 'product.product'
180 'sale_line_warn' : fields.selection(WARNING_MESSAGE,'Sale Order Line', help=WARNING_HELP, required=True),
181 'sale_line_warn_msg' : fields.text('Message for Sale Order Line'),
182 'purchase_line_warn' : fields.selection(WARNING_MESSAGE,'Purchase Order Line', help=WARNING_HELP, required=True),
183 'purchase_line_warn_msg' : fields.text('Message for Purchase Order Line'),
187 'sale_line_warn' : 'no-message',
188 'purchase_line_warn' : 'no-message',
193 class sale_order_line(osv.osv):
194 _inherit = 'sale.order.line'
195 def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
196 uom=False, qty_uos=0, uos=False, name='', partner_id=False,
197 lang=False, update_tax=True, date_order=False, packaging=False,
198 fiscal_position=False, flag=False, context=None):
201 return {'value': {'th_weight' : 0, 'product_packaging': False,
202 'product_uos_qty': qty}, 'domain': {'product_uom': [],
204 product_obj = self.pool.get('product.product')
205 product_info = product_obj.browse(cr, uid, product)
209 if product_info.sale_line_warn != 'no-message':
210 if product_info.sale_line_warn == 'block':
211 raise osv.except_osv(_('Alert for %s !') % (product_info.name), product_info.sale_line_warn_msg)
212 title = _("Warning for %s") % product_info.name
213 message = product_info.sale_line_warn_msg
214 warning['title'] = title
215 warning['message'] = message
217 result = super(sale_order_line, self).product_id_change( cr, uid, ids, pricelist, product, qty,
218 uom, qty_uos, uos, name, partner_id,
219 lang, update_tax, date_order, packaging, fiscal_position, flag, context=context)
221 if result.get('warning',False):
222 warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']
223 warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message']
225 return {'value': result.get('value',{}), 'warning':warning}
229 class purchase_order_line(osv.osv):
230 _inherit = 'purchase.order.line'
231 def product_id_change(self,cr, uid, ids, pricelist, product, qty, uom,
232 partner_id, date_order=False, fiscal_position=False, date_planned=False,
233 name=False, price_unit=False, notes=False, context=None):
236 return {'value': {'price_unit': 0.0, 'name':'','notes':'', 'product_uom' : False}, 'domain':{'product_uom':[]}}
237 product_obj = self.pool.get('product.product')
238 product_info = product_obj.browse(cr, uid, product)
242 if product_info.purchase_line_warn != 'no-message':
243 if product_info.purchase_line_warn == 'block':
244 raise osv.except_osv(_('Alert for %s !') % (product_info.name), product_info.purchase_line_warn_msg)
245 title = _("Warning for %s") % product_info.name
246 message = product_info.purchase_line_warn_msg
247 warning['title'] = title
248 warning['message'] = message
250 result = super(purchase_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty, uom,
251 partner_id, date_order, fiscal_position)
253 if result.get('warning',False):
254 warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']
255 warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message']
257 return {'value': result.get('value',{}), 'warning':warning}
259 purchase_order_line()
262 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: