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

existing object reference cannot be change

By
Lakay lakay
on 10/10/14, 12:25 AM 1,949 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

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

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
0

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 10/10/14, 1:51 AM

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

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
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

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

1 follower(s)

Stats

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