Skip to content

Model year incorrectly identified for certain heavy vehicles #24

Open
@emesterhazy

Description

@emesterhazy

Issue

The current implementation of Vin.year returns the incorrect year for some heavy trucks and vans:

In [1]: from libvin import Vin

In [2]: v = Vin('1FUJGLDR69LAC9984')

In [3]: v.year
Out[3]: 2039

In [4]: v.is_pre_2010
Out[4]: False

The correct model year for this VIN is 2009 (source).

For vehicles with a gross vehicle weight rating (GVWR) over 10,000 lbs the 7th digit of the VIN does not indicate if the vehicles was manufactured before or after 2009 as it does for passenger vehicles.

Potential solutions

One potential solution(https://github.com/emesterhazy/python-libvin/commit/58de6905448b774de2127944b76198400b3f46e7) is to check Vin.year and overwrite the is_pre_2010 condition if the model year is more than X years into the future. For the example above, the fix would check the model year when the Vin object is created, and overwrite the is_pre_2010 property since 2039 is too far into the future. Then when Vin.year is accessed it will return the correct year (2009), and Vin.is_pre_2010 will return True.

class Vin(object):
    def __init__(self, vin):
        self.vin = vin.upper()

        # Overwrite is_pre_2010 attribute if it would result in a model year
        # more than 2 years into the future. See notes in is_pre_2010
        self._pre_2010_overwrite = False
        if (not self.is_pre_2010 and
                YEARS_CODES_PRE_2040[self.vin[9]] >= datetime.now().year + 2):
            self._pre_2010_overwrite = True

...

    @property
        def is_pre_2010(self):

            if self._pre_2010_overwrite:
                return True
            else:
                return self.vin[6].isdigit()

The downside to this is that the fix will also "correct" valid passenger car VINs for vehicles with model years more than 2 years into the future. However, I don't think this will be an issue in real world use.

I have a pull request ready if you agree with this approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions