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

Need Python code to run the Compute Price from BOM server action

購読

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

この質問にフラグが付けられました
pythonAutomatedActions
2 返信
6807 ビュー
アバター
Wilson Yiu

Our product cost changes rapidly.  I want to update the cost of a manufactured product automatically by running the Compute Price from BOM server action, when the cost of a component of its BOM is changed. 

0
アバター
破棄
Odoo4Life

which Odoo version are you on?

Wilson Yiu
著作者

I am using version 15

Ray Carnes (ray)

For others reading this isn't always necessary as Odoo can update the cost automatically based on the costs of purchased components that are used and the time they are used. Remember that the BoM is the recipe, not what is used. If people stick to the recipe all the time and always use the newly purchased components this strategy will work fine. If you sometimes use components in stock and/or ever use more or less components than the BoM plans for, then this option won't be better than having Odoo do it based on a FIFO or AVERAGE cost for your products (components and finished goods). With this approach, the things you make in March using products you paid for in January will be costed as if you made them using products you paid for in March.

Wilson Yiu
著作者

Thank you for clarifying, Ray! Typical manufacturing businesses should utilize the Odoo built-in features whenever possible. My client is an EOM manufacturer for highly customized products. They don't stock inventory. When a client wants to place an order, they always get the up-to-date cost from vendors first. Then, they will add their manufacturing cost and margin on top in their price quotation to the client. Therefore, they cannot use the built-in features to compute cost from previous POs. Especially under the current US market situation where raw materials cost increases rapidly. Therefore, they need this customization to ensure that their quotation will not go below desired margin.

アバター
Wilson Yiu
著作者 最善の回答

Thank you, Nomad_King!  I have found the solution based on your reply.  Here is the Automated Action Python Code for the On Update trigger of the Product model:  

# Load the related BOM records for the current product
rec_boms = env['mrp.bom.line'].search([('product_id', '=', record.id)]).mapped('bom_id')

for bom in rec_boms:
    # Load the referencing product of the BOM
    for ref_prod in bom.product_tmpl_id:
        prod = env['product.product'].search([('id', '=', ref_prod.id )])

        # Call the Update Price from BOM method to update the product cost
        prod.button_bom_cost()

1
アバター
破棄
Pubalan Sivasangkar

Hi I got error like this.

Error:
Odoo Server Error

Traceback (most recent call last):
File "/home/odoo/src/odoo/14.0/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/home/odoo/src/odoo/14.0/odoo/http.py", line 683, in dispatch
result = self._call_function(**self.params)
File "/home/odoo/src/odoo/14.0/odoo/http.py", line 359, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/odoo/src/odoo/14.0/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/home/odoo/src/odoo/14.0/odoo/http.py", line 347, in checked_call
result = self.endpoint(*a, **kw)
File "/home/odoo/src/odoo/14.0/odoo/http.py", line 912, in __call__
return self.method(*args, **kw)
File "/home/odoo/src/odoo/14.0/odoo/http.py", line 531, in response_wrap
response = f(*args, **kw)
File "/home/odoo/src/odoo/14.0/addons/web/controllers/main.py", line 1398, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/home/odoo/src/odoo/14.0/addons/web/controllers/main.py", line 1386, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odoo/src/odoo/14.0/odoo/api.py", line 399, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/home/odoo/src/odoo/14.0/odoo/api.py", line 386, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/odoo/src/odoo/14.0/odoo/addons/base/models/ir_cron.py", line 83, in method_direct_trigger
cron.with_user(cron.user_id).with_context(lastcall=cron.lastcall).ir_actions_server_id.run()
File "/home/odoo/src/odoo/14.0/odoo/addons/base/models/ir_actions.py", line 632, in run
res = runner(run_self, eval_context=eval_context)
File "/home/odoo/src/odoo/14.0/odoo/addons/base/models/ir_actions.py", line 501, in _run_action_code_multi
safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action'
File "/home/odoo/src/odoo/14.0/odoo/tools/safe_eval.py", line 346, in safe_eval
raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/odoo/src/odoo/14.0/odoo/http.py", line 639, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/odoo/src/odoo/14.0/odoo/http.py", line 315, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: <class 'AttributeError'>: "'NoneType' object has no attribute 'id'" while evaluating
"rec_boms = env['mrp.bom.line'].search([('product_id', '=', record.id)]).mapped('bom_id')\n\nfor bom in rec_boms:\n # Load the referencing product of the BOM\n for ref_prod in bom.product_tmpl_id:\n prod = env['product.product'].search([('id', '=', ref_prod.id )])\n\n # Call the Update Price from BOM method to update the product cost\n prod.button_bom_cost()"

アバター
IT Admin
最善の回答

You can create a scheduled action. This worked for me in odoo v14.

# Load all BOM records for all the products
rec_boms = self.env['mrp.bom'].search([('product_tmpl_id', '!=', False)]).mapped('product_tmpl_id.id')
    
    # Load the referencing product of the BOM
    for ref_prod in rec_boms:
        prod = self.env['product.template'].search([('id', '=', ref_prod )])
        #Update Price from BOM method to update the product cost
        prod.button_bom_cost()
0
アバター
破棄
ディスカッションを楽しんでいますか?読むだけでなく、参加しましょう!

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

登録
関連投稿 返信 ビュー 活動
Automated action doesn't work in Odoo 16 but Odoo 14
python AutomatedActions
アバター
アバター
1
11月 23
2978
Please help me with odoo 14 community automated action 解決済
python AutomatedActions
アバター
アバター
1
11月 22
3350
Automated Action: Enrich Event Registration with Partner ID
python AutomatedActions
アバター
アバター
1
8月 22
3392
Automated action - Correct syntax for getting the product variant name instead of the product(template) name 解決済
python AutomatedActions
アバター
アバター
アバター
2
1月 22
6869
Automated action - Python syntax for assigning a known value to a field 解決済
python AutomatedActions
アバター
アバター
1
7月 20
4345
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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