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

[SOLVED] New API Search/Browse - how?

購読

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

この質問にフラグが付けられました
searchbrowseodoo8.0newAPI
6 返信
38162 ビュー
アバター
Dr Obx

Guys, I'm a beginner so sometimes I have a problem with some things. I would like to get a value from sale_order_line.

In my table I have a column named: item_location

How to get data from this column?

class sale_order_line(models.Model):
    _inherit = 'sale.order.line'

    item_location = fields.Char(compute='get_location', string = 'Item location', type='Char')

    def get_location(self):
        location = self.env['sale.order.line'].search([('product_id','=',self.product_id.id)])
        print ' Self product ID :', self.product_id.id# Ok
        print ' Self ID :', self.id # ok
        print ' Location ID :', location.id # ok
        print ' Location name :', location.item_location # False
        res = location.item_location # this is what I need

        return res

sale_order_line()

but I still missing something because I can't get a value from the item_location column.

How to do it with a new API ?

GOT IT!

You guys are right, I don't have to do it using Search or Browse in this case ;) because that field is available directly :)

Ii's another valuable lesson for me, THANK YOU GUYS


1
アバター
破棄
Dr Obx
著作者

I managed to make it works but for some reason I can't see it in order form(table), any ideas why ?

PY

(I edited your code you readability.)

Dr Obx
著作者

PY: Where ?

PY

just the display, your code, can't you see the code is now in a proper code block (pre tag) ? easier to read when well indented and all

Dr Obx
著作者

Yes I think everything is done correctly, I still cant see the content of 'location' field. But I can see "item_location" instead so 'location' is not required anymore ;) Thanks for help :)

アバター
Axel Mendoza
最善の回答

Hi @Dr Obx

You need put the model of that query and the domain like:

location = self.env['sale.order.line'].search([('product_id','=',self.product_id.id)])

bolded are the changes to your code, the model is sale.order.line like every other api model method interaction and the domain need to be changed to pass exactly the id value of the product_id relation field because the domain parser will not do it for you, you need to pass exactly the value in the param #3 of the domain tuple.

Also if your item_location field is on the sale.order.line model you need to access it like:

location.item_location

if it's on the product.product model then you could get it (using your actual code) like:

location.product_id.item_location

but you could directly access the product if you don't need the sale.order.line changing your search like:

product = self.env['product.product'].search([('id','=',self.product_id.id)])
item_location = product.item_location

this last is guessing where is located the field item_location because was not clear to me in your answer

Hope this helps

********************************** Update*****************************************

Seeing your code changes seems that you are doing more than needed for get the item_location.

1- The item_location is on your sale.order.line so you could access it directly from the outside of the model, you don't need a computed field for that.

2- The search is not necessary because search usually is for get the ids and you already have the id, so a search with that domain will produce the same self.id value but with the browse applied so you could directly use the browse like:

location = self.env['sale.order.line'].browse(self.id)

But I repeat you could directly get the value from the outside without using a computed field. Also for the same thing there is a field definition way that will cause that Odoo get the value of others fields in the table or walking through many2one relations fields, like:

item_location = fields.Char(related='item_location', string = 'Item location')

And nothing more is needed

The thing appears to be that the sale order line doesn't have a value for the item_location field

6
アバター
破棄
Dr Obx
著作者

Hi Axel, I changed it a bit but it seems not working. I can browse the name, state etc but I can't get item_location. Field is in table 100% but for some reason i cant get the value from it ;(

from openerp import fields, tools, models, api, _

class sale_order_line(models.Model):
	_inherit = 'sale.order.line'
	item_location = fields.Char()
	location = fields.Char(compute='get_location', string = 'Location', type='Char')
	
	def get_location(self):
		location = self.env['sale.order.line'].search([('id','=',self.id)])
		print '== item location ==============================================================='
		print '   Self product ID   :', self.product_id.id
		print '   Product name      :', location.name
		print '   Location ID       :', location.id
		print '   Location name     :', location.item_location
		print '================================================================================'
		res = location.id
		return res
sale_order_line()
Result:
== item location ===============================================================
   Self product ID   : 694
   Product name      : Intel Celeron D 331 2.66GHz 256K FSB 533Mhz Skt LGA 775 pin SL7TV CPU Processor
   Location ID       : 425
   Location name     : False
================================================================================
Axel Mendoza

please see my answer update

Dr Obx
著作者

I can see it printed on screen but I can't see it in Odoo ...

Axel Mendoza

worked then?

Dr Obx
著作者

Yes Axel it worked but there was no data in table 'item_location' :) That's why I was getting 'False' instead of the actual location name :) But like I said, I can see it now on screen in CMD but it won't show location name in form ;(

アバター
Anil Kesariya
最善の回答

DR Obx,


If you are calling your method on compute attribute, it will work like functional field.

This method will automatically load for sale order line model self, because you already using that method in same model so you don't need to call search method in sale.order line.


Here you go,

Do one thing,

set api.multi decorator on your method.

So, your method will look lik,

@api.multi
get_location(self):
for line in self:
#self will work for all sale order line you can directly check in line record, line itself will appear as browse record

Second note, if your sale order line does not having any location value in that case of course it will give you false value, you have to put if condition for that, if you location than move further for next execution.

Hope this might help you.


Regards,

Anil.

4
アバター
破棄
Dr Obx
著作者

Thank you Anil, So I don't need search just pick self.item_location ? :)

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

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

登録
関連投稿 返信 ビュー 活動
Search function getting right value in many2one field? 解決済
function search browse
アバター
アバター
2
10月 15
9622
why ORM methods not working properly in custom module
search browse ORM v15
アバター
アバター
1
3月 22
3697
What is 'better': search or browse? 解決済
v7 orm search browse
アバター
アバター
1
12月 23
21745
fulltext search FTS migrate to odoo 8.0, full text search support in forum 解決済
search forum fulltext odoo8.0
アバター
アバター
2
3月 17
10062
group_by filter doesn't work
search group_by search_view odoo8.0
アバター
0
3月 17
4136
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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