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

How to use same field more than once in a form?

購読

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

この質問にフラグが付けられました
moduleviewwidgetfield
3 返信
24878 ビュー
アバター
thenon

What would the view xml look like for a module that needed to use the same field more than once?

Explanatory example: you want to allow a phone number to be editable (like normal),

< field name="phone" />

but also want to do something like:

< field name="phone" widget="web_skypeButton" />

elsewhere on the page.

Whenever I include both, neither gets the value. Is there a better way of doing this?

2
アバター
破棄
thenon
著作者

A related field from the object to itself?

アバター
Francesco OpenCode
最善の回答

You must use a function field for this:

class your_class(osv.osv):

    _inherit = "your.class"

    def _your_function(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for id in ids:
            record = self.browse(cr, uid, id)
            res.update({id:record.phone})
        return res

    _columns = {
        'your_field' : fields.function(_your_function, type='char', size=32, method=True, store=False, multi=False),
        }

your_class()

and this is your view:

<record id="your_view" model="ir.ui.view">
            <field name="name">your.view.form</field>
            <field name="model">your.class</field>
            <field name="inherit_id" ref="original_module.original_form_view"/>
            <field name="arch" type="xml">
                <field name="phone" position="after">
                        <field name="your_field"/>
                </field>
            </field>
        </record>
5
アバター
破棄
thenon
著作者
  Thanks for that.   By record.phone I assume you meant record.your_field?

If so, I'm still confused by what the view would look like. This doesn't work for example:

   &lt;field name="arch" type="xml"&gt;
            &lt;field name="email" position="after"&gt;
                &lt;field name="your_field" string="Short code"/&gt;
            &lt;/field&gt;

            &lt;field name="your_field" position="after"&gt;
                &lt;field name="_your_function" string="Short code2"/&gt;
            &lt;/field&gt;
  &lt;/field&gt;


  and neither does:
thenon
著作者
         &lt;field name="arch" type="xml"&gt;
            &lt;field name="email" position="after"&gt;
                &lt;field name="your_field" string="Short code"/&gt;
                &lt;field name="_your_function" string="Short code2"/&gt;
            &lt;/field&gt;
  &lt;/field&gt;
Francesco OpenCode

I edit the answer with right situation

thenon
著作者

Thanks Francesco, but that view only contains one instance of the field, not two?

Francesco OpenCode

two. Phone is the original field and Your_Field is the second instance

thenon
著作者

In my instance phone is NOT already on the view - I'm trying to display two fields - one as normal edit, one as a widget (see my sample code) . I used phone as an easy to understand example to demonstrate the use case, but I need to declare both. The first field is actually the edit field. The second is going to be rendered by a widget and display something different with that field.

Francesco OpenCode

I'm sorry but I can't explain in 500 charaters how to create a view for openerp module. All you need to know is that with the field function you can duplicate your original field content. I do assume that you already know how to create a view for an openerp module.

thenon
著作者

Perhaps you could advise if this code is correct? http://pastebin.com/5TJx3d55

Francesco OpenCode

line 14 must be: res.update({id:record.mycol})

thenon
著作者

That code is not quite correct (should be record.mycol) - but now have it working essentially in that both are being rendered ! Thank you. Now just need to work out how to include a xpath AND a normal "after" field at the same time...

thenon
著作者

And the answer for anyone else looking, is to wrap in a <data> element.

アバター
Ray Carnes
最善の回答

I think you probably need a related field. Every time I've seen people put the same field on a form more than once, things don't work properly.

It much easier and probably faster than using functional fields as other answers suggested.

    _columns = {
        'phone': fields.integer('Phone'),
        'phone_2': fields.related('phone', string='Phone'),
    }

3
アバター
破棄
アバター
Vasiliy Birukov
最善の回答

You can define two field:

  • first - what you need
  • second - functional field, that return value from first field

This code for python:

class phone_example(osv.osv):
    _name = 'phone.example'

    def _get_phone(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for phone in self.browse(cr, uid, ids, context=context):
            res[phone.id] = phone.phone
        return res

    _columns = {
        'phone': fields.integer('Phone'),
        'phone_2': fields.function(_get_phone, method=True),
    }

Then you can use two field, that will show the same.

Note. Second field will show only data from DB. If you change first in form, second don't update while you don't save form. Use also onchange method for update second field realtime.

2
アバター
破棄
thenon
著作者

I'm very new to python - what would that second one look like in code please?

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

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

登録
関連投稿 返信 ビュー 活動
What are the available widgets in v7?
view widget field v7
アバター
アバター
1
3月 15
5057
How to add widget to boolean field??
widget field odoo
アバター
アバター
1
3月 25
8125
How to show datetime field as "xx days ago"
view field datetime
アバター
0
3月 21
3695
How to show a symbol inside a field like with the monetary widget? 解決済
widget field monetary
アバター
アバター
1
5月 17
5274
how to customize year range in date field? 解決済
date widget field
アバター
アバター
1
8月 15
6196
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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