Has anyone made an automation to attribute a customer tag with the purchase of a product? This seems like a remedial need/function but even in automations I can't seem to find options for this.
Thanks!
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Has anyone made an automation to attribute a customer tag with the purchase of a product? This seems like a remedial need/function but even in automations I can't seem to find options for this.
Thanks!
You could create an Automation Rule like this (only rudimentarily tested):

Automation Rule for
Model: Sales Order Line
Trigger: On create and edit
Before Update Domain: Match all records
Apply on: Match all of the following rules: Order Status = Sales Order
When updating: Order Status
Action To Do: Execute Code
# Set Sale Order Line's Product Tags on Customer
for rec in records:
# loop over all sale order lines that just had their status udpated
for tag_id in rec.product_id.product_tag_ids:
# in case there is a tag on the current SO line's product,
# check if this tag exists for usage with customers already,
# if it doesn't, create it
customer_tag_id = env['res.partner.category'].search([('name', '=', tag_id.name)])
if not customer_tag_id:
customer_tag_id = env['res.partner.category'].create({'name': tag_id.name})
# set the tag to the customer
rec.order_id.partner_id.write({'category_id': [Command.link(customer_tag_id.id)]})
Notes:
This example isn't optimized, i.e. only setting a tag when not already present on the customer, etc. However, it should do the trick.
Since Product Tags and Customer Tags are different, the example works like this: First, if there is a Tag assigned to the Product (of the Sale Order Line that is just having its Status updated to 'Sale Order') it checks whether a Tag with the same Name exists for Customers. If it doesn't, a new Tag is created. Then, this Customer Tag (named like the Product's Tag) is written to the Customer of the Sale Order (Line).
Product:

Customer:

Sale Order (draft):

Sale Order (confirmed):

... and therefore, Customer update:

See also: https://www.odoo.com/documentation/19.0/applications/studio/automated_actions.html and https://www.odoo.com/documentation/19.0/developer/reference/backend/orm.html.
And also the Help tab of the Execute Code option:
The following variables can be used:
env: environment on which the action is triggered
model: model of the record on which the action is triggered; is a void recordset
record: record on which the action is triggered; may be be void
records: recordset of all records on which the action is triggered in multi mode; may be void
time, datetime, dateutil, timezone: useful Python libraries
float_compare(): utility function to compare floats based on a specific precision
log(message, level='info'): logging function to record debug information in ir.logging table
_logger.info(message): logger to emit messages in server logs
UserError: exception class for raising user-facing warning messages
Command: x2many commands namespace
To return an action, assign: action = {...}
To notify progress for CRON call and re-trigger a call if there is remaining tasks, use env['ir.cron']._notify_progress(done=task_done_count, remaining=task_remaining_count)
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.
Hmm this might be a little pedantic for what I am trying to achieve now that I get an eye on it. So what I'm trying to do is simply update the customer with a new price list when they have an active subscription. My subscription product is called "Bronze". The pricelist is called "Bronze" as well.
Then I want the pricelist to be updated to "Default" when no subscription is in progress for that customer.
Does that make sense? I've been through automations all weekend and I can't seem to get the correct prompts to make this happen.
How is this related to your initial question? Please make up your mind before posting a question.
Christoph it is "related" because it's the same problem I'm trying to solve. I explained it in the second sentence that perhaps my initial means is wrong. My mind is "made up". Please fully read comments before getting angry. I found a much easier solution.