Skip to Content
मेन्यू
This question has been flagged
3 Replies
1869 Views

Hello everybody,


I would like to know how to automatically change the name of an opportunity in CRM.

I would like this opportunity to look like REN/01022024/RANDOM_NUMBERS_OR_LETTERS


I think we need to go through automation but I don't see how to do it

Avatar
Discard
Best Answer

It can also be done with an Automated Action.  

You have to create new Sequence numbering and then some simple Python code in the Automated Action.

Sequence Numbering:  


The Python code in the Automated Action will be something like this:

for record in records:
  ref = env['ir.sequence'].next_by_code('crm.lead.sequence')
  record['name'] = ref

This example provides more details: https://odootricks.tips/set-sequence-numbers-for-sales-orders/

Avatar
Discard
Best Answer

Hi,

Please utilise the provided code below to update the opportunity name.

from odoo import models, fields, api

import random

from datetime import datetime


class CRMOpportunity(models.Model):

    _inherit = 'crm.lead'


    name = fields.Char(string="Opportunity Name", compute="_compute_custom_opportunity_name", store=True)


    @api.depends('date_deadline')

    def _compute_custom_opportunity_name(self):

        for opportunity in self:

            # Format date as "DDMMYYYY"

            formatted_date = datetime.strptime(opportunity.date_deadline, '%Y-%m-%d').strftime('%d%m%Y')

            

            # Generate random letters/numbers (you may adjust this based on your requirements)

            random_part = ''.join(random.choices('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', k=6))


            # Combine the elements

            opportunity.name = f'REN/{formatted_date}/{random_part}'

Regards

Avatar
Discard
Best Answer

Hello Galien, 

For this you need to generate the sequence. you can follow this community answer : https://www.odoo.com/forum/help-1/create-a-sequence-number-internal-reference-for-project-task-110287


Thanks

Avatar
Discard
Related Posts Replies Views Activity
1
अप्रैल 23
8330
1
दिस॰ 24
1210
2
मार्च 24
1679
0
अक्तू॰ 21
1830
3
जन॰ 20
3295