ผลต่างระหว่างรุ่นของ "Tutorial Odoo 9.0 Part 10 : Workflows"

จาก Morange Wiki
(หน้าที่ถูกสร้างด้วย '== Workflow ==')
 
(Workflow)
 
(ไม่แสดง 1 รุ่นระหว่างกลางโดยผู้ใช้คนเดียวกัน)
แถว 1: แถว 1:
 
== Workflow ==
 
== Workflow ==
 +
เป็นการเขียนให้ แสดงรูปแบบลำดับการทำงานของขั้นตอน
 +
 +
=== แก้ไข openacademy/models.py ===
 +
<pre>
 +
attendees_count = fields.Integer(
 +
        string="Attendees count", compute='_get_attendees_count', store=True)
 +
 +
    state = fields.Selection([
 +
        ('draft', "Draft"),
 +
        ('confirmed', "Confirmed"),
 +
        ('done', "Done"),
 +
    ], default='draft')
 +
 +
    @api.multi
 +
    def action_draft(self):
 +
        self.state = 'draft'
 +
 +
    @api.multi
 +
    def action_confirm(self):
 +
        self.state = 'confirmed'
 +
 +
    @api.multi
 +
    def action_done(self):
 +
        self.state = 'done'
 +
 +
    @api.depends('seats', 'attendee_ids')
 +
    def _taken_seats(self):
 +
        for r in self:
 +
</pre>
 +
 +
=== แก้ไข openacademy/openacademy.py ===
 +
<pre>
 +
<field name="model">openacademy.session</field>
 +
            <field name="arch" type="xml">
 +
                <form string="Session Form">
 +
                    <header>
 +
                        <button name="action_draft" type="object"
 +
                                string="Reset to draft"
 +
                                states="confirmed,done"/>
 +
                        <button name="action_confirm" type="object"
 +
                                string="Confirm" states="draft"
 +
                                class="oe_highlight"/>
 +
                        <button name="action_done" type="object"
 +
                                string="Mark as done" states="confirmed"
 +
                                class="oe_highlight"/>
 +
                        <field name="state" widget="statusbar"/>
 +
                    </header>
 +
 +
                    <sheet>
 +
                        <group>
 +
                            <group string="General">
 +
</pre>
 +
 +
*จะได้ผลลัพธ์ เป็นดังนี้ คือจะแสดงระบบการทำงานให้เห็นว่าจะไปพบกับอะไรบ้าง
 +
 +
[[ไฟล์:Odoo10-1.png|800 px]]
 +
 +
=== แก้ openacademy/__openerp__.py ===
 +
<pre>'templates.xml',
 +
        'views/openacademy.xml',
 +
        'views/partner.xml',
 +
        'views/session_workflow.xml',
 +
    ],
 +
    # only loaded in demonstration mode
 +
    'demo': [</pre>
 +
=== แก้ openacademy/models.py ===
 +
<pre> ('draft', "Draft"),
 +
        ('confirmed', "Confirmed"),
 +
        ('done', "Done"),
 +
    ])
 +
 +
    @api.multi
 +
    def action_draft(self):</pre>
 +
=== แก้ openacademy/views/openacademy.xml ===
 +
<pre><field name="arch" type="xml">
 +
                <form string="Session Form">
 +
                    <header>
 +
                        <button name="draft" type="workflow"
 +
                                string="Reset to draft"
 +
                                states="confirmed,done"/>
 +
                        <button name="confirm" type="workflow"
 +
                                string="Confirm" states="draft"
 +
                                class="oe_highlight"/>
 +
                        <button name="done" type="workflow"
 +
                                string="Mark as done" states="confirmed"
 +
                                class="oe_highlight"/>
 +
                        <field name="state" widget="statusbar"/></pre>
 +
=== สร้าง openacademy/views/session_workflow.xml ===
 +
