Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Need Help: Odoo 16 Lead Transfer Module - Notifications & Activity Logging Not Working

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
javascriptcrmpythonnotificationsodooodoo16
1 Répondre
2190 Vues
Avatar
Abhishek

Need Help: Odoo 16 Lead Transfer Module - Notifications & Activity Logging Not Working


Current Situation


I have created a custom lead transfer module in Odoo 16 for transferring leads between sales team members. The basic transfer functionality works, but I'm facing issues with notifications and activity logging.


## Current Code


My current implementation:


```python

class LeadTransferWizard(models.TransientModel):

    _name = 'lead.transfer.wizard'

    _description = 'Lead Transfer Wizard'


    lead_id = fields.Many2one('crm.lead', string='Lead', required=True)

    user_id = fields.Many2one('res.users', string='Transfer To', required=True)

    note = fields.Text(string='Note')


    def action_transfer(self):

        self.ensure_one()

        lead = self.lead_id

        try:

            # Update lead

            lead.write({

                'transferred_to_user_id': lead.id,

                'res_model_id': self.env['ir.model']._get('crm.lead').id,

            })

           

            # Post note in chatter

            lead.message_post(

                body=_('Lead transferred to %s') % self.user_id.name,

                message_type='notification',

                subtype_xmlid='mail.mt_note'

            )

           

            return {

                'type': 'ir.actions.client',

                'tag': 'display_notification',

                'params': {

                    'message': _('Lead transferred successfully'),

                    'type': 'success',

                }

            }

           

        except Exception as e:

            lead.write({'transfer_lead_status': 'draft'})

            raise UserError(_('Failed to transfer lead: %s') % str(e))

```


## Issues I'm Facing


1. **Notification Problems:**

   - Users are not getting desktop notifications when leads are assigned to them

   - Need popup notifications with sound alerts

   - Want the notifications to be more visible and attention-grabbing


2. **Activity Logging Issues:**

   - Activity timestamps are not being logged properly

   - No priority system for transferred leads

   - Can't track precise transfer times


## What I Need


1. **Notification Requirements:**

   - Desktop notifications with sound

   - Browser popup notifications

   - Real-time alerts when leads are transferred

   - Notifications should include:

     * Lead name

     * Priority

     * Sender information

     * Quick action buttons (if possible)


2. **Activity Logging Requirements:**

   - Precise timestamps for all transfer actions

   - Priority-based due dates

   - Complete activity history

   - Proper tracking of all lead movements


## Technical Details


- Odoo Version: 16.0

- Modules installed:

  * CRM

  * Mail

  * Bus

- Browser: Chrome/Firefox (latest versions)


## Questions


1. What's the correct way to implement browser notifications in Odoo 16?

2. How can I add sound to the notifications?

3. What's the best approach for accurate activity timestamp logging?

4. How can I implement a priority system for transferred leads?

5. Is there a way to make notifications persistent until acknowledged?


## What I've Tried


1. Attempted to use bus.bus for notifications:

```python

self.env['bus.bus']._sendone(

    self.user_id.partner_id,

    'lead.transfer',

    {'message': 'New lead assigned'}

)

```

But this doesn't seem to trigger any notifications.


2. Tried adding sound:

```javascript

var audio = new Audio('/path/to/sound.mp3');

audio.play();

```

But couldn't get it working in the Odoo environment.


## Additional Information


- The basic lead transfer functionality works fine

- Users have appropriate access rights

- Browser notifications are enabled

- No JavaScript errors in console

- Server logs show no errors


Any help or guidance would be greatly appreciated. Thank you in advance!


0
Avatar
Ignorer
Avatar
Saif Sabri
Meilleure réponse

My response was crafted with AI assistance, tailored to provide detailed and actionable guidance for your query.
To address the issues you're facing with notifications and activity logging in your custom Odoo 16 Lead Transfer Module, let's break down the solutions step by step. We'll cover both notifications and activity logging improvements.

1. Notification Improvements

Desktop Notifications with Sound

To implement desktop notifications with sound, you need to use Odoo's Bus (Browser Unidirectional Server) system and JavaScript for handling notifications on the client side.

Step 1: Send Notification via Bus

Update your action_transfer method to send a notification via the Bus system:

python   Copy

def action_transfer(self):
    self.ensure_one()
    lead = self.lead_id
    try:
        # Update lead
        lead.write({
            'user_id': self.user_id.id,  # Assign lead to the new user
            'date_transferred': fields.Datetime.now(),  # Log transfer time
        })

        # Post note in chatter
        lead.message_post(
            body=_('Lead transferred to %s') % self.user_id.name,
            message_type='notification',
            subtype_xmlid='mail.mt_note'
        )

        # Send Bus notification
        notification = {
            'type': 'lead_transfer',
            'lead_name': lead.name,
            'priority': lead.priority,
            'sender': self.env.user.name,
            'message': _('Lead %s has been transferred to you.') % lead.name,
        }
        self.env['bus.bus']._sendone(
            self.user_id.partner_id,
            'lead.transfer.notification',
            notification
        )

        return {
            'type': 'ir.actions.client',
            'tag': 'display_notification',
            'params': {
                'message': _('Lead transferred successfully'),
                'type': 'success',
            }
        }

    except Exception as e:
        lead.write({'transfer_lead_status': 'draft'})
        raise UserError(_('Failed to transfer lead: %s') % str(e))
Step 2: Handle Notification in JavaScript

Add JavaScript to handle the Bus notification and display it as a desktop notification with sound.

  1. Create a new JavaScript file (e.g., lead_transfer_notification.js) in your module's static/src/js/ directory.
  2. Add the following code:

javascript  Copy

odoo.define('lead_transfer.notification', function (require) {
    "use strict";

    var Bus = require('bus.bus');
    var Notification = require('web.Notification');

    // Listen for Bus notifications
    Bus.on('lead.transfer.notification', null, function (notification) {
        // Play sound
        var audio = new Audio('/lead_transfer/static/src/sounds/notification.mp3');
        audio.play();

        // Display desktop notification
        Notification.create({
            title: 'New Lead Transferred',
            message: notification.message,
            type: 'info',
            sticky: true,  // Make notification persistent
            buttons: [
                {
                    text: 'View Lead',
                    click: function () {
                        window.open(`/web#id=${notification.lead_id}&model=crm.lead&view_type=form`, '_blank');
                    }
                }
            ]
        });
    });
});
  1. Include the JavaScript file in your module's assets_backend template:

xml

Copy

<template id="assets_backend" inherit_id="web.assets_backend">
    <xpath expr="." position="inside">
        <script type="text/javascript" src="/lead_transfer/static/src/js/lead_transfer_notification.js"></script>
    </xpath>
</template>

Run HTML
  1. Add a sound file (e.g., notification.mp3) to your module's static/src/sounds/ directory.

2. Activity Logging Improvements

Precise Timestamps and Priority System

To log precise timestamps and implement a priority system, update your crm.lead model and action_transfer method.

Step 1: Add Fields to crm.lead

Add the following fields to your crm.lead model:

python  Copy

class CrmLead(models.Model):
    _inherit = 'crm.lead'

    date_transferred = fields.Datetime(string='Transfer Date', readonly=True)
    transfer_priority = fields.Selection([
        ('0', 'Low'),
        ('1', 'Medium'),
        ('2', 'High'),
    ], string='Transfer Priority', default='0')
Step 2: Update action_transfer Method

Update the action_transfer method to log the transfer timestamp and priority:

python  Copy

def action_transfer(self):
    self.ensure_one()
    lead = self.lead_id
    try:
        # Update lead
        lead.write({
            'user_id': self.user_id.id,
            'date_transferred': fields.Datetime.now(),
            'transfer_priority': self.transfer_priority,  # Add priority
        })

        # Post note in chatter
        lead.message_post(
            body=_('Lead transferred to %s with priority %s') % (self.user_id.name, dict(lead._fields['transfer_priority'].selection).get(lead.transfer_priority)),
            message_type='notification',
            subtype_xmlid='mail.mt_note'
        )

        # Send Bus notification
        notification = {
            'type': 'lead_transfer',
            'lead_name': lead.name,
            'priority': lead.transfer_priority,
            'sender': self.env.user.name,
            'message': _('Lead %s has been transferred to you with priority %s.') % (lead.name, dict(lead._fields['transfer_priority'].selection).get(lead.transfer_priority)),
        }
        self.env['bus.bus']._sendone(
            self.user_id.partner_id,
            'lead.transfer.notification',
            notification
        )

        return {
            'type': 'ir.actions.client',
            'tag': 'display_notification',
            'params': {
                'message': _('Lead transferred successfully'),
                'type': 'success',
            }
        }

    except Exception as e:
        lead.write({'transfer_lead_status': 'draft'})
        raise UserError(_('Failed to transfer lead: %s') % str(e))

3. Persistent Notifications

To make notifications persistent until acknowledged, use the sticky option in the Notification.create method (as shown in the JavaScript code above).

Summary

  • Notifications: Use Odoo's Bus system and JavaScript to send desktop notifications with sound.
  • Activity Logging: Add fields for timestamps and priority, and update the action_transfer method to log these details.
  • Persistent Notifications: Use the sticky option in JavaScript notifications.

0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Call wizard view in js function
javascript python odoo
Avatar
Avatar
1
déc. 22
4454
TypeError: Cannot read property 'taxes_by_id' of undefined at DiscountButton.apply_discount
javascript python odoo
Avatar
0
déc. 20
50
How to call JavaScript from python function?
javascript python odoo
Avatar
0
déc. 15
14443
Display header only on the first page and footer on the last page Qweb Odoo 14
javascript python xml odoo
Avatar
Avatar
Avatar
2
août 24
7916
How to set default values to fields in Odoo 14
javascript python xml odoo
Avatar
Avatar
1
oct. 22
25562
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now