Пример #1
0
 def onchange_fiscalcode(self, cr, uid, ids, fiscalcode, context=None):
     name = 'fiscalcode'
     if fiscalcode:
         if len(fiscalcode) == 11:
             res_partner_pool = self.pool.get('res.partner')
             chk = res_partner_pool.simple_vat_check(
                 cr, uid, 'it', fiscalcode)
             if not chk:
                 return {'value': {name: False},
                         'warning': {
                     'title': 'Invalid fiscalcode!',
                     'message': 'Invalid vat number'}
                 }
             individual = False
         elif len(fiscalcode) != 16:
             return {'value': {name: False},
                     'warning': {
                 'title': 'Invalid len!',
                 'message': 'Fiscal code len must be 11 or 16'}
             }
         else:
             fiscalcode = fiscalcode.upper()
             chk = control_code(fiscalcode[0:15])
             if chk != fiscalcode[15]:
                 value = fiscalcode[0:15] + chk
                 return {'value': {name: value},
                         'warning': {
                             'title': 'Invalid fiscalcode!',
                             'message': 'Fiscal code could be %s' % (value)}
                         }
             individual = True
         return {'value': {name: fiscalcode,
                           'individual': individual}}
     return {'value': {'individual': False}}
Пример #2
0
    def test_control_code(self):
        inputs = {
            # fiscal codes tested in this module
            'MRTNTN23M02D969': 'P',
            'MRSMSR81D60Z611': 'H',
            'RCDLSN84S16D969': 'Z',
            'CNTCHR83T41D969': 'D',
            'BNCSFN85T58G702': 'W',
            'RCCMNL83S18D969': 'H',
            'FOXDRA26C24H872': 'Y',
            'MAILCU91A25F839': 'D'
        }

        for cf, expected in inputs.items():
            self.assertEquals(expected, control_code(cf))
Пример #3
0
    def test_control_code(self):
        inputs = { 
            # fiscal codes tested in this module
            'MRTNTN23M02D969': 'P',
            'MRSMSR81D60Z611': 'H',
            'RCDLSN84S16D969': 'Z',
            'CNTCHR83T41D969': 'D',
            'BNCSFN85T58G702': 'W',
            'RCCMNL83S18D969': 'H',
            'FOXDRA26C24H872': 'Y',
            'MAILCU91A25F839': 'D'
        }

        for cf, expected in inputs.items():
            self.assertEquals(expected, control_code(cf))
Пример #4
0
 def onchange_fiscalcode(self,
                         cr,
                         uid,
                         ids,
                         fiscalcode,
                         name,
                         context=None):
     if fiscalcode:
         if len(fiscalcode) == 11:
             chk = self.pool['res.partner'].simple_vat_check(
                 cr, uid, 'it', fiscalcode)
             if not chk:
                 return {
                     'value': {
                         name: False
                     },
                     'warning': {
                         'title': 'Invalid fiscalcode!',
                         'message': 'Invalid vat number'
                     }
                 }
         elif len(fiscalcode) != 16:
             return {
                 'value': {
                     name: False
                 },
                 'warning': {
                     'title': 'Invalid len!',
                     'message': 'Fiscal code len must be 11 or 16'
                 }
             }
         else:
             fiscalcode = fiscalcode.upper()
             chk = codicefiscale.control_code(fiscalcode[0:15])
             if chk != fiscalcode[15]:
                 value = fiscalcode[0:15] + chk
                 return {
                     'value': {
                         name: value
                     },
                     'warning': {
                         'title': 'Invalid fiscalcode!',
                         'message': 'Fiscal code could be %s' % value
                     }
                 }
         return {'value': {name: fiscalcode}}
     return {}
Пример #5
0
 def onchange_fiscalcode(self):
     name = 'fiscalcode'
     if self.fiscalcode:
         if self.country_id and self.country_id.code != 'IT':
             self.individual = True
         elif len(self.fiscalcode) == 11:
             res_partner_model = self.env['res.partner']
             chk = res_partner_model.simple_vat_check('it', self.fiscalcode)
             if not chk:
                 return {
                     'value': {
                         name: False
                     },
                     'warning': {
                         'title': 'Invalid fiscalcode!',
                         'message': 'Invalid vat number'
                     }
                 }
             self.individual = False
         elif len(self.fiscalcode) != 16:
             return {
                 'value': {
                     name: False
                 },
                 'warning': {
                     'title': 'Invalid len!',
                     'message': 'Fiscal code len must be 11 or 16'
                 }
             }
         else:
             self.individual = True
             self.fiscalcode = self.fiscalcode.upper()
             chk = codicefiscale.control_code(self.fiscalcode[0:15])
             if chk != self.fiscalcode[15]:
                 value = self.fiscalcode[0:15] + chk
                 return {
                     'value': {
                         name: value
                     },
                     'warning': {
                         'title': 'Invalid fiscalcode!',
                         'message': 'Fiscal code could be %s' % (value)
                     }
                 }
     else:
         self.individual = False
Пример #6
0
 def clean(self):
     """Validate model fields"""
     # Check tax code field
     tax_code = self.tax_code.upper().strip().ljust(16)
     if not codicefiscale.isvalid(tax_code):
         # Invalid tax code
         raise ValidationError(
             {'tax_code': pgettext_lazy('Employee', 'Invalid Tax Code')})
     elif codicefiscale.control_code(tax_code[:15]) != tax_code[15]:
         # Unmatching check digit
         raise ValidationError(
             {'tax_code': pgettext_lazy('Employee', 'Incorrect Tax Code')})
     elif Employee.objects.filter(tax_code=tax_code).exclude(pk=self.id):
         # Existing tax code
         raise ValidationError(
             {'tax_code': pgettext_lazy('Employee', 'Existing Tax Code')})
     else:
         # No errors
         self.tax_code = tax_code