2
# -*- coding: utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2012 TeMPO Consulting, MSF. All Rights Reserved
7
# Developer: Olivier DOSSMANN
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
25
from osv import fields
26
from tools.translate import _
27
from account_override import ACCOUNT_RESTRICTED_AREA
30
class res_partner(osv.osv):
32
_inherit = 'res.partner'
35
'donation_payable_account': fields.many2one('account.account', "Donation Payable Account",
36
domain=ACCOUNT_RESTRICTED_AREA['partner_donation']),
39
def _is_linked_to_any_posted_accounting_entry(self, cr, uid, partner_id,
42
sql = "select ml.id from account_move_line ml" \
43
" left join account_move m on m.id=ml.move_id" \
44
" where m.state='posted' and ml.partner_id=%d limit 1" % (partner_id, )
48
return res and res[0] > 0 or False
50
def write(self, cr, uid, ids, vals, context=None):
51
if ids and 'name' in vals:
52
current_name_recs = self.read(cr, uid, ids, ['name'],
54
new_name = vals.get('name', False)
55
for r in current_name_recs:
56
if new_name != r['name']:
57
# check if partner is linked to a posted entry
58
# if the case forbid its name modification
59
if self._is_linked_to_any_posted_accounting_entry(cr, uid,
60
r['id'], context=context):
61
raise osv.except_osv(_('Error'),
62
_('You can not rename a partner linked to posted' \
63
' accounting entries'))
65
return super(res_partner, self).write(cr, uid, ids, vals,
70
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: