Odoo Help

0

existing object reference cannot be change

By
Lakay lakay
on 10/10/14, 12:25 AM 2,560 views

Hi, 

I override the class sale_order to change the object reference of the field  'partner_invoice_id' from 'res.partner' to my customize object 'addressinformation_billing' I went through restarting the server and then update the modules list and then install the my customize module. after clicking install it gave me error   

Integrity Error

The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: addressinformation_billing - addressinformation.billing]

after pressing 'OK' i went to models and check if the object reference had been changed, and yes it changes but the customize module was not installed because of the Integrity error.

Here is my override .py code

class sale_order(osv.osv):
        _name='sale.order'
        _inherit='sale.order'
        _columns={
                'partner_invoice_id': fields.many2one('addressinformation_billing', 'Delivery Address', readonly=True, required=False, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Invoice address for current sales order."),

}
sale_order()

 

any advice? thanks

0

Hi,

It is possible you have to take care following things to achieve your goal.

1) Your custom module is depends on "sale" module.

2) You have to inherit "sale.order" model in your custom code. And then give new defination for the same field as like below.

'partner_shipping_id': fields.many2one('other.model', 'Delivery Address', readonly=True, required=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Delivery address for current sales order."),

3) You have to restart the server and then after you have to install / update your custom module.

Thats it. It will change the reference of the field 'partner_shopping_id' to 'other.model'

It is overidding right? i put this on my customize module class sale_order(osv.osv): _name='sale.order' _inherit='sale.order' _columns={ 'partner_invoice_id': fields.many2one('addressinformation_billing', 'Delivery Address', readonly=True, required=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Invoice address for current sales order."), } sale_order() and to the instruction above, and then after i install my module im getting this Integrity Error The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it - creation/update: a mandatory field is not correctly set [object with reference: addressinformation_billing - addressinformation.billing] do i need to delete the field declaration in the sale.py or change the object reference same as in my customize module ?

Lakay lakay
on 10/10/14, 2:20 AM

Hello, Just give your field defination as like below. I think you have done one mistake into other.model. 'partner_invoice_id': fields.many2one('addressinformation.billing', 'Delivery Address', readonly=True, required=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Invoice address for current sales order."), Instead of addressinformation_billing you have to write addressinformation.billing because model name is like : addressinfromation.billing

Emipro Technologies Pvt. Ltd.
on 10/10/14, 2:28 AM

when i tried what you said class sale_order(osv.osv): _name='sale.order' _inherit='sale.order' _columns={ 'partner_invoice_id': fields.many2one('addressinformation.billing', 'Delivery Address', readonly=True, required=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Invoice address for current sales order."), } sale_order() it gives me KeyError: 'addressinformation.billing'

Lakay lakay
on 10/10/14, 2:44 AM

May I know the other model name (except res.partner) which you want to set for the 'partner_invoice_id' field ?

Emipro Technologies Pvt. Ltd.
on 10/10/14, 2:47 AM

emipro, after the error i check the object and it now changes!, but i cannot install my costumize module

Lakay lakay
on 10/10/14, 3:00 AM

Can you update your question and write down your code, xml of your custom module ? We will resolve your issue.

Emipro Technologies Pvt. Ltd.
on 10/10/14, 3:05 AM

its now edited but i didn't include the xml

Lakay lakay
on 10/10/14, 5:00 AM

Please make your new model with atleast one "." like "addressinformation.billing" you have create new model without "." that is the issue. So, please make it with "." I hope it will resolve. It is a very simple and very necessary requirement.

Emipro Technologies Pvt. Ltd.
on 10/10/14, 5:14 AM

Have you try with at least one "." in new model ?

Emipro Technologies Pvt. Ltd.
on 10/10/14, 6:45 AM

yes already tried that but didn't work, this is what written in my server log after the error occured, line 149, in wrapper except_orm : ('Integrity_Error'), the operation cannot be completed, probably due to the following :\n deletion: you may be trying to delete a record while other records still reference it \n -creation/update: a mandatory field is not correctly set\n\n[object with reference: addressinformation_billing - addressinfrmation.billing]')..

Lakay lakay
on 10/13/14, 9:47 PM
0
Ben Bernard
On 10/10/14, 2:07 AM

Don't just "upgrading the modules list", you have to also upgrade the sale module. You can do it via the web interface. Other option is to make new custom module as described by @Emipro

yes i followed that but theres a new error, integrity error

Lakay lakay
on 10/10/14, 5:05 AM
0
deep
On 10/10/14, 3:26 AM

When a relation is established, in the database the Foreign Key of that object will be saved for that column... but later if you wished to change the object but you want to retain the same column... then in the database, do drop the Foreign key constraint for that column.. and upgrade the module...

So in your case:

Go to database  >> sale_order (Table) >> Constraints >> "sale_order_partner_shipping_id_fkey"

drop the constraint "sale_order_partner_shipping_id_fkey"... and then upgrade your module

can i do it in web UI? or need to access database via postgresql because in Odoo v9.0 alpha its on Settings > Database structure > model constraints ... there i can find the sale_order_partner_invoice_id_fkey and sale_order_partner_shipping_id_fkey and i check the checkbox and deleted them (after restarting and upgrading the module the problem when i installing still occured) is it the same as drop? as you mention "drop the constraint "sale_order_partner_shipping_id_fkey"."?

Lakay lakay
on 10/10/14, 5:04 AM

Am not sure about this, dropping from web UI... try accessing the database..

deep
on 10/10/14, 5:21 AM

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

1 follower(s)

Stats

Asked: 10/10/14, 12:25 AM
Seen: 2560 times
Last updated: 3/16/15, 8:10 AM