~ubuntu-branches/ubuntu/quantal/openerp6.1/quantal

« back to all changes in this revision

Viewing changes to openerp/addons/warning/warning.py

  • Committer: Package Import Robot
  • Author(s): Yolanda Robla
  • Date: 2012-09-20 15:29:00 UTC
  • Revision ID: package-import@ubuntu.com-20120920152900-woyy3yww8z6acmsk
Tags: upstream-6.1-1+dfsg
ImportĀ upstreamĀ versionĀ 6.1-1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
import time
 
23
from osv import fields,osv
 
24
from tools.translate import _
 
25
 
 
26
WARNING_MESSAGE = [
 
27
                   ('no-message','No Message'),
 
28
                   ('warning','Warning'),
 
29
                   ('block','Blocking Message')
 
30
                   ]
 
31
 
 
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.')
 
33
 
 
34
class res_partner(osv.osv):
 
35
    _inherit = 'res.partner'
 
36
    _columns = {
 
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'),
 
45
    }
 
46
    _defaults = {
 
47
         'sale_warn' : 'no-message',
 
48
         'purchase_warn' : 'no-message',
 
49
         'picking_warn' : 'no-message',
 
50
         'invoice_warn' : 'no-message',
 
51
    }
 
52
 
 
53
res_partner()
 
54
 
 
55
 
 
56
class sale_order(osv.osv):
 
57
    _inherit = 'sale.order'
 
58
    def onchange_partner_id(self, cr, uid, ids, part):
 
59
        if not part:
 
60
            return {'value':{'partner_invoice_id': False, 'partner_shipping_id':False, 'partner_order_id':False, 'payment_term' : False}}
 
61
        warning = {}
 
62
        title = False
 
63
        message = 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
 
70
            warning = {
 
71
                    'title': title,
 
72
                    'message': message,
 
73
            }
 
74
 
 
75
        result =  super(sale_order, self).onchange_partner_id(cr, uid, ids, part)
 
76
 
 
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']
 
80
 
 
81
        return {'value': result.get('value',{}), 'warning':warning}
 
82
sale_order()
 
83
 
 
84
 
 
85
class purchase_order(osv.osv):
 
86
    _inherit = 'purchase.order'
 
87
    def onchange_partner_id(self, cr, uid, ids, part):
 
88
        if not part:
 
89
            return {'value':{'partner_address_id': False}}
 
90
        warning = {}
 
91
        title = False
 
92
        message = 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
 
99
            warning = {
 
100
                'title': title,
 
101
                'message': message
 
102
                }
 
103
        result =  super(purchase_order, self).onchange_partner_id(cr, uid, ids, part)
 
104
 
 
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']
 
108
 
 
109
        return {'value': result.get('value',{}), 'warning':warning}
 
110
 
 
111
purchase_order()
 
112
 
 
113
 
 
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):
 
118
        if not partner_id:
 
119
            return {'value': {
 
120
            'address_contact_id': False ,
 
121
            'address_invoice_id': False,
 
122
            'account_id': False,
 
123
            'payment_term': False,
 
124
            }
 
125
        }
 
126
        warning = {}
 
127
        title = False
 
128
        message = 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)
 
133
 
 
134
            title = _("Warning for %s") % partner.name
 
135
            message = partner.invoice_warn_msg
 
136
            warning = {
 
137
                'title': title,
 
138
                'message': message
 
139
                }
 
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)
 
142
 
 
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']
 
146
 
 
147
        return {'value': result.get('value',{}), 'warning':warning}
 
148
 
 
149
account_invoice()
 
150
 
 
151
class stock_picking(osv.osv):
 
152
    _inherit = 'stock.picking'
 
153
 
 
154
    def onchange_partner_in(self, cr, uid, context, partner_id=None):
 
155
        if not partner_id:
 
156
            return {}
 
157
        partner = self.pool.get('res.partner.address').browse(cr, uid, [partner_id])[0].partner_id
 
158
        warning = {}
 
159
        title = False
 
160
        message = False
 
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
 
166
            warning = {
 
167
                'title': title,
 
168
                'message': message
 
169
            }
 
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']
 
174
 
 
175
        return {'value': result.get('value',{}), 'warning':warning}
 
176
 
 
177
stock_picking()
 
178
 
 
179
class product_product(osv.osv):
 
180
    _inherit = 'product.product'
 
181
    _columns = {
 
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'),
 
186
     }
 
187
 
 
188
    _defaults = {
 
189
         'sale_line_warn' : 'no-message',
 
190
         'purchase_line_warn' : 'no-message',
 
191
    }
 
192
 
 
193
product_product()
 
194
 
 
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):
 
201
        warning = {}
 
202
        if not product:
 
203
            return {'value': {'th_weight' : 0, 'product_packaging': False,
 
204
                'product_uos_qty': qty}, 'domain': {'product_uom': [],
 
205
                   'product_uos': []}}
 
206
        product_obj = self.pool.get('product.product')
 
207
        product_info = product_obj.browse(cr, uid, product)
 
208
        title = False
 
209
        message = False
 
210
 
 
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
 
218
 
 
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)
 
222
 
 
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']
 
226
 
 
227
        return {'value': result.get('value',{}), 'warning':warning}
 
228
 
 
229
sale_order_line()
 
230
 
 
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):
 
236
        warning = {}
 
237
        if not product:
 
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)
 
241
        title = False
 
242
        message = False
 
243
 
 
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
 
251
 
 
252
        result =  super(purchase_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty, uom,
 
253
            partner_id, date_order, fiscal_position)
 
254
 
 
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']
 
258
 
 
259
        return {'value': result.get('value',{}), 'warning':warning}
 
260
 
 
261
purchase_order_line()
 
262
 
 
263
 
 
264
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: