Skip to content

Instantly share code, notes, and snippets.

@mrsarm
Created July 18, 2014 20:58
Show Gist options
  • Save mrsarm/4699a24ca1b0bc12eb84 to your computer and use it in GitHub Desktop.
Save mrsarm/4699a24ca1b0bc12eb84 to your computer and use it in GitHub Desktop.
OpenERP / Odoo Script - Adds Partner ID constraints in those columns without FK
/*
* OpenERP / Odoo Script - Adds Partner ID constraints.
*
* Issue:
* Sometimes, OpenERP / Odoo defines foreign keys without constraints.
* This mainly happens with related fields with store=True,
* which create a column of integers without constraints.
*
* Author: Mariano Ruiz <mrsarm@gmail.com>
* Created: 2014-07-18
*
* NOTE: If the script fails, verify if the BBDD has all the tables
* present here. Also you should be check if your database has more
* references to the partner table.
* If you execute this with ``psql`` command without ``-1`` argument
* (single transaction), only will be added those fkeys that
* currently not exist and the table exist.
*/
ALTER TABLE account_invoice_line ADD CONSTRAINT account_invoice_line_partner_id_fkey FOREIGN KEY (partner_id) REFERENCES res_partner(id);
ALTER TABLE stock_picking ADD CONSTRAINT stock_picking_partner_id_fkey FOREIGN KEY (partner_id) REFERENCES res_partner(id);
ALTER TABLE account_move ADD CONSTRAINT account_move_partner_id_fkey FOREIGN KEY (partner_id) REFERENCES res_partner(id);
ALTER TABLE payment_mode ADD CONSTRAINT payment_mode_partner_id_fkey FOREIGN KEY (partner_id) REFERENCES res_partner(id);
ALTER TABLE hr_analytic_timesheet ADD CONSTRAINT hr_analytic_timesheet_partner_id_fkey FOREIGN KEY (partner_id) REFERENCES res_partner(id);
ALTER TABLE purchase_order_line ADD CONSTRAINT purchase_order_line_partner_id_fkey FOREIGN KEY (partner_id) REFERENCES res_partner(id);
ALTER TABLE sale_order_line ADD CONSTRAINT sale_order_line_partner_id_fkey FOREIGN KEY (order_partner_id) REFERENCES res_partner(id);
ALTER TABLE stock_move ADD CONSTRAINT stock_move_partner_id_fkey FOREIGN KEY (partner_id) REFERENCES res_partner(id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment