Odoo Help


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

on 5/25/14, 10:38 PM 1,908 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

    <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"/>


    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


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


        <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>

        <!--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 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 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 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 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>

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

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


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