This question has been flagged
3 Replies
6242 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

Avatar
Discard
Best Answer

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'

Avatar
Discard
Author

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 ?

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

Author

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'

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

Author

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

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

Author

its now edited but i didn't include the xml

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.

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

Author

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]')..

Best Answer

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

Avatar
Discard
Author

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

Best Answer

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

Avatar
Discard
Author

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"."?

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