<pre><openerp>
 +
    <data>
 +
        <record model="workflow" id="wkf_session">
 +
            <field name="name">OpenAcademy sessions workflow</field>
 +
            <field name="osv">openacademy.session</field>
 +
            <field name="on_create">True</field>
 +
        </record>
 +
 +
        <record model="workflow.activity" id="draft">
 +
            <field name="name">Draft</field>
 +
            <field name="wkf_id" ref="wkf_session"/>
 +
            <field name="flow_start" eval="True"/>
 +
            <field name="kind">function</field>
 +
            <field name="action">action_draft()</field>
 +
        </record>
 +
        <record model="workflow.activity" id="confirmed">
 +
            <field name="name">Confirmed</field>
 +
            <field name="wkf_id" ref="wkf_session"/>
 +
            <field name="kind">function</field>
 +
            <field name="action">action_confirm()</field>
 +
        </record>
 +
        <record model="workflow.activity" id="done">
 +
            <field name="name">Done</field>
 +
            <field name="wkf_id" ref="wkf_session"/>
 +
            <field name="kind">function</field>
 +
            <field name="action">action_done()</field>
 +
        </record>
 +
 +
        <record model="workflow.transition" id="session_draft_to_confirmed">
 +
            <field name="act_from" ref="draft"/>
 +
            <field name="act_to" ref="confirmed"/>
 +
            <field name="signal">confirm</field>
 +
        </record>
 +
        <record model="workflow.transition" id="session_confirmed_to_draft">
 +
            <field name="act_from" ref="confirmed"/>
 +
            <field name="act_to" ref="draft"/>
 +
            <field name="signal">draft</field>
 +
        </record>
 +
        <record model="workflow.transition" id="session_done_to_draft">
 +
            <field name="act_from" ref="done"/>
 +
            <field name="act_to" ref="draft"/>
 +
            <field name="signal">draft</field>
 +
        </record>
 +
        <record model="workflow.transition" id="session_confirmed_to_done">
 +
            <field name="act_from" ref="confirmed"/>
 +
            <field name="act_to" ref="done"/>
 +
            <field name="signal">done</field>
 +
        </record>
 +
    </data>
 +
</openerp></pre>
 +
=== แก้ openacademy/views/session_workflow.xml ===
 +
<pre><field name="act_to" ref="done"/>
 +
            <field name="signal">done</field>
 +
        </record>
 +
 +
        <record model="workflow.transition" id="session_auto_confirm_half_filled">
 +
            <field name="act_from" ref="draft"/>
 +
            <field name="act_to" ref="confirmed"/>
 +
            <field name="condition">taken_seats &gt; 50</field>
 +
        </record>
 +
    </data>
 +
</openerp></pre>
 +
=== แก้ openacademy/views/session_workflow.xml ===
 +
<pre><field name="on_create">True</field>
 +
        </record>
 +
 +
        <record model="ir.actions.server" id="set_session_to_draft">
 +
            <field name="name">Set session to Draft</field>
 +
            <field name="model_id" ref="model_openacademy_session"/>
 +
            <field name="code">
 +
model.search([('id', 'in', context['active_ids'])]).action_draft()
 +
            </field>
 +
        </record>
 +
        <record model="workflow.activity" id="draft">
 +
            <field name="name">Draft</field>
 +
            <field name="wkf_id" ref="wkf_session"/>
 +
            <field name="flow_start" eval="True"/>
 +
            <field name="kind">dummy</field>
 +
            <field name="action"></field>
 +
            <field name="action_id" ref="set_session_to_draft"/>
 +
        </record>
 +
 +
        <record model="ir.actions.server" id="set_session_to_confirmed">
 +
            <field name="name">Set session to Confirmed</field>
 +
            <field name="model_id" ref="model_openacademy_session"/>
 +
            <field name="code">
 +
