Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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?
The Chart of Accounts was updated and all of the partners now have no AP or AP accounts set.
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. You should backup your database and test this on a backup and only do this on a production system if you are 100% certain it works the way you want.
AP and AR accounts for partners are stored in the ir_property table. Set one partner with the accounts you want and take a look at this table in SQL to get familiar with the structure and how these properties are represented.
Query the table this way:
SELECT name, type, company_id, fields_id, value_reference, res_id FROM ir_property WHERE name = 'property_account_receivable' or name = 'property_account_payable';
An example output would be this:
name, type, company_ud, fields_id, value_reference, res_id
property_account_payable, many2one, 1, 1960, "account.account,64, "res.partner,17"
property_account_receivable, many2one, 1, 1957, "account.account,59", "res.partner,17"
Looking at res_id - this tells you that the property is being attached to record 17 of the res_partner model.
Looking at fields_id - this tells you that the property is being attached to field 1960 (payable) or 1957 (receivable) of the res_partner model.
Looking at value_reference - this tells you that the property is a link to an account and that ID 64 represents the payable account and ID 59 represents the receivable account.
Once you verify how this looks on your database, for each partner you run the following two SQL statements:
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,1960,'account.account,64','res.partner,db_id_of_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,1957,'account.account,59','res.partner,db_id_of_partner');
TIP: If you are rusty on your SQL, you can 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 (you can do this in a text editor). I did this because it was easier for me than working out how to loop through every partner.
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
|Asked: 12/30/14, 1:37 PM|
|Seen: 1364 times|
|Last updated: 3/23/17, 5:33 AM|