Esempio n. 1
0
def codice_fiscale_persona(persona):
    from base.comuni import COMUNI
    try:
        codice_comune = COMUNI[persona.comune_nascita.lower()]
    except KeyError:
        codice_comune = 'D000'

    try:
        return build(persona.cognome, persona.nome, persona.data_nascita,
                     persona.genere, codice_comune)
    except:
        # Dati personali imcompatibili per creare un codice fiscale corretto.
        return build(names.get_last_name(), names.get_first_name(),
                     persona.data_nascita, persona.genere, codice_comune)
Esempio n. 2
0
def codice_fiscale_persona(persona):
    from base.comuni import COMUNI
    try:
        codice_comune = COMUNI[persona.comune_nascita.lower()]
    except KeyError:
        codice_comune = 'D000'
    return build(persona.cognome, persona.nome, persona.data_nascita, persona.genere, codice_comune)
Esempio n. 3
0
 def calcola_cf(self):
     if not self.data_nascita or \
        not self.municipalita or \
        not self.sesso:
         raise Exception('Dati mancanti')
     return codicefiscale.build(self.cognome, self.nome, self.data_nascita,
                                self.sesso, self.municipalita)
Esempio n. 4
0
 def compute_fc(self, cr, uid, ids, context):
     active_id = context.get('active_id', [])
     partner = self.pool.get('res.partner').browse(cr, uid, active_id,
                                                   context)
     form_obj = self.browse(cr, uid, ids, context)
     for wizard in form_obj:
         if (not wizard.fiscalcode_surname
                 or not wizard.fiscalcode_firstname or not wizard.birth_date
                 or not wizard.birth_city or not wizard.sex):
             raise osv.except_osv(_('Error'),
                                  _('One or more fields are missing'))
         if not wizard.birth_city.cadaster_code:
             raise osv.except_osv(_('Error'), _('Cataster code is missing'))
         birth_date = datetime.datetime.strptime(wizard.birth_date,
                                                 "%Y-%m-%d")
         # CF = self._codicefiscale(
         #     wizard.fiscalcode_surname, wizard.fiscalcode_firstname, str(
         #         birth_date.day),
         #     str(birth_date.month), str(birth_date.year), wizard.sex,
         #     wizard.birth_city.cadaster_code)
         CF = build(wizard.fiscalcode_surname, wizard.fiscalcode_firstname,
                    birth_date, wizard.sex, wizard.birth_city.cadaster_code)
         if partner.fiscalcode and partner.fiscalcode != CF:
             raise osv.except_osv(
                 _('Error'),
                 _('Existing fiscal code %s is different from the computed '
                   'one (%s). If you want to use the computed one, remove '
                   'the existing one') % (partner.fiscalcode, CF))
         self.pool.get('res.partner').write(cr, uid, active_id, {
             'fiscalcode': CF,
             'individual': True
         })
     return {}
Esempio n. 5
0
 def compute_fc(self):
     active_id = self._context.get('active_id')
     partner = self.env['res.partner'].browse(active_id)
     for f in self:
         if (not f.fiscalcode_surname or not f.fiscalcode_firstname
                 or not f.birth_date or not f.birth_city or not f.sex):
             raise UserError(_('One or more fields are missing'))
         nat_code = self._get_national_code(f.birth_city.name,
                                            f.birth_province.code,
                                            f.birth_date)
         if not nat_code:
             raise UserError(_('National code is missing'))
         c_f = build(f.fiscalcode_surname, f.fiscalcode_firstname,
                     f.birth_date, f.sex, nat_code)
         if partner.fiscalcode and partner.fiscalcode != c_f:
             raise UserError(
                 _('Existing fiscal code %(partner_fiscalcode)s is different '
                   'from the computed one (%(compute)s). If you want to use'
                   ' the computed one, remove the existing one' % {
                       'partner_fiscalcode': partner.fiscalcode,
                       'compute': c_f
                   }))
         partner.fiscalcode = c_f
         partner.company_type = 'person'
     return {'type': 'ir.actions.act_window_close'}
Esempio n. 6
0
 def compute_fc(self):
     active_id = self._context.get('active_id')
     partner = self.env['res.partner'].browse(active_id)
     for f in self:
         if (not f.fiscalcode_surname or not f.fiscalcode_firstname
                 or not f.birth_date or not f.birth_city or not f.sex):
             raise except_orm(_('Error'),
                              ('One or more fields are missing'))
         nat_code = self._get_national_code(f.birth_city.name,
                                            f.birth_province.name,
                                            f.birth_date)
         if not nat_code:
             raise except_orm(_('Error'), _('National code is missing'))
         birth_date = datetime.datetime.strptime(f.birth_date, "%Y-%m-%d")
         CF = build(f.fiscalcode_surname, f.fiscalcode_firstname,
                    birth_date, f.sex, nat_code)
         if partner.fiscalcode and partner.fiscalcode != CF:
             raise except_orm(
                 _('Error'),
                 ('Existing fiscal code %s is different from the computed'
                  ' one (%s). If you want to use the computed one, remove'
                  ' the existing one') % (partner.fiscalcode, CF))
         partner.fiscalcode = CF
         partner.individual = True
     return {'type': 'ir.actions.act_window_close'}
Esempio n. 7
0
def codice_fiscale_persona(persona):
    from base.comuni import COMUNI
    try:
        codice_comune = COMUNI[persona.comune_nascita.lower()]
    except KeyError:
        codice_comune = 'D000'
    return build(persona.cognome, persona.nome, persona.data_nascita,
                 persona.genere, codice_comune)
Esempio n. 8
0
    def test_build(self):
        tests = { 

            'RCCMNL83S18D969H': ( 
                "Rocca", "Emanuele", 
                datetime.datetime(1983, 11, 18),
                'M','D969'
            ),

            'CNTCHR83T41D969D': ( 
                "Cintoi", "Chiara", 
                datetime.datetime(1983, 12, 1),
                'F','D969'
            ),

            'BNCSFN85T58G702W': ( 
                "Bianucci", "Stefania", 
                datetime.datetime(1985, 12, 18),
                'F','G702'
            ),

            'RCDLSN84S16D969Z': ( 
                "Arcidiacono", "Alessandro", 
                datetime.datetime(1984, 11, 16),
                'M','D969'
            ),

            'FOXDRA26C24H872Y': ( 
                "Fo", "Dario", 
                datetime.datetime(1926, 3, 24),
                'M',
                # born in Sangiano
                'H872'
            ),

            'MAILCU91A25F839D': (
                "Maio", "Luca",
                datetime.datetime(1991, 1, 25),
                'M',
                'F839'
            ),

            'HRYXXX11S05Z222K': (
                "Haryana", 
                # Indian person with only one name reported on her passport
                "",
                datetime.datetime(1911, 11, 5),
                'M',
                'Z222'
            )
        }
        
        for expected, data in tests.items():
            cf = build(surname=data[0], name=data[1], 
                       birthday=data[2], sex=data[3],
                       municipality=data[4])
        
            self.assertEquals(expected, cf)
Esempio n. 9
0
 def compute_fiscal_code(self, cr, uid, ids, context):
     partners = self.browse(cr, uid, ids, context)
     for partner in partners:
         if not partner.fiscalcode_surname or not partner.fiscalcode_firstname or not partner.birth_date or not partner.birth_city or not partner.sex:
             raise orm.except_orm('Error', 'One or more fields are missing')
         birth_date = datetime.datetime.strptime(partner.birth_date, "%Y-%m-%d")
         CF = build(partner.fiscalcode_surname, partner.fiscalcode_firstname, birth_date, partner.sex, partner.birth_city.cadaster_code)
         partner.write({'fiscalcode': CF})
     return True
Esempio n. 10
0
 def compute_fiscal_code(self, cr, uid, ids, context):
     partners = self.browse(cr, uid, ids, context)
     for partner in partners:
         if not partner.fiscalcode_surname or not partner.fiscalcode_firstname or not partner.birth_date or not partner.birth_city or not partner.sex:
             raise orm.except_orm('Error', 'One or more fields are missing')
         birth_date = datetime.datetime.strptime(partner.birth_date, "%Y-%m-%d")
         CF = build(partner.fiscalcode_surname, partner.fiscalcode_firstname, birth_date, partner.sex, partner.birth_city.cadaster_code)
         partner.write({'fiscalcode': CF})
     return True
Esempio n. 11
0
    def test_01_locale_bug(self):
        try:
            locale.setlocale(locale.LC_ALL, "it_IT")
        except locale.Error:
            print "Skipping test_01_locale_bug, it_IT not available"
            return

        expected = "MRARSS91A25G693C"
        actual = build("mario", "rossi", datetime.datetime(1991, 1, 25), "M", "G693")
        self.assertEquals(expected, actual)