model.search([('id', 'in', context['active_ids'])]).action_confirm()
 +
            </field>
 +
        </record>
 +
        <record model="workflow.activity" id="confirmed">
 +
            <field name="name">Confirmed</field>
 +
            <field name="wkf_id" ref="wkf_session"/>
 +
            <field name="kind">dummy</field>
 +
            <field name="action"></field>
 +
            <field name="action_id" ref="set_session_to_confirmed"/>
 +
        </record>
 +
 +
        <record model="ir.actions.server" id="set_session_to_done">
 +
            <field name="name">Set session to Done</field>
 +
            <field name="model_id" ref="model_openacademy_session"/>
 +
            <field name="code">
 +
model.search([('id', 'in', context['active_ids'])]).action_done()
 +
            </field>
 +
        </record>
 +
        <record model="workflow.activity" id="done">
 +
            <field name="name">Done</field>
 +
            <field name="wkf_id" ref="wkf_session"/>
 +
            <field name="kind">dummy</field>
 +
            <field name="action"></field>
 +
            <field name="action_id" ref="set_session_to_done"/>
 +
        </record>
 +
 +
        <record model="workflow.transition" id="session_draft_to_confirmed"></pre>
 +
 +
*จะได้หน้าของ workflow
 +
 +
หัวข้อถัดไป [[Tutorial Odoo 9.0 Part 11 : Security]]

รุ่นแก้ไขปัจจุบันเมื่อ 08:01, 19 กรกฎาคม 2559

Workflow

เป็นการเขียนให้ แสดงรูปแบบลำดับการทำงานของขั้นตอน

แก้ไข openacademy/models.py

 attendees_count = fields.Integer(
        string="Attendees count", compute='_get_attendees_count', store=True)

    state = fields.Selection([
        ('draft', "Draft"),
        ('confirmed', "Confirmed"),
        ('done', "Done"),
    ], default='draft')

    @api.multi
    def action_draft(self):
        self.state = 'draft'

    @api.multi
    def action_confirm(self):
        self.state = 'confirmed'

    @api.multi
    def action_done(self):
        self.state = 'done'

    @api.depends('seats', 'attendee_ids')
    def _taken_seats(self):
        for r in self:

แก้ไข openacademy/openacademy.py

<field name="model">openacademy.session</field>
            <field name="arch" type="xml">
                <form string="Session Form">
                    <header>
                        <button name="action_draft" type="object"
                                string="Reset to draft"
                                states="confirmed,done"/>
                        <button name="action_confirm" type="object"
                                string="Confirm" states="draft"
                                class="oe_highlight"/>
                        <button name="action_done" type="object"
                                string="Mark as done" states="confirmed"
                                class="oe_highlight"/>
                        <field name="state" widget="statusbar"/>
                    </header>

                    <sheet>
                        <group>
                            <group string="General">
  • จะได้ผลลัพธ์ เป็นดังนี้ คือจะแสดงระบบการทำงานให้เห็นว่าจะไปพบกับอะไรบ้าง
มีข้อผิดพลาดในการสร้างรูปย่อ: ไฟล์สูญหาย

แก้ openacademy/__openerp__.py

'templates.xml',
        'views/openacademy.xml',
        'views/partner.xml',
        'views/session_workflow.xml',
    ],
    # only loaded in demonstration mode
    'demo': [

แก้ openacademy/models.py

 ('draft', "Draft"),
        ('confirmed', "Confirmed"),
        ('done', "Done"),
    ])

    @api.multi
    def action_draft(self):

แก้ openacademy/views/openacademy.xml

<field name="arch" type="xml">
                <form string="Session Form">
                    <header>
                        <button name="draft" type="workflow"
                                string="Reset to draft"
                                states="confirmed,done"/>
                        <button name="confirm" type="workflow"
                                string="Confirm" states="draft"
                                class="oe_highlight"/>
                        <button name="done" type="workflow"
                                string="Mark as done" states="confirmed"
                                class="oe_highlight"/>
                        <field name="state" widget="statusbar"/>

สร้าง openacademy/views/session_workflow.xml

