Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2019 Copyright 2019 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'CRM Lead Currency', | ||
'summary': """ | ||
On leads/opportunities, add the amount in the customer's currency.""", | ||
'version': '12.0.1.0.0', | ||
'license': 'AGPL-3', | ||
'author': 'Camptocamp SA,Odoo Community Association (OCA)', | ||
'website': 'https://github.com/OCA/crm', | ||
'depends': [ | ||
'crm', | ||
], | ||
'data': [ | ||
'views/crm_lead_opportunity_currency_views.xml', | ||
], | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import crm_lead |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2018 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class CrmLead(models.Model): | ||
_inherit = 'crm.lead' | ||
|
||
customer_currency_id = fields.Many2one( | ||
string='Customer currency', | ||
comodel_name='res.currency', | ||
default=lambda self: self.env.user.company_id.currency_id, | ||
) | ||
amount_customer_currency = fields.Monetary( | ||
string='Customer amount', | ||
currency_field='customer_currency_id', | ||
) | ||
is_same_currency = fields.Boolean( | ||
string='Same currency', | ||
compute='_compute_is_same_currency', | ||
) | ||
|
||
@api.onchange('customer_currency_id', 'amount_customer_currency') | ||
def _onchange_currency(self): | ||
self.planned_revenue = self.get_revenue_in_company_currency() | ||
|
||
@api.multi | ||
def get_revenue_in_company_currency(self): | ||
"""Compute the planned revenue in the company currency. | ||
If the customer currency is different than the company currency, | ||
the planned revenue is computed in the company currency. | ||
""" | ||
self.ensure_one() | ||
if self.is_same_currency: | ||
return self.planned_revenue | ||
return self.customer_currency_id._convert( | ||
self.amount_customer_currency or 0, | ||
self.company_currency, | ||
self.env.user.company_id, | ||
fields.Datetime.now(), | ||
) | ||
|
||
@api.multi | ||
@api.depends('customer_currency_id', 'company_id.currency_id') | ||
def _compute_is_same_currency(self): | ||
for lead in self: | ||
lead.is_same_currency = ( | ||
lead.customer_currency_id == ( | ||
lead.company_currency or | ||
self.env.user.company_id.currency_id | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
No specific configuration is needed but multi-currency should be enabled for the module | ||
to make sense. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Thierry Ducrest <thierry.ducrest@camptocamp.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This module allows to select a specific currency for a lead or an opportunity. | ||
If the selected currency is different to the company currency, an amount in the customer | ||
currency can be set and the expected revenue of the opportunity will automatically be | ||
computed in the company currency. The default rate used for the computation is the rate | ||
of the day. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Just install the module. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To use this module, you need to: | ||
|
||
#. Created a new opportunity in the CRM and set a customer currency on it. |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_crm_opportunity_currency |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2019 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from odoo.tests.common import SavepointCase | ||
|
||
|
||
class TestCrmOpportunityCurrency(SavepointCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.lead = cls.env['crm.lead'].create({ | ||
'name': 'test lead' | ||
}) | ||
|
||
def test_is_same_currency(self): | ||
self.lead.customer_currency_id = self.lead.company_id.currency_id | ||
self.assertTrue(self.lead.is_same_currency) | ||
self.lead.customer_currency_id = self.ref('base.CHF') | ||
self.assertFalse(self.lead.is_same_currency) | ||
|
||
def test_same_currency_planned_revenue_not_updated(self): | ||
self.lead.customer_currency_id = self.lead.company_id.currency_id | ||
self.lead.planned_revenue = 100 | ||
self.lead.amount_customer_currency = 124 | ||
self.lead._onchange_currency() | ||
self.assertEqual(self.lead.planned_revenue, 100) | ||
|
||
def test_different_currency_planned_revenue_updated(self): | ||
self.lead.planned_revenue = 100 | ||
self.lead.customer_currency_id = self.ref('base.CHF') | ||
self.lead.amount_customer_currency = 124 | ||
self.lead._onchange_currency() | ||
self.assertNotEqual(self.lead.planned_revenue, 100) |
47 changes: 47 additions & 0 deletions
47
crm_lead_currency/views/crm_lead_opportunity_currency_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0"?> | ||
|
||
<odoo> | ||
|
||
<record id="crm_case_form_view_oppor" model="ir.ui.view"> | ||
<field name="name">crm.lead.form.oppor</field> | ||
<field name="model">crm.lead</field> | ||
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/> | ||
<field name="arch" type="xml"> | ||
<field name="partner_id" position="before"> | ||
<field name="customer_currency_id"/> | ||
<field name="is_same_currency" invisible="1"/> | ||
<field name="amount_customer_currency" attrs="{'invisible': [('is_same_currency', '=', True)]}" /> | ||
</field> | ||
<field name="planned_revenue" position="attributes"> | ||
<attribute name="attrs">{'readonly': [('is_same_currency', '=', False)]}</attribute> | ||
<attribute name="force_save">1</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<!-- In kanban display the amount in the customer currency as suitable --> | ||
<record id="crm_case_kanban_view_leads" model="ir.ui.view"> | ||
<field name="name">crm.lead.kanban.lead</field> | ||
<field name="model">crm.lead</field> | ||
<field name="inherit_id" ref="crm.crm_case_kanban_view_leads"/> | ||
<field name="arch" type="xml"> | ||
|
||
<field name="planned_revenue" position="after"> | ||
<field name="is_same_currency"/> | ||
<field name="amount_customer_currency"/> | ||
<field name="customer_currency_id"/> | ||
</field> | ||
|
||
<xpath expr="//templates//field[@name='planned_revenue']" position="replace"> | ||
<t t-if="record.is_same_currency.raw_value"> | ||
<field name="planned_revenue" widget="monetary" options="{'currency_field': 'company_currency'}"/> | ||
</t> | ||
<t t-else=""> | ||
<field name="amount_customer_currency" widget="monetary" options="{'currency_field': 'customer_currency_id'}"/> | ||
</t> | ||
</xpath> | ||
|
||
</field> | ||
</record> | ||
|
||
</odoo> |