Sunday, April 28, 2013

OpenERP 7.0 : Gain/Loss Exchange Rate Account

What is Gain and Loss Exchange Rate Account ? How We can use and configure it in OpenERP ?

To enable it, First install account_voucher module.

Go to the Settings --> Configuration --> Invoicing and In Features option, Tick 'Allow Multi Currencies'.

As soon as you will tick it, You will see 2 more account fields which are Gain Exchange Rate Account and Loss Exchange Rate Account.

Gain Exchange Rate Account should have Regular as Internal Type and Income as Account Type.

Loss Exchange Rate Account should have Regular as Internal Type and Expense as Account Type.

Scenario 1:

Suppose INR is base currency and USD has rate 50.00 in respect of INR.
I create an invoice of 1000 USD and validate it. Now before payment, I change rate of USD from 50.00 to 40.00.
After setting a new rate, I make a payment of it. After payment, I can see that Gain Exchange Rate Account will be credit with 5.00 amount.
1000/50 = 20 and 1000/40 = 25 means 25-20 = 5

Scenario 2:

Suppose INR is base currency and USD has rate 50.00 in respect of INR.
I create an invoice of 1000 USD and validate it. Now before payment, I change rate of USD from 50.00 to 60.00.
After setting a new rate, I make a payment of it. After payment, I can see that Loss Exchange Rate Account will be debit with 3.33 amount.
1000/50 = 20 and 1000/60 = 16.67 means 20-16.67 = 3.33

It means that Gain / Loss Exchange Rate Account will be updated on the base of Residual Amount.
If Residual Amount is > 0, OpenERP will consider Loss Exchange Rate Account for debit.
If Residual Amount is < 0, OpenERP will consider Gain Exchange Rate Account for credit.

Hope this post will help you, guys. See you later.

Cheers,
Priyesh Solanki

Saturday, April 13, 2013

OpenERP 7.0 : Attributes _track and track_visibility


_track on the object is used to track events related to a document (an invoice has been paid, an opportunity is won, a task is blocked, ...). Users can follow events, represented by a mail.message.subtype, on any object.

It's different from the track_visibility attribute that you can define on a field which is used to track changes on this field. (e.g. Stage: Proposition --> Negotiation)

Both _track and track_visibility produces messages on the document. Your object need to inherit from mail.thread.

If an object is inherited from 'mail.thread' then _track is used to send notifications. Therefore 'module.subtype_xml' is the related  "Message Subtype". These subtypes have to be declared in XML. Here is an example:

<record id="subtype_xml" model="mail.message.subtype">
    <field name="name">Relevant Fields</field> 
    <field name="res_model">project.issue</field>
    <field name="default" eval="True"/>
    <field name="description">The issue has been closed.</field>
</record>

Then whenever the field "field" is updated, all subtypes ("subtype_xml", "subtype_xml2") of this field are processed.

This means that the related method (in this example: lambda ...) is called and if the result is True, then for all users which follow this object and have checked the subtype a notification is created.

In the user preferences every user can choose whether he/she wants to be updated by email in case of new notifications.

You can also set a mail.message.subtype that depends on an other to act through a relation field. Here is an example from crm for Sales Teams crm.case.section using the section_id m2o in crm.lead: 

<record id="mt_lead_won" model="mail.message.subtype">
    <field name="name">Opportunity Won</field>
    <field name="res_model">crm.lead</field>
    <field name="default" eval="False"/>
    <field name="description">Opportunity Won</field>
</record>

<record id="mt_salesteam_lead_won" model="mail.message.subtype">
    <field name="name">Opportunity Won</field>
    <field name="res_model">crm.case.section</field>
    <field name="parent_id" eval="ref('mt_lead_won')"/>
    <field name="relation_field">section_id</field>
</record>

This allows a user to follow all "Opportunities Won" that are in a specific sales team. The user follow the event "Opportunity Won" on a sales team and he will become automatically follower of all leads/opportunities of this sales team and _track event.

Hope this post will help you to understand the concept of _track and track_visibility.

Cheers,
Priyesh Solanki