Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to v2 factutrapi #100

Merged
merged 14 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8, 3.9, '3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SHELL := bash
PATH := ./venv/bin:${PATH}
PYTHON = python3.8
PYTHON = python3.9
PROJECT = facturapi
isort = isort $(PROJECT) tests setup.py examples
black = black -S -l 79 --target-version py38 $(PROJECT) tests setup.py examples
Expand Down
2 changes: 1 addition & 1 deletion facturapi/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..types.exc import FacturapiResponseException
from ..version import CLIENT_VERSION

API_HOST = 'www.facturapi.io/v1'
API_HOST = 'www.facturapi.io/v2'


class Client:
Expand Down
10 changes: 8 additions & 2 deletions facturapi/resources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,26 @@ class Deletable(Resource):

"""

_query_params: ClassVar = BaseQuery

@classmethod
def _delete(cls, id: str) -> Resource:
def _delete(cls, id: str, **query_params) -> Resource:
"""Delete an specific resource.

Performs a DELETE request on the ID.

Args:
id: The ID of the resource to delete.
query_params: Send aditional information over uri

Returns:
Resource: The deleted resource.

"""
response = client.delete(f'/{cls._resource}/{id}')
q = cls._query_params(**query_params)
response = client.delete(
f'/{cls._resource}/{id}?{urlencode(q.dict())}'
)
return cls._from_dict(response)


Expand Down
10 changes: 7 additions & 3 deletions facturapi/resources/customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pydantic import BaseModel
from pydantic.dataclasses import dataclass

from ..types.enums import TaxSystemType
from ..types.general import CustomerAddress
from .base import Creatable, Queryable, Retrievable, Updatable

Expand All @@ -30,9 +31,10 @@ class CustomerRequest(BaseModel):

legal_name: str
tax_id: str
tax_system: TaxSystemType
email: str
phone: Optional[str]
address: Optional[CustomerAddress]
address: CustomerAddress


class CustomerUpdateRequest(BaseModel):
Expand All @@ -51,6 +53,7 @@ class CustomerUpdateRequest(BaseModel):

legal_name: Optional[str]
tax_id: Optional[str]
tax_system: Optional[TaxSystemType]
email: Optional[str]
phone: Optional[str]
address: Optional[CustomerAddress]
Expand All @@ -72,8 +75,8 @@ class Customer(Creatable, Queryable, Retrievable, Updatable):
tax_id (str): RFC of the customer.
email (str): Email of the customer.
address (CustomerAddress): Address data of the model. Optional.
tax_system (TaxSystemType): Enum from catalogue of SAT
phone (str): Phone of the customer. Defaults to `None`.

"""

_resource: ClassVar = 'customers'
Expand All @@ -83,7 +86,8 @@ class Customer(Creatable, Queryable, Retrievable, Updatable):
legal_name: str
tax_id: str
email: str
address: Optional[CustomerAddress]
address: CustomerAddress
tax_system: Optional[TaxSystemType] = None
phone: Optional[str] = None

@classmethod
Expand Down
8 changes: 5 additions & 3 deletions facturapi/resources/invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class to create the resource and a class to represent an
Namespace,
ProductBasicInfo,
)
from ..types.queries import InvoiceQuery
from .base import Creatable, Deletable, Downloadable, Queryable, Retrievable
from .customers import Customer, CustomerRequest
from .resources import retrieve_property
Expand Down Expand Up @@ -49,7 +50,7 @@ class InvoiceItem(BaseModel):
product: Union[
str, ProductBasicInfo, Dict
] # TO DO: Change Dict for ProductRequest
custom_keys: Optional[List[str]]
customs_keys: Optional[List[str]]
complement: Optional[str]
parts: Optional[List[ItemPart]]
property_tax_account: Optional[str]
Expand Down Expand Up @@ -142,6 +143,7 @@ class Invoice(Creatable, Deletable, Downloadable, Queryable, Retrievable):

_resource: ClassVar = 'invoices'
_relations: ClassVar = ['customer']
_query_params = InvoiceQuery

