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

Get single object

購読

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

この質問にフラグが付けられました
many2oneodoo
3 返信
12447 ビュー
アバター
Sylwester Zalewski

Hi, sorry Iam new to odoo and python, so I have tree view with product history in the product equipment class which works fine but I want to also get first element value (product.history.customer) from the tree view but I have following error "ValueError: dictionary update sequence element #0 has length 1; 2 is required"

class product_history(osv.osv):

_name = 'product.history'

_description = 'product History'

_columns = {

'equipment_id': fields.many2one('product.equipment','Unit of work ref', required=True),

'customer': fields.many2one('res.partner', 'Customer',required=True),

'start_date': fields.date("Start Date"),

'end_date': fields.date("End Date"),

}

product_history()

class product_equipment(osv.osv):

_name = "product.equipment"

_description = "equipment"

_inherit = ['mail.thread','ir.needaction_mixin','product.history']

_columns = {

'main_location': fields.function(_last_name,type='many2one', string='Location', readonly = True),

}

def last_location(self, cr, uid, ids, field_name, arg, context=None):

return self.pool.get('product.history').browse(cr, uid, ids)

product_equipment()




0
アバター
破棄
アバター
Temur
最善の回答

from your question I do not see how to identify last location for particular product, but here is how to get last location

class product_equipment(osv.osv):
_name = "product.equipment"
_description = "equipment"
_inherit = ['mail.thread','ir.needaction_mixin','product.history']

_columns = {
'main_location': fields.function(_last_name,type='many2one',obj='product.history', string='Location',readonly=True),
}

def _last_name(self, cr, uid, ids, field_name, arg, context=None): res = {}
      for id in ids: res[id] =
self.pool.get('product.history').search(cr, uid, [ ], limit=1, order="create_date desc")
return res
product_equipment()

it'll find the latest location from all locations... but you'll need to add search domain inside [ ] of search function, in order to get last location for a particular product if you're going to track multiple products (for a single product it should work as is)...

0
アバター
破棄
Temur

please try above code first and check if it works in general with empty [ ] -search domain... then we'll need to implement correct domain, it should be something like:

[ ( 'id', 'in', location_ids) ]
where location_ids is variable containing all location ids related to current product. it may be retrieved from one2many field you use for display location list...
Temur

suggestion of search domain:

class product_equipment(osv.osv):
    _name = "product.equipment"
    _description = "equipment"
    _inherit = ['mail.thread','ir.needaction_mixin','product.history']

    _columns = {
        'main_location': fields.function(_last_name,type='many2one',obj='product.history', string='Location',readonly=True),
        'location_ids': fields.one2many('product.history', 'equipment_id', 'Location History'), 
# I think you have already "location_ids" field(maybe with different name), but it's not included in the question.... if so, please adapt field name to your case, otherwise add this field...
    }

    def _last_name(self, cr, uid, ids, field_name, arg, context=None):
        res = {}
        for id in ids:
            location_ids = self.browse(cr, uid, id, context).location_ids.ids
            res[id] = self.pool.get('product.history').search(cr, uid, [( 'id', 'in', location_ids) ], limit=1, order="create_date desc")
        return res
product_equipment()
Sylwester Zalewski
著作者

hi, Thanks for your help!! but I still have some problems, because I cant see the result but if I change the type in "main_location" from many2one to e.g char (which shows the ID) I can see the correct ID so I dont know how to fix that. Also I would like to know if I can show the customer not the name from class history.

Temur

either:

'main_location': fields.function(_last_name,type='many2one',obj='product.history', string='Location',readonly=True),
OR
'main_location': fields.function(_last_name,type='many2one', relation='product.history', string='Location',readonly=True),
should work.. make sure you add obj='product.history' (or relation=) part to the field definition.
Sylwester Zalewski
著作者

That's what I did but it doesn't work, I don't know why, it looks like empty space... any suggestions ?

Temur

to 'product.history' object definition add the following line:

_rec_name = "customer"
-it'll show customer instead of name of product.history record... and try with obj='product.history' in 'main_location' field definition, without relation='product.history', do not forget to restart odoo and then update/upgrade module from "Settings/Modules/Local Modules" page as you make changes.
アバター
Axel Mendoza
最善の回答

It's not clear what you are trying to do, but here are some corrections in bold:

class product_equipment(osv.osv):
_name = "product.equipment"
    _description = "equipment"
    _inherit = ['mail.thread','ir.needaction_mixin','product.history']

    _columns = {
        'main_location': fields.function(_last_name,type='many2one',relation='product.history', string='Location',readonly=True),
    }

    def _last_name(self, cr, uid, ids, field_name, arg, context=None):
        return self.pool.get('product.history').browse(cr, uid, ids[0])
product_equipment()
0
アバター
破棄
Sylwester Zalewski
著作者

unfortunately its not working and same error appears. I will try to explain it better so - I have history list at the bottom in the equipment class and I want to show the last added element outside the list (in the form to show current customer )

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

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

登録
関連投稿 返信 ビュー 活動
ver=Any: field meny2one the recommended way...
many2one odoo
アバター
アバター
アバター
2
3月 24
2409
ODOO9: How to correct this condition?
many2one odoo
アバター
アバター
1
4月 16
3924
many2one field search for by multiple criteria (name, phone number, etc)?
many2one search odoo
アバター
アバター
アバター
2
2月 25
9434
many2one unlink without delete (v16)
many2one odoo odoo16features
アバター
アバター
1
4月 24
2480
many2one options=no_open in tree view not working in odoo
invoice many2one odoo
アバター
アバター
1
10月 23
9765
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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