~unifield-team/unifield-wm/us-671-homere

« back to all changes in this revision

Viewing changes to account_override/res_partner.py

[UF-43] fix added noupdate to demo data

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- coding: utf-8 -*-
3
 
##############################################################################
4
 
#
5
 
#    OpenERP, Open Source Management Solution
6
 
#    Copyright (C) 2012 TeMPO Consulting, MSF. All Rights Reserved
7
 
#    Developer: Olivier DOSSMANN
8
 
#
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.
13
 
#
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.
18
 
#
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/>.
21
 
#
22
 
##############################################################################
23
 
 
24
 
from osv import osv
25
 
from osv import fields
26
 
from tools.translate import _
27
 
from account_override import ACCOUNT_RESTRICTED_AREA
28
 
 
29
 
 
30
 
class res_partner(osv.osv):
31
 
    _name = 'res.partner'
32
 
    _inherit = 'res.partner'
33
 
 
34
 
    _columns = {
35
 
        'donation_payable_account': fields.many2one('account.account', "Donation Payable Account",
36
 
            domain=ACCOUNT_RESTRICTED_AREA['partner_donation']),
37
 
    }
38
 
 
39
 
    def _is_linked_to_any_posted_accounting_entry(self, cr, uid, partner_id,
40
 
        context=None):
41
 
        res = False
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, )
45
 
 
46
 
        cr.execute(sql)
47
 
        res = cr.fetchone()
48
 
        return res and res[0] > 0 or False
49
 
 
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'],
53
 
                context=context)
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'))
64
 
 
65
 
        return super(res_partner, self).write(cr, uid, ids, vals,
66
 
            context=context)
67
 
 
68
 
 
69
 
res_partner()
70
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: