Skip to content

Instantly share code, notes, and snippets.

/README Secret

Created January 12, 2018 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7a82c58c7ac73d8b2c2f3b29981f2ee7 to your computer and use it in GitHub Desktop.
Save anonymous/7a82c58c7ac73d8b2c2f3b29981f2ee7 to your computer and use it in GitHub Desktop.
Difference between Live Currency Rate module commits in FlectraRepo versions
This is a diff between the files of the flectrahq/flectra repository between the version
of October 18, and the one of December 25 (release 1.0), inside the addons/live_currency_rate
module directory.
- All files of October 18 were added by revision 1d9e0c967a4447e5a7535bcda6622e98cccb4f0f
- All files of December 25 were added by revision 067a69a62ee8b329d3a8a4722ee3a9c0ce1be9a0
In addition to the following differences, the file 'service_cron_data.xml' was renamed to
'currency_rate_cron_data.xml' but kept unchanged, except for the "name" field of the
ir.cron record, changed from "Currency rate update" to "On upadte Currency rate" (sic).
(This is visible by the appearance and disappearance of those files at the end of the diff)
diff -ur ./addons/live_currency_rate/__manifest__.py ../flectra20171225xmas/addons/live_currency_rate/__manifest__.py
--- ./addons/live_currency_rate/__manifest__.py 2017-12-19 10:04:32.063608556 +0100
+++ ../flectra20171225xmas/addons/live_currency_rate/__manifest__.py 2017-12-26 01:29:50.037668603 +0100
@@ -4,6 +4,7 @@
'name': 'Live Currency Rate Update',
'version': '1.0',
'category': 'Accounting',
+ 'author': 'Flectra',
'description': """
Import exchange rates from three different sources on the internet :
@@ -22,7 +23,7 @@
],
'data': [
'views/account_config_setting_view.xml',
- 'views/service_cron_data.xml',
+ 'views/currency_rate_cron_data.xml',
],
'installable': True,
'auto_install': True,
diff -ur ./addons/live_currency_rate/models/account_config_setting.py ../flectra20171225xmas/addons/live_currency_rate/models/account_config_setting.py
--- ./addons/live_currency_rate/models/account_config_setting.py 2017-12-19 10:04:32.063608556 +0100
+++ ../flectra20171225xmas/addons/live_currency_rate/models/account_config_setting.py 2017-12-26 01:29:50.037668603 +0100
@@ -1,7 +1,5 @@
-# -*- coding: utf-8 -*-
# Part of Flectra. See LICENSE file for full copyright and licensing details.
-
import datetime
from lxml import etree
import json
@@ -11,14 +9,43 @@
from flectra.exceptions import UserError
+
+class AccountConfigSettings(models.TransientModel):
+ _inherit = 'res.config.settings'
+
+ interval_unit = fields.Selection(related="company_id.interval_unit",)
+ provider = fields.Selection(related="company_id.provider",)
+ execution_date = fields.Date(related="company_id.execution_date")
+
+ @api.onchange('interval_unit')
+ def onupdate_interval_unit_provider(self):
+ dict = {'daily': relativedelta(days=+1),
+ 'weekly': relativedelta(weeks=+1),
+ 'manually': False,
+ 'monthly': relativedelta(months=+1)}
+ if self.interval_unit:
+ next_update = dict[self.interval_unit]
+ else:
+ self.execution_date = False
+ return
+ if next_update:
+ self.execution_date = datetime.datetime.now() + next_update
+
+ @api.multi
+ def live_currency_rates_update(self):
+ companies = \
+ self.env['res.company'].browse(
+ [record.company_id.id for record in self])
+ companies.currency_getter_factory()
+
class ResCompany(models.Model):
_inherit = 'res.company'
interval_unit = fields.Selection([
- ('manually', 'Manually'),
- ('daily', 'Daily'),
+ ('monthly', 'Monthly'),
('weekly', 'Weekly'),
- ('monthly', 'Monthly')],
+ ('daily', 'Daily'),
+ ('manually', 'Manually')],
default='manually', string='Interval Unit')
provider = fields.Selection([('yahoo', 'Yahoo'),
('ecb', 'European Central Bank'),
@@ -35,7 +62,7 @@
provider = obj.provider
dict = {
'yahoo': '_get_updated_currency_yahoo',
- 'ecb': '_update_currency_ecb',
+ 'ecb': '_ecb_live_currency_rate',
'fta': 'currencyConverterfta',
'nbp': 'get_updated_currency_nbp',
}
@@ -44,9 +71,9 @@
if hasattr(obj, result):
result = getattr(obj, result)()
if not result:
- raise UserError(_('Unable to connect to the online exchange \
- rate platform. The web service may be temporary down. \
- Please try again in a moment.'))
+ raise UserError(_("There is problems with web service today \
+ but it will be resolved. We're sorry for any inconvenience \
+ this may have caused."))
def currencyConverteryahoo(self, currency_from, currency_to):
currency_pairs = currency_from + currency_to
@@ -63,7 +90,6 @@
currency_data = json.loads(response)
if not currency_data.get('query') or \
not currency_data['query'].get('results'):
- # result is None, web service not available for the moment.
return False
rates = currency_data['query']['results']['rate']['Rate']
return rates
@@ -111,7 +137,7 @@
dom.xpath(xpath_curr_rate, namespaces=ns)[0])
return res
- def _update_currency_ecb(self):
+ def _ecb_live_currency_rate(self):
currency_obj = self.env['res.currency']
rate_obj = self.env['res.currency.rate']
main_currency = self.currency_id.name
@@ -265,32 +291,3 @@
record.execution_date = datetime.datetime.now() + next_update
to_update += record
to_update.currency_getter_factory()
-
-
-class AccountConfigSettings(models.TransientModel):
- _inherit = 'res.config.settings'
-
- interval_unit = fields.Selection(related="company_id.interval_unit",)
- provider = fields.Selection(related="company_id.provider",)
- execution_date = fields.Date(related="company_id.execution_date")
-
- @api.onchange('interval_unit')
- def onchange_currency_interval_unit(self):
- dict = {'daily': relativedelta(days=+1),
- 'weekly': relativedelta(weeks=+1),
- 'manually': False,
- 'monthly': relativedelta(months=+1)}
- if self.interval_unit:
- next_update = dict[self.interval_unit]
- else:
- self.execution_date = False
- return
- if next_update:
- self.execution_date = datetime.datetime.now() + next_update
-
- @api.multi
- def update_currency_rates(self):
- companies = \
- self.env['res.company'].browse(
- [record.company_id.id for record in self])
- companies.currency_getter_factory()
Only in ../flectra20171225xmas/addons/live_currency_rate/models: __pycache__
diff -ur ./addons/live_currency_rate/views/account_config_setting_view.xml ../flectra20171225xmas/addons/live_currency_rate/views/account_config_setting_view.xml
--- ./addons/live_currency_rate/views/account_config_setting_view.xml 2017-12-19 10:04:32.063608556 +0100
+++ ../flectra20171225xmas/addons/live_currency_rate/views/account_config_setting_view.xml 2017-12-26 01:29:50.037668603 +0100
@@ -19,7 +19,7 @@
<div class="row">
<label string="Next Run" for="execution_date" class="col-md-3 o_light_label"/>
<field name="execution_date"/>
- <button name="update_currency_rates" type="object" class="btn-link">
+ <button name="live_currency_rates_update" type="object" class="btn-link">
<i title="Update now" class="fa fa-fw fa-refresh"></i>
</button>
</div>
Only in ../flectra20171225xmas/addons/live_currency_rate/views: currency_rate_cron_data.xml
Only in ./addons/live_currency_rate/views: service_cron_data.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment