OpenERP中的完整性错误

时间:2014-05-15 05:03:16

标签: python xml openerp

大家好,我一直在使用OpenERP-7中的模块,我遇到了单击按钮时发生的完整性错误。          我的模块工作正常,直到昨天,但后来我在xml视图中进行了一些更改,比如从product.product类继承了一些字段.xml视图工作正常,但是按钮功能在我将继承的字段包含到我之后给了我完整性错误我的模块。我的python代码如下:

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()

这是我的xml代码:

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

我的xml代码中的两个按钮与两个函数相关联。一个是返回当前产品的表单视图,另一个是返回默认产品表单以创建新产品。点击时的按钮会出现以下错误:

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]  

当我尝试添加一个新按钮只是为了显示一条消息时,我仍然得到相同的完整性错误。我认为这是因为那些继承的字段或者可能是其他的东西。请指导我这个方向以便我可以能够解决这个问题。谢谢你的问候

2 个答案:

答案 0 :(得分:2)

您继承自product.product,这意味着product.product中的所有字段都会出现在您的deg.form模型中,这就是您的错误。 您的视图xml(错误字典:categ1是其中的两倍)并未显示来自product.product模型的必填字段。所以你不能在你的视图中设置它们,但它们是必需的(例如名称,categories_id,type),这样就会出错。

不再需要它们的方法是覆盖所需的列。


完整性错误

操作无法完成,可能是由于以下原因: - 删除:您可能正在尝试删除记录,而其他记录仍然引用它 - 创建/更新:未正确设置必填字段

[参考对象:名称 - 名称]

答案 1 :(得分:0)

我已经解决了完整性问题。我之前使用inheritance by prototyping导致错误。然后我意识到我应该使用class inheritance,因为我不需要父类的所有字段。为此,我们必须小心设置值_name == _inherit.