如何在odoo的表单视图中给one2many字段获取树视图?

时间:2016-08-01 13:12:15

标签: forms python-2.7 treeview odoo-8

我想在表单视图中给出一个树视图,我需要给出one2many字段。

我已经给了one2many字段,我也在表单视图中获得树视图。

但问题是当我在表单视图的树视图中给出一些值时,我保存记录时显示此错误

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: make - make] 

当我没有在树视图中给出任何值并保存记录时,它不会显示任何错误。

我的代码是

的.py

class vansdent_bill(osv.osv):
_name = "vansdent.bill"
_description = "Vans Dent"
_columns = {
     'name': fields.char('Year', required=True),
     'make': fields.char('Make', required=True),
     'model': fields.char('Model', required=True),
     'customer': fields.many2one('res.partner', 'Customer', domain=[('customer', '=', True)]),
     'serviceid': fields.many2one('vans.dent', 'Service ID', select=True),
     'vin':fields.char('VIN'),
    'description':fields.char('Description'),
    'part':fields.char('Part'),
    'price':fields.char('Price'),
    'quantity':fields.char('Qty'),
    'labour':fields.char('Labour'),
    'paint':fields.char('Paint'),
    'other':fields.char('Other'),
    'empty': fields.char('empty', ondelete='cascade'),
    'order_line': fields.one2many('vansdent.bill', 'empty', 'Order Lines'),
    'type':fields.char('Type'),
    'hours':fields.char('Hours'),
    'rate':fields.char('Rate/hr'),
    'total':fields.char('Total'),
    'tax':fields.char('Taxable'),
    'tamount':fields.char('Taxable Amount'),
    'atax':fields.char('Tax'),
    'ntotal':fields.char('Net Total'),
    'desc':fields.text('Descriptiom'),
    'empty2': fields.char('empty', ondelete='cascade'),
    'order_line2': fields.one2many('vansdent.bill', 'empty2', 'Order Lines'),
}

def vansdentbill_service(self, cr, uid, ids, serviceid=False, context=None):

     res = {}

     if serviceid:

         service_obj = self.pool.get('vans.dent')

         rec = service_obj.browse(cr, uid, serviceid)

         res = {'value': {'name': rec.year.name, 'model': rec.model.name, 'make': rec.make.name,'vin':rec.vin}}

     else:

         res = {'value': {'name': False, 'model': False, 'make': False,'vin':False}}

     return res

.XML

  <record id="vans_service_form_view" model="ir.ui.view">
            <field name="name">vans.service.form</field>
            <field name="model">vansdent.bill</field>
             <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Billing">
                <sheet>
                    <group>
                    <group>
                     <field name="serviceid" on_change="vansdentbill_service(serviceid)"/>
                        <field name="customer"/>
                        <field name="vin"/>
                        </group>
                        <group>
                    <field name="name" />
                    <field name="make"  />
                    <field name="model"/>
                    </group>

                    </group>
                    <notebook>
                        <page string="Service">
                        <field name="order_line">
                        <tree string="Service Details" editable="bottom">
                            <field name="description"/>
                            <field name="part"/>
                            <field name="price"/>
                            <field name="quantity"/>
                            <field name="labour"  />
                            <field name="paint"/>
                            <field name="other"/>
                        </tree>
                            </field>
                        <separator string="Totals"/>
                            <field name="order_line2">
                                <tree string="Bill Details" editable="bottom">
                                      <field name="type"/>
                            <field name="hours"/>
                            <field name="rate"/>
                            <field name="total"/>
                            <field name="tax"  />
                            </tree>
                            </field>
                             <group class="oe_subtotal_footer oe_right">
                            <field name="tamount" widget="monetary" options="{'currency_field': 'currency_id'}"/>
                            <field name="atax" widget="monetary" options="{'currency_field': 'currency_id'}"/>
                             <div class="oe_subtotal_footer_separator oe_inline">
                                <label for="ntotal"/>
                            </div>
                            <field name="ntotal" nolabel="1" class="oe_subtotal_footer_separator" widget="monetary" options="{'currency_field': 'currency_id'}"/>
                            </group>
                             <div class="oe_clear"/>
                        <field name="desc" class="oe_inline" placeholder="Terms and conditions..."/>
                        </page>
                    </notebook>
                </sheet>
            </form>
</field>
   </record>

   <record model="ir.ui.view" id="vans_service_tree_view">
        <field name="name">vans.service.tree</field>
        <field name="model">vansdent.bill</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
        <tree string="Service">
            <field name="serviceid"/>
            <field name="customer"/>
            <field name="vin"/>
        <field name="name"/>
        <field name="make"/>
        <field name="model"/>

        </tree>
    </field>
       </record>

        <record model="ir.actions.act_window" id="vans_service_buy_form">
 <field name="name">vansdent.Service</field>
<field name="res_model">vansdent.bill</field>
</record>


 <menuitem name="Billing" parent="base.menu_sales" id="vansdent_service_menu_mainform" action="vans_service_buy_form" sequence="6"/>

我只需要在表单视图中使用树视图,而不是与one2many字段的任何依赖关系。

我怎样才能做到这一点?

...谢谢

1 个答案:

答案 0 :(得分:1)

错误与make字段有关,该字段设置为required。最有可能的是,您尝试创建/更新记录而不设置其值。它不会显示在树视图中,因此除非有默认值或其他方法来设置它,否则用户无法执行此操作,因此出现错误:

  
      
  • 创建/更新:未正确设置必填字段
  •   
     

[参考对象:make - make]