コンテンツへスキップ
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 move around workflow states back and forth?

購読

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

この質問にフラグが付けられました
workflowstateactivitybackstatesforthtransition
1 返信
23440 ビュー
アバター
Vivekrajan Rayappan

Hi,

I would like to add new states in between the quote and order state. I also want to easily move around states back and forth by just a click of a button.

How to do that?

4
アバター
破棄
Vivekrajan Rayappan
著作者

Good Job. Thanks

Walid Redwan

Great Answer Timo, Thanks

アバター
Timo Talvitie, Vizucom Oy
最善の回答

First you have to define the new states you want to add. To do that you can create a new module with a class that inherits from sale.order. Copy the existing states that are defined in the sale module (sale.py line 189) and add your new state to the selection field. The result should look something like this:

class Sale_order(osv.Model):

    _inherit = 'sale.order'

    _columns = {
        'state': fields.selection([
            ('draft', 'Draft Quotation'),
            ('my_new_state', 'My New State'),
            ('sent', 'Quotation Sent'),
            ('cancel', 'Cancelled'),
            ('waiting_date', 'Waiting Schedule'),
            ('progress', 'Sales Order'),
            ('manual', 'Sale to Invoice'),
            ('invoice_except', 'Invoice Exception'),
            ('done', 'Done'),
            ], 'Status', readonly=True, track_visibility='onchange',
            help="Gives the status of the quotation or sales order. \nThe exception status is automatically set when a cancel operation occurs in the processing of a document linked to the sales order. \nThe 'Waiting Schedule' status is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
    }

To actually get the new state to show up in the form view's progress bar, you need to inherit and customize the sale order's form view and add your new state to the comma-separated list inside the statusbar_visible attribute:

<openerp>
    <data>
        <!-- Inherit the sale order model's form view and customize -->
        <record id="sale_form_view" model="ir.ui.view">
            <field name="name">sale.order.form.inherit</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <!-- Statusbar widget should also contain the new status -->
                <field name="state" position="replace">
                    <field name="state" widget="statusbar" statusbar_visible="draft,my_new_state,sent,invoiced,done" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>
                </field>
            </field>
        </record>
    </data>
</openerp>

After this you should be able to see the new state in your progress bar:

image description

There's still no functionality to advance to the new state though. To sort this out we will use workflows. The documentation defines workflows as follows:

A workflow is a directed graph where the nodes are called "activities" and the arcs are called "transitions".

Activities define work that should be done within the OpenERP server, such as changing the state of some records, or sending emails.

Transitions control how the workflow progresses from activity to activity.

If you take a look at the workflow of the sale module (sale_workflow.xml) you'll notice both the activities and the transitions are defined using simple <record> tags. You'll also note that there are already activities for the existing states, e.g. act_draft and act_sent. What we need to do is add a new activity for our new state to our own module. The workflow XML is usually put into a separate XML file, like this:

<openerp>
    <data>
        <!-- Create new activity for the new state -->
        <record id="act_my_new_state" model="workflow.activity">
            <field name="wkf_id" ref="sale.wkf_sale"/>
            <field name="name">my_new_state</field>
            <field name="kind">function</field>
            <field name="action">action_my_new_function()</field>
        </record>
    </data>
</openerp>

That code tells OpenERP that once a user arrives to this activity (which is a part of an existing sale.wkf_sale workflow) via some transition, a python function called action_my_new_function() should be executed. But before defining the function itself, let's finish the rest of the XML. We now need to define the transitions between different states.

Let's say we want to be able to progress from Draft Quotation to My New State, from My New State to Quotation Sent, and also go back from Quotation Sent to My New State. For that we need the following transitions:

<openerp>
    <data>
        <!-- Create new activity for the new state -->
        <record id="act_my_new_state" model="workflow.activity">
            <field name="wkf_id" ref="sale.wkf_sale"/>
            <field name="name">my_new_state</field>
            <field name="kind">function</field>
            <field name="action">action_my_new_function()</field>
        </record>

        <!-- Create transitions -->
        <!-- From Draft to new state -->
        <record id="trans_draft_my_new_state" model="workflow.transition">
            <field name="act_from" ref="sale.act_draft"/>
            <field name="act_to" ref="act_my_new_state"/>
            <field name="signal">signal_my_new_state_forward</field>
        </record>    

        <!-- From new state to Quotation Sent -->
        <record id="trans_new_state_sent" model="workflow.transition">
            <field name="act_from" ref="act_my_new_state"/>
            <field name="act_to" ref="sale.act_sent"/>
            <field name="signal">signal_quotation_sent</field>
        </record>

        <!-- From Quotation Sent back to new state -->
        <record id="trans_sent_new_state" model="workflow.transition">
            <field name="act_from" ref="sale.act_sent"/>
            <field name="act_to" ref="act_my_new_state"/>
            <field name="signal">signal_my_new_state_backward</field>
        </record>  

    </data>
</openerp>

Note the act_from and act_to fields: we have only defined one activity inside our module, we are mostly referencing existing activities that are defined inside the sale module.

The signals tell what user inputs are used to trigger the transition, In our example we'll use the press of a button as a trigger. Let's add new buttons to the form view definition. Note the states attributes, they limit in which states the button will be visible. The name attribute of the button matches the signal defined in the workflow and thus triggers the transition to a specific activity.

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <!-- Inherit the sale order model's form view and customize -->
        <record id="sale_form_view" model="ir.ui.view">
            <field name="name">sale.order.form.inherit</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">

                <!-- Statusbar widget should also contain the new statuses -->
                <field name="state" position="replace">
                    <field name="state" widget="statusbar" statusbar_visible="draft,my_new_state,sent,invoiced,done" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>
                </field>

                <field name="state" position="before">
                    <!-- From draft to new state -->
                    <button string="Send to new state" type="workflow" name="signal_my_new_state_forward" states="draft" class="oe_highlight"/>

                    <!-- From new state to Quotation Sent -->
                    <button string="Mark as sent" type="workflow" name="signal_quotation_sent" states="my_new_state" class="oe_highlight"/> 

                    <!-- From Quotation Sent back to new state -->
                    <button string="Back to new state" type="workflow"  name="signal_my_new_state_backward" states="sent" class="oe_highlight"/>
                </field>
            </field>
        </record>
    </data>
</openerp>

Now if we create a new quotation and save it, we can see one of the new buttons.

image description

The rest of the buttons appear when we progress in the states. If you click the new button nothing happens because we have not yet written the Python code that actually changes the sale order's state on button click. This requires only little code that is put inside our sale order subclass. Note that the function name is the same as in the action of our new activity, i.e. action_my_new_function()

def action_my_new_function(self, cr, uid, ids, context=None):
    res = self.write(cr, uid, ids, {'state': 'my_new_state'}, context=context)    
    return res

And that's it, now you should be able to jump between the states. There's a lot of fine-tuning you can still do after that, but hopefully this gives the basic idea of how states, transitions and activities work.

You will likely need to also override and customize some of the existing buttons defined in the sale module (e.g. to get the Print button to show up also in the new state).

You may also run into view inheritance issues if you are using many different modules that customize the sale views. One way to deal with the issue is this.

11
アバター
破棄
Mazhar Iqbal Rana

All is set but button is not triggering the state to next.It says action_my_new_function() is not defined though I have defined it as you said above under sale_order class. Also it says return res is not valid

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

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

登録
関連投稿 返信 ビュー 活動
Workflow stucked/frozen (on migration?)
action workflow state activity odoo8
アバター
0
8月 16
4230
I Want to Add New States in Purchase Order, How Can I Know Workflow ID That Are Already There?
workflow activity
アバター
0
9月 19
5099
How to extend the transition value of existing workflow? 解決済
workflow activity odoo8.0
アバター
アバター
アバター
4
12月 17
6207
Transition in the workflow doesn't work - Recreate an invoice per percentage after canceled the old one
workflow invoice transition
アバター
1
6月 16
5245
Avoid State's change if record is in edit mode (Odoo 8.0)
workflow state change
アバター
アバター
1
4月 16
6119
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • 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