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 ##############################################################################
22 from openerp.osv import fields,osv
23 from openerp.tools.translate import _
26 ('no-message','No Message'),
27 ('warning','Warning'),
28 ('block','Blocking Message')
31 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.')
33 class res_partner(osv.osv):
34 _inherit = 'res.partner'
36 'sale_warn' : fields.selection(WARNING_MESSAGE, 'Sales Order', help=WARNING_HELP, required=True),
37 'sale_warn_msg' : fields.text('Message for Sales Order'),
38 'purchase_warn' : fields.selection(WARNING_MESSAGE, 'Purchase Order', help=WARNING_HELP, required=True),
39 'purchase_warn_msg' : fields.text('Message for Purchase Order'),
40 'picking_warn' : fields.selection(WARNING_MESSAGE, 'Stock Picking', help=WARNING_HELP, required=True),
41 'picking_warn_msg' : fields.text('Message for Stock Picking'),
42 'invoice_warn' : fields.selection(WARNING_MESSAGE, 'Invoice', help=WARNING_HELP, required=True),
43 'invoice_warn_msg' : fields.text('Message for Invoice'),
46 'sale_warn' : 'no-message',
47 'purchase_warn' : 'no-message',
48 'picking_warn' : 'no-message',
49 'invoice_warn' : 'no-message',
54 class sale_order(osv.osv):
55 _inherit = 'sale.order'
56 def onchange_partner_id(self, cr, uid, ids, part, context=None):
58 return {'value':{'partner_invoice_id': False, 'partner_shipping_id':False, 'payment_term' : False}}
62 partner = self.pool.get('res.partner').browse(cr, uid, part, context=context)
63 if partner.sale_warn != 'no-message':
64 title = _("Warning for %s") % partner.name
65 message = partner.sale_warn_msg
70 if partner.sale_warn == 'block':
71 return {'value': {'partner_id': False}, 'warning': warning}
73 result = super(sale_order, self).onchange_partner_id(cr, uid, ids, part, context=context)
75 if result.get('warning',False):
76 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
77 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
79 return {'value': result.get('value',{}), 'warning':warning}
82 class purchase_order(osv.osv):
83 _inherit = 'purchase.order'
84 def onchange_partner_id(self, cr, uid, ids, part, context=None):
86 return {'value':{'partner_address_id': False}}
90 partner = self.pool.get('res.partner').browse(cr, uid, part, context=context)
91 if partner.purchase_warn != 'no-message':
92 title = _("Warning for %s") % partner.name
93 message = partner.purchase_warn_msg
98 if partner.purchase_warn == 'block':
99 return {'value': {'partner_id': False}, 'warning': warning}
101 result = super(purchase_order, self).onchange_partner_id(cr, uid, ids, part, context=context)
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,
115 partner_bank_id=False, company_id=False,
120 'payment_term': False,
126 partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
127 if partner.invoice_warn != 'no-message':
128 title = _("Warning for %s") % partner.name
129 message = partner.invoice_warn_msg
135 if partner.invoice_warn == 'block':
136 return {'value': {'partner_id': False}, 'warning': warning}
138 result = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id,
139 date_invoice=date_invoice, payment_term=payment_term,
140 partner_bank_id=partner_bank_id, company_id=company_id, context=context)
142 if result.get('warning',False):
143 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
144 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
146 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, ids, partner_id=None, context=None):
155 partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
159 if partner.picking_warn != 'no-message':
160 title = _("Warning for %s") % partner.name
161 message = partner.picking_warn_msg
166 if partner.picking_warn == 'block':
167 return {'value': {'partner_id': False}, 'warning': warning}
169 result = super(stock_picking_in, self).onchange_partner_in(cr, uid, ids, partner_id, context)
170 if result.get('warning',False):
171 warning['title'] = title and title +' & '+ result['warning']['title'] or result['warning']['title']
172 warning['message'] = message and message + ' ' + result['warning']['message'] or result['warning']['message']
174 return {'value': result.get('value',{}), 'warning':warning}
177 class product_product(osv.osv):
178 _inherit = 'product.template'
180 'sale_line_warn' : fields.selection(WARNING_MESSAGE,'Sales Order Line', help=WARNING_HELP, required=True),
181 'sale_line_warn_msg' : fields.text('Message for Sales 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',
192 class sale_order_line(osv.osv):
193 _inherit = 'sale.order.line'
194 def product_id_change_with_wh(self, cr, uid, ids, pricelist, product, qty=0,
195 uom=False, qty_uos=0, uos=False, name='', partner_id=False,
196 lang=False, update_tax=True, date_order=False, packaging=False,
197 fiscal_position=False, flag=False, warehouse_id=False, context=None):
200 return {'value': {'th_weight' : 0, 'product_packaging': False,
201 'product_uos_qty': qty}, 'domain': {'product_uom': [],
203 product_obj = self.pool.get('product.product')
204 product_info = product_obj.browse(cr, uid, product)
208 if product_info.sale_line_warn != 'no-message':
209 title = _("Warning for %s") % product_info.name
210 message = product_info.sale_line_warn_msg
211 warning['title'] = title
212 warning['message'] = message
213 if product_info.sale_line_warn == 'block':
214 return {'value': {'product_id': False}, 'warning': warning}
216 result = super(sale_order_line, self).product_id_change_with_wh( cr, uid, ids, pricelist, product, qty,
217 uom, qty_uos, uos, name, partner_id,
218 lang, update_tax, date_order, packaging, fiscal_position, flag, warehouse_id=warehouse_id, context=context)
220 if result.get('warning',False):
221 warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']
222 warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message']
224 return {'value': result.get('value',{}), 'warning':warning}
227 class purchase_order_line(osv.osv):
228 _inherit = 'purchase.order.line'
229 def onchange_product_id(self,cr, uid, ids, pricelist, product, qty, uom,
230 partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
231 name=False, price_unit=False, state='draft', notes=False, context=None):
234 return {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or '', 'product_uom' : uom or False}, 'domain':{'product_uom':[]}}
235 product_obj = self.pool.get('product.product')
236 product_info = product_obj.browse(cr, uid, product)
240 if product_info.purchase_line_warn != 'no-message':
241 title = _("Warning for %s") % product_info.name
242 message = product_info.purchase_line_warn_msg
243 warning['title'] = title
244 warning['message'] = message
245 if product_info.purchase_line_warn == 'block':
246 return {'value': {'product_id': False}, 'warning': warning}
248 result = super(purchase_order_line, self).onchange_product_id(cr, uid, ids, pricelist, product, qty, uom,
249 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)
251 if result.get('warning',False):
252 warning['title'] = title and title +' & '+result['warning']['title'] or result['warning']['title']
253 warning['message'] = message and message +'\n\n'+result['warning']['message'] or result['warning']['message']
255 return {'value': result.get('value',{}), 'warning':warning}
259 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: