İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

Copy One2many fields information to another model

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
one2manyone2manyfieldv18CommunityEdition
2 Cevaplar
1612 Görünümler
Avatar
Shreya Doodipala

In my custom (inherited) crm.lead model, I have the following one2many field for secondary sales people:

sales_secondary_ids = fields.One2many('custom.crm.sales.secondary', 'lead_id', string='Secondary Salespeople', index=True, tracking=True)

The custom.crm.sales.secondary model has the following fields:

lead_id = fields.Many2one('crm.lead', string='Opportunity', ondelete='cascade')

user_id = fields.Many2one('res.users', string='Salesperson', required=True, check_company=True, tracking=True, domain=lambda self: self._get_sales_users_domain())

team_id = fields.Many2one('crm.team', string='Sales Team', check_company=True, tracking=True, related='user_id.sale_team_id', ondelete="set null", readonly=True, store=True)

team_leader_id = fields.Many2one('res.users', string='Team Leader', related='team_id.user_id', store=True, readonly=True)


currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, required=True, default=lambda self: self.env.company.currency_id)

deal_share = fields.Monetary('Share of Deal', currency_field='currency_id', tracking=True)

among other fields and functions.


How do I copy the one2many fields' information from crm.lead to another model for further operations and views? I want to auto update this model whenever a new lead is created or updated in crm.lead using

def _update_master_view(self):

        for lead in self:

            extension = self.env['custom.crm.lead.view'].search([('lead_id', '=', lead.id)], limit=1)

            if extension:

                # Update existing record (if you want to sync additional data, you can add it here)

                extension.write({})

            else:

                # Create new extension record

                self.env['custom.crm.lead.view'].create({

                    'lead_id': lead.id,

                    extension.write({})

                })

in the create and write methods.


I  can't create a one2many field in the custom.crm.lead.view model as it requires the custom.crm.sales.secondary to have a many2one relation on this model.


Odoo v18 Community Edition

0
Avatar
Vazgeç
Avatar
Moaaz Gafar
En İyi Yanıt

Hi 

Store Secondary Sales Data Directly 

Instead of trying to replicate the one2many relationship, store the secondary sales data as computed/stored fields or JSON in your custom.crm.lead.view model:

class CustomCrmLeadView(models.Model):
    _name = 'custom.crm.lead.view'
    _description = 'CRM Lead View Extension'
   
    lead_id = fields.Many2one('crm.lead', string='Lead', required=True, ondelete='cascade')
   
    # Store secondary sales data as JSON or separate fields
    secondary_sales_data = fields.Text('Secondary Sales Data', help='JSON data of secondary salespeople')
    secondary_sales_count = fields.Integer('Secondary Sales Count', compute='_compute_secondary_sales', store=True)
    secondary_sales_names = fields.Char('Secondary Salespeople Names', compute='_compute_secondary_sales', store=True)
    total_deal_share = fields.Float('Total Deal Share', compute='_compute_secondary_sales', store=True)
   
    @api.depends('lead_id.sales_secondary_ids')
    def _compute_secondary_sales(self):
        for record in self:
            if record.lead_id and record.lead_id.sales_secondary_ids:
                secondary_data = []
                names = []
                total_share = 0
               
                for secondary in record.lead_id.sales_secondary_ids:
                    data = {
                        'user_id': secondary.user_id.id,
                        'user_name': secondary.user_id.name,
                        'team_id': secondary.team_id.id if secondary.team_id else False,
                        'team_name': secondary.team_id.name if secondary.team_id else '',
                        'deal_share': secondary.deal_share,
                    }
                    secondary_data.append(data)
                    names.append(secondary.user_id.name)
                    total_share += secondary.deal_share or 0
               
                record.secondary_sales_data = json.dumps(secondary_data)
                record.secondary_sales_count = len(secondary_data)
                record.secondary_sales_names = ', '.join(names)
                record.total_deal_share = total_share
            else:
                record.secondary_sales_data = '[]'
                record.secondary_sales_count = 0
                record.secondary_sales_names = ''
                record.total_deal_share = 0

Best regards, 

E: m.gafar2024@gmail.com

0
Avatar
Vazgeç
Avatar
D Enterprise
En İyi Yanıt

Hii,

Define a mirror model:
class CustomCrmLeadSecondaryView(models.Model):

    _name = 'custom.crm.secondary.view'

    _description = 'Synced Secondary Sales Data for Leads'


    lead_id = fields.Many2one('crm.lead', string='Lead', ondelete='cascade')

    view_id = fields.Many2one('custom.crm.lead.view', string='Master View', ondelete='cascade')


    user_id = fields.Many2one('res.users', string='Salesperson')

    team_id = fields.Many2one('crm.team', string='Sales Team')

    team_leader_id = fields.Many2one('res.users', string='Team Leader')

    deal_share = fields.Monetary('Share of Deal', currency_field='currency_id')

    currency_id = fields.Many2one('res.currency', string='Currency')


Update _update_master_view to also sync the secondary salespeople

Inherit crm.lead, and update create and write:
class CrmLead(models.Model):

    _inherit = 'crm.lead'


    def _update_master_view(self):

        for lead in self:

            extension = self.env['custom.crm.lead.view'].search([('lead_id', '=', secondary.currency_id.id,

                })


    @api.model

    def create(self, vals):

        lead = super().create(vals)

        lead._update_master_view()

        return lead


    def write(self, vals):

        result = super().write(vals)

        self._update_master_view()

        return result

In custom.crm.lead.view, add a One2many to show them
class CustomCrmLeadView(models.Model):

    _name = 'custom.crm.lead.view'


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

    secondary_sales_view_ids = fields.One2many('custom.crm.secondary.view', 'view_id', string='Secondary Sales')


0
Avatar
Vazgeç
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Custom functionality with One2many field
one2many one2many_list v18 CommunityEdition
Avatar
Avatar
1
May 25
2024
Modify Pivot View
Pivot v18 CommunityEdition
Avatar
Avatar
1
Haz 25
1863
Unable to send email notifications through write
notifications v18 CommunityEdition
Avatar
Avatar
1
Haz 25
1912
Hide Records based on user group only in a particular view
views record_rule v18 CommunityEdition
Avatar
Avatar
Avatar
2
Eyl 25
1542
Unable to pass context to an action
context server_action v18 CommunityEdition
Avatar
Avatar
1
Tem 25
1734
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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