OpenERP 5.0.16, 6.0.3, 6.0.4 & 6.1 Technical Tutorial : Memperbaiki Relationship many2one

Ketika membuat sebuah field many2one di OpenERP, terkadang developer salah menuliskan ke object mana many2one tersebut direlasikan. Jika field tersebut sudah terbuat, developer tidak bisa serta-merta mengkoreksi file .py untuk membetulkan relasi tersebut.

CONTOH
class object_contoh(osv.osv):
    _columns = {
               'name' : fields.char(string='Nama', size=100),
               'partner_id' : fields.many2one(obj='account.account', string='Partner'),
               }

Relasi many2one pada baris ke-4 harusnya ke object res.partner

LANGKAH KOREKSI

#1 Betulkan file .py nya

class object_contoh(osv.osv):
    _columns = {
               'name' : fields.char(string='Nama', size=100),
               'partner_id' : fields.many2one(obj='res.partner', string='Partner'),
               }

#2 Restart Server

#3 Update module dimana file .py tsb berada

#4 Perbaiki constraint pada tabel yang salah dengan menggunakan pgadmin

Sintaks SQL asal :

ALTER TABLE object_contoh
    ADD CONSTRAINT object_contoh_partner_id_fkey FOREIGN KEY (partner_id)
        REFERENCES account_account (id) MATCH SIMPLE
        ON UPDATE NO ACTION ON DELETE SET NULL;

Koreksi menjadi (perhatikan baris ke-3):

ALTER TABLE object_contoh
    ADD CONSTRAINT object_contoh_partner_id_fkey FOREIGN KEY (partner_id)
        REFERENCES res_partner (id) MATCH SIMPLE
        ON UPDATE NO ACTION ON DELETE SET NULL;
No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s