Esempio n. 12
0
    def test_01_locale_bug(self):
        try:
            locale.setlocale(locale.LC_ALL, "it_IT")
        except locale.Error:
            print("Skipping test_01_locale_bug, it_IT not available")
            return

        expected = "MRARSS91A25G693C"
        actual = build("mario", "rossi", datetime.datetime(1991, 1, 25), "M",
                       "G693")
        self.assertEquals(expected, actual)
Esempio n. 13
0
def cf_build(surname, name, year, month, day, sex, municipality):
    """``cf_build(surname, name, year, month, day, sex, municipality) -> string``

    Computes the fiscal code for the given person data.

    eg: cf_build('Rocca', 'Emanuele', 1983, 11, 18, 'M', 'D969') 
        -> RCCMNL83S18D969H
    """
    birthday = datetime.datetime(year, month, day)

    return cf.build(surname, name, birthday, sex, municipality)
Esempio n. 14
0
    def test_build(self):
        tests = {
            'RCCMNL83S18D969H': ("Rocca", "Emanuele",
                                 datetime.datetime(1983, 11, 18), 'M', 'D969'),
            'CNTCHR83T41D969D':
            ("Cintoi", "Chiara", datetime.datetime(1983, 12, 1), 'F', 'D969'),
            'BNCSFN85T58G702W': ("Bianucci", "Stefania",
                                 datetime.datetime(1985, 12, 18), 'F', 'G702'),
            'RCDLSN84S16D969Z': ("Arcidiacono", "Alessandro",
                                 datetime.datetime(1984, 11, 16), 'M', 'D969'),
            'FOXDRA26C24H872Y': (
                "Fo",
                "Dario",
                datetime.datetime(1926, 3, 24),
                'M',
                # born in Sangiano
                'H872'),
            'MAILCU91A25F839D':
            ("Maio", "Luca", datetime.datetime(1991, 1, 25), 'M', 'F839'),
            'HRYXXX11S05Z222K': (
                "Haryana",
                # Indian person with only one name reported on her passport
                "",
                datetime.datetime(1911, 11, 5),
                'M',
                'Z222'),
            'FOXMRA83S18D969V': (
                "Fo'",
                "Mario",
                # Short surname with apostrophe
                datetime.datetime(1983, 11, 18),
                'M',
                'D969'),
            'YXXAXX83S18D969R': (
                "Y",
                "A",
                # Extremely short surname, and name (Korean example)
                datetime.datetime(1983, 11, 18),
                'M',
                'D969'),
        }

        for expected, data in tests.items():
            cf = build(surname=data[0],
                       name=data[1],
                       birthday=data[2],
                       sex=data[3],
                       municipality=data[4])

            self.assertEquals(expected, cf)
Esempio n. 15
0
def cf_build(surname, name, year, month, day, sex, municipality):
    """``cf_build(surname, name, year, month, day, sex, municipality) -> string``

    Computes the fiscal code for the given person data.

    eg: cf_build('Rocca', 'Emanuele', 1983, 11, 18, 'M', 'D969') 
        -> RCCMNL83S18D969H
    """

    birthday = datetime.datetime(year, month, day)
    if sex.upper() in ['MASCHILE','MASCHIO','UOMO','M']:
        sex='M'
    else:
        sex='F'

    return cf.build(surname, name, birthday, sex, municipality)
Esempio n. 16
0
 def test_new_registered_gender_is_set(self):
     genere_list = ['M', 'F']
     for genere in genere_list:
         nome = names.get_first_name()
         cognome = names.get_last_name()
         nascita = datetime(random.randint(1960, 1990),
                            random.randint(1, 12),
                            random.randint(1, 28))
         p = Persona(
             nome=nome,
             cognome=cognome,
             data_nascita=nascita,
             codice_fiscale=codicefiscale.build(nome, cognome, nascita, genere, 'D969'),
             comune_nascita=random.sample(COMUNI.keys(), 1)[0],
             indirizzo_residenza='Via Prova, 34',
             comune_residenza=random.sample(COMUNI.keys(), 1)[0],
             provincia_residenza='EE',
             cap_residenza='00100',)
         p.save()
         self.assertEquals(p.genere_codice_fiscale, genere)
         self.assertEquals(p.genere, genere)
