Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
3949 Vues

Hello
I have one button in sale order, I also set on change for this button to set visible or invisible (readonly),
When I create a sale order and add one product in the sale order line. 
My problem was that my button will readonly still I'll not save the sale order.

What should I do, if I want to make visible this button and I can open wizard using this button without saving the sale order.? 

Here my code: 

Py:

@ api.onchange ('product_id', 'quantity') 
def onchange_check_related_product (self):
for order_line in self:
if order_line.product_id.cross_product_ids:
order_line.is_related_product = True
else:
order_line.is_related_product = False
is_related_product = fields.Boolean ('Is Related')

is_related_product = fields.boolean ( ' Is Related ' )



XML:record model = "ir.ui.view" id = "sale_order_cross_product_view">
<field name = "name"> sale.order.cross.product.view </ field>
<field name = "model"> sale.order </ field>
<field name = "inherit_id" ref = "sale.view_order_form" />
<field name = "arch" type = "xml">
<xpath expr = "// notebook / page [@ name = 'order_lines'] / field [@ name = 'order_line'] / tree / field [@ name = 'product_id'] "
position =" after ">
<field name =" is_related_product "invisible =" 1 "/>
<button type ="object "name =" action_cross_sell "string =" Cross Sell "
icon =" fa-th-list "
attrs = "{'invisible': ['|', ('state', 'not in', ['draft', 'sent']), ('is_related_product', '=', False)]}"> < / button>

</ xpath>
</ field>
</ record>
Avatar
Ignorer
Meilleure réponse

Hello,

It's default behaviour of Odoo that any button of One2many field will be disable until you save it, you can't make it enable without saving record.

Avatar
Ignorer
Auteur

Okay Mital Ma'am

Thank you for your reply.

But any solution to this situation, Please let me know if you have a solution.

Meilleure réponse

Hi, 

You need to change the behavior from `@api.onchange` to `@api.depends` because you probably use this method as a computed field.

In the other hand, whenever you use action_cross_sell as a button (type: object) of your model, Odoo will save (without hitting button Save) that model first and then, your action_cross_sell will be executed later on.


Thanks,

Avatar
Ignorer
Auteur

Thank you for replay

If it's helpful, you could mask my answer as done. Thanks

But how can I hide the button when not in edit mode ?

If I apply the `oe_edit_only` class will still make it disabled until I manually save the order