Hello to all , I have been working on a module in OpenERP-7 and I have come across an Integrity error which is occurring on clicking the button. My module was working fine untill yesterday but then I made some changes in the xml view like inheriting some fields from product.product class.The xml view is working ok but the button function is giving me integrity error just after I included the inherited fields into my module.My python code is given below:
import time
from lxml import etree
from openerp.osv import fields, osv
from openerp import tools
class deg_form(osv.osv):
_name = "deg.form"
_inherit="product.product"
_columns = {
'categ1':fields.many2one('product.category','Category'),
'categ2':fields.many2one('product.category','Category'),
'my_products':fields.many2one('product.product','Parent'),
}
def Product_Category_OnChange(self,cr,uid,ids,categ1):
pro_id=[]
cr.execute('select id,name from product_template where categ_id in (select id from product_category where parent_id in (select id from product_category where parent_id='+str(categ1)+')) union select id,name from product_template where categ_id in (select id from product_category where parent_id='+str(categ1)+') union select id,name from product_template where categ_id='+str(categ1))
res = cr.fetchall()
for pid,name in res:
pro_id.append((pid))
return {'domain':{'my_products':[('id','in',pro_id)]}}
def create_product(self,cr,uid,ids,context):
return{
'view_type': 'form',
'view_mode': 'form',
'res_model': 'product.product',
'context': "{}",
'type': 'ir.actions.act_window'}
def show_product(self,cr,uid,ids,context):
for id in ids:
deg_obj=self.pool.get('deg.form').browse(cr,uid,id)
my_id=int(deg_obj.my_products)
return{
'view_type': 'form',
'view_mode': 'form',
'res_model': 'product.product',
'res_id':my_id,
'context': "{}",
'type': 'ir.actions.act_window'}
deg_form()
Here is my xml code:
<?xml version="1.0" ?><openerp>
<data>
<!-- ############################# MAIN FORM VIEW ######################### -->
<record id="mywin_form_view" model="ir.ui.view">
<field name="name">mywin.form</field>
<field name="model">deg.form</field>
<field eval="7" name="priority"/>
<field name="arch" type="xml">
<form string="FORM DATA" version="7.0">
<h1>
<label for="categ1" string="Parent Category"/>
<field name="categ1" on_change="Product_Category_OnChange(categ1)" />
</h1>
<h1>
<label for="categ2" string="Child Category"/>
<field name="categ2" />
</h1>
<div name="options" position="inside">
<field name="asset_ok"/>
<label for="asset_ok"/>
<!-- <field name="asset_type" attrs="{'invisible':[]}"/>-->
</div>
<field name="asset_type"/>
<newline/>
<newline/>
<!-- NOEBOOK STARTED -->
<notebook>
<page string="Asset Informations" attrs="{'invisible':[('asset_ok','=',False)]}">
<group colspan="2" col="4" attrs="{'invisible': [('asset_type', '!=', 'phones')]}">
<separator colspan="2" string="Phone Details"/>
<newline/>
<field name="phone_id"/>
<field name="phone_data_id"/>
<field name="contr_exp_phone"/>
<field name="job_num_phone"/>
<field name="phone_num_phone"/>
<field name="person_phone"/>
<field name="mgr_phone"/>
<field name="remarks_phone"/>
<field name="radio_phone"/>
<field name="pm_phone"/>
<field name="dept_code_phone"/>
</group>
<group colspan="2" col="4" attrs="{'invisible': [('asset_type', '!=', 'equipment')]}">
<separator colspan="2" string="Equipment Details"/>
<newline/>
<field name="mon_pay_equip"/>
<field name="dealer_equip"/>
<field name="insp_time_equip"/>
<field name="ins_ren_date_equip"/>
<field name="make_equip"/>
<field name="model_equip"/>
<field name="serial_num_equip"/>
<field name="btu_equip"/>
<field name="location_equip"/>
<field name="pur_date_equip"/>
<field name="warr_equip" />
<field name="term_warr_equip"/>
<field name="warr_contact_equip"/>
<field name="remarks_equip"/>
<field name="issue_date_equip"/>
<field name="issue_to_equip"/>
<field name="ret_date_equip"/>
<field name="cost_equip"/>
<field name="vendour_equip"/>
<field name="equip_quant_equip"/>
<field name="inv_date_equip"/>
<field name="lease_agg_num_equip"/>
<field name="loan_term_equip"/>
<field name="state_reg_equip"/>
</group>
<group colspan="2" col="4" attrs="{'invisible': [('asset_type', '!=', 'copiers')]}">
<separator colspan="2" string="Copier Details"/>
<newline/>
<field name="mon_pay_copier"/>
<field name="start_date_copier"/>
<field name="make_copier"/>
<field name="serial_num_copier"/>
<field name="excess_copy_copier"/>
<field name="quat_allow_copier"/>
<field name="term_copier"/>
<field name="reg_expdate_copier"/>
<field name="service_copier"/>
<field name="service_num_copier"/>
<field name="location_copier"/>
<field name="vendour_copier"/>
<field name="lease_agg_num_copier"/>
<field name="remarks_copier"/>
</group>
<group colspan="2" col="4" attrs="{'invisible': [('asset_type', '!=', 'vehicles')]}">
<separator colspan="2" string="Vehicle Details"/>
<newline/>
<field name="fuel_card_vehicle"/>
<field name="maintain_card_vehicle"/>
<field name="pass_tag_vehicle"/>
<field name="stage_reg_vehicle"/>
<field name="plate_vehicle"/>
<field name="plate_type_vehicle"/>
<field name="vin_no_vehicle"/>
<field name="ls_ln_term_vehicle"/>
<field name="tot_mileage_vehicle"/>
<field name="monthly_payment_vehicle"/>
<field name="dealer_vehicle" />
<field name="reg_exp_date_vehicle"/>
<field name="ins_exp_date_vehicle"/>
<field name="loss_payee_vehicle"/>
<field name="mileage_receipt_vehicle"/>
<field name="mileage_vehicle"/>
<field name="mileage_date_vehicle"/>
<field name="driver_vehicle"/>
<field name="unit_num_vehicle"/>
<field name="probblem_vehicle"/>
<field name="v_cost_vehicle"/>
<field name="v_date_vehicle"/>
<field name="own_type_vehicle"/>
</group>
<group colspan="2" col="4" attrs="{'invisible': [('asset_type', '!=', 'jackets')]}">
<separator colspan="2" string="Jacket Details"/>
<newline/>
<field name="jack_size_id"/>
<field name="name_jacket"/>
<field name="title_jacket"/>
<field name="supervisor_jacket"/>
</group>
<group colspan="2" col="4" attrs="{'invisible': [('asset_type', '!=', 'ndt')]}">
<separator colspan="2" string="NDT Details"/>
<newline/>
<field name='equip_type_ndt'/>
<field name="equip_quant_ndt"/>
<field name="model_num_ndt"/>
<field name="serial_num_ndt"/>
<field name="pers_resp_ndt"/>
<field name="last_calibration_ndt"/>
<field name="next_calibration_ndt"/>
<field name="operation_ndt"/>
<field name="last_review_ndt"/>
</group>
<separator colspan="1" string="_________________________________________________________________" />
</page>
</notebook>
<h1>
<label for="my_products" string="Products" />
<field name="my_products" />
</h1>
<button name="show_product" string="SHOW PRODUCT" type="object"/>
<button name="create_product" string="CREATE PRODUCT" type="object"/>
<!-- NOTEBOOK ENDED -->
</form>
</field>
</record>
<!-- ############################# MAIN TREE VIEW ######################### -->
<record id="mywin_tree_view" model="ir.ui.view">
<field name="name">myform.tree</field>
<field name="model">deg.form</field>
<field eval="7" name="priority"/>
<field name="arch" type="xml">
<tree string="FORM DATA" version="7.0">
<field name="categ1"/>
</tree>
</field>
</record>
<!-- ############################# ######################### -->
<record id="mywin_new_action" model="ir.actions.act_window">
<field name="name">New</field>
<field name="res_model">deg.form</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="mywin_tree_view"/>
</record>
<record id="mywin_new_form" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="mywin_form_view"/>
<field name="act_window_id" ref="mywin_new_action"/>
</record>
<record id="mywin_new_tree" model="ir.actions.act_window.view">
<field eval="3" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="mywin_tree_view"/>
<field name="act_window_id" ref="mywin_new_action"/>
</record>
<!-- *****************Main Calling Menu*********************** -->
<menuitem id="myform" name="Search Product" sequence="1"/>
<menuitem id="myform_menu" name="Main Menu" parent="myform" />
<menuitem action="mywin_new_action" id="myform1_menu" name="Search Product" parent="myform_menu"/>
</data>
</openerp>
The two buttons in my xml code are associated to two functions . One is returning the form view of the current product and other is returning the default product form for creating new product.The buttons on clicking are giving following 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: name - name]
When I try to add a new button just to show a message, I still get the same integrity error.I think it is because of that inherited fields or may be something else.Please guide me to the direction so that I may be able to fix this. Thanks n Regards