Esempio n. 17
0
 def compute_fc(self):
     active_id = self._context.get("active_id")
     partner = self.env["res.partner"].browse(active_id)
     for f in self:
         if (
             not f.fiscalcode_surname
             or not f.fiscalcode_firstname
             or not f.birth_date
             or not f.birth_city
             or not f.sex
         ):
             raise UserError(_("One or more fields are missing"))
         nat_code = self._get_national_code(
             f.birth_city.name, f.birth_province.code, f.birth_date
         )
         if not nat_code:
             raise UserError(_("National code is missing"))
         c_f = build(
             f.fiscalcode_surname,
             f.fiscalcode_firstname,
             f.birth_date,
             f.sex,
             nat_code,
         )
         if partner.fiscalcode and partner.fiscalcode != c_f:
             raise UserError(
                 _(
                     "Existing fiscal code %(partner_fiscalcode)s is different "
                     "from the computed one (%(compute)s). If you want to use"
                     " the computed one, remove the existing one"
                     % {"partner_fiscalcode": partner.fiscalcode, "compute": c_f}
                 )
             )
         partner.fiscalcode = c_f
         partner.company_type = "person"
     return {"type": "ir.actions.act_window_close"}
Esempio n. 18
0
    def import_file(self, invoice_file):
        csv_data = base64.b64decode(invoice_file.datas)
        data_file = StringIO(csv_data.decode("utf-8"))
        data_file.seek(0)
        file_reader = []
        csv_reader = csv.DictReader(data_file)
        file_reader.extend(csv_reader)
        agency = ""
        freelancer = ""
        for line in file_reader:
            if line['Agency'] != "":
                if self.env['res.partner'].search([('name', '=',
                                                    line['Agency'])]):
                    agency = self.env['res.partner'].search([('name', '=',
                                                              line['Agency'])])
                else:
                    # Update for fiscale code compute
                    generic_city = self.env[
                        'res.city.it.code.distinct'].search([('name', '=',
                                                              'MILANO')])
                    generic_state = self.env['res.country.state'].search([
                        ('name', '=', 'Milano')
                    ])
                    generic_country = self.env['res.country'].search([
                        ('name', '=', 'Italy')
                    ])
                    national_code = self.env[
                        'wizard.compute.fc']._get_national_code(
                            generic_city.name, generic_state.code,
                            fields.Date.today())
                    fiscal_code = build(line['Agency'], line['Agency'],
                                        fields.Date.today(), 'M',
                                        national_code)
                    agency = self.env['res.partner'].create({
                        'name':
                        line['Agency'],
                        'company_type':
                        'company',
                        'supplier':
                        True,
                        'street':
                        'Generic freelancer address',
                        'city':
                        'MILANO',
                        'country_id':
                        generic_country.id,
                        'zip':
                        '20019',
                        'vat':
                        'BE0477472701',
                        'fiscalcode':
                        fiscal_code,
                    })

            if line['Freelancer'] != "":
                if self.env['res.partner'].search([('name', '=',
                                                    line['Freelancer'])]):
                    freelancer = self.env['res.partner'].search([
                        ('name', '=', line['Freelancer'])
                    ])
                else:
                    # Update for fiscale code compute
                    name = self.splitFullName(line['Freelancer'])
                    generic_city = self.env[
                        'res.city.it.code.distinct'].search([('name', '=',
                                                              'MILANO')])
                    generic_state = self.env['res.country.state'].search([
                        ('name', '=', 'Milano')
                    ])
                    generic_country = self.env['res.country'].search([
                        ('name', '=', 'Italy')
                    ])
                    national_code = self.env[
                        'wizard.compute.fc']._get_national_code(
                            generic_city.name, generic_state.code,
                            fields.Date.today())
                    fiscal_code = build(name['lastname'], name['firstname'],
                                        fields.Date.today(), 'M',
                                        national_code)
                    freelancer = self.env['res.partner'].create({
                        'firstname':
                        name['firstname'],
                        'lastname':
                        name['lastname'],
                        'name':
                        line['Freelancer'],
                        'company_type':
                        'person',
                        'supplier':
                        True,
                        'street':
                        'Generic freelancer address',
                        'city':
                        'MILANO',
                        'country_id':
                        generic_country.id,
                        'zip':
                        '20019',
                        'vat':
                        'BE0477472701',
                        'fiscalcode':
                        fiscal_code,
                    })

            self.env['upwork.invoice'].create({
                'name':
                line['Ref ID']
                if 'Ref ID' in line.keys() else 'Ref ID Missing',
                'date':
                line['Date'] if 'Date' in line.keys() else '',
                'invoice_type':
                line['Type'] if 'Type' in line.keys() else '',
                'description':
                line['Description'] if 'Description' in line.keys() else '',
                'agency':
                agency.id if bool(agency) == True else '',
                'freelancer':
                freelancer.id if bool(freelancer) == True else '',
                'team':
                line['Team'] if 'Team' in line.keys() else '',
                'account_name':
                line['Account Name'] if 'Account Name' in line.keys() else '',
                'po':
                line['PO'] if 'PO' in line.keys() else '',
                'amount':
                float(line['Amount'])
                if bool(line['Amount']) and 'Amount' in line.keys() else None,
                'amount_local_currency':
                float(line['Amount in local currency'])
                if bool(line['Amount in local currency'])
                and 'Amount in local currency' in line.keys() else None,
                'balance':
                float(line['Balance']) if bool(line['Balance'])
                and 'Balance' in line.keys() else None,
                'invoice_file':
                invoice_file,
            })
