Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Register payment using XMLRPC

Subscribe

Get notified when there's activity on this post

This question has been flagged
accountpaymentaccount.invoicexmlrpcaccount.voucher
5 Replies
14608 Views
Avatar
Vlad Janicek

Hi there,

I have been trying to register an invoice payment through OpenERP. I have been able to manually create and approve the invoice, the voucher and its line

I'm currently creating the voucher using this information:

def create_voucher(name, amount, journal_id, account_id,
                   period_id, partner_id, move_id):
    model = 'account.voucher'
    r = {
        'name': name,
        'amount': amount,
        'journal_id': journal_id,
        'account_id': account_id,
        'period_id': period_id,
        'partner_id': partner_id,
        'type': 'receipt',
        # Colocar move_id
        'move_id': move_id
    }
# executing XMLRPC stuff

And im creating voucher lines with this info

def create_voucher_line(name, amount, voucher_id, partner_id, account_id):
    model = 'account.voucher.line'
    r = {
        'name': name,
        'payment_option': 'without_writeoff',
        'amount': amount,
        'voucher_id': voucher_id,
        'partner_id': partner_id,
        'account_id': account_id,
        #'move_id': move_id
        #'amount': 0,
        #'type': 'cr'
    }
# executing XMLRPC stuff

I can successfully see the voucher record and it's lines but this is where I may be wrong. How do I register that voucher into an invoice payment?? I have tried to use proforma voucher with no success

db_conn.exec_workflow('mydb', 1, 'admin', 'account.voucher',  'proforma_voucher', voucher_id)

If I'm successfully creating a voucher and it's lines, what would be the final step to register that as a payment??

Thanks a lot for your help

jhv

2
Avatar
Discard
Aron Lorincz

I've added an (I think) simple-to-follow answer here: https://www.odoo.com/forum/help-1/question/how-to-apply-payment-to-invoice-via-xml-rpc-37795#answer_93799

Avatar
Carlos Castillo
Best Answer

Hi,

I had the same issue and in my case I needed to remove the field "move_id" from account.voucher and adding the field "move_line_id" to account.voucher.line, have you tried that?

move_line_id should match the ID of the account.move.line whose "move_id" field matches the "move_id" field of the invoice you created

I also set 'type'='cr' for account.voucher.line

After that, executing workflow('account.voucher', 'proforma_voucher', voucher_id) worked ok,

Hope this helps!

3
Avatar
Discard
Vlad Janicek
Author

Had few days without checking this and yes!! i found out how to do it and is exactly what you said!!

Avatar
Luc Vanwaelscappel
Best Answer

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)
1
Avatar
Discard
Peter Alabaster

Thanks for this - helped me to write test cases for registering payment on invoices. For some reason i was getting the 'double_check > 1' case, and it turned out it was a stock account getting into the mix with a debit above 0. I'm not sure if this is a config issue or just that the above code doesn't take into account the stock accounts (V8). Either way, cheers !

Avatar
Ashif Abdulrahman
Best Answer

no need to inherit account.voucher. after creating the account.voucher record, you just add this in your XMLRPC script.

self.sock.execute(self.dbname, self.uid, self.pwd, 'account.voucher', 
                             'button_proforma_voucher', voucher_id, {})

voucher_id should be the ID of the created voucher.

1
Avatar
Discard
Vlad Janicek
Author

I did, as I mentioned in my post, but it didnt chante its status. Am i missing something with the voucher or its line? Should I add another record? or should I add more lines per voucher?

Jack Richard

@Vlad Janicek what is the issue with it? have you got any errors?

Vlad Janicek
Author

I may be inserting wrong records in voucher lines... I get no errors when I execute the workflow. Ashif suggested execute but execute is for browsing. I used exec_workflow. I only get False and no changes are made

Vlad Janicek
Author

any ideas? im about to give up

Vlad Janicek
Author

I tried that too. I get this returned: {'type': 'ir.actions.act_window_close'}

That is the button that is pressed in the register payment wizard view. Wont this avoid all the functions in that view?

I tried that when I realized that I have to execute all the onmove functions in order to have all the account_voucher_lines records.

Thanks a lot, I really appreciate your help dude! I'll keep trying to figure it out

Vlad Janicek
Author

I even found out that 'confirm_paid' would make an invoice as 'paid' but wont tie it to a voucher. wf_service.trg_validate(uid, 'account.invoice', invoice_id, 'confirm_paid', cr). The invoice will be paid but it wont register it's payment. Doesn't work for us either

Avatar
Ferdinand Gassauer
Best Answer

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

  1. create and open invoice
  2. create and post payment move
  3. 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)

0
Avatar
Discard
Avatar
Vlad Janicek
Author Best Answer

Thank you very much for for answer and help.

I tried that already and it didn't work. It may be that I'm missing to add the exact move_line_id or any other record to account_voucher_line or that I'm missing something else.

Just in case, I followed everything you said with no payment being registered.

This is how I inherited account_voucher:

class account_voucher(osv.osv):
    _inherit = 'account.voucher'

    def action_proforma_voucher(self, cr, uid, voucher_id, context=None):
        wf_service = netsvc.LocalService("workflow")
        wf_service.trg_validate(uid, 'account.voucher', voucher_id,
                                'proforma_voucher', cr)
        wf_service.trg_write(uid, 'account.voucher', voucher_id, cr)
        return True

BTW I printed both outputs

wf_service.trg_validate(uid, ...
wf_service.trg_write(uid, 'acc...

and they print False and None respectively

This is what I used to execute the XMLRPC call

def set_payment(voucher_id):
    db_conn = xmlrpclib.ServerProxy(dc.url + '/xmlrpc/object')
    return db_conn.execute('mydb', myuid, 'mypass', 'account.voucher',
                           'action_proforma_voucher', voucher_id, {})

I still don't understand this process. What is exactly needed by the 'proforma_voucher' WF process? I have checked all the onchange functions in the register payment view and they create many account_voucher_lines whereas I'm just creating one.

Thanks a lot for your help pal

0
Avatar
Discard
Ashif Abdulrahman

There is an another way, i have updated my previous answer. check it out....

Vlad Janicek
Author

@Ashif: thanks! I updated my last comment. It didnt work either.

Vlad Janicek
Author

Still trying... doing each onchange by hand and it doesn't work

Ashif Abdulrahman

hi, please check this too...

Vlad Janicek
Author

Updated, still not working

Vlad Janicek
Author

Any ideas?

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to update delay charges?
account payment account.invoice payment_term
Avatar
0
Mar 15
4903
Any module for delay charges?
module account payment account.invoice total
Avatar
0
Mar 15
4823
can't validate invoice in multi-company (Document type: Account, Operation: read) Solved
account account.invoice
Avatar
Avatar
Avatar
Avatar
Avatar
5
Dec 23
22872
Openerp 7 Indian Accounting
account account.invoice
Avatar
0
Mar 15
4751
Export accounting entry of payment with linked invoice sequence number
invoice account payment
Avatar
Avatar
1
May 25
2464
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now