jthmiranda
jthmiranda

Reputation: 73

How to create an action server OpenERP 7

<record id="rule_605" model="ir.actions.server">    
       <field name="name">Example of action server item</field>
       <field name="condition">True</field>
       <field name="state">code</field>  
       <field name="sequence" eval="456"/>
       <field name="code">True</field>
       <field name="model_id" eval="Selling"/>
 </record>

I'm confused with above code fragment inside of my custom module.?

What is the right way to do it? I know some fields maybe are wrong!

How to set the model_id?

Upvotes: 2

Views: 6352

Answers (1)

user1576199
user1576199

Reputation: 3207

Server action is one of the most powerful features of Open ERP (but poorly documented i should say). I am trying here to explain the Server Actions in open ERP to my best.

Server Actions, are used to trigger one or more actions to be performed on the server side, when a specific stage of a workflow is reached.

Eg.

  1. When a Sales Order is approved add it to history of customer.
  2. When a Sales Invoice is confirmed, mail to customer.
  3. When a CRM case is closed, popup a window on client side for summary of interaction/ feedback etc.

To create a server action goto: Administration>>Customization>>Actions>>Server Actions.

Steps in Creation:

Step 1: Definition of Server Action

  1. Action Name: As obvious as the name is

  2. Object: The object/model from which the server action will be triggered. Eg. Sale Order

  3. Action Type: More on this later as each case will be handled. Sequence: Used when Action Type is multi actions, where a series of actions will occur in the order of sequence.

  4. Condition: A single line python condition. eg. if you want to send sms alerts whenever a voucher of more than 5000 occurs. object.amount>5000. If there are no conditions, you must give True for the execution.

  5. Action Type Specific Tab: Here I will explain each action type in detail

    1. Dummy: A dummy stage does nothing. (God knows why its there..)

    2. Client Action: You can select a form to Open, a wizard to run or a report to launch. Select the report from the list.

    3. Iteration: Based on a python loop expression, you can iterate server actions, eg: When a stock inward move occurs and you confirm it, you want each line item to be historised.. you can loop on expression object.move_lines and create another server action which is referred to do the historising job.

    4. Python Code: you can execute a multiline python code. the returned value is the value of the variable action = {}. This makes sense only if you want to pop a specific window(form) specific to the context. IMHO you wont need a return value. Note: The code is executed using the exec function of python, which is run in the dictionary namespace with variables: object, time, cr, uid, ids

    5. Trigger: Any transition of the workflow can be triggered using this. The options you need to set are. Workflow Model: The target object on which you want to trigger the workflow. 'Trigger on' field should have the ID of the target model record. Eg have the ID of invoice if you want to trigger a change in invoice. 'Trigger Name' is the signal you have to use to initiate the transition. The drop down lists all possible triggers. Note:Trigger Name list shows all possible transitions from ther models also, so ensure you select the right trigger. Models are given in bracket.

    6. Email: Set an email address, Subject & message. You need to configure the Open ERP builting smtpserver for this. Power email, a generic email architecture for Open ERP can be used for emailing as it offers a lot more features and automated emails (no messing with server actions required). Its available at: http://launchpad.net/poweremail and downloads at http://launchpad.net/poweremail/+download

    7. SMS: Choose mobile no. eg: [[ object.shipping_address.mobile ]] and the subject.

    8. Create Object: This is used to create a new record in any model, when the server action is triggered. The historise feature discussed can be implemented using this. Field mappings are used to give value for fields in record

Let us see this example

<record id="ir_actions_server_timsheet_sheet" model="ir.actions.server">
            <field name="sequence" eval="5"/>
            <field name="state">code</field>
            <field name="type">ir.actions.server</field>
            <field name="model_id" ref="model_hr_timesheet_current_open"/>
            <field name="code">action = pool.get('hr.timesheet.current.open').open_timesheet(cr, uid, None, context)</field>
            <field name="condition">True</field>
            <field name="name">My Timesheet</field>
        </record>

Here model_hr_timesheet_current_open is the reference of object for which object this action gone to fire, for your case <field name="model_id" eval="Selling"/> model_id not selling but object reference for which this gos this fire action.

Upvotes: 5

Related Questions