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?
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
|Asked: 7/3/14, 5:55 PM|
|Seen: 1190 times|
|Last updated: 3/16/15, 8:10 AM|