Esempio n. 1
0
def insert_into_provider(item, user):
    try:
        if item:
            provider = ProviderModel()
            provider.business_name = item['business_name']
            provider.fantasy_name = item['fantasy_name']
            provider.type_provider = item['type_provider']
            provider.cnpj = item['cnpj']
            provider.address = item['address']
            # provider.password = item['password']
            provider.user_id = user.id
            provider.save()

            return {"succes": True, "message": 'Provider created'}
        else:
            user.delete()
            return {
                "succes": False,
                "message": 'Not created provider, invalid payload'
            }

    except Exception as e:
        user.delete()
        return {
            "succes": False,
            "message": f'{e} invalid payload',
            'type_error': 'provider/utils'
        }
Esempio n. 2
0
    def post(self):
        try:
            data = request.get_json()
            item = ProviderModel()

            for parameter in data:
                setattr(item, parameter, data[parameter])
            item.save()

            return "success", 201
        except:
            return "error", 401
Esempio n. 3
0
def first_provider():
    if ProviderModel.get_by_cnpj("04790618000153") != None:
        return
    new_provider = ProviderModel()
    new_provider.name = "Fornecedor 01"
    new_provider.cnpj = "04790618000153"
    new_provider.address = "Endereço 01"
    new_provider.city = "Cidade 01"
    new_provider.country = "País 01"
    new_provider.cep_code = "000000-000"
    new_provider.responsible_name = "Matheus D'Adamo Milani"
    new_provider.responsible_email = "*****@*****.**"
    new_provider.responsible_phone = "+55(11)97717-9999"
    new_provider.active = True
    new_provider.save()
    return
Esempio n. 4
0
    def test_save_provider(self):
        providers = len(ProviderModel.list())

        new_provider = ProviderModel()
        new_provider.name = "Fornecedor 02"
        new_provider.cnpj = "98617744000154"
        new_provider.address = "Endereço 02"
        new_provider.city = "Cidade 02"
        new_provider.country = "País 02"
        new_provider.cep_code = "000000-000"
        new_provider.responsible_name = "Matheus D'Adamo Milani 01"
        new_provider.responsible_email = "*****@*****.**"
        new_provider.responsible_phone = "+55(11)97717-8888"
        new_provider.active = True
        new_provider.save()

        assert providers + 1 == len(ProviderModel.list())