I need to extend a form (stock.view_inventory_form) in Odoo 10. The form has a sub-tree populated with related records from another model. Here's the part of the original form that I want to change:
<field name="line_ids" string="Inventory Details" context="{'default_location_id': location_id, 'default_product_id': product_id, 'default_prod_lot_id': lot_id, 'default_package_id': package_id, 'default_partner_id': partner_id}" mode="tree,kanban">
<tree string="Inventory Details" editable="bottom" decoration-info="product_qty != theoretical_qty" decoration-danger="theoretical_qty < 0">
<field name="product_id" domain="[('type','=','product')]"/>
<field name="product_uom_id" string="UoM" groups="product.group_uom"/>
<field name="location_id" domain="[('id', 'child_of', parent.location_id)]" groups="stock.group_stock_multi_locations"/>
<field name="prod_lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/>
<field name="package_id" domain="['|', ('location_id','=', False), ('location_id', '=', location_id)]" groups="stock.group_tracking_lot"/>
<field name="partner_id" groups="stock.group_tracking_owner"/>
<field name="theoretical_qty" readonly="1"/>
<field name="product_qty" string="Real Quantity"/>
<field name="state" invisible="True"/>
</tree>
</field>
Where line_ids is a field from a related model (stock.inventory.line). So I extended the model with the following:
class stock_inventory_line(models.Model):
_inherit = 'stock.inventory.line'
x_container_details = fields.Char('Container details')
x_wagon_no = fields.Char('Wagon No')
x_seal_no = fields.Char('Seal No')
x_invoice_no = fields.Integer('Invoice No')
x_net_weight = fields.Integer('Net weight')
x_gross_weight = fields.Integer('Gross Weight')
Then I tried to extend the form with the following code:
<record id="view_form_todo_task_inherited" model="ir.ui.view">
<field name="name">Test</field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="stock.view_inventory_form"/>
<field name="arch" type="xml">
<field name="line_ids">
<field name="x_container_details"/>
<field name="x_wagon_no"/>
</field>
</field>
</record>
Odoo is not returning any error, but my fields are not showed in the (sub) tree of the form.. what am I doing wrong?
Thanks to anyone that can help with this!
This is not the right way to extend a view, you should take a look documentation.
You need to specify the position were you want to add or replace fields, this is an example to insert fields at the end of the list:
<record id="view_form_todo_task_inherited" model="ir.ui.view">
<field name="name">Test</field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="stock.view_inventory_form"/>
<field name="arch" type="xml">
<!-- to insert your fields at the end of the list -->
<xpath expr="//tree/field[#name='state']" position="after" >
<field name="x_container_details"/>
<field name="x_wagon_no"/>
</xpath>
</field>
I hope this can be helpfull for you.
I've set up a wizard in OpenERP 7.0 that is updating fields correctly and all is working fine. But I would like to send a signal to the workflow from that wizard after user submits information to check if there is any transition to be taken.
My wizard code is the following:
from openerp.osv import osv
from openerp.osv import fields
from openerp.tools.translate import _
class ref_generic_request(osv.osv_memory):
_name='ref.generic.request'
_columns = {
'reformulation_info': fields.text('Reformulation instructions', help='Instructions for the requestor justification the reformulation needs'),
}
def save_info(self, cr, uid, ids, context=None):
if 'active_id' in context:
info=self.browse(cr,uid,ids)[0].reformulation_info
self.pool.get('generic.request').write(cr,uid,context['active_id'],{'reformulation_info' : info, 'needs_reformulation': 1})
return {
'type': 'ir.actions.act_window_close',
}
ref_generic_request()
And in this particular case I would like to signal this function in my generic.request object:
def req_reformulate_request(self, cr, uid, ids, context=None):
req = self.browse(cr, uid, ids, context=context)
goto = req[0].state
if goto:
self.write(cr, uid, ids, {'goto': goto, 'state': 'req_reformulation', 'needs_reformulation': True} )
else:
self.write(cr, uid, ids, {'state': 'req_reformulation', 'needs_reformulation': True})
self.insert_trace(cr, uid, ids, context)
return True
How should I do that?
Do I have to call the function inside the def save_info()? (I've tried this call self.pool.get('generic.request').req_reformulate_request(cr, uid, context['active_id'], context) but it throws so many errors, that I quickly gave up this approach)
Do I have to return something like 'signal': 'generic.request.req_reformulate_request' ?
Since I didn't find any information on this, I'm completely lost here, so any help would be very appreciated!
Thanks!
Here is the workflow definition:
<?xml version="1.0"?>
<openerp>
<data>
<record model="workflow" id="wkf_request">
<field name="name">request.wkf</field>
<field name="osv">generic.request</field>
<field name="on_create">True</field>
</record>
<!-- actividades -->
<record model="workflow.activity" id="act_draft">
<field name="wkf_id" ref="wkf_request" />
<field name="flow_start">True</field>
<field name="name">request_draft</field>
<field name="kind">function</field>
<field name="action">request_draft()</field>
</record>
<record model="workflow.activity" id="act_submit">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_submitted</field>
<field name="kind">function</field>
<field name="action">submit_request()</field>
</record>
<record model="workflow.activity" id="act_confirm">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_confirmed</field>
<field name="kind">function</field>
<field name="action">confirm_request()</field>
</record>
<record model="workflow.activity" id="act_closed_nconf">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed_nconf</field>
<field name="action_id" ref="ir_actions_server_send_email_when_closed_nconf"/>
<field name="kind">function</field>
<field name="action">close_nconf_request()</field>
<field name="flow_stop">True</field>
</record>
<record model="workflow.activity" id="act_req_reformulate">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_reformulation</field>
<field name="kind">function</field>
<field name="action">req_reformulate_request()</field>
</record>
<record model="workflow.activity" id="act_treatment">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_treatment</field>
<field name="kind">function</field>
<field name="action">treat_request()</field>
</record>
<record model="workflow.activity" id="act_taken">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_take</field>
<field name="kind">function</field>
<field name="action">take_request()</field>
</record>
<record model="workflow.activity" id="act_given">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_give</field>
<field name="kind">function</field>
<field name="action">give_request()</field>
</record>
<record model="workflow.activity" id="act_closed">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed</field>
<field name="kind">function</field>
<field name="action">close_request()</field>
<field name="flow_stop">True</field>
</record>
<record model="workflow.activity" id="act_awaiting_auth">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_awaiting_authorization</field>
<field name="kind">function</field>
<field name="action">wait_auth_request()</field>
</record>
<record model="workflow.activity" id="act_closed_ref">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed_ref</field>
<field name="kind">function</field>
<field name="action">close_ref_request()</field>
<field name="flow_stop">True</field>
</record>
<record model="workflow.activity" id="act_awaiting_appr">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_awainting_approval</field>
<field name="kind">function</field>
<field name="action">wait_appr_request()</field>
</record>
<record model="workflow.activity" id="act_closed_disappr">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed_disappr</field>
<field name="kind">function</field>
<field name="action">close_disappr_request()</field>
<field name="flow_stop">True</field>
</record>
<!-- transições -->
<record model="workflow.transition" id="request_t1">
<field name="act_from" ref="act_draft" />
<field name="act_to" ref="act_submit" />
<field name="signal">submit_request</field>
</record>
<!--
<record model="workflow.transition" id="request_t101">
<field name="act_from" ref="act_draft" />
<field name="act_to" ref="act_confirm" />
<field name="signal">submit_request</field>
<field name="condition">check_responsible()</field>
</record>
-->
<record model="workflow.transition" id="request_t102">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_confirm" />
<field name="condition">check_responsible()</field>
</record>
<record model="workflow.transition" id="request_t2">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_req_reformulate" />
<field name="signal">req_reformulate_request</field>
</record>
<record model="workflow.transition" id="request_t3">
<field name="act_from" ref="act_req_reformulate" />
<field name="act_to" ref="act_submit" />
<field name="signal">submit_request</field>
</record>
<record model="workflow.transition" id="request_t1001">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_confirm" />
<field name="condition">ref_goto_confirmed()</field>
</record>
<record model="workflow.transition" id="request_t1002">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_treatment" />
<field name="condition">ref_goto_treatment()</field>
</record>
<record model="workflow.transition" id="request_t4">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_confirm" />
<field name="signal">confirm_request</field>
</record>
<record model="workflow.transition" id="request_t5">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_closed_nconf" />
<field name="signal">close_nconf_request</field>
</record>
<record model="workflow.transition" id="request_t6">
<field name="act_from" ref="act_confirm" />
<field name="act_to" ref="act_treatment" />
<field name="signal">treat_request</field>
</record>
<record model="workflow.transition" id="request_t7">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_closed" />
<field name="signal">close_request</field>
</record>
<record model="workflow.transition" id="request_t7011">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_taken" />
<field name="signal">take_request</field>
</record>
<record model="workflow.transition" id="request_t7012">
<field name="act_from" ref="act_taken" />
<field name="act_to" ref="act_treatment" />
</record>
<record model="workflow.transition" id="request_t7021">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_given" />
<field name="signal">give_request</field>
</record>
<record model="workflow.transition" id="request_t7022">
<field name="act_from" ref="act_given" />
<field name="act_to" ref="act_treatment" />
</record>
<record model="workflow.transition" id="request_t8">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_awaiting_auth" />
<field name="signal">wait_auth_request</field>
</record>
<record model="workflow.transition" id="request_t9">
<field name="act_from" ref="act_awaiting_auth" />
<field name="act_to" ref="act_closed_ref" />
<field name="signal">close_ref_request</field>
</record>
<record model="workflow.transition" id="request_t10">
<field name="act_from" ref="act_awaiting_auth" />
<field name="act_to" ref="act_treatment" />
<field name="signal">auth_send_processing</field>
</record>
<record model="workflow.transition" id="request_t11">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_req_reformulate" />
<field name="signal">req_reformulate_request</field>
</record>
<record model="workflow.transition" id="request_t12">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_awaiting_appr" />
<field name="signal">wait_appr_request</field>
</record>
<record model="workflow.transition" id="request_t13">
<field name="act_from" ref="act_awaiting_appr" />
<field name="act_to" ref="act_closed_disappr" />
<field name="signal">close_disappr_request</field>
</record>
<record model="workflow.transition" id="request_t14">
<field name="act_from" ref="act_awaiting_appr" />
<field name="act_to" ref="act_treatment" />
<field name="signal">appr_send_processing</field>
</record>
</data>
</openerp>
The transition I want to trigger in this particular case is the one with id="request_t2"
<record model="workflow.transition" id="request_t2">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_req_reformulate" />
<field name="signal">req_reformulate_request</field>
</record>
And here is a screenshot of the workflow, the highlighted transition is the one I want to trigger.
I finaly found the answer. I'll leave here the modified python code that made it!
from openerp.osv import osv
from openerp.osv import fields
from openerp.tools.translate import _
import netsvc
class ref_generic_request(osv.osv_memory):
_name='ref.generic.request'
_columns = {
'reformulation_info': fields.text('Reformulation instructions', help='Instructions for the requestor justification the reformulation needs'),
}
def save_info(self, cr, uid, ids, context=None):
if 'active_id' in context:
info=self.browse(cr,uid,ids)[0].reformulation_info
self.pool.get('generic.request').write(cr,uid,context['active_id'],{'reformulation_info' : info, 'needs_reformulation': 1})
wf_service = netsvc.LocalService('workflow')
wf_service.trg_validate(uid,'generic.request',context['active_id'],'req_reformulate_request',cr)
return {
'type': 'ir.actions.act_window_close',
}
ref_generic_request()
So, resuming, I had to add 3 lines to my code:
import netsvc
And, after saving my info, invoked the workflow with these two:
wf_service = netsvc.LocalService('workflow')
wf_service.trg_validate(uid,'generic.request',context['active_id'],'req_reformulate_request',cr)
Hope this will help someone! :)
On odoo8 use signal_workflow method.
#api.multi
def confirm_multi_payslips(self):
for payslip in self:
payslip.signal_workflow('hr_verify_sheet')
I am beginner in OpenERP, I want to create a wizard to duplicate an object many time, which when i click on the button the wizard open a form the content if this form it's ( textbox + ok button) the textBox for to write how many time the wizard will call copy function to copy the object
This is my class
class immo_article(osv.osv):
_name = "immo.article"
_description = "immo article"
_columns = {
'name':fields.integer('N d inventaire',required=True , size=10),
}
_defaults = {
'date_creation': fields.date.context_today,
}
immo_article()
and this my view
<record id="immo_article_form" model="ir.ui.view">
<field name="name">immo.article.form</field>
<field name="model">immo.article</field>
<field name="arch" type="xml">
<form string="article" >
<button string="%(action_duplicate_object)d" type="action" name="duplicate.wiz"/>
<field name="name" />
</form>
</field>
</record>
<record id="immo_article_tree" model="ir.ui.view">
<record id="immo_article_tree" model="ir.ui.view">
<field name="name">immo.article.tree</field>
<field name="model">immo.article</field>
<field name="arch" type="xml">
<tree string="articles">
<field name="name" />
</tree>
</field>
</record>
<record id="immo_article_form_act" model="ir.actions.act_window">
<field name="name">Article</field>
<field name="res_model">immo.article</field>
<field name="view_mode">tree,form</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_id" ref="immo_article_tree"/>
<field name="help" type="html"></field>
</record>
and this my wizard .py
class duplicate_wiz(osv.osv_memory):
_name = 'duplicate.wiz'
_description = 'duplicate wizard'
_columns = {
'number_of_copies':fields.integer('Number of copies', size=2 , required=True),
}
_defaults = {
'number_of_copies': '0',
}
def duplicate_object(self, cr, uid, ids, context=None):
data = self.read(cr, uid, ids)[0]
article_id = context['active_id']
try:
number_of_copies = data['number_of_copies']
except:
raise osv.except_osv(_('Error'), _('Trouble!'))
return {'type': 'ir.actions.act_window_close'}
duplicate_wiz()
and this my wizard view
<record id="dup_view" model="ir.ui.view">
<field name="name">duplicate.wizard</field>
<field name="model">duplicate.wiz</field>
<field name="priority">1</field>
<field name="arch" type="xml">
<form string="Duplicate" version="7.0">
<group col="2">
<field name="number_of_copies"/>
</group>
<footer>
<button name="duplicate_object" string="_Import" type="action" class="oe_highlight"/>
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_duplicate_object" model="ir.actions.act_window">
<field name="name">duplicater action</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">duplicate.wiz</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="dup_view"/>
</record>
</data>
I know I have many errors in wizard code, because I don't know how to it and how I can call the wizard from the button, anyone can help me with this ?
I don't have time now to read all your code, but the button on immo.article.form should have action reference in name attribute, not in string:
<button name="%(action_duplicate_object)d" type="action" string="A string"/>
I''m using OpenERP 7.0 to develop a new module. I have this workflow with two path to reach one same state "confirmed". One path is submitting a request from wich you are not responsible, thus it has to be submitted and then confirmed by the responsible person, or submit a resquest and, if you are responsible, the confirmation step is skipped and goes directly to the "confirmed" case. When I try to send the request to be treated , it work if the process came from the first path (through confirmation) and doesn't if it went directly from "draft" to "confirmed".
Here is a screenshot of the workflow
My workflow definition:
<?xml version="1.0"?>
<openerp>
<data>
<record model="workflow" id="wkf_request">
<field name="name">request.wkf</field>
<field name="osv">generic.request</field>
<field name="on_create">True</field>
</record>
<!-- actividades -->
<record model="workflow.activity" id="act_draft">
<field name="wkf_id" ref="wkf_request" />
<field name="flow_start">True</field>
<field name="name">request_draft</field>
<field name="kind">function</field>
<field name="action">request_draft()</field>
</record>
<record model="workflow.activity" id="act_submit">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_submitted</field>
<field name="kind">function</field>
<field name="action">submit_request()</field>
</record>
<record model="workflow.activity" id="act_confirm">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_confirmed</field>
<field name="kind">function</field>
<field name="action">confirm_request()</field>
</record>
<record model="workflow.activity" id="act_closed_nconf">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed_nconf</field>
<field name="kind">function</field>
<field name="action">close_nconf_request()</field>
<field name="flow_stop">True</field>
</record>
<record model="workflow.activity" id="act_req_reformulate">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_reformulation</field>
<field name="kind">function</field>
<field name="action">req_reformulate_request()</field>
</record>
<record model="workflow.activity" id="act_treatment">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_treatment</field>
<field name="kind">function</field>
<field name="action">tratamento()</field>
</record>
<record model="workflow.activity" id="act_closed">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed</field>
<field name="kind">function</field>
<field name="action">close_request()</field>
<field name="flow_stop">True</field>
</record>
<!-- transições -->
<record model="workflow.transition" id="request_t1">
<field name="act_from" ref="act_draft" />
<field name="act_to" ref="act_submit" />
<field name="signal">submit_request</field>
</record>
<record model="workflow.transition" id="request_t101">
<field name="act_from" ref="act_draft" />
<field name="act_to" ref="act_confirm" />
<field name="signal">confirm_request</field>
</record>
<record model="workflow.transition" id="request_t2">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_req_reformulate" />
<field name="signal">req_reformulate_request</field>
</record>
<record model="workflow.transition" id="request_t3">
<field name="act_from" ref="act_req_reformulate" />
<field name="act_to" ref="act_submit" />
<field name="signal">submit_request</field>
</record>
<record model="workflow.transition" id="request_t4">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_confirm" />
<field name="signal">confirm_request</field>
</record>
<record model="workflow.transition" id="request_t5">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_closed_nconf" />
<field name="signal">close_nconf_request</field>
</record>
<record model="workflow.transition" id="request_t6">
<field name="act_from" ref="act_confirm" />
<field name="act_to" ref="act_treatment" />
<field name="signal">tratamento</field>
</record>
<record model="workflow.transition" id="request_t7">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_closed" />
<field name="signal">close_request</field>
</record>
</data>
</openerp>
Button in the view definition:
<button name="tratamento" class="oe_highlight oe_view_mode_only" string="Send to processing!" type="workflow" states="confirmed" />
And finaly, here is the code of the relevant funcions in my py object
def request_draft(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'draft'})
self.insert_trace(cr, uid, ids, context)
return True
def submit_request(self, cr, uid, ids, context=None):
resp = self.browse(cr,uid,ids,context)
if resp[0].needs_reformulation:
self.write(cr, uid, ids, {'needs_reformulation': False, 'reformulation_info': ''}) #clean up reformulation settings
if resp[0].goto:
self.write(cr, uid, ids, {'goto':'','state': resp[0].goto}) # if request is already in motion, clean up the goto tag and go to where it came from
elif resp[0].is_responsible: # else check if requestor is responsible
self.write(cr, uid, ids, {'state': 'confirmed'})
else: # if not
self.write(cr, uid, ids, {'state': 'submitted'})
self.insert_trace(cr, uid, ids, context)
return True
def confirm_request(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'confirmed'})
self.insert_trace(cr, uid, ids, context)
return True
(...)
# this function works when state is confirmed and came through confirmation, and doesn't when requestor is responsible and is directly confirmed
def tratamento(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'treatment'})
self.insert_trace(cr, uid, ids, context)
return True
def close_request(self, cr, uid, ids, context=None):
req = self.browse(cr, uid, ids, context=context)
if(req[0].authorized): #check if request has been authorized
self.write(cr, uid, ids, {'state': 'closed_auth'})
elif(req[0].approved): #or approved
self.write(cr, uid, ids, {'state': 'closed_appr'})
else: #if not, simply close the request!
self.write(cr, uid, ids, {'state': 'closed'})
self.insert_trace(cr, uid, ids, context)
return True
Anyone has any clue of what is causing this? Thanks in advance!
It wasn't working because I was jumping to that state through a "shortcut" in my python code, bypassing a workflow transition.
To solve this I added some conditions to the workflow (and thus some new transitions) and now it is working fine.
Since I find that OpenERP documentation is so poor, I'll let here my solution, hoping this will eventually help someone in the future.
Workflow screenshot:
Workflow definition:
<?xml version="1.0"?>
<openerp>
<data>
<record model="workflow" id="wkf_request">
<field name="name">request.wkf</field>
<field name="osv">generic.request</field>
<field name="on_create">True</field>
</record>
<!-- actividades -->
<record model="workflow.activity" id="act_draft">
<field name="wkf_id" ref="wkf_request" />
<field name="flow_start">True</field>
<field name="name">request_draft</field>
<field name="kind">function</field>
<field name="action">request_draft()</field>
</record>
<record model="workflow.activity" id="act_submit">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_submitted</field>
<field name="kind">function</field>
<field name="action">submit_request()</field>
</record>
<record model="workflow.activity" id="act_confirm">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_confirmed</field>
<field name="kind">function</field>
<field name="action">confirm_request()</field>
</record>
<record model="workflow.activity" id="act_closed_nconf">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed_nconf</field>
<field name="kind">function</field>
<field name="action">close_nconf_request()</field>
<field name="flow_stop">True</field>
</record>
<record model="workflow.activity" id="act_req_reformulate">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_reformulation</field>
<field name="kind">function</field>
<field name="action">req_reformulate_request()</field>
</record>
<record model="workflow.activity" id="act_treatment">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_treatment</field>
<field name="kind">function</field>
<field name="action">treat_request()</field>
</record>
<record model="workflow.activity" id="act_closed">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed</field>
<field name="kind">function</field>
<field name="action">close_request()</field>
<field name="flow_stop">True</field>
</record>
<record model="workflow.activity" id="act_awaiting_auth">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_awaiting_authorization</field>
<field name="kind">function</field>
<field name="action">wait_auth_request()</field>
</record>
<record model="workflow.activity" id="act_closed_ref">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed_ref</field>
<field name="kind">function</field>
<field name="action">close_ref_request()</field>
<field name="flow_stop">True</field>
</record>
<record model="workflow.activity" id="act_awaiting_appr">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_awainting_approval</field>
<field name="kind">function</field>
<field name="action">wait_appr_request()</field>
</record>
<record model="workflow.activity" id="act_closed_disappr">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed_disappr</field>
<field name="kind">function</field>
<field name="action">close_disappr_request()</field>
<field name="flow_stop">True</field>
</record>
<!-- transições -->
<record model="workflow.transition" id="request_t1">
<field name="act_from" ref="act_draft" />
<field name="act_to" ref="act_submit" />
<field name="signal">submit_request</field>
</record>
<!-- this transition appens when condition is satisfied (function returns true if requestor is responsible) -->
<record model="workflow.transition" id="request_t102">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_confirm" />
<field name="condition">check_responsible()</field>
</record>
<record model="workflow.transition" id="request_t2">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_req_reformulate" />
<field name="signal">req_reformulate_request</field>
</record>
<record model="workflow.transition" id="request_t3">
<field name="act_from" ref="act_req_reformulate" />
<field name="act_to" ref="act_submit" />
<field name="signal">submit_request</field>
</record>
<record model="workflow.transition" id="request_t1001">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_confirm" />
<field name="condition">ref_goto_confirmed()</field>
</record>
<record model="workflow.transition" id="request_t1002">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_treatment" />
<field name="condition">ref_goto_treatment()</field>
</record>
<record model="workflow.transition" id="request_t4">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_confirm" />
<field name="signal">confirm_request</field>
</record>
<record model="workflow.transition" id="request_t5">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_closed_nconf" />
<field name="signal">close_nconf_request</field>
</record>
<record model="workflow.transition" id="request_t6">
<field name="act_from" ref="act_confirm" />
<field name="act_to" ref="act_treatment" />
<field name="signal">treat_request</field>
</record>
<record model="workflow.transition" id="request_t7">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_closed" />
<field name="signal">close_request</field>
</record>
<record model="workflow.transition" id="request_t8">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_awaiting_auth" />
<field name="signal">wait_auth_request</field>
</record>
<record model="workflow.transition" id="request_t9">
<field name="act_from" ref="act_awaiting_auth" />
<field name="act_to" ref="act_closed_ref" />
<field name="signal">close_ref_request</field>
</record>
<record model="workflow.transition" id="request_t10">
<field name="act_from" ref="act_awaiting_auth" />
<field name="act_to" ref="act_treatment" />
<field name="signal">auth_send_processing</field>
</record>
<record model="workflow.transition" id="request_t11">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_req_reformulate" />
<field name="signal">req_reformulate_request</field>
</record>
<record model="workflow.transition" id="request_t12">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_awaiting_appr" />
<field name="signal">wait_appr_request</field>
</record>
<record model="workflow.transition" id="request_t13">
<field name="act_from" ref="act_awaiting_appr" />
<field name="act_to" ref="act_closed_disappr" />
<field name="signal">close_disappr_request</field>
</record>
<record model="workflow.transition" id="request_t14">
<field name="act_from" ref="act_awaiting_appr" />
<field name="act_to" ref="act_treatment" />
<field name="signal">appr_send_processing</field>
</record>
</data>
</openerp>
Relevant python code:
def request_draft(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'draft'})
self.insert_trace(cr, uid, ids, context)
return True
# workflow condition returns true if requestor is responsible
def check_responsible(self, cr, uid, ids, context=None):
return self.browse(cr, uid, ids, context)[0].is_responsible
# next two functions are also workflow conditions
def ref_goto_confirmed(self, cr, uid, ids, context=None):
req = self.browse(cr, uid, ids, context)
if req[0].needs_reformulation and req[0].goto == 'confirmed':
self.write(cr, uid, ids, {'needs_reformulation': False, 'reformulation_info': ''}) #clean up reformulation settings
self.write(cr, uid, ids, {'goto':'','state': 'confirmed'}) # if request is already in motion, clean up the goto tag and go to where it came from
return True
return False
def ref_goto_treatment(self, cr, uid, ids, context=None):
req = self.browse(cr, uid, ids, context)
if req[0].needs_reformulation and req[0].goto == 'treatment':
self.write(cr, uid, ids, {'needs_reformulation': False, 'reformulation_info': ''}) #clean up reformulation settings
self.write(cr, uid, ids, {'goto':'','state': 'treatment'}) # if request is already in motion, clean up the goto tag and go to where it came from
#self.insert_trace(cr, uid, ids, context)
return True
return False
def confirm_request(self, cr, uid, ids, context=None):
resp = self.browse(cr,uid,ids,context)
self.write(cr, uid, ids, {'state': 'confirmed'})
self.insert_trace(cr, uid, ids, context)
return True
def submit_request(self, cr, uid, ids, context=None):
req = self.browse(cr,uid,ids,context)
if req[0].needs_reformulation:
if req[0].goto == 'submitted':
self.write(cr, uid, ids, {'needs_reformulation': False, 'reformulation_info': ''}) #clean up reformulation settings
self.write(cr, uid, ids, {'goto':'','state': 'submitted'})
self.insert_trace(cr, uid, ids, context)
return True
return False
else:
self.write(cr, uid, ids, {'state': 'submitted'})
self.insert_trace(cr, uid, ids, context)
return True
def close_nconf_request(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'closed_nconf'})
self.insert_trace(cr, uid, ids, context)
return True
def req_reformulate_request(self, cr, uid, ids, context=None):
req = self.browse(cr, uid, ids, context=context)
goto = req[0].state
if goto:
self.write(cr, uid, ids, {'goto': goto, 'state': 'req_reformulation', 'needs_reformulation': True} )
else:
self.write(cr, uid, ids, {'state': 'req_reformulation', 'needs_reformulation': True})
self.insert_trace(cr, uid, ids, context)
return True
Hope this will help someone! :)