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

Override and Change the middle of a function

購読

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

この質問にフラグが付けられました
inheritanceodoo12
7 返信
26045 ビュー
アバター
Janath Manthila

Hi all,

I would like to override a function called _cart_update which is in the website_sale module. But I want to change the middle of the function (I want to do something in the middle of the function code). So I tried to rewrite the function in my custom module and add the website_sale module as a dependency module (I rewrite the function without adding any super() calls). My function gets the function call. No problem with that. But there are other modules that override the same function with super() calls. Sadly, those functions will not be executed. But I want them to be executed.

Is there any issue with my work? or is there any other way to do this?

Thank you.

3
アバター
破棄
Janath Manthila
著作者

@Jake Robinson

Thank you. Your way worked!!!. Can you provide more details on the first approach (Changing where the hook is) ? I couldn't understand what you were saying. Could you please provide an example of that??

(Sorry I don't have enough Karma to comment on your answer. :( )

Nimesh Jadav

Hello @Janath Manthila

Hope you are well.

I have the same concern. Can you please help me? If you got any solution.

Thanks

アバター
Jake Robinson
最善の回答

Hi Janath

This kind of customisation is one of the trickiest parts of developing with Odoo, and poor approaches to this are one of the most common reasons I've seen apps break (especially app store apps, they love to override base code and not call super).

There are two main approaches:

Changing where the hook is: It's much better not to rewrite Odoo code, so trying another approach is always preferable. Is the code you're trying to edit actually being run in the _cart_update function, or is this function calling another function with some values that you'd like to change, or something else? If another function is being called, you can add a flag to the context before calling _cart_update, then make the change the other function that is being called if that flag exists. 

Overriding the original function: Rather than inheriting it, you can override the definition. You can do this with the following code:

from odoo.addons.website_sale.models.sale_order import SaleOrder as OriginalSaleOrder


def _cart_update(self, product_id=None, line_id=None, add_qty=0, set_qty=0, **kwargs):
# Insert the original code with your changes here

OriginalSaleOrder._cart_update = _cart_update

This just replaces the website_sale level of _cart_update, so all other modules will still function as normal, no need to call any super.

10
アバター
破棄
Yaman Alsaman

Thank you

wizardz

the problem with this is, when you uninstall the module the

´´´ OriginalSaleOrder._cart_update = _cart_update ´´´

part stays and blocks the basic function....

wizardz

So when you install or uninstall the module with the _cart_update = _cart_update override you need to restart odoo to see the real changes. Otherwise it uses the same code.

Is there any elegant way to override the middle of a basic method? This seems a little bit tricky, what if you just use the same methodname in the same class from the custom module? This will override the basic methods too.

アバター
Muhammed Nishad
最善の回答

Hi Janatha,

Try this

def _cart_update(self):
    //copy the code from the function
    //add the code on the middle
    //the rest of the method you want to replace
    return super(className,self)._cart_update(self)
0
アバター
破棄
Ermin Trevisan

Please avoid this empty space.

Muhammed Nishad

@Ermin Trevisan Broh, I couldn't find any unnecessary white space in the answer, If you can find any, kindly edit and remove it, if not rollback your vote.

andy aditya

Now empty space is gone LoL

アバター
Ravi Gadhia
最善の回答

Is there any issue with my work? 
   No there is no issue as long as your module dependency tree is intact/clear.  ​
is there any other way to do this?
   No there no way to override something which is in the middle of the method           

0
アバター
破棄
アバター
Janath Manthila
著作者 最善の回答

Hi Muhammed 

Thank you for the reply.

But will it be a double code execution because we rewrite the code and call the parent function by adding super()?

Hi Ravi,

Thank you for the reply. Do you have any thoughts on why it doesn't execute the other functions which are written in other modules (using super())?

0
アバター
破棄
Muhammed Nishad

that's true brother, let me check if there is any way to walk around it.

Ravi Gadhia

it's because you do not call super in your method so it will not execute other functions. in this case you may change the module dependency it's will change MRO (Method Resolution Order) so it will call first other methods then your method.

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

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

登録
関連投稿 返信 ビュー 活動
Function inheritance
inheritance odoo12
アバター
0
9月 20
2945
I am trying to inherit a <templates id="template" xml:space="preserve"> template, but that ate my last full week.
inheritance qweb odoo12
アバター
アバター
1
6月 20
13098
How to inherit one group access rights to another group in odoo12 解決済
inheritance accessrights odoo12
アバター
アバター
1
8月 19
7127
Can't inherit base.view_partner_form of res.partner
inheritance
アバター
アバター
アバター
アバター
アバター
4
2月 25
4038
Include in inherit from JS class
inheritance
アバター
アバター
1
8月 24
2909
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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