Skip to content

Commit a4690ec

Browse files
authored
Migration to v2 factutrapi (#100)
* migration complete * linterD * upgrade python * python 3.9 * 3.10 * 3.8 * 1 * upgrade pydantic * bump request * much better * enum plus * fixed * upgrade version * bump cv
1 parent a81f0c6 commit a4690ec

38 files changed

+212
-195
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
strategy:
2222
matrix:
23-
python-version: [3.6, 3.7, 3.8]
23+
python-version: [3.7, 3.8, 3.9, '3.10']
2424
steps:
2525
- uses: actions/checkout@v2
2626
- name: Set up Python ${{ matrix.python-version }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL := bash
22
PATH := ./venv/bin:${PATH}
3-
PYTHON = python3.8
3+
PYTHON = python3.9
44
PROJECT = facturapi
55
isort = isort $(PROJECT) tests setup.py examples
66
black = black -S -l 79 --target-version py38 $(PROJECT) tests setup.py examples

facturapi/http/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ..types.exc import FacturapiResponseException
99
from ..version import CLIENT_VERSION
1010

11-
API_HOST = 'www.facturapi.io/v1'
11+
API_HOST = 'www.facturapi.io/v2'
1212

1313

1414
class Client:

facturapi/resources/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,26 @@ class Deletable(Resource):
188188
189189
"""
190190

191+
_query_params: ClassVar = BaseQuery
192+
191193
@classmethod
192-
def _delete(cls, id: str) -> Resource:
194+
def _delete(cls, id: str, **query_params) -> Resource:
193195
"""Delete an specific resource.
194196
195197
Performs a DELETE request on the ID.
196198
197199
Args:
198200
id: The ID of the resource to delete.
201+
query_params: Send aditional information over uri
199202
200203
Returns:
201204
Resource: The deleted resource.
202205
203206
"""
204-
response = client.delete(f'/{cls._resource}/{id}')
207+
q = cls._query_params(**query_params)
208+
response = client.delete(
209+
f'/{cls._resource}/{id}?{urlencode(q.dict())}'
210+
)
205211
return cls._from_dict(response)
206212

207213

facturapi/resources/customers.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import datetime as dt
88
from typing import ClassVar, Optional, cast
99

10+
from cuenca_validations.types import SATRegimeCode
1011
from pydantic import BaseModel
1112
from pydantic.dataclasses import dataclass
1213

@@ -22,6 +23,7 @@ class CustomerRequest(BaseModel):
2223
Attributes:
2324
legal_name (str): Full name of the customer.
2425
tax_id (str): RFC of the customer.
26+
tax_system: SATRegimeCode regime code from SAT
2527
email (str): Email of the customer.
2628
phone (str): Phone of the customer. Optional.
2729
address (CustomerAddress): Address object of the customer. Optional.
@@ -30,9 +32,10 @@ class CustomerRequest(BaseModel):
3032

3133
legal_name: str
3234
tax_id: str
35+
tax_system: SATRegimeCode
3336
email: str
3437
phone: Optional[str]
35-
address: Optional[CustomerAddress]
38+
address: CustomerAddress
3639

3740

3841
class CustomerUpdateRequest(BaseModel):
@@ -43,6 +46,7 @@ class CustomerUpdateRequest(BaseModel):
4346
Attributes:
4447
legal_name (str): Full name of the customer. Optional.
4548
tax_id (str): RFC of the customer. Optional.
49+
tax_system: SATRegimeCode regime code from SAT
4650
email (str): Email of the customer. Optional.
4751
phone (str): Phone of the customer. Optional.
4852
address (CustomerAddress): Address object of the customer. Optional.
@@ -51,6 +55,7 @@ class CustomerUpdateRequest(BaseModel):
5155

5256
legal_name: Optional[str]
5357
tax_id: Optional[str]
58+
tax_system: Optional[SATRegimeCode]
5459
email: Optional[str]
5560
phone: Optional[str]
5661
address: Optional[CustomerAddress]
@@ -72,8 +77,8 @@ class Customer(Creatable, Queryable, Retrievable, Updatable):
7277
tax_id (str): RFC of the customer.
7378
email (str): Email of the customer.
7479
address (CustomerAddress): Address data of the model. Optional.
80+
tax_system (SATRegimeCode): Enum from catalogue of SAT
7581
phone (str): Phone of the customer. Defaults to `None`.
76-
7782
"""
7883

7984
_resource: ClassVar = 'customers'
@@ -83,7 +88,8 @@ class Customer(Creatable, Queryable, Retrievable, Updatable):
8388
legal_name: str
8489
tax_id: str
8590
email: str
86-
address: Optional[CustomerAddress]
91+
address: CustomerAddress
92+
tax_system: Optional[SATRegimeCode] = None
8793
phone: Optional[str] = None
8894

8995
@classmethod

facturapi/resources/invoices.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class to create the resource and a class to represent an
1818
Namespace,
1919
ProductBasicInfo,
2020
)
21+
from ..types.queries import InvoiceQuery
2122
from .base import Creatable, Deletable, Downloadable, Queryable, Retrievable
2223
from .customers import Customer, CustomerRequest
2324
from .resources import retrieve_property
@@ -49,7 +50,7 @@ class InvoiceItem(BaseModel):
4950
product: Union[
5051
str, ProductBasicInfo, Dict
5152
] # TO DO: Change Dict for ProductRequest
52-
custom_keys: Optional[List[str]]
53+
customs_keys: Optional[List[str]]
5354
complement: Optional[str]
5455
parts: Optional[List[ItemPart]]
5556
property_tax_account: Optional[str]
@@ -142,6 +143,7 @@ class Invoice(Creatable, Deletable, Downloadable, Queryable, Retrievable):
142143

143144
_resource: ClassVar = 'invoices'
144145
_relations: ClassVar = ['customer']
146+
_query_params = InvoiceQuery
145147

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

177179
@classmethod
178-
def cancel(cls, invoice_id: str) -> 'Invoice':
180+
def cancel(cls, invoice_id: str, motive: str) -> 'Invoice':
179181
"""Cancel an invoice.
180182
181183
Calls a DELETE request on invoice resource.
@@ -187,7 +189,7 @@ def cancel(cls, invoice_id: str) -> 'Invoice':
187189
Invoice: The cancelled invoice resource.
188190
189191
"""
190-
return cast('Invoice', cls._delete(invoice_id))
192+
return cast('Invoice', cls._delete(invoice_id, **dict(motive=motive)))
191193

192194
@property
193195
def customer(self) -> Customer:

facturapi/types/enums.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class InvoiceUse(str, Enum):
5757
gastos_transportacion_escolar = 'D08'
5858
cuentas_ahorro_pensiones = 'D09'
5959
servicios_educativos = 'D10'
60-
por_definir = 'P01'
60+
sin_efectos_fiscales = 'S01'
61+
pagos = 'CP01'
62+
nomina = 'CN01'
6163

6264

6365
class PaymentForm(str, Enum):

facturapi/types/queries.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ def dict(self, *args, **kwargs) -> Dict[str, Any]:
7171
kwargs.setdefault('exclude_unset', True)
7272
d = super().dict(*args, **kwargs)
7373
return d
74+
75+
76+
class InvoiceQuery(BaseQuery):
77+
motive: Optional[str]

facturapi/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = '0.0.2' # pragma: no cover
1+
__version__ = '0.0.3' # pragma: no cover
22
CLIENT_VERSION = __version__

requirements-test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pytest==6.2.*
22
pytest-cov==3.0.*
33
pytest-vcr==1.0.*
4-
black==21.9b0
4+
black==22.3.0
55
isort==5.7.*
66
flake8==3.8.*
77
mypy==0.812

0 commit comments

Comments
 (0)