hildogjr / KiCost

Build cost spreadsheet for a KiCad project.
MIT License
493 stars 97 forks source link

Non stock for mouser #521

Closed diegosarli closed 2 years ago

diegosarli commented 2 years ago

Hi, Mouser is returning NonStock for all the parts

version 1.1.8

best regards Diego

set-soft commented 2 years ago

Hi @diegosarli ! Can you post an example? Are you sure they have stock for the parts you selected? Are you using the Mouser P/N or just trying to search by value?

I tried our regression test and got stock for 710-696101000002 and 530-5MF6-R

Bnjamn commented 2 years ago

Me too
It doesn't provide stock information from mouser.
I'm using a ".csv" file with the manufacturerPN.

I tried with the reference you mention, adding also the supplierPN, but without success. I'm using Kicost 1.1.9

hkleen commented 2 years ago

I am also seeing this. At least for me this seems to be caused by Mouser translating the content of the response json to the users language. If I do: curl -X POST "https://api.mouser.com/api/v1/search/partnumber?apiKey=***KEY_REMOVED***" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"SearchByPartRequest\": { \"mouserPartNumber\": \"187-CL31A106MBHNNNE\" }}" I the response is as follows:

{
  "Errors": [],
  "SearchResults": {
    "NumberOfResult": 1,
    "Parts": [
      {
        "Availability": "385316 Auf Lager",
        "DataSheetUrl": "https://www.mouser.com/datasheet/2/585/MLCC-1837944.pdf",
        "Description": "Kondensator aus mehreren Keramikschichten MLCC - SMD/SMT 10uF+/-20% 50V X5R 3 1206",
        "FactoryStock": "0",
        "ImagePath": "https://www.mouser.com/images/samsung/images/MLCC_t.jpg",
        "Category": "Kondensator aus mehreren Keramikschichten MLCC - SMD/SMT",
        "LeadTime": "226 Tage",
        "LifecycleStatus": "",
        "Manufacturer": "Samsung Electro-Mechanics",
        "ManufacturerPartNumber": "CL31A106MBHNNNE",
        "Min": "1",
        "Mult": "1",
        "MouserPartNumber": "187-CL31A106MBHNNNE",
        "ProductAttributes": [
          {
            "AttributeName": "Verpackung",
            "AttributeValue": "Cut Tape"
          },
          {
            "AttributeName": "Verpackung",
            "AttributeValue": "MouseReel"
          },
          {
            "AttributeName": "Verpackung",
            "AttributeValue": "Reel"
          },
          {
            "AttributeName": "Standardpackungsmenge",
            "AttributeValue": "2000"
          }
        ],
        "PriceBreaks": [
          {
            "Quantity": 1,
            "Price": "0,285 €",
            "Currency": "EUR"
          },
          {
            "Quantity": 10,
            "Price": "0,172 €",
            "Currency": "EUR"
          },
          {
            "Quantity": 100,
            "Price": "0,11 €",
            "Currency": "EUR"
          },
          {
            "Quantity": 500,
            "Price": "0,078 €",
            "Currency": "EUR"
          },
          {
            "Quantity": 1000,
            "Price": "0,068 €",
            "Currency": "EUR"
          },
          {
            "Quantity": 2000,
            "Price": "0,064 €",
            "Currency": "EUR"
          }
        ],
        "AlternatePackagings": null,
        "ProductDetailUrl": "https://eu.mouser.com/ProductDetail/Samsung-Electro-Mechanics/CL31A106MBHNNNE?qs=vLWxofP3U2ynwxdpGjlUyw%3D%3D",
        "Reeling": true,
        "ROHSStatus": "RoHS Compliant",
        "SuggestedReplacement": "",
        "MultiSimBlue": 0,
        "UnitWeightKg": {
          "UnitWeight": 0.000027
        },
        "InfoMessages": [],
        "ProductCompliance": [
          {
            "ComplianceName": "TARIC",
            "ComplianceValue": "8532240000"
          },
          {
            "ComplianceName": "BRHTS",
            "ComplianceValue": "85322410"
          },
          {
            "ComplianceName": "CNHTS",
            "ComplianceValue": "8532241000"
          },
          {
            "ComplianceName": "USHTS",
            "ComplianceValue": "8532240020"
          },
          {
            "ComplianceName": "JPHTS",
            "ComplianceValue": "853224000"
          },
          {
            "ComplianceName": "ECCN",
            "ComplianceValue": "EAR99"
          }
        ]
      }
    ]
  }
}

Quite a few of the items seem to be translated to the users language (in my case german) so the "availability" key contains the value "385316 Auf Lager" instead of "385316 in stock" and this is obviously not handled correctly by the regular expression in api_mouser.py

set-soft commented 2 years ago

Hi @hkleen ! This explains why it fails for some people and not for others. In english you can get "NNNN In Stock" and "None", but you could also get "NNNN On Order", which isn't really in stock.

The following patch should solve your problem: 7fe35522d22f7099ba5bd85cfd1ad56b0488e2c2

It should also solve it for @Bnjamn and @diegosarli but I'm not sure if it will solve the problem for everyone. Using --debug 10 now you get things like:

DEBUG:Availability: 6809 In Stock (kicost.distributors - api_mouser.py:348)
...
DEBUG:- Search for stock: <re.Match object; span=(0, 13), match='6809 In Stock'> (kicost.distributors - api_mouser.py:352)
...
DEBUG:- Detected stock: 6809 (kicost.distributors - api_mouser.py:355)

So we will be able to adjust the detection. Can you confirm that this works? (at least for german ;-)

hkleen commented 2 years ago

Hi @set-soft ! Sure thing! Just tried out the new version and everything seems to work just fine, at least for german. Also the "NNNN On Order" case, which is "NNNN Auf Bestellung" in german, is handled correctly and results in No Stock reported. At least for me this fixed the problem. Thanks for the quick fix!

set-soft commented 2 years ago

Note for @Bnjamn and @diegosarli: if you find it doesn't work for your language please open a new issue including the debug output explained above. In this way I'll be able to fix a particular language.

Bnjamn commented 2 years ago

Hello set-soft,
it work's better right now.
Thanks for the quick fix.
Never the less, from my observation, it doesn't show the effective stock of Mouser, but the maximum quantity Mouser can ship.

For example, AD835ARZ here : -----> https://www.mouser.fr/ProductDetail/Analog-Devices/AD835ARZ?qs=%2FtpEQrCGXCx2l1%252Byta%2FM0g%3D%3D
Mouser have a stock of : 4 486pcs
But we can buy only 196pcs max.

I'm also interesting of getting the "On Order" column, is there a possibility to add columns in the Kicost results ?

Best, Benjamin.

set-soft commented 2 years ago

Hi @Bnjamn ! Currently KiCost has just one column for the stock. Adding extra columns for one distributor is complex.

If you take a look at @hkleen data (from a direct query using curl) you'll see Mouser only informs a fuzzy field called Availability. If they have stock the field says "XXX In stock", if they have pending orders, but no stock, they indicate "XXX On order". But never both values.

Note: we could add the on order stuff as a comment, I'll think about it

set-soft commented 1 year ago

Hi @Bnjamn ! The above patch will help in the case that Mouser reports the part is "On Order". As I mentioned before we get only the fuzzy Availability, but now parts that aren't in stock, but on order will be known by looking at the cell comment.