Odoo Help

2

1
10 Answers
2
Aron Lorincz Hungary
11/23/15, 11:26 AM

To add a hopefully "it just works" solution:

if not invoice.state == "open":
return
payable_amount = ... # The amount you want to pay
voucher = self.env["account.voucher"].create({
"name": "",
"amount": payable_amount,
"journal_id": self.env["account.journal"].search([("type", "=", "bank")], limit=1).id,
"account_id": invoice.partner_id.property_account_receivable.id,
"period_id": self.env["account.voucher"]._get_period(),
"partner_id": invoice.partner_id.id,
"type": "receipt"
})
voucher_line = self.env["account.voucher.line"].create({
"name": "",
"payment_option": "without_writeoff",
"amount": payable_amount,
"voucher_id": voucher.id,
"partner_id": invoice.partner_id.id,
"account_id": invoice.partner_id.property_account_receivable.id,
"type": "cr",
"move_line_id": invoice.move_id.line_id[0].id,
})
voucher.signal_workflow("proforma_voucher")
2
Carlos Castillo Spain
12/10/13, 6:51 AM

Thank you Boniface, that's the solution.

I figured it out yesterday at the end, the problem i had was that the account used in voucher didn't match with the default account of the Journal.

So, at the end, the workflow i used works like this (just insert and pay one invoice, if you want to pay all the partner's open invoices can be done the way Boniface said):

  1. Create invoice
  2. Create invoice lines
  3. Open Invoice (account.invoice workflow, action: invoice_open)
  4. Opening invoice will create an account.move related with the invoice
  5. Create Voucher specifying amount of the payment (matching invoice's amount), journal, account and period
  6. Create Voucher line with "move_line_id" matching Invoice's account.move.line Id
  7. Post payment (via account.voucher workflow, action: proforma_voucher)

In my case, this worked perfectly.

Hope this will help

1 Comment
Vlad Janicek Venezuela
2/16/14, 8:24 PM

I have tried for days this and had no success in registering the payment. i opened this threat http://help.openerp.com/question/44048/register-payment-using-xmlrpc/

1
Ferdinand Gassauer Austria
8/18/14, 1:32 AM

I suggest to create a python function (module) which is called via XMLRPC  - XMLRPC is much to slow

create and open invoice
create and post payment move
reconcile
        for inv in invoice_ids: 
            invoice_id = inv.id
            wf_service.trg_validate(uid, 'account.invoice', invoice_id, 'invoice_open', cr)
            for inv_open in invoice_obj.browse(cr, uid, [invoice_id] , context):
                invoices.append(inv_open.number)
                # payment
                journal_id = journal_obj.search(cr, uid, [('code','=', order_vals['pay_method'])])[0]
                journal = journal_obj.browse(cr, uid, [journal_id], context)[0]
                move_val = {
                    'partner_id' : inv_open.partner_id.id,
                    'date'       : inv_open.date_invoice,
                    'period_id'  : inv_open.period_id.id,
                    'journal_id' : journal_id,
                    'ref' : order_vals['pay_ref']
                }
                move_id =  move_obj.create(cr, uid, move_val, context)
                line_val = {
                    'account_id' : inv_open.account_id.id,
                    'credit'     : inv_open.residual,
                    'move_id'    : move_id,
                    'name'       : order_vals['pay_ref']
                }  
                line_val.update(move_val)
                line_id = move_line_obj.create(cr, uid, line_val, context)
                reconcile_lines = [line_id]
                line_val = {
                    'account_id' : journal.default_debit_account_id.id,
                    'debit'      : inv_open.residual,
                    'move_id'    : move_id,
                    'name'       : order_vals['pay_ref']
                }  
                line_val.update(move_val)
                line_id = move_line_obj.create(cr, uid, line_val, context)
                move_obj.button_validate(cr, uid, [move_id], context=context)

                inv_move_line_id = move_line_obj.search(cr, uid, [('move_id','=',inv_open.move_id.id), ('account_id','=', inv_open.account_id.id) ])[0]
                reconcile_lines.append(inv_move_line_id)
                move_line_obj.reconcile(cr, uid, reconcile_lines)

                invoice_obj.invoice_print(cr, uid, [inv_open.id], 'account.invoice', context)

1 Comment
Bino Canada
10/27/15, 10:09 AM

This worked for me, Thanks.. Just need to change 3 things i have changed below for invoice_id in invoice_ids: # invoice_id = inv.id wf_service.trg_validate(uid, 'account.invoice', invoice_id, 'invoice_open', cr) for inv_open in invoice_obj.browse(cr, uid, [invoice_id] , context): #invoices.append(inv_open.number) # payment journal_id = journal_obj.search(cr, uid, [('code','=', order_vals['pay_method'])])[0]

0
Alkivi SAS France
5/2/14, 12:31 PM

Hi guys,

I've been facing the same issue here, and here is the code that is currently working for us. Any feedback are appreciated :) Transaction object is a custom one, but contains the journal_id related to the bank account and an amount.

    invoice = self.browse(cr, uid, ids[0], context=context)
    move = invoice.move_id

    # First part, create voucher
    account = transaction.journal_id.default_credit_account_id or transaction.journal_id.default_debit_account_id
    period_id = self.pool.get('account.voucher')._get_period(cr, uid)
    partner_id = self.pool.get('res.partner')._find_accounting_partner(invoice.partner_id).id,

    voucher_data = {
        'partner_id': partner_id,
        'amount': abs(transaction.amount),
        'journal_id': transaction.journal_id.id,
        'period_id': period_id,
        'account_id': account.id,
        'type': invoice.type in ('out_invoice','out_refund') and 'receipt' or 'payment',
        'reference' : invoice.name,
    }

    _logger.debug('voucher_data')
    _logger.debug(voucher_data)

    voucher_id = self.pool.get('account.voucher').create(cr, uid, voucher_data, context=context)
    _logger.debug('test')
    _logger.debug(voucher_id)

    # Equivalent to workflow proform
    self.pool.get('account.voucher').write(cr, uid, [voucher_id], {'state':'draft'}, context=context)

    # Need to create basic account.voucher.line according to the type of invoice need to check stuff ...
    double_check = 0
    for move_line in invoice.move_id.line_id:
        # According to invoice type
        if invoice.type in ('out_invoice','out_refund'):
            if move_line.debit > 0.0:
                line_data = {
                    'name': invoice.number,
                    'voucher_id' : voucher_id,
                    'move_line_id' : move_line.id,
                    'account_id' : invoice.account_id.id,
                    'partner_id' : partner_id,
                    'amount_unreconciled': abs(move_line.debit),
                    'amount_original': abs(move_line.debit),
                    'amount': abs(move_line.debit),
                    'type': 'cr',
                }
                _logger.debug('line_data')
                _logger.debug(line_data)

                line_id = self.pool.get('account.voucher.line').create(cr, uid, line_data, context=context)
                double_check += 1
        else:
            if move_line.credit > 0.0:
                line_data = {
                    'name': invoice.number,
                    'voucher_id' : voucher_id,
                    'move_line_id' : move_line.id,
                    'account_id' : invoice.account_id.id,
                    'partner_id' : partner_id,
                    'amount_unreconciled': abs(move_line.credit),
                    'amount_original': abs(move_line.credit),
                    'amount': abs(move_line.credit),
                    'type': 'dr',
                }
                _logger.debug('line_data')
                _logger.debug(line_data)

                line_id = self.pool.get('account.voucher.line').create(cr, uid, line_data, context=context)
                double_check += 1

    # Cautious check to see if we did ok
    if double_check == 0:
        _logger.warning(invoice)
        _logger.warning(voucher_id)
        raise osv.except_osv(_("Warning"), _("I did not create any voucher line"))
    elif double_check > 1:
        _logger.warning(invoice)
        _logger.warning(voucher_id)
        raise osv.except_osv(_("Warning"), _("I created multiple voucher line ??"))


    # Where the magic happen
    self.pool.get('account.voucher').button_proforma_voucher(cr, uid, [voucher_id], context=context)
0
Jaakko Komulainen Finland
11/28/13, 6:50 AM

You need to reconcile the invoice from the voucher view. If the voucher has same partner as open invoice, it should offer you to reconcile the payment amount from that partners open invoice(s). After fully reconciled, the invoice moves to paid state and a journal entry is generated.

Hope this helps.

3 Comments
Carlos Castillo Spain
11/28/13, 8:26 AM

Thanks for the answer. The problem is that i need to do everything via XML-RPC, How could I reconcile the invoice that way?

Jaakko Komulainen Finland
11/28/13, 8:56 AM

I haven't looked into automatic reconciliation myself, but I guess you could try to use the openerp's reconcile tool at accounting/periodic processing/reconciliation/automatic reconciliation via XML-RPC.

Boniface Irungu Kenya
12/9/13, 10:03 AM

I figured out how to solve this. I had a client request to integrate openerp with another php based payment platform. Please check this answer http://stackoverflow.com/questions/16238044/openerp-7-api-invoice-validation-and-payment/20471961#20471961

hope this helps you.

Ask a Question
Keep Informed
3 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now