示例#1
0
 def check_code(self):
     super(PartyIdentifier, self).check_code()
     if self.type == 'ar_cuit':
         if not cuit.is_valid(self.code):
             self.raise_user_error('invalid_vat', {
                     'code': self.code,
                     'party': self.party.rec_name,
                     })
     elif self.type == 'ar_foreign':
         self.check_foreign_vat()
示例#2
0
    def __register__(cls, module_name):
        pool = Pool()
        Country = pool.get('country.country')
        PartyAddress = pool.get('party.address')
        PartyAFIPVatCountry = pool.get('party.afip.vat.country')
        party_afip_vat_country = PartyAFIPVatCountry.__table__()
        party_address = PartyAddress.__table__()
        country = Country.__table__()
        sql_table = cls.__table__()
        cursor = Transaction().cursor
        super(PartyIdentifier, cls).__register__(module_name)

        identifiers = []
        cursor.execute(*sql_table.select(
                sql_table.id, sql_table.party, sql_table.code, sql_table.type))
        for identifier_id, party_id, code_country, type in cursor.fetchall():
            if not code_country or type is not None:
                continue
            type = None
            code = None
            vat_country = ''
            if code_country.startswith('AR'):
                code = code_country[2:]
                if len(code) < 11:
                    type = 'ar_dni'
                elif cuit.is_valid(code):
                    type = 'ar_cuit'
            else:
                code = code_country
                type = 'ar_foreign'
                cursor_pa = Transaction().cursor
                cursor_pa.execute(*party_address.join(country,
                        condition=party_address.country == country.id
                        ).select(country.code,
                        where=(party_address.party == party_id)))
                row = cursor_pa.dictfetchone()
                if row:
                    vat_country = row['code']
                    country, = Country.search([('code','=',vat_country)])
                    cursor_pa = Transaction().cursor
                    cursor_pa.execute(*party_afip_vat_country.select(
                        party_afip_vat_country.vat_country,
                        where=(party_afip_vat_country.vat_number == code)))
                    afip_vat_country = cursor_pa.dictfetchone()
                    if afip_vat_country is None:
                        afip_vat_countrys = []
                        country, = Country.search([('code','=',vat_country)])
                        afip_vat_countrys.append(
                                PartyAFIPVatCountry(type_code='0', vat_country=country, vat_number=code))
                        PartyAFIPVatCountry.save(afip_vat_countrys)
            identifiers.append(
                cls(id=identifier_id, code=code, type=type, vat_country=vat_country))
        cls.save(identifiers)
示例#3
0
    def get_party_tax_identifier(cls, invoice):
        code = ''
        if invoice.party_tax_identifier:
            code = invoice.party_tax_identifier.code
        elif invoice.party.vat_number:
            code = invoice.party.vat_number
        else:
            for identifier in invoice.party.identifiers:
                if identifier.type == 'ar_dni':
                    code = identifier.code

        if cuit.is_valid(code):
            code = cuit.format(code)
        elif dni.is_valid(code):
            code = dni.format(code)
        return code
示例#4
0
    def __register__(cls, module_name):
        pool = Pool()
        Country = pool.get('country.country')
        Party = pool.get('party.party')
        PartyAddress = pool.get('party.address')
        PartyAFIPVatCountry = pool.get('party.afip.vat.country')
        party_afip_vat_country = PartyAFIPVatCountry.__table__()
        party_address = PartyAddress.__table__()
        party = Party.__table__()
        country_table = Country.__table__()
        sql_table = cls.__table__()
        cursor = Transaction().connection.cursor()
        TableHandler = backend.get('TableHandler')
        table_a = TableHandler(cls, module_name)
        super(PartyIdentifier, cls).__register__(module_name)

        identifiers = []
        cursor.execute(*sql_table.select(
                sql_table.id, sql_table.party, sql_table.code, sql_table.type,
        where=(sql_table.code != 'AR')))
        for identifier_id, party_id, code_country, identifier_type in cursor.fetchall():
            identifiers = []
            if not code_country or identifier_type is not None:
                continue

            type = identifier_type
            code = None
            vat_country = ''
            cursor.execute(*party.select(
                party.tipo_documento, where=(party.id == party_id)))
            party_row = cursor.dictfetchone()
            if party_row['tipo_documento'] and party_row['tipo_documento'] == '96' and len(code_country) < 11:
                code = code_country
                type = 'ar_dni'
            elif code_country.startswith('AR'):
                code = code_country[2:]
                if cuit.is_valid(code):
                    type = 'ar_cuit'
                else:
                    type = identifier_type
            elif len(code_country) < 11:
                code = code_country
                type = 'ar_dni'
            else:
                code = code_country
                type = 'ar_foreign'
                cursor_pa = Transaction().connection.cursor()
                cursor_pa.execute(*party_address.join(country_table,
                        condition=party_address.country == country_table.id).select(country_table.code,
                        where=(party_address.party == party_id)))
                row = cursor_pa.dictfetchone()
                if row:
                    vat_country = row['code']
                    country, = Country.search([('code', '=', vat_country)])
                    cursor_pa = Transaction().connection.cursor()
                    cursor_pa.execute(*party_afip_vat_country.select(
                        party_afip_vat_country.vat_country,
                        where=(party_afip_vat_country.vat_number == code)))
                    afip_vat_country = cursor_pa.dictfetchone()
                    if afip_vat_country is None:
                        afip_vat_countrys = []
                        country, = Country.search([('code','=',vat_country)])
                        afip_vat_countrys.append(
                                PartyAFIPVatCountry(type_code='0', vat_country=country, vat_number=code))
                        PartyAFIPVatCountry.save(afip_vat_countrys)
            identifiers.append(
                cls(id=identifier_id, code=code, type=type, vat_country=vat_country))
            cls.save(identifiers)

        # Migrate to 4.0
        if table_a.column_exist('vat_country'):
            cursor.execute(*sql_table.select(
                    sql_table.id, sql_table.vat_country, sql_table.country,
            where=(sql_table.type == 'ar_foreign')))

            for identifier_id, vat_country, country in cursor.fetchall():
                if vat_country != '':
                    country_code, = Country.search([('code','=',vat_country)])
                    cursor.execute(*sql_table.update(
                            [sql_table.country, sql_table.vat_country], [country_code.id, ''],
                    where=(sql_table.id == identifier_id)))
            table_a.drop_column('vat_country')