~sebastien.beau/e-commerce-addons/e-commerce-addons-invoice-payment-method

« back to all changes in this revision

Viewing changes to invoice_payment_method/invoice.py

  • Committer: Akretion Bot
  • Date: 2013-10-03 09:40:48 UTC
  • Revision ID: code.bot@akretion.com-20131003094048-a3jjibaxkhzgzw6i
[IMP] improve module invoice_payment_method, and fix the missing payment method

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#
21
21
###############################################################################
22
22
 
23
 
from openerp.osv import osv, fields
24
 
 
25
 
 
26
 
class account_invoice(osv.Model):
 
23
from openerp.osv import orm, fields
 
24
 
 
25
class sale_order(orm.Model):
 
26
    _inherit = "sale.order"
 
27
 
 
28
    def _prepare_invoice(self, cr, uid, order, lines, context=None):
 
29
        vals = super(sale_order, self)._prepare_invoice(cr, uid, order,
 
30
                                                     lines, context=context)
 
31
        vals['payment_method_id'] = order.payment_method_id.id
 
32
        return vals
 
33
 
 
34
 
 
35
class account_invoice(orm.Model):
27
36
    _inherit = "account.invoice"
28
37
 
29
38
    _columns = {
44
53
                    WHERE account_invoice.id = rel.invoice_id;
45
54
            """)
46
55
    
47
 
    def _prepare_invoice(self, cr, uid, order, lines, context=None):
48
 
        vals = super(account_invoice, self)._prepare_invoice(cr, uid, order,
49
 
                                                     lines, context=context)
50
 
        vals['payment_method_id'] = order.payment_method_id.id
51
 
        return vals
 
56
    def onchange_payment_method_id(self, cr, uid, ids, payment_method_id, context=None):
 
57
        if context is None:
 
58
            context = {}
 
59
        res = {'value':{}}
 
60
        method_obj = self.pool['payment.method']
 
61
        #compatibility for sale_payment_method_sale_journal
 
62
        if method_obj._columns.get('sale_account_id'):
 
63
            method = method_obj.browse(cr, uid, payment_method_id, context=context)
 
64
            if method.sale_account_id:
 
65
                res['value']['account_id'] = method.sale_account_id.id
 
66
            if method.sale_journal_id:
 
67
                res['value']['journal_id'] = method.sale_journal_id.id
 
68
        return res
 
69
 
 
70
    def _prepare_refund(self, cr, uid, invoice_id, *args, **kwargs):
 
71
        result = super(account_invoice, self)._prepare_refund(cr, uid, invoice_id, *args, **kwargs)
 
72
        invoice = self.read(cr, uid, invoice_id, ['payment_method_id'], context=kwargs['context'])
 
73
        result['payment_method_id'] = invoice['payment_method_id'][0]
 
74
        return result
 
 
b'\\ No newline at end of file'