~sebastien.beau/openerp-connector/e-commerce-addons-refactor-sale-payment

« back to all changes in this revision

Viewing changes to sale_payment_method/sale.py

  • Committer: Sébastien Beau
  • Date: 2013-08-10 16:15:06 UTC
  • Revision ID: sebastien.beau@akretion.com-20130810161506-xsz0bqmmgphi0066
[REF] start to refactor sale_payment_method, the aim is to link the sale order to the move line and not the move. Indeed when we import a bank statement and we used the module account_bank_statement_one_move we have 1 one with X customer payment. So we have no choice the sale must be linked to the move lines

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        so_obj = self.pool.get('sale.order')
42
42
        return so_obj._get_order(cr, uid, ids, context=context)
43
43
 
44
 
    def _amount_residual(self, cr, uid, ids, field_name, args, context=None):
 
44
    def _get_amount(self, cr, uid, ids, fields, args, context=None):
45
45
        res = {}
46
46
        for order in self.browse(cr, uid, ids, context=context):
47
 
            amount = order.amount_total
48
 
            for move in order.payment_ids:
49
 
                amount -= move.amount
50
 
            res[order.id] = amount
 
47
            #TODO add support when payment is linked to many order
 
48
            paid_amount = 0
 
49
            for line in order.payment_ids:    
 
50
                paid_amount = line.debit - line.credit
 
51
            res[order.id] = {
 
52
                    'amount_paid': paid_amount, 
 
53
                    'residual': order.amount_total - paid_amount,
 
54
                    }
51
55
        return res
52
56
 
53
57
    def _payment_exists(self, cursor, user, ids, name, arg, context=None):
57
61
        return res
58
62
 
59
63
    _columns = {
60
 
        'payment_ids': fields.many2many('account.move',
 
64
        'payment_ids': fields.many2many('account.move.line',
61
65
                                        string='Payments Entries'),
62
66
        'payment_method_id': fields.many2one('payment.method',
63
67
                                             'Payment Method',
64
68
                                             ondelete='restrict'),
65
69
        'residual': fields.function(
66
 
            _amount_residual,
 
70
            _get_amount,
67
71
            digits_compute=dp.get_precision('Account'),
68
72
            string='Balance',
69
 
            store=False),
 
73
            store=False,
 
74
            multi='payment'),
 
75
        'amount_paid': fields.function(
 
76
            _get_amount,
 
77
            digits_compute=dp.get_precision('Account'),
 
78
            string='Amount Paid',
 
79
            store=False,
 
80
            multi='payment'),
70
81
        'payment_exists': fields.function(
71
82
            _payment_exists,
72
83
            string='Has automatic payment',