replaysMike / Binner

Open source parts inventory system for makers, electronics hobby, and professional engineers
https://binner.io
GNU General Public License v3.0
268 stars 41 forks source link

Currency not being $ #111

Closed rfwerk closed 1 year ago

rfwerk commented 1 year ago

When importing orders or viewing components on Mouser I get an error as only '$' is parsed:

2023-03-05 21:11:40.8976|ERROR|Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware|An unhandled exception has occurred while executing the request.|System.FormatException: The input string '€ 0,141' was

not in a correct format.

at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, ReadOnlySpan`1 value, TypeCode type)

at Binner.Common.Integrations.Models.Mouser.PriceBreak.get_Cost() in C:\projects\binner\Binner\Library\Binner.Common\Integrations\Models\Mouser\MouserPart.cs:line 63

Code does:

        get
        {
            if (!string.IsNullOrEmpty(Price))
                return double.Parse(Price.Replace("$", ""));
            return 0;
        }

For the moment I will patch my copy to play with it a bit

replaysMike commented 1 year ago

Hi there :) it’s possible Mouser has recently changed their api. I’m back from vacation tomorrow and will get this updated right away.

-Michael

On Mon, Mar 6, 2023 at 3:14 PM rfwerk @.***> wrote:

When importing orders or viewing components on Mouser I get an error as only '$' is parsed:

2023-03-05 21:11:40.8976|ERROR|Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware|An unhandled exception has occurred while executing the request.|System.FormatException: The input string '€ 0,141' was

not in a correct format.

at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, ReadOnlySpan`1 value, TypeCode type)

at Binner.Common.Integrations.Models.Mouser.PriceBreak.get_Cost() in C:\projects\binner\Binner\Library\Binner.Common\Integrations\Models\Mouser\MouserPart.cs:line 63

Code does:

    get
    {
        if (!string.IsNullOrEmpty(Price))
            return double.Parse(Price.Replace("$", ""));
        return 0;
    }

For the moment I will patch my copy to play with it a bit

— Reply to this email directly, view it on GitHub https://github.com/replaysMike/Binner/issues/111, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATJ54V3C7K3FHXG3WR7K3LW2ZHTHANCNFSM6AAAAAAVRUKNCM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

replaysMike commented 1 year ago

I wasn't able to repro this on my end, perhaps you have a part that has no cost associated with it for some reason. However, I have patched the issue regardless and it will be included in v.2.2.6

rfwerk commented 1 year ago

Hi, I tested your fix, but it does not solve the issue. For a component, for me using the EU site for Mouser, the variable price = "€ 0,931" So it should check for "€", next to "$" and possibly more currencies. It does not help if I set the currency in my account to US$. My orders can be imported then, but parts still carry the price in EUR.

replaysMike commented 1 year ago

ah - I misunderstood the question, didn't realize you were in EU and Mouser supports euros. I'll fix this properly then - right now ;)

replaysMike commented 1 year ago

ok I've implemented a new culture based currency formatter in commit b76e152

it will get merged in with today's release but feel free to test it if you like

replaysMike commented 1 year ago

Now available in v2.2.6. Let me know if you are still experiencing the issue

rfwerk commented 1 year ago

Hi, now loading web orders or searching components works, thanks. Of course everything has $ signs but that is because the rest of the app has no concept of currency I guess. But this is enough to test it.

replaysMike commented 1 year ago

Thanks for letting me know - I'll add this to my task list for the next release (next week) to properly internationalize currencies. It definitely was not designed with that in mind at the start, but shouldn't be too difficult to update.

hyperglitch commented 7 months ago

This happened when I tried to import Mouser order on version 2.6.1, local installation

API Error
System.FormatException
Failed to import order!
An exception occurred of type System.FormatException
The input string '€ 218,63' was not in a correct format.

Same web order number and API keys on the binner.io resulted in more verbose error message:

API Error
System.FormatException
Failed to import order! An exception occurred of type System.FormatException
The input string '€ 218,63' was not in a correct format.
Api Endpoint: https://binner.io/api/part/import
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, ReadOnlySpan`1 value, TypeCode type) at System.Double.Parse(String s) at Binner.Services.PartService.GetExternalMouserOrderAsync(OrderImportRequest request) in C:\projects\binner-io\Binner\Library\Binner.Services\PartService.cs:line 514 at Binner.Services.PartService.GetExternalOrderAsync(OrderImportRequest request) in C:\projects\binner-io\Binner\Library\Binner.Services\PartService.cs:line 241 at Binner.Web.Controllers.PartController.OrderImportAsync(OrderImportRequest request) in C:\projects\binner-io\Binner\Binner.Web\Controllers\PartController.cs:line 498

Let me know if I can enable some additional debugging info or I can (privately) give you the order number and API key to check.