Reputation: 769
Any idea how I can fill in some fields on the product page when I quick create this from a Sales Order. These fields are based on the Sales Order (name and customer). Do I need to pass them with context?
Thanks
Upvotes: 1
Views: 1575
Reputation: 10189
Yes, it can be done with context
. In your sale.order.line
XML views, you have a Many2one
field named product_id
(it points to product.product
model).
You have to specify the default value you want for each product.product
field, extracting the value for the fields of the current view (sale.order.line
):
<xpath expr="//field[@name='product_id']" position="attributes">
<attribute name="context">{'default_field_1': field_1, 'default_field_2': field_2}</attribute>
</xpath>
Where default_field_1
and default_field_2
are fields of the product.product
model, and field_1
and field_2
are fields of sale.order.line
model.
Example:
<xpath expr="//field[@name='product_id']" position="attributes">
<attribute name="context">{'default_name': name}</attribute>
</xpath>
In the above case, when you create a new product (clicking on the create option of the dropdown of the Many2one
field product_id
) from sale.order.line
tree or form view, the product.product
form would be opened with the name
field automatically filled in with the name of the current sale order line.
Upvotes: 0