Reputation: 1382
i Open my tree view with a button but the problem is that it's open without edit option or save. I want to have a possibility to change price and qty and save it
@api.multi
def button_details(self):
context = self.env.context.copy()
context['view_buttons'] = True
view_id = self.env.ref('cfg.view_order_line_form_view').id
view = {
'name': _('Details'),
'view_type': 'form',
'view_mode': 'tree, form',
'res_model': 'sale.order.line',
'views' : [(view_id,'tree')],
'type': 'ir.actions.act_window',
'target': 'new',
'readonly': True,
'res_id': self.id,
'context': context
}
return view
<record id="view_order_line_form_view" model="ir.ui.view">
<field name="name">sale.order.line.forma</field>
<field name="model">sale.order.line</field>
<field name="arch" type="xml">
<tree string="Form" editable="bottom">
<field name="product_id" />
<field name="product_uom_qty" string="Qty" placeholder="Qty"/>
<field name="price_unit" string="Price"/>
</tree>
</field>
</record>
Updated my question with picutre. This is how my tree view looks but i want to delete products or change qty
Upvotes: 1
Views: 910
Reputation: 1531
Add 'flags' in python code and delete="true" in your xml code. At the top you will see a drop-down with name 'More', clicking it will give delete option.
@api.multi
def button_details(self):
context = self.env.context.copy()
context['view_buttons'] = True
view_id = self.env.ref('cfg.view_order_line_form_view').id
view = {
'name': _('Details'),
'view_type': 'form',
'view_mode': 'tree, form',
'res_model': 'sale.order.line',
'views' : [(view_id,'tree')],
'type': 'ir.actions.act_window',
'target': 'new',
'readonly': True,
'res_id': self.id,
'flags': {'sidebar': True},
'context': context
}
return view
<record id="view_order_line_form_view" model="ir.ui.view">
<field name="name">sale.order.line.forma</field>
<field name="model">sale.order.line</field>
<field name="arch" type="xml">
<tree string="Form" editable="bottom" delete="true">
<field name="product_id" />
<field name="product_uom_qty" string="Qty" placeholder="Qty"/>
<field name="price_unit" string="Price"/>
</tree>
</field>
</record>
Upvotes: 2