Odoo Help


This community 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.


How to mass update the AR and AP accounts on 100,000 Partners? SQL?

Ray Carnes
on 7/3/14, 5:55 PM 1,160 views

I have over 100,000 partners that need to have their Account Payable and Account Receivable accounts changed. 

How do I do this via SQL? 


Ray Carnes

--Ray Carnes--
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

Ray Carnes
On 7/3/14, 5:59 PM

WARNING: Updating the PostgreSQL database via SQL is considered a very advanced technique and should never be done unless you have a complete understanding of the Odoo schema and business logic, and you perform extensive testing on what you are attempting to do.


AP and AR accounts for partners are stored in the ir_property table. 

The field database id's are 1102 (AR) and 1104 (AP).  If you manually set the accounts and search where res_id = 'res.partner,DATABASE_ID_OF_PARTNER' you can see the two relevant rows and verify the field id's for yourself.

You need to know the database id's of your AP and AR accounts, and once you do, for each partner you run the following SQL statements 

1. Delete existing AR and AP account settings for every partner:

delete from ir_property where name in ('property_account_payable','property_account_receivable');

The next two statements need to be run for EVERY partner:

2. Add an AR account to a partner:

insert into ir_property (create_uid,create_date, write_date,write_uid, name,type,company_id,fields_id,value_reference,res_id) VALUES (1,current_date,current_date,1,'property_account_receivable','many2one',1,1102,'account.account,db_id_of_ar_account','res.partner,db_id_of_partner'); 

3. Add an AP account to a partner:

insert into ir_property (create_uid,create_date, write_date,write_uid, name,type,company_id,fields_id,value_reference,res_id) VALUES (1,current_date,current_date,1,'property_account_payable','many2one',1,1104,'account.account,db_id_of_ap_account','res.partner,db_id_of_partner'); 

TIP: Export all of the database id's into a CSV file, prepend the relevant SQL, replace the linefeed character with the end quote and a semicolon, save the result as a *.sql file and import into the database.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 7/3/14, 5:55 PM
Seen: 1160 times
Last updated: 3/16/15, 8:10 AM