Code

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#18537 closed Bug (fixed)

Error in calculation of check digit in ARCUITField

Reported by: mmoya@… Owned by: foxyNinja7
Component: contrib.localflavor Version: 1.4
Severity: Normal Keywords: ARCUITField, localflavor.ar
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

There is a bug in the calculation of check digit on forms.py from django.contrib.localflavor.ar.

When using ARCUITField and enter a valid CUIT terminated (that is, check digit) in 0 or 9, the clean method raise a Validation error message.

To replicate the bug, just enter a valid cuit number with the format XX-XXXXXXXX-0, and you will see the error "Invalid CUIT".

The problem is in the _calc_cd(self, cuit) method, that not take care of this two special cases. More info in http://es.wikipedia.org/wiki/C%C3%B3digo_%C3%9Anico_de_Identificaci%C3%B3n_Tributaria

A quick fix for this could be:

    def _calc_cd(self, cuit):
        mults = (5, 4, 3, 2, 7, 6, 5, 4, 3, 2)
        tmp = sum([m * int(cuit[idx]) for idx, m in enumerate(mults)])
        aux_cd = 11 - tmp % 11
        if aux_cd == 11:
            aux_cd = 0
        elif aux_cd == 10:
            aux_cd = 9
        return str(aux_cd)


Thanks,

Attachments (0)

Change History (9)

comment:1 Changed 2 years ago by claudep

  • Component changed from Forms to contrib.localflavor
  • Easy pickings set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 2 years ago by foxyNinja7

  • Owner changed from nobody to foxyNinja7
  • Status changed from new to assigned

comment:3 Changed 2 years ago by foxyNinja7

Local git branch for this change: https://github.com/kevinschaul/django

comment:4 Changed 2 years ago by foxyNinja7

  • Has patch set

comment:5 Changed 2 years ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In [1d2982362df1dbd9b08ffcc1d2506b2e3789250e]:

Fixed #18537 -- Fixed CUIT calculation in ar localflavor

Thanks mmoya at 8ksoft.com.ar for the report and Kevin Shaul for the
initial patch.

comment:6 Changed 2 years ago by Claude Paroz <claude@…>

In [1d2982362df1dbd9b08ffcc1d2506b2e3789250e]:

Fixed #18537 -- Fixed CUIT calculation in ar localflavor

Thanks mmoya at 8ksoft.com.ar for the report and Kevin Shaul for the
initial patch.

comment:7 Changed 2 years ago by Claude Paroz <claude@…>

In [1d2982362df1dbd9b08ffcc1d2506b2e3789250e]:

Fixed #18537 -- Fixed CUIT calculation in ar localflavor

Thanks mmoya at 8ksoft.com.ar for the report and Kevin Shaul for the
initial patch.

comment:8 Changed 2 years ago by Claude Paroz <claude@…>

In [1d2982362df1dbd9b08ffcc1d2506b2e3789250e]:

Fixed #18537 -- Fixed CUIT calculation in ar localflavor

Thanks mmoya at 8ksoft.com.ar for the report and Kevin Shaul for the
initial patch.

comment:9 Changed 2 years ago by aaugustin

Oops -- sorry for the repeated notifications, this is my fault.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.