<openerp>
    <data>
        <record model="workflow" id="wkf_session">
            <field name="name">OpenAcademy sessions workflow</field>
            <field name="osv">openacademy.session</field>
            <field name="on_create">True</field>
        </record>

        <record model="workflow.activity" id="draft">
            <field name="name">Draft</field>
            <field name="wkf_id" ref="wkf_session"/>
            <field name="flow_start" eval="True"/>
            <field name="kind">function</field>
            <field name="action">action_draft()</field>
        </record>
        <record model="workflow.activity" id="confirmed">
            <field name="name">Confirmed</field>
            <field name="wkf_id" ref="wkf_session"/>
            <field name="kind">function</field>
            <field name="action">action_confirm()</field>
        </record>
        <record model="workflow.activity" id="done">
            <field name="name">Done</field>
            <field name="wkf_id" ref="wkf_session"/>
            <field name="kind">function</field>
            <field name="action">action_done()</field>
        </record>

        <record model="workflow.transition" id="session_draft_to_confirmed">
            <field name="act_from" ref="draft"/>
            <field name="act_to" ref="confirmed"/>
            <field name="signal">confirm</field>
        </record>
        <record model="workflow.transition" id="session_confirmed_to_draft">
            <field name="act_from" ref="confirmed"/>
            <field name="act_to" ref="draft"/>
            <field name="signal">draft</field>
        </record>
        <record model="workflow.transition" id="session_done_to_draft">
            <field name="act_from" ref="done"/>
            <field name="act_to" ref="draft"/>
            <field name="signal">draft</field>
        </record>
        <record model="workflow.transition" id="session_confirmed_to_done">
            <field name="act_from" ref="confirmed"/>
            <field name="act_to" ref="done"/>
            <field name="signal">done</field>
        </record>
    </data>
</openerp>

แก้ openacademy/views/session_workflow.xml

<field name="act_to" ref="done"/>
            <field name="signal">done</field>
        </record>

        <record model="workflow.transition" id="session_auto_confirm_half_filled">
            <field name="act_from" ref="draft"/>
            <field name="act_to" ref="confirmed"/>
            <field name="condition">taken_seats > 50</field>
        </record>
    </data>
</openerp>

แก้ openacademy/views/session_workflow.xml

<field name="on_create">True</field>
        </record>

        <record model="ir.actions.server" id="set_session_to_draft">
            <field name="name">Set session to Draft</field>
            <field name="model_id" ref="model_openacademy_session"/>
            <field name="code">
model.search([('id', 'in', context['active_ids'])]).action_draft()
            </field>
        </record>
        <record model="workflow.activity" id="draft">
            <field name="name">Draft</field>
            <field name="wkf_id" ref="wkf_session"/>
            <field name="flow_start" eval="True"/>
            <field name="kind">dummy</field>
            <field name="action"></field>
            <field name="action_id" ref="set_session_to_draft"/>
        </record>

        <record model="ir.actions.server" id="set_session_to_confirmed">
            <field name="name">Set session to Confirmed</field>
            <field name="model_id" ref="model_openacademy_session"/>
            <field name="code">
model.search([('id', 'in', context['active_ids'])]).action_confirm()
            </field>
        </record>
        <record model="workflow.activity" id="confirmed">
            <field name="name">Confirmed</field>
            <field name="wkf_id" ref="wkf_session"/>
            <field name="kind">dummy</field>
            <field name="action"></field>
            <field name="action_id" ref="set_session_to_confirmed"/>
        </record>

        <record model="ir.actions.server" id="set_session_to_done">
            <field name="name">Set session to Done</field>
            <field name="model_id" ref="model_openacademy_session"/>
            <field name="code">
model.search([('id', 'in', context['active_ids'])]).action_done()
            </field>
        </record>
        <record model="workflow.activity" id="done">
            <field name="name">Done</field>
            <field name="wkf_id" ref="wkf_session"/>
            <field name="kind">dummy</field>
            <field name="action"></field>
            <field name="action_id" ref="set_session_to_done"/>
        </record>

        <record model="workflow.transition" id="session_draft_to_confirmed">
  • จะได้หน้าของ workflow

หัวข้อถัดไป Tutorial Odoo 9.0 Part 11 : Security