Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currency import using 1forge.com API & add conversion loss % calculation #446

Merged
merged 4 commits into from Aug 20, 2018

Conversation

AlexHeylin
Copy link

Currency import using 1forge.com API
Add conversion loss % calculation
Add two fields to system table to support this.

Note: need to import SQL manually for now, as expecting this to be integrated into v3.7 upgrade file.

@devangn
Copy link
Contributor

devangn commented Jul 2, 2018

@AlexHeylin Thanks for the PR. We'll observe the implementation, analyze its impact on other features and flow and merge it once confirm.

$debugstring = "";
foreach ($quotesData as $quote) {
$debugstring = $debugstring . "A," ;
if (isset(Common_model::$global_config ['system_config'] ['currency_conv_loss_pct'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AlexHeylin

Thanks for the PR.

Would you please explain the use of currency_conv_lost_pct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When changing currency it's usual for there to be fees involved. For example 5% bank fee - in this case you'd set currency_conv_lost_pct to 5 (in Configuration > Settings > Global > Currency Conversion Loss Percentage) and when the system imports the market rate, it will allow for this 5% loss and put the rate you actually get into the DB. This helps ensure the system calculates conversion more accurately. Say the market rate is 2 USD = 1 GBP, and base currency is GBP, if I set currency_conv_lost_pct to 5 the rate in the DB will be 1.9 USD = 1 GBP.

If you don't want to allow for any loss (the way it used to be) then just set Currency Conversion Loss Percentage = 0 and it will use the rate directly from the API.

The two new system variables need to be created by importing the SQL also in the PR. If use manually runs currency update without setting the API key, if will return error message saying to set it in Configuration > Settings > Global > API key for currency rate import from 1forge.com

Please don't merge this yet - I've seen a couple of improvements (remove debug / check DB write worked / log to disk) I should make. Also this is failing on one of my systems and I've not yet found out why. If I make more changes to the code in the same branch, do I need to do a new PR or just let you know this one is OK to process?
Thanks @smrdoshi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explanation @AlexHeylin

I got the idea. Let's do it.
Once you will be done all the modifications in your branch, you will need to send new PR.

function __construct() {
parent::__construct ();
// if(!defined( 'CRON' ) )
// exit();
$this->load->model ( "db_model" );
$this->load->library ( "astpp/common" );
$this->fp = fopen("/var/log/astpp/astpp-currency.log", "a+");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update @AlexHeylin

Would you please use variable for log path in place of using static path?

Use Common_model::$global_config ['system_config'] ['log_path']

Thanks

@AlexHeylin
Copy link
Author

@smrdoshi - Thanks for pointing that out. I actually copied it from web_interface/astpp/application/controllers/ProcessInvoice.php
This tests OK on my test system, and I'm happy for you to commit if you are happy.
Thanks!

@smrdoshi
Copy link
Contributor

smrdoshi commented Jul 20, 2018 via email

@AlexHeylin
Copy link
Author

This has worked well in both my dev and prod environments so please merge. Will you merge this, or do you want me to submit a new request? Thanks

@smrdoshi
Copy link
Contributor

smrdoshi commented Aug 11, 2018 via email

@smrdoshi smrdoshi merged commit dd46e9e into iNextrix:v3.6 Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants