Skip to Content
Menu
This question has been flagged
3 Replies
2397 Views

I created a field in Product form view and i need to show that field on the sales quote.

But, i need to show that field only if it's not empty.

So, if the field is empty, i need to show the product name, and if the field is not empty, i need to show it's content.

I'm trying to accomplish this using a relation and adding the following code in Studio:

If (product_id.x_studio_descrio_1) == "":
  x_studio_descrio_1 = product_id.x_studio_descrio_1
Else:
  x_studio_descrio_1 = product_variant_id.name

So, product_id.x_studio_descrio_1 is the field name i want to show if it's not empty, and x_studio_descrio_1 is the field i'll show it in.
If it possible to do this relation? Relate one or another?

Is my code wrong?

Avatar
Discard
Best Answer

Yes you can use Python code in an Automated Action, but I'd use a new field for the description that you want to show.  I hope that this example is helpful:

This image has an empty alt attribute; its file name is automated-action-to-set-product-description.jpg
if record.x_studio_extended_description: 
    record['x_studio_print_description'] = record.x_studio_extended_description 
else: 
    record['x_studio_print_description'] = record.name

https://odootricks.tips/simple-conditions-in-an-automated-action/


For a Form View you can add both fields to the View but condition them so that only one is displayed.

Click on "Conditional" next to "Invisible" and the following window is displayed:


Select the field product_id.x_studio_descrio_1

https://odootricks.tips/adding-fields-using-odoo-studio/

Avatar
Discard
Author

Thank you so much for your help and sorry i took so long to reply.

I think my lack of clarification didn't help, but the field i'm trying to add is a detailed description of the product. Like the description that already exists on sales quote, but i need to add it before it turns into a sales quote, so i need the description in the product itself.

So, resuming... what will happen is i'll have products with a detailed description and products without a detailed description in the sales quote, so i'd need the same field to display the product name or the detailed description. One or the other, in the same column, so i don't have two different columns in the quotation sent to the client.

I updated my answer. I hope that points you in the right direction.

Author

Gorgeous solution! Thank you so much!

Related Posts Replies Views Activity
0
Oct 23
332
1
Feb 20
1263
4
Mar 15
6493
1
Mar 15
3258
0
May 24
10