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

Added support for Norwegian bank account numbers #275

Merged
merged 2 commits into from
Jan 22, 2017

Conversation

thor
Copy link
Contributor

@thor thor commented Jan 10, 2017

This includes tests that cover it up fairly well, as well as some documentation to go along.
I makemessages -l nb and compilemessages -l nb, but if you import from Transifex either way, then I can do the changes there. 🌞

I haven't been able to figure out exactly what the roadmap is; while it seemed to be a link with Django's roadmap, it also seemed like you're free to release when you've got a worthwhile release, and so I tossed it on a hope of 1.4.2. Admittedly I can change that to 1.5 if need be. 👍

All Changes

  • Add an entry to the docs/changelog.rst describing the change.

  • Add an entry for your name in the docs/authors.rst file if it's not
    already there.

  • Adjust your i ports to a standard form by running this command:

    `isort --recursive --line-width 120 localflavor tests`
    

New Fields Only

  • Prefix the country code to all fields.

  • Field names should be easily understood by developers from the target
    localflavor country. This means that English translations are usually
    not the best name unless it's for something standard like postal code,
    tax / VAT ID etc.

  • Prefer 'PostalCodeField' for postal codes as it's
    international English; ZipCode is a term specific to the United
    States postal system.

  • Add meaningful tests. 100% test coverage is not required but all
    validation edge cases should be covered.

  • Add .. versionadded:: <next-version> comment markers to new
    localflavors.

  • Add documentation for all fields.

Copy link
Member

@benkonrath benkonrath left a comment

Choose a reason for hiding this comment

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

Since this is adding a new feature, this PR will be included in version 1.5. I'm going try to be more regular about releasing new versions so you shouldn't have to wait 6 months to get this change in a released version.

We use Transifex for translations so please remove the translations changes from this PR. The translations will be synced to Transifex after the PR is merged.

There is an IBAN specified for Noway. It it common that people use the non-IBAN version of the bank account number?

raise ValidationError(self.error_messages['invalid_length'])

# Adhere for the special rule of these being "clearing" accounts
if bank_number[4:5] == "00":
Copy link
Member

Choose a reason for hiding this comment

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

bank_number[4:5] can never be 2 characters. Did you mean to write bank_number[4:6]? I found this because I noticed that line 145 isn't covered by the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching that!
I've looked into the clearing numbers, and it's been a struggle to find any more details about exactly how to validate these, so I'm removing it and adding a note about bank clearing numbers in the function docstring.

@benkonrath
Copy link
Member

Please also add a changelog entry for this PR. Thanks.

@benkonrath benkonrath self-assigned this Jan 12, 2017
@benkonrath benkonrath added this to the 1.5 milestone Jan 12, 2017
Includes tests, update to docs and uses to_python, validate and
prepare_value only.
@thor
Copy link
Contributor Author

thor commented Jan 14, 2017

I've updated with a less messy version that does the same thing without overriding Field.clean() itself.

I've updated the versionadded, as well as added the changelog entry for 1.5. 👍
Furthermore, I've also removed the translations -- do you think you could add a note about that to CONTRIBUTING, or someplace similar?

@benkonrath Extremely so. IBANs are only used in the context of international transactions, and never otherwise referred to domestically.

Copy link
Member

@benkonrath benkonrath left a comment

Choose a reason for hiding this comment

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

Just the two small changes and it's good to go. Thanks.


def to_python(self, value):
value = super(NOBankAccountNumber, self).to_python(value)
return value.replace(".", "").replace(" ", "")
Copy link
Member

Choose a reason for hiding this comment

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

Can you change the double quotes to single quotes just to be consistent with the rest of the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

return value.replace(".", "").replace(" ", "")

def prepare_value(self, value):
return "{}.{}.{}".format(value[0:4], value[4:6], value[6:11])
Copy link
Member

Choose a reason for hiding this comment

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

I think it's worth adding a test for the formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a simple test to validate it. 👍

We rely on the validation to prevent faulty values from entering the
form in the first place.
@benkonrath benkonrath merged commit 0f4aa82 into django:master Jan 22, 2017
@benkonrath
Copy link
Member

Thanks again for your contribution!

@thor
Copy link
Contributor Author

thor commented Jan 22, 2017

Thanks for the helpful feedback! 👍

@thor
Copy link
Contributor Author

thor commented May 18, 2017

@benkonrath Hi Ben! Sorry for bumping this, but I'm wondering when you're looking to release a new version? I feel like releasing small and often might be preferable to releasing only with new Django releases, or similarly. :)

@benkonrath
Copy link
Member

@thor No problem. Thanks for checking in. I was actually planning to do a release this week but other commitments got in the way. I make sure I get it out next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants