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