Odoo Help


Prefill fields in creation form

Andrea Mazzacani
on 11/14/16, 6:42 AM 541 views

Hi i created a module  with a model related to sale.order with a Many2one field. I added a notebook to the sale.order view with a tree view of my model, similar to order line.


What i need to do is to prefill fields with current order (sale.order) and order date.


my code:


class waycon_rtv(models.Model):
_description = 'Rtv' _name = 'waycon.rtv'
  #omitted fields that don't need to be prefilled
order_id = fields.Many2one('sale.order', string='Order Reference', required=True, ondelete='cascade',
  index=True, copy=False)

date = fields.Date(string="Data", help="Data creazione documento", required=True)

order_partner_id = fields.Many2one(related='order_id.partner_id', store=True, string='Customer')

#field added to sale.order
class waycon_custom_order(models.Model):
_inherit = 'sale.order'
rtv = fields.One2many( 'waycon.rtv', 'order_id',string='Related rtvs')


<record id="my_view_sale_form_inherit" model="ir.ui.view">	
    <field name="name">view.sale.order.form.inherit</field>
    <field name="model">sale.order</field>
    <field name="type">form</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
         <page string="R.T.V." >
         <field name="rtv" mode="tree,kanban" string="RTV">
             <tree String="RTV_tree">
                 <field name="date"/>
                 <field name="amount"/>
                 <field name="date"/>
                 <field name="note"/>

The only field prefilled is partner.id and i still don't understand how odoo do it since it's relater to order_id that is not filled. I wasn't able to add images directly in post so i used pasteboard and copy/past links.

Thank You in advance

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/14/16, 6:42 AM
Seen: 541 times
Last updated: 11/14/16, 9:28 AM