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

How to give one2many field to create grid view in the form?

By
Uppili Arivukkannu
on 7/25/16, 5:08 AM 529 views

I want to create grid view in the form view.

I have written the xml for the grid view. But I searched and see that for gird view it must have one2many field above the tree. What is the reason to give one2many field?

My codes are given below

.py

class vansdent(osv.osv):

_name = "vans.dent"

_description = "Vans Dent"

_rec_name = 'service'

_description = "Vals Dent"

_columns = {

'year': fields.many2one('dent.year', 'Year', required=True, select=True),

'make': fields.many2one('vals.make','Make', required=True),

'model': fields.many2one('car.model','Model', required=True, select=True),

'service': fields.char('Service ID', required=True),

'vcustomer':fields.many2one('res.partner', 'Customer', domain=[('customer', '=', True)], select=True),

'vin':fields.char('VIN'),

}

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.char('Customer', required=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'),

}

def vansdent_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, 'customer':rec.vcustomer.name, 'vin':rec.vin}}

else:

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

return res


.xml

<record id="vansdent_form_view" model="ir.ui.view">

<field name="name">vans.dent.form</field>

<field name="model">vans.dent</field>

<field name="type">form</field>

<field name="arch" type="xml">

<form string="Customer Details">

<sheet>

<group>

<field name="service"/>

<field name="vcustomer"/>

<field name="vin"/>

<field name="year"/>

<field name="make"/>

<field name="model"/>

</group>

</sheet>

</form>

</field>

</record>

<record model="ir.ui.view" id="vansdent_tree_view">

<field name="name">vans.dent.tree</field>

<field name="model">vans.dent</field>

<field name="type">tree</field>

<field name="arch" type="xml">

<tree string="customer details">

<field name="service"/>

<field name="vcustomer"/>

<field name="vin"/>

<field name="year"/>

<field name="make"/>

<field name="model"/>

</tree>

</field>

</record>

<record model="ir.actions.act_window" id="vans_dent_form">

<field name="name">Vansdent Customers</field>

<field name="res_model">vans.dent</field>

</record>

<menuitem name="Service" id="vansdent_menu" parent="base.menu_product"/>

<menuitem name="Details" parent="vansdent_menu" id="vansdent_menu_mainform" action="vans_dent_form"/>

<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="vansdent_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="one2many field">

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

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


How should I set one2many field for this condition. Help me with a code?

Thanks

If I try to add one2many field in any one class it shows "keyerror". Help me to set a one2many field to give that in xml to set a table or grid view in form.

Uppili Arivukkannu
on 7/25/16, 5:24 AM

I have tried to achieve this I added two fields in the second class

'empty': fields.char('empty'),

'order_line': fields.one2many('vansdent.bill', 'empty', 'Order Lines'),

and add one2many field in xml. It shows the grid view in the form. But while saving it shows

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]

Uppili Arivukkannu
on 7/25/16, 6:14 AM
0
zarzarsan
On 9/7/16, 4:04 AM

you need to add many2one field in class vansdent()

e.g : 'vansdent_bill_id':fields.many2one('vansdent.bill', 'Vansdent Bill'), 

and you need to add one2many field in class vansdent_bill()

e.g: 'vans_dent_ids':fields.one2many('vans.dent','vansdent_bill_id','Vans'),

and them you can add one2many field in .xml 

<field name="one2many field"> replace by <field name="vans_dent_ids">

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 7/26/16, 2:33 AM

what exactly are you trying to do?

Are you trying to establish One2many relation between 2 objects?

Or

Are do you just need a table view placing your basic fields?


 If it is One2Many then please read the document about relation columns, before trying and learning it all in a wrong way.

Thanks for your replay.

I just need the tree view placing my basic fields in form view.

Till now I can't understand about one2many field.

Please assist

Uppili Arivukkannu
on 8/1/16, 9:45 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: 7/25/16, 5:08 AM
Seen: 529 times
Last updated: 9/7/16, 4:04 AM