Skip to Content
Menu
This question has been flagged
4 Replies
4158 Views

Hello,

I'm playing with the Odoo demo's Studio feature. I would like to display the customer "Tags" on a quotation, sale order, or invoice once the customer has been selected.

Studio has many related options such as "Related Fields", "Many2Many", and "Tags". I've tried all three, in various combinations for the past 2 hours, but I can't seem to get those tags to show correctly. I imagine and would hope Studio has the power to do this, but without any documentation it's incredibly difficult to figure out what is the correct property to choose. 

Thank you!
Michael

Avatar
Discard
Best Answer

Hi Michael,

Yes and no. You can do it partially with Odoo studio but you will also need to use other technical features from Odoo to create this. The closest you would get with Odoo studio itself is by creating a related field to Contact > Tags > Display name but this would only work for one tag. 

As the tags field on a contact can contain multiple records you'll need to first create a many2many field (to the model res.partner.category) with Odoo studio and set the widget "tags" on this new field. The next step is to create an automated action (from Settings > Automation > Automated actions). In this automated action you should set the model "sale.order" and the trigger condition on "Based on Form Modification". You can then set the field which should be watched when changed - which is the equivalent of @api.onchange for a developer - in the "On Change Fields" field. Finally set the "Action to do" field to "Execute Python Code". In this field we can now write Python code to set the labels from the partner if there are any, otherwise we'll set it to False. The Python code should look like this:

if record.partner_id.category_id:
    # Will set all tags from the customer on the field x_studio_field_ul4O7                                          
record.write({
'x_studio_field_Ul4P7': [(6, 0, record.partner_id.category_id.ids)]
})
else:
record.write({
'x_studio_field_Ul4P7': False
})

Your result should look like this:
https://imgur.com/0jLEpo3

After changing to a partner which has a label on the sale order you'll see they are automatically set:
https://imgur.com/IEQxhTs

P.S: Sorry for the image links but posting images has been broken for weeks in the Odoo forum. I've got an official Odoo ticket open for it but it is taking a while. I'll try to update this once it is fixed.


Regards,
Yenthe

Avatar
Discard
Author

Jeez, thank for taking the time to write up such a detailed answer! I'll give this a shot tomorrow. I really appreciate it, kind of shocked! Will study.

Hopefully though, Odoo can keep working on making Studio easier for the non-programmers :p

You're welcome! There have been quite some similar posts in the past and it looks like not too many people know how to do this. Hopefully it can help you and some others in the future. ;-) Odoo Studio improves every version so it'll get better and better.

Hello Yventhe, Is there an updated version of this guide for Odoo 15? I have related field for customer tag showing on their opportunity and quote/sales order (which is read only, to edit the staff member needs to go into customer profile to change, which is the behaviour we want). However, on a new lead, i can't seem to create the correct method to save a new customer profile including the required "tag/label(partner_id.category_id)" for the new customer (i.e once the lead is converted, and a new customer is created, the tag/label(partner_id.category_id) viewed in leads by means of a custom many2many tag widget doesn't carry over to the customers profile? What am i doing wrong?

Thank you in advance!

Best Answer

I think this can be done in Odoo Studio.

  1. Add a related field.  

  2. Select Customer > Tags 

  3. Change the Widget to "Many2Many tags" and (in Odoo 11/ 12 set your new field to 'Read Only').

Step-by-Step: odootricks.tips/odoo-studio-partner-tags-sales-order/ 

Yenthe's approach will give you a new field on the Sales Order, if that's what you need.  


Avatar
Discard