Odoo Help

0

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?

By
Ray Carnes
on 12/30/14, 1:37 PM 1,639 views

The Chart of Accounts was updated and all of the partners now have no AP or AP accounts set.

2
Ray Carnes
On 12/30/14, 1:56 PM

Version 8.0:

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.  

 

I have Over 100.000 Partners And I need their payable and receivable accounts changed and also Journal Entries on their account changed accordingly.How?

Zura Tsiklauri
on 3/11/15, 9:08 AM

Once you have changed the accounts, go to the Journal Entries and update the ID's based on the changes you have made. MAKE SURE you test this and UNDERSTAND what you are doing. Update account_move_line set account_id = NEW where account_id = OLD (provided there are no other entries using this account, if there are you need a query that isolates them).

Bista Solutions US, Ray Carnes
on 3/11/15, 8:30 PM

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

Question tools

3 follower(s)

Stats

Asked: 12/30/14, 1:37 PM
Seen: 1639 times
Last updated: 3/23/17, 5:33 AM