~julie-w/unifield-wm/UTP-925

« back to all changes in this revision

Viewing changes to register_accounting/account.py

  • Committer: duy.vo at msf
  • Date: 2011-08-24 09:14:23 UTC
  • mto: This revision was merged to the branch mainline in revision 247.
  • Revision ID: duy.vo@geneva.msf.org-20110824091423-605i4n1w9gdzseis
[IMP] UF-418-419 reconcile + acc. class 5 for Dr/Cr

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        'type_for_register': lambda *a: 'none',
41
41
    }
42
42
 
43
 
    def name_get(self, cr, uid, ids, context={}):
44
 
        """
45
 
        Give only code account for each id given by ids
46
 
        """
47
 
        res = self.pool.get('account.account').read(cr, uid, ids, ['code'], context=context)
48
 
        return [(int(x['id']), x['code']) for x in res]
49
 
 
50
43
account_account()
51
44
 
52
45
class account_move(osv.osv):
75
68
                res[move.id] = "%s,%s"%(prev._table_name, prev.id)
76
69
        return res
77
70
 
 
71
    def _reconcile_compute(self, cr, uid, ids, name, args, context, where =''):
 
72
        # UF-418: Add a new column to show the reconcile or partial reconcile value in the Journal Entries list
 
73
        if not ids: 
 
74
            return {}
 
75
        # get the ids of the reconcile or partially reconcile lines
 
76
        cr.execute( 'SELECT move_id, case when reconcile_partial_id is null then reconcile_id else reconcile_partial_id end '\
 
77
                    'FROM account_move_line '\
 
78
                    'WHERE move_id IN %s ', (tuple(ids),))
 
79
        result = dict(cr.fetchall())
 
80
        rec_pool = self.pool.get('account.move.reconcile')
 
81
 
 
82
        for id in ids:
 
83
            result.setdefault(id, None)
 
84
            # from each reconcile or partially reconcile id, get the name and amount in case of partially reconcile
 
85
            if result[id]:
 
86
                # this logic is taken from account_move_reconcile.name_get        
 
87
                r = rec_pool.browse(cr, uid, result[id], context=context)
 
88
                total = reduce(lambda y,t: (t.debit or 0.0) - (t.credit or 0.0) + y, r.line_partial_ids, 0.0)
 
89
                if total:
 
90
                    result[id] = '%s (%.2f)' % (r.name, total)
 
91
                else:
 
92
                    result[id] = r.name
 
93
        return result
 
94
 
78
95
    _columns = {
79
96
        'partner_type': fields.function(_get_third_parties_from_move_line, string="Third Parties", selection=[('account.bank.statement', 'Register'), ('hr.employee', 'Employee'), 
80
97
            ('res.partner', 'Partner')], size=128, readonly="1", type="reference", method=True),
 
98
        'reconcile_id': fields.function(_reconcile_compute, method=True, string='Reconcile', type='char'),
81
99
    }
82
100
 
83
101
account_move()