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

Prefill fields in creation form

By
Andrea Mazzacani
on 11/14/16, 6:42 AM 86 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.

http://pasteboard.co/r6AofgsQh.jpg

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

http://pasteboard.co/r6CcSwByC.jpg

my code:

Model

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

View:

<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">
 
         <notebook>
         <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"/>
             </tree>
         </field>
         </page>
         </notebook>
  </field>
</record>

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


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: 11/14/16, 6:42 AM
Seen: 86 times
Last updated: 11/14/16, 9:28 AM