Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to get date in a workflow state when button is pressed in open erp 7?

By
Suthan
on 5/25/14, 10:38 PM 1,176 views

Hi I have a workflow with states pending,approved and complete, i'm trying to get the date automatically in the 'WO_APPROVE_DATE' field, when the approved button is pressed, how do i implement this? pls help..

the buttons

    <header> 
    <button name="pending_draft" string="Pending" states="pending" class="oe_highlight"   type="workflow"/>
    <button name="approved_draft" string="Approved" states="approved" class="oe_highlight" type="workflow"/>
    <button name="complete" string="Active" states="active" class="oe_highlight" type="workflow"/>
    </header>


class

    class work_order(osv.osv):


    sel_states = [
        ('pending', 'Pending'),
        ('approved', 'Approved'),
        ('active', 'Complete')
    ]

    _name = "work_order.work_order"
    _description = "Work Order Details"

    _rec_name = "WO_CODE"
    _columns = {
        'WO_CODE' : fields.char("Work Order Code", size=64, required=True, readonly=True ),
        'WO_ASSIGNED_TO' : fields.many2one("hr.employee", "Assigned To", ondelete="no action", domain=[('job_id', '=', ('Crew Supervisor'))]),
        'WO_NOTES' : fields.text("Description"),
        'WO_APPROVE_DATE' : fields.datetime("EngineerApproval Date"),
        'state' : fields.selection(sel_states, "Workflow"),
    }

    def workorder_pending(self, cr, uid, ids):
        self.write(cr, uid, ids, {'state' : 'pending'})
        return True

    def workorder_approved(self, cr, uid, ids):
        self.write(cr, uid, ids, {'state' : 'approved'})
        return True

    def workorder_complete(self, cr, uid, ids):
        self.write(cr, uid, ids, {'state' : 'active'})
        return True

workflow.xml

    <?xml version="1.0" encoding="utf-8"?>

<openerp>
    <data>

        <record id="workorder_workflow" model="workflow">
            <field name="name">work_order.workflow</field>
            <field name="osv">work_order.work_order</field>
            <field name="on_create">True</field>
        </record>

        <!--workflow activity-->
        <record id="act_pending" model="workflow.activity">
            <field name="wkf_id" ref="workorder_workflow"/>
            <field name="flow_start">True</field>
            <field name="name">pending</field>
            <field name="kind">function</field>
            <field name="action">workorder_pending()</field>
        </record>
        
        <record id="act_approved" model="workflow.activity">
            <field name="wkf_id" ref="workorder_workflow"/>
            <field name="name">approved</field>
            <field name="kind">function</field>
            <field name="action">workorder_approved()</field>
        </record>

    <record id="act_complete" model="workflow.activity">
            <field name="wkf_id" ref="workorder_workflow"/>
            <field name="flow_stop">True</field>
            <field name="name">complete</field>
            <field name="kind">function</field>
            <field name="action">workorder_complete()</field>
        </record>

    <record id="trans_pending_approved" model="workflow.transition">
            <field name="act_from" ref="act_pending"/>
            <field name="act_to" ref="act_approved"/>
            <field name="signal">pending_draft</field>
        </record>

    <record id="trans_approved_complete" model="workflow.transition">
            <field name="act_from" ref="act_approved"/>
            <field name="act_to" ref="act_complete"/>
            <field name="signal">complete</field>
        </record>

1
anonymous 2183
On 5/25/14, 11:03 PM

import time

......

def workorder_approved(self, cr, uid, ids):

        approvedDate = current_date = time.strftime("%x")
        self.write(cr, uid, ids, {'state' : 'approved', 'WO_APPROVE_DATE' : approvedDate})
        return True

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/25/14, 10:38 PM
Seen: 1176 times
Last updated: 3/16/15, 8:10 AM