Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
1871 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
dub 23
8330
1
pro 24
1211
2
bře 24
1681
0
říj 21
1830
3
led 20
3295