created_at: dt.datetime
livemode: bool
Expand Down Expand Up @@ -175,7 +177,7 @@ def create(cls, data: InvoiceRequest) -> 'Invoice':
return cast('Invoice', cls._create(**cleaned_data))

@classmethod
def cancel(cls, invoice_id: str) -> 'Invoice':
def cancel(cls, invoice_id: str, motive: str) -> 'Invoice':
"""Cancel an invoice.

Calls a DELETE request on invoice resource.
Expand All @@ -187,7 +189,7 @@ def cancel(cls, invoice_id: str) -> 'Invoice':
Invoice: The cancelled invoice resource.

"""
return cast('Invoice', cls._delete(invoice_id))
return cast('Invoice', cls._delete(invoice_id, **dict(motive=motive)))

@property
def customer(self) -> Customer:
Expand Down
29 changes: 29 additions & 0 deletions facturapi/types/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,32 @@ class PaymentMethod(str, Enum):

contado = 'PUE'
parcialidades = 'PPD'


class TaxSystemType(str, Enum):
"""Regimen fiscal from SAT catalogue."""

GRL_PM = "601" # General de Ley Personas Morales
PM_FN = "603" # Personas Morales con Fines no Lucrativos
SAL_IS = "605" # Sueldos y Salarios e Ingresos Asimilados a Salarios
ARR = "606" # Arrendamiento
DEM_ING = "608" # Demás ingresos
CONS = "609" # Consolidación
RES_EXT = "610" # Residentes en el Extranjero sin Establecimiento Permanente en México # noqa: E501
DIV = "611" # Ingresos por Dividendos (socios y accionistas)
PF_AEP = "612" # Personas Físicas con Actividades Empresariales y Profesionales # noqa: E501
INT = "614" # Ingresos por intereses
SIN_OBL = "616" # Sin obligaciones fiscales
SCP_DIF = "620" # Sociedades Cooperativas de Producción que optan por diferir sus ingresos # noqa: E501
INC_FISC = "621" # Incorporación Fiscal
AGRO_GAN_SILV_PES = "622" # Actividades Agrícolas, Ganaderas, Silvícolas y Pesqueras # noqa: E501

OP_GRUPO_SOC = "623" # Opcional para Grupos de Sociedades
COOR = "624" # Coordinados
HID = "628" # Hidrocarburos
ENAJ_ADQ = "607" # Régimen de Enajenación o Adquisición de Bienes
PREF_EM_MULT = "629" # De los Regímenes Fiscales Preferentes y de las Empresas Multinacionales # noqa: E501
ENAJ_ACC_BOL = "630" # Enajenación de acciones en bolsa de valores
ING_PREM = "615" # Régimen de los ingresos por obtención de premios
AE_PLAT_TEC = "625" # Régimen de las Actividades Empresariales con ingresos a través de Plataformas Tecnológicas # noqa: E501
RS_CONF = "626" # Régimen Simplificado de Confianza
4 changes: 4 additions & 0 deletions facturapi/types/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ def dict(self, *args, **kwargs) -> Dict[str, Any]:
kwargs.setdefault('exclude_unset', True)
d = super().dict(*args, **kwargs)
return d


class InvoiceQuery(BaseQuery):
motive: Optional[str]
2 changes: 1 addition & 1 deletion facturapi/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.0.2' # pragma: no cover
__version__ = '0.0.3.dev1' # pragma: no cover
CLIENT_VERSION = __version__
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pytest==6.2.*
pytest-cov==3.0.*
pytest-vcr==1.0.*
black==21.9b0
black==22.3.0
isort==5.7.*
flake8==3.8.*
mypy==0.812
2 changes: 1 addition & 1 deletion tests/http/cassettes/test_invalid_auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interactions:
User-Agent:
- facturapi-python/0.0.1
method: GET
uri: https://www.facturapi.io/v1/invoices
uri: https://www.facturapi.io/v2/invoices
response:
body:
string: '{"message":"Not authenticated","ok":false}'
Expand Down
Loading