コンテンツへスキップ
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
このフォーラムについて
ヘルプ

Storing function field upon creation of resource in dependent model

購読

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

この質問にフラグが付けられました
transaction
2 返信
5453 ビュー
アバター
Richard Lewis

I have a function field which is defined like this:

def _get_field_value(self, cr, uid, ids, field_name, args, context=None):
    return ...

def _get_related_others(self, cr, uid, other_ids, context=None):
    return self.pool.get('this.model').search(cr, uid,
                         [('other_id','in',other_ids)], context=None)

'field': fields.function(_get_field_value, ...,
    store={'other.model': (_get_related_others, ['other_field'], 10)}),

The idea is that when the user creates a new resource in the other.model an update of 'field' is triggered. The update is triggered without any problems, but the _get_related_others can't retrieve the given other_ids from other.model. It gets passed a list containing one id (of a new other.model resource), but self.pool.get('other.model').search() returns no IDs.

I can see that the newly created other.model resource is not in the database at the time that _get_related_others is called, but isn't this just because it's in a transaction that's yet to be committed? And shouldn't the self.pool.get('other.model').search() call be working with the same transaction? And therefore have access to he newly created other.model resource?

Otherwise, please explain how/whether this is possible.

EDIT

Apologies, I abstracted my actual problem incorrectly. I'm aware that the aim is to return a list of IDs on this.model that need to be updated, but the problem is that I want to select resources from this.model which are related to the resource(s) on other.model that changed.

this.model has a field, 'other_id', that points to other.model. In my _get_related_others method I intend to select all the this.model resources where other_id is in the list of other_ids that changed. However, I find that:

self.search(cr, uid, [('other_id','in',other_ids)], context=None)

is wrong because self is actually a other.model object (I expected it to be this.model). And

self.pool.get('this.model').search(cr, uid, [('other_id','in',other_ids)], context=None)

(as I've edited to above to now read) doesn't work as it returns an empty list. It should be returning resources on this.model whose other_id field points to the newly created resource on other.model.

I hope that's a bit clearer?

0
アバター
破棄
Lucio

I am not sure what do you want to do, are you trying to look for the newly created id? Isn't that the id in other_ids?

Lucio

But if you just created the other.model, how is it that any of the this.model is related with it? If, on creation, you set the relation through other.model in, lets say, field first_model, you can access to it whit something like self.browse(cr,ids[0],context).first_model

Richard Lewis
著作者

Now, I have to apologise again. I've worked more on this today and found that the problem was very specifically to do with the actual models I was working with, and that my abstract version here would actually work fine. So I guess this question is either 'answered' or, better, 'asked in error'; not sure if there's a state for that.

アバター
filsystem
最善の回答

You have to return the id(s) of current model from _get_related_others, not id(s) from other.model. Try something like that:

def _get_related_others(self, cr, uid, other_ids, context=None):
    result = set()
    for om in self.pool.get('other.model').browse(cr, uid, other_ids):
        result.add(om.id)
    return list(result)
1
アバター
破棄
アバター
Andreas Brueckl
最善の回答

In the function _get_related_others the variable other_ids contains the Ids of the model other.model.

The job of this function is to return Ids of the current model (do not know how the model is called in your example).

But returning Ids of the model other.model is not correct!

I know that this is confusing, but once you got it it will be more clear :-)

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

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

登録
関連投稿 返信 ビュー 活動
how to change summernote toolbar language (web_editor)
transaction
アバター
0
8月 22
3189
Managing transactions between countries (Multi-currency)
transaction
アバター
0
3月 15
4005
Inter company transfer
transaction intercompany
アバター
アバター
1
8月 20
9075
How to remove all the transactions? 解決済
warehouses transaction
アバター
アバター
アバター
2
11月 19
17988
accessing one record with two counters at once
transaction counter
アバター
0
8月 16
4271
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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