~serpent-consulting-services/openerp-usa/fix-shipping_api_ups_cc

« back to all changes in this revision

Viewing changes to base_nationalacct/partner.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

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) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
6
 
#    Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
7
 
#
8
 
#    This program is free software: you can redistribute it and/or modify
9
 
#    it under the terms of the GNU General Public License as published by
10
 
#    the Free Software Foundation, either version 3 of the License, or
11
 
#    (at your option) any later version.
12
 
#
13
 
#    This program is distributed in the hope that it will be useful,
14
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
#    GNU General Public License for more details.
17
 
#
18
 
#    You should have received a copy of the GNU General Public License
19
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 
#
21
 
##############################################################################
22
 
 
23
 
from osv import fields, osv
24
 
 
25
 
class res_partner(osv.osv):
26
 
    _inherit = "res.partner"
27
 
    
28
 
    #===========================================================================
29
 
    # Overriding a function defined on account module.
30
 
    # This is to include the payable and receivable from child partners if the 
31
 
    # account is a national account.
32
 
    #===========================================================================
33
 
    def _credit_debit_get(self, cr, uid, ids, field_names, arg, context=None):
34
 
        """
35
 
        calculating payable and receivable from account moves for the mentioned partners
36
 
        """
37
 
        query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
38
 
        cr.execute("""
39
 
                   SELECT l.partner_id, a.type, SUM(l.debit-l.credit)
40
 
                   FROM account_move_line l
41
 
                   LEFT JOIN account_account a ON (l.account_id=a.id)
42
 
                   WHERE a.type IN ('receivable','payable')
43
 
                   AND l.partner_id IN %s
44
 
                   AND l.reconcile_id IS NULL
45
 
                   AND """ + query + """
46
 
                   GROUP BY l.partner_id, a.type
47
 
                   """,(tuple(ids), ))
48
 
        maps = {'receivable': 'credit', 'payable': 'debit'}
49
 
        res = {}
50
 
        for id in ids:
51
 
            res[id] = dict.fromkeys(field_names, 0)
52
 
        for pid, type, val in cr.fetchall():
53
 
            if val is None: val = 0
54
 
            partner = self.browse(cr, uid, pid, context=context)
55
 
            #Include the payable and receivable form child partner if the Partner is national account
56
 
            if partner.nat_acc_parent:
57
 
                res[pid][maps[type]] = (type == 'receivable') and val or -val
58
 
                child_partner_ids = self.search(cr, uid, [('parent_id', 'child_of', [partner.id])], context=context)
59
 
                if child_partner_ids: 
60
 
                    child_partner_ids.remove(partner.id)
61
 
                    for val in self.read(cr, uid, child_partner_ids, ['credit', 'debit'], context=context):
62
 
                        res[pid][maps[type]] += val.get(maps[type], 0)
63
 
            else:
64
 
                res[pid][maps[type]] = (type == 'receivable') and val or -val
65
 
            
66
 
        return res
67
 
 
68
 
    def _credit_search(self, cr, uid, obj, name, args, context=None):
69
 
        """
70
 
        search function for the credit field
71
 
        """
72
 
        return self._asset_difference_search(cr, uid, obj, name, 'receivable', args, context=context)
73
 
    
74
 
    def _debit_search(self, cr, uid, obj, name, args, context=None):
75
 
        """ 
76
 
        search function for the debit field 
77
 
        """
78
 
        return self._asset_difference_search(cr, uid, obj, name, 'payable', args, context=context)
79
 
    
80
 
    _columns = {
81
 
        'credit': fields.function(_credit_debit_get, fnct_search=_credit_search, method=True, string='Total Receivable', multi='dc', 
82
 
                                  help="Total amount this customer owes you."),
83
 
        'debit': fields.function(_credit_debit_get, fnct_search=_debit_search, method=True, string='Total Payable', multi='dc', 
84
 
                                 help="Total amount you have to pay to this supplier."),
85
 
        'nat_acc_parent': fields.boolean('National Acct Parent', help='Designates this partner as the top level parent of a "National Account".'),
86
 
        }
87
 
    
88
 
    _defaults = {
89
 
        'nat_acc_parent': False,
90
 
        }
91
 
 
92
 
res_partner()
93
 
 
94
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: