Odoo Help


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

Ray Carnes
on 7/3/14, 5:55 PM 1,640 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
Keyport, United States
--Ray Carnes--

Senior ERP Analyst

OpenERP 6.1, 7.0; Odoo 8.0, 9.0, 10.0.

Completed Odoo Functional and Technical Training.

Functional Areas:

  • CRM/Sales

  • Inventory

  • Manufacturing

  • Accounting

  • Purchasing

Major Skills:

  • Business Process Reengineering

  • Efficiency Consulting

  • User Needs and GAP Analysis;

  • Functional and Technical Design;

  • Prototyping and Proof of Concepts;

  • Requirements Specifications;

  • Agile Implementation;

  • Data Migration;

  • Configuration & Customization (UI and code);

  • Integration - Odoo and non Odoo Applications and Services;

  • Training and Knowledge Transfer;

  • Go Live Support;

  • Helpdesk;

  • Version Upgrades and Migration.

  • Accounting Expert.

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. 

I am a skilled Communicator and I only take the serious things seriously!

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.

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.


Odoo Training Center

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

Test it now

Question tools

1 follower(s)


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