İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
1876 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
En İyi Yanıt

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
Vazgeç
En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Nis 23
8334
CRM automations Çözüldü
1
Ara 24
1214
2
Mar 24
1692
0
Eki 21
1834
3
Oca 20
3295