コンテンツへスキップ
Odoo メニュー
  • サインイン
  • 無料で15日試す
  • アプリ
    財務
    • 会計
    • 請求
    • 経費
    • スプレッドシート(BI)
    • ドキュメント管理
    • 署名
    販売
    • CRM
    • 販売
    • POS店舗
    • POSレストラン
    • サブスクリプション
    • レンタル
    ウェブサイト
    • ウェブサイトビルダー
    • eコマース
    • ブログ
    • フォーラム
    • ライブチャット
    • eラーニング
    サプライチェーン
    • 在庫
    • 製造
    • 製品ライフサイクル管理 (PLM)
    • 購買
    • 整備
    • 品質
    人事業務
    • 従業員管理
    • 採用
    • 休暇管理
    • 人事評価
    • リファラル
    • フリート
    マーケティング
    • ソーシャルマーケティング
    • メールマーケティング
    • SMSマーケティング
    • イベント
    • マーケティングオートメーション
    • アンケート調査
    サービス
    • プロジェクト管理
    • タイムシート
    • フィールドサービス
    • ヘルプデスク
    • 計画
    • アポイントメント
    生産性向上ツール
    • ディスカッション
    • 承認
    • IoT
    • VoIP
    • ナレッジ
    • WhatsApp
    サードパーティアプリ Odooスタジオ Odooクラウドプラットホーム
  • インダストリー(業種別ソリューション)
    小売
    • 書店
    • アパレルショップ
    • 家具専門店
    • 食料品店
    • 金物店
    • 玩具店
    飲食・ホスピタリティ業界
    • バー・パブ
    • レストラン
    • ファストフード
    • ゲストハウス
    • 飲料販売代理店
    • ホテル
    不動産
    • 不動産会社
    • 建築事務所
    • 建設
    • 不動産管理
    • 造園
    • 住宅所有者組合
    コンサルティング
    • 会計事務所
    • Odooパートナー
    • マーケティングエージェンシー
    • 法律事務所
    • 人材派遣
    • 監査・認証
    製造
    • テキスタイル
    • 金属
    • 家具
    • 飲食
    • 醸造所
    • コーポレートギフト
    ヘルス & フィットネス
    • スポーツクラブ
    • 眼鏡店
    • フィットネスセンター
    • ウェルネス専門家
    • 薬局
    • ヘアサロン
    業種
    • 便利屋
    • IT ハードウェア・サポート
    • 太陽エネルギーシステム
    • 靴メーカー
    • クリーニングサービス
    • 空調設備サービス
    その他
    • 非営利団体
    • 環境機関
    • ビルボードレンタル
    • 写真
    • 自転車リース
    • ソフトウェアリセラー
    すべての業種を見る
  • コミュニティ
    学ぶ
    • チュートリアル
    • ドキュメンテーション
    • 認定
    • トレーニング
    • ブログ
    • ポッドキャスト
    教育サポート
    • 教育プログラム
    • Scale Up! ビジネスゲーム
    • Odooオフィス訪問
    ソフトを入手
    • ダウンロード
    • エディションを比較
    • リリース
    コラボレーション
    • Github
    • フォーラム
    • イベント
    • 翻訳
    • パートナーになる
    • パートナー様向けサービス
    • 会計事務所を登録
    サービス利用
    • パートナー一覧
    • 会計事務所一覧
    • 今すぐ相談する
    • 導入支援サービス
    • お客様一覧
    • サポート
    • アップグレード
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    製品デモを利用する
  • 料金
  • ヘルプ

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

  • CRM
  • e-Commerce
  • 会計
  • 在庫
  • PoS
  • プロジェクト
  • MRP
All apps
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
ヘルプ

Copy One2many fields information to another model

購読

この投稿に活動があった際に通知を受け取ります

この質問にフラグが付けられました
one2manyone2manyfieldv18CommunityEdition
2 返信
1622 ビュー
アバター
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
アバター
破棄
アバター
Moaaz Gafar
最善の回答

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
アバター
破棄
アバター
D Enterprise
最善の回答

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
アバター
破棄
ディスカッションを楽しんでいますか?読むだけでなく、参加しましょう!

今すぐアカウントを作成して、限定機能を利用したり、素晴らしいコミュニティと交流しましょう!

登録
関連投稿 返信 ビュー 活動
Custom functionality with One2many field
one2many one2many_list v18 CommunityEdition
アバター
アバター
1
5月 25
2026
Modify Pivot View
Pivot v18 CommunityEdition
アバター
アバター
1
6月 25
1869
Unable to send email notifications through write
notifications v18 CommunityEdition
アバター
アバター
1
6月 25
1924
Hide Records based on user group only in a particular view
views record_rule v18 CommunityEdition
アバター
アバター
アバター
2
9月 25
1546
Unable to pass context to an action
context server_action v18 CommunityEdition
アバター
アバター
1
7月 25
1741
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • Github
  • Runbot
  • 翻訳
サービス
  • Odoo.shホスティング
  • サポート
  • アップグレード
  • カスタム開発
  • 教育プログラム
  • 会計事務所一覧
  • パートナー一覧
  • パートナーになる
企業情報
  • 会社概要
  • ブランドアセット
  • お問い合わせ
  • 採用情報
  • イベント
  • ポッドキャスト
  • ブログ
  • お客様一覧
  • リーガル情報 • プライバシーポリシー
  • セキュリティ
الْعَرَبيّة 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(オドゥー)は、CRM、eコマース、会計、在庫管理、POS、プロジェクト管理など、企業のさまざまな業務を一つのシステムで管理できる、ベルギー発のオープンソースのERPソフトウェアです。

高機能で使いやすく、完全に統合されたERPとして、ユニークな価値を提供しています。

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