问题描述:

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

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

网友答案:

first add this lines for importing packages

from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare
import time
from datetime import datetime

then change function like this

def workorder_approved(self, cr, uid, ids):
        self.write(cr, uid, ids, {'state' : 'approved','WO_APPROVE_DATE':time.strftime(DEFAULT_SERVER_DATE_FORMAT)})
        return True
相关阅读:
Top