Odoo Help

Welcome!

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.

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,122 views

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

1

Ray Carnes

--Ray Carnes--
15677
| 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 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

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

2 follower(s)

Stats

Asked: 12/30/14, 1:37 PM
Seen: 1122 times
Last updated: 3/16/15, 8:10 AM