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 openerp.osv import fields,osv
24 from openerp.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, 'Sales Order', help=WARNING_HELP, required=True),
38 'sale_warn_msg' : fields.text('Message for Sales 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',
55 class sale_order(osv.osv):
56 _inherit = 'sale.order'
57 def onchange_partner_id(self, cr, uid, ids, part, context=None):
59 return {'value':{'partner_invoice_id': False, 'partner_shipping_id':False, 'payment_term' : False}}
63 partner = self.pool.get('res.partner').browse(cr, uid, part, context=context)
64 if partner.sale_warn != 'no-message':
65 if partner.sale_warn == 'block':
66 raise osv.except_osv(_('Alert for %s!') % (partner.name), partner.sale_warn_msg)
67 title = _("Warning for %s") % partner.name
68 message = partner.sale_warn_msg
74 result = super(sale_order, self).onchange_partner_id(cr, uid, ids, part, context=context)
76 if result.get('warning',False):
77 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
78 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
80 return {'value': result.get('value',{}), 'warning':warning}
83 class purchase_order(osv.osv):
84 _inherit = 'purchase.order'
85 def onchange_partner_id(self, cr, uid, ids, part):
87 return {'value':{'partner_address_id': False}}
91 partner = self.pool.get('res.partner').browse(cr, uid, part)
92 if partner.purchase_warn != 'no-message':
93 if partner.purchase_warn == 'block':
94 raise osv.except_osv(_('Alert for %s!') % (partner.name), partner.purchase_warn_msg)
95 title = _("Warning for %s") % partner.name
96 message = partner.purchase_warn_msg
101 result = super(purchase_order, self).onchange_partner_id(cr, uid, ids, part)
103 if result.get('warning',False):
104 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
105 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
107 return {'value': result.get('value',{}), 'warning':warning}
111 class account_invoice(osv.osv):
112 _inherit = 'account.invoice'
113 def onchange_partner_id(self, cr, uid, ids, type, partner_id,
114 date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
118 'payment_term': False,
124 partner = self.pool.get('res.partner').browse(cr, uid, partner_id)
125 if partner.invoice_warn != 'no-message':
126 if partner.invoice_warn == 'block':
127 raise osv.except_osv(_('Alert for %s!') % (partner.name), partner.invoice_warn_msg)
129 title = _("Warning for %s") % partner.name
130 message = partner.invoice_warn_msg
135 result = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id,
136 date_invoice=date_invoice, payment_term=payment_term,
137 partner_bank_id=partner_bank_id, company_id=company_id)
139 if result.get('warning',False):
140 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
141 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
143 return {'value': result.get('value',{}), 'warning':warning}
146 class stock_picking(osv.osv):
147 _inherit = 'stock.picking'
149 def onchange_partner_in(self, cr, uid, ids, partner_id=None, context=None):
152 partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
156 if partner.picking_warn != 'no-message':
157 if partner.picking_warn == 'block':
158 raise osv.except_osv(_('Alert for %s!') % (partner.name), partner.picking_warn_msg)
159 title = _("Warning for %s") % partner.name
160 message = partner.picking_warn_msg
165 result = super(stock_picking, self).onchange_partner_in(cr, uid, ids, partner_id, context)
166 if result.get('warning',False):
167 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
168 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
170 return {'value': result.get('value',{}), 'warning':warning}
173 class stock_picking(osv.osv):
174 _inherit = 'stock.picking'
176 def onchange_partner_in(self, cr, uid, ids, partner_id=None, context=None):
179 partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
183 if partner.picking_warn != 'no-message':
184 if partner.picking_warn == 'block':
185 raise osv.except_osv(_('Alert for %s!') % (partner.name), partner.picking_warn_msg)
186 title = _("Warning for %s") % partner.name
187 message = partner.picking_warn_msg
192 result = super(stock_picking_in, self).onchange_partner_in(cr, uid, ids, partner_id, context)
193 if result.get('warning',False):
194 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
195 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
197 return {'value': result.get('value',{}), 'warning':warning}
199 class product_product(osv.osv):
200 _inherit = 'product.product'
202 'sale_line_warn' : fields.selection(WARNING_MESSAGE,'Sales Order Line', help=WARNING_HELP, required=True),
203 'sale_line_warn_msg' : fields.text('Message for Sales Order Line'),
204 'purchase_line_warn' : fields.selection(WARNING_MESSAGE,'Purchase Order Line', help=WARNING_HELP, required=True),
205 'purchase_line_warn_msg' : fields.text('Message for Purchase Order Line'),
209 'sale_line_warn' : 'no-message',
210 'purchase_line_warn' : 'no-message',
214 class sale_order_line(osv.osv):
215 _inherit = 'sale.order.line'
216 def product_id_change_with_wh(self, cr, uid, ids, pricelist, product, qty=0,
217 uom=False, qty_uos=0, uos=False, name='', partner_id=False,
218 lang=False, update_tax=True, date_order=False, packaging=False,
219 fiscal_position=False, flag=False, warehouse_id=False, context=None):
222 return {'value': {'th_weight' : 0, 'product_packaging': False,
223 'product_uos_qty': qty}, 'domain': {'product_uom': [],
225 product_obj = self.pool.get('product.product')
226 product_info = product_obj.browse(cr, uid, product)
230 if product_info.sale_line_warn != 'no-message':
231 if product_info.sale_line_warn == 'block':
232 raise osv.except_osv(_('Alert for %s!') % (product_info.name), product_info.sale_line_warn_msg)
233 title = _("Warning for %s") % product_info.name
234 message = product_info.sale_line_warn_msg
235 warning['title'] = title
236 warning['message'] = message
238 result = super(sale_order_line, self).product_id_change_with_wh( cr, uid, ids, pricelist, product, qty,
239 uom, qty_uos, uos, name, partner_id,
240 lang, update_tax, date_order, packaging, fiscal_position, flag, warehouse_id=warehouse_id, context=context)
242 if result.get('warning',False):
243 warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']
244 warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message']
246 return {'value': result.get('value',{}), 'warning':warning}
249 class purchase_order_line(osv.osv):
250 _inherit = 'purchase.order.line'
251 def onchange_product_id(self,cr, uid, ids, pricelist, product, qty, uom,
252 partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
253 name=False, price_unit=False, state='draft', notes=False, context=None):
256 return {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or '', 'product_uom' : uom or False}, 'domain':{'product_uom':[]}}
257 product_obj = self.pool.get('product.product')
258 product_info = product_obj.browse(cr, uid, product)
262 if product_info.purchase_line_warn != 'no-message':
263 if product_info.purchase_line_warn == 'block':
264 raise osv.except_osv(_('Alert for %s!') % (product_info.name), product_info.purchase_line_warn_msg)
265 title = _("Warning for %s") % product_info.name
266 message = product_info.purchase_line_warn_msg
267 warning['title'] = title
268 warning['message'] = message
270 result = super(purchase_order_line, self).onchange_product_id(cr, uid, ids, pricelist, product, qty, uom,
271 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)
273 if result.get('warning',False):
274 warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']
275 warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message']
277 return {'value': result.get('value',{}), 'warning':warning}
281 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: