Skip to Content
Menu
This question has been flagged
1 Reply
7539 Views

I have added a button in sale.order.line.

<button name="service_line" type="object" icon="fa-check"/>

on clicking it a form view is opened using ir.actions.act_window.

def service_line(self):
form = self.env.ref('product_availability_analysis.form_view_product_group_so').id
context = self.env.context.copy()
context.update({'order_line_id': self.id})
return {
'name': _('Lines'),
'view_type': 'form',
'view_mode': 'form',
'views': [(form, 'form')],
'view_id': form,
'res_model': 'product.group',
'res_id': self.product_id.group_id.id,
'context': context,
'type': 'ir.actions.act_window',
}

On this product.group form view I have added a button in action dropdown.

<record id="add_service_in_sale_order" model="ir.actions.server">
<field name="name">Add To Order</field>
<field name="model_id" ref="alsalman_products_config.model_product_group"/>
<field name="context">{'order_line_id': env.context.get('order_line_id')}</field>
<field name="state">code</field>
<field name="code">action = model.action_create()
</field>
<field name="binding_model_id" ref="alsalman_products_config.model_product_group"/>
</record>

How do I get order_line_id in the function(action_create) called from ir.actions.server? 

On product group form when I trigger any onchange function to check active_id, 

it is of sale.order.line but after clicking Add To Order in action_create active_id is of 

product.group and no track of order_line_id. I have also tried passing the context but no luck.

Avatar
Discard
Best Answer

can you check order_line_id is available as active is in env.context inside the server action code. 
if it's there then you can try something model.with_context(env.context).action_create()

Avatar
Discard
Author

No, context gets overwritten by default context in server action code. I solved this problem by dummy domain. I also passed my order_line_id in domain, with or condition. Domain remain constant unless object changes. I know this isn't a correct way but i guess this was the only way I had. Thanks for your time.

Related Posts Replies Views Activity
1
Jul 23
581
2
Jan 23
1273
5
Dec 22
4220
0
May 22
1898
2
Nov 20
3680