~extra-addons-commiter/e-commerce-addons/7.0

« back to all changes in this revision

Viewing changes to sale_quick_payment/wizard/pay_sale_order.py

  • Committer: Guewen Baconnier
  • Date: 2013-01-14 07:40:50 UTC
  • mfrom: (231.1.12 e-commerce-addons)
  • Revision ID: guewen.baconnier@camptocamp.com-20130114074050-kitvv6l8hiojxo6f
[MRG] from lp:~extra-addons-commiter/e-commerce-addons/trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import decimal_precision as dp
26
26
from datetime import datetime
27
27
 
 
28
#TODO add button on sale_form header instead of more button
 
29
 
28
30
class pay_sale_order(TransientModel):
29
31
    _name = 'pay.sale.order'
30
32
    _description = 'Wizard to generate a payment from the sale order'
35
37
        'date': fields.datetime('Payment Date'),
36
38
        }
37
39
 
38
 
    def _get_journal_id(self, cr, uid, args):
39
 
        if args.get('payment_method_id'):
40
 
            payment_method = self.pool.get('payment.method').browse(cr, uid, args['payment_method_id'])
41
 
            return payment_method.journal_id.id
 
40
    def _get_journal_id(self, cr, uid, context=None):
 
41
        if context is None:
 
42
            context = {}
 
43
        if context.get('active_id'):
 
44
            order = self.pool.get('sale.order').browse(cr, uid, context['active_id'], context=context)
 
45
            if order.payment_method_id:
 
46
                return order.payment_method_id.journal_id.id
42
47
        return False
43
48
 
44
 
    def _get_amount(self, cr, uid, args):
45
 
        if args.get('amount_total'):
46
 
            return args['amount_total']
 
49
    def _get_amount(self, cr, uid, context=None):
 
50
        if context is None:
 
51
            context = {}
 
52
        if context.get('active_id'):
 
53
            order = self.pool.get('sale.order').browse(cr, uid, context['active_id'], context=context)
 
54
            return order.residual
47
55
        return False
48
56
 
49
57
    _defaults = {
60
68
        @param ids: List of account chart’s IDs
61
69
        @return: dictionary of Product list window for a given attributs set
62
70
        """
63
 
        for wizard in self.browse(cr, uid, ids, context=context):
64
 
            self.pool.get('sale.order').pay_sale_order(cr, uid, context['active_id'], wizard.journal_id.id, wizard.amount, wizard.date, context=context)
 
71
        wizard = self.browse(cr, uid, ids[0], context=context)
 
72
        self.pool.get('sale.order').pay_sale_order(cr, uid, context['active_id'], wizard.journal_id.id, wizard.amount, wizard.date, context=context)
65
73
        return {'type': 'ir.actions.act_window_close'}
 
74
 
 
75
    def pay_sale_order_and_confirm(self, cr, uid, ids, context=None):
 
76
        """
 
77
        Pay the sale order
 
78
        @param cr: the current row, from the database cursor,
 
79
        @param uid: the current user’s ID for security checks,
 
80
        @param ids: List of account chart’s IDs
 
81
        @return: dictionary of Product list window for a given attributs set
 
82
        """
 
83
        self.pay_sale_order(cr, uid, ids, context=context)
 
84
        return self.pool.get('sale.order').action_button_confirm(cr, uid, [context['active_id']], context=context)
 
85