Esempio n. 19
0
    def create(self, values):
        res = super(UpworkInvoice, self).create(values)
        partner = None
        upwork_partner = None
        if bool(res.freelancer):
            partner = res.freelancer.id
        if bool(res.agency):
            partner = res.agency.id

        if bool(self.env['res.partner'].search([('name', '=', 'Upwork')])):
            upwork_partner = self.env['res.partner'].search([('name', '=',
                                                              'Upwork')])
        else:
            generic_city = self.env['res.city.it.code.distinct'].search([
                ('name', '=', 'MILANO')
            ])
            generic_state = self.env['res.country.state'].search([('name', '=',
                                                                   'Milano')])
            generic_country = self.env['res.country'].search([('name', '=',
                                                               'Italy')])
            national_code = self.env['wizard.compute.fc']._get_national_code(
                generic_city.name, generic_state.code, fields.Date.today())
            fiscal_code = build('Upwork', 'Upwork', fields.Date.today(), 'M',
                                national_code)
            upwork_partner = self.env['res.partner'].create({
                'name':
                'Upwork',
                'company_type':
                'company',
                'supplier':
                True,
                'street':
                'Generic freelancer address',
                'city':
                'MILANO',
                'country_id':
                generic_country.id,
                'zip':
                '20019',
                'vat':
                'BE0477472701',
                'fiscalcode':
                fiscal_code,
            })

        if res.invoice_type == "Hourly":
            tax = self.env['account.tax'].search([('name', '=',
                                                   'Iva al 22% (credito)')])
            journal = self.env['account.invoice']._default_journal().id
            product = self.env['product.product'].create({
                'name': res.description,
                'type': 'service'
            })
            supplier_line = {
                'product_id': product.id,
                'name': product.name,
                'quantity': 1,
                'account_id': journal,
                'invoice_line_tax_ids': [(4, tax.id, 0)],
                'price_unit': abs(res.amount_converted),
            }
            record_line = {
                'type': 'in_invoice',
                'partner_id': partner,
                'date_invoice':
                res.invoice_date if bool(res.invoice_date) else None,
                'upwork_invoice': res.id,
                'invoice_line_ids': [(0, 0, supplier_line)],
            }
            record = self.env['account.invoice'].create(record_line)
            record.action_invoice_open()
            wizard = self.env['wizard.export.fatturapa'].create({})
            export_e_invoice = wizard.with_context({
                'active_ids': [record.id]
            }).exportFatturaPA()
        elif res.invoice_type == "Processing Fee":
            tax = self.env['account.tax'].search([('name', '=',
                                                   'Iva al 22% (credito)')])
            journal = self.env['account.invoice']._default_journal().id
            product = self.env['product.product'].create({
                'name': res.description,
                'type': 'service'
            })
            supplier_line = {
                'product_id': product.id,
                'name': product.name,
                'quantity': 1,
                'account_id': journal,
                'invoice_line_tax_ids': [(4, tax.id, 0)],
                'price_unit': abs(res.amount_converted),
            }
            record_line = {
                'type': 'in_invoice',
                'partner_id': upwork_partner.id,
                'date_invoice':
                res.invoice_date if bool(res.invoice_date) else None,
                'upwork_invoice': res.id,
                'invoice_line_ids': [(0, 0, supplier_line)],
            }
            record = self.env['account.invoice'].create(record_line)
            record.action_invoice_open()
            wizard = self.env['wizard.export.fatturapa'].create({})
            export_e_invoice = wizard.with_context({
                'active_ids': [record.id]
            }).exportFatturaPA()

        return res
Esempio n. 20
0
    def compute_cf(self):

        city = City.objects(Denom_Italiana=self.birthplace).first()
        cf_code = city.Codice
        self.codice_fiscale = build(self.last_name, self.first_name,
                                    self.birthdate, self.gender, str(cf_code))