diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b1f1a0..86e2f14 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, '3.10'] + python-version: [3.8, 3.9, '3.10'] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/facturapi/resources/base.py b/facturapi/resources/base.py index bf14814..c8ba8b5 100644 --- a/facturapi/resources/base.py +++ b/facturapi/resources/base.py @@ -41,8 +41,12 @@ def __init__(self, **_): # pragma: no cover @classmethod def _from_dict(cls, obj_dict: Dict[str, Any]) -> 'Resource': - cls._filter_excess_fields(obj_dict) - return cls(**obj_dict) + try: + cls._filter_excess_fields(obj_dict) + return cls(**obj_dict) + except Exception as e: + print(obj_dict) + raise e @classmethod def _filter_excess_fields(cls, obj_dict: Dict[str, Any]) -> None: diff --git a/facturapi/resources/invoices.py b/facturapi/resources/invoices.py index f922d35..72af57f 100644 --- a/facturapi/resources/invoices.py +++ b/facturapi/resources/invoices.py @@ -17,6 +17,7 @@ class to create the resource and a class to represent an ItemPart, Namespace, ProductBasicInfo, + RelatedDocument, ) from ..types.queries import InvoiceQuery from .base import Creatable, Deletable, Downloadable, Queryable, Retrievable @@ -101,11 +102,11 @@ class InvoiceRequest(BaseModel): exchange: Optional[float] = 1.0 conditions: Optional[str] foreign_trade: Optional[Dict] - related: Optional[List[str]] - relation: Optional[InvoiceRelation] + related_documents: Optional[List[RelatedDocument]] pdf_custom_section: Optional[str] addenda: Optional[str] namespaces: Optional[Namespace] + global_: Optional[Dict] = None @dataclass @@ -161,6 +162,7 @@ class Invoice(Creatable, Deletable, Downloadable, Queryable, Retrievable): series: Optional[str] = None related: Optional[List[str]] = None relation: Optional[InvoiceRelation] = None + global_: Optional[Dict] = None @classmethod def create(cls, data: InvoiceRequest) -> 'Invoice': @@ -174,10 +176,15 @@ def create(cls, data: InvoiceRequest) -> 'Invoice': """ cleaned_data = data.dict(exclude_unset=True, exclude_none=True) + if data.global_: + cleaned_data['global'] = cleaned_data.pop('global_') + return cast('Invoice', cls._create(**cleaned_data)) @classmethod - def cancel(cls, invoice_id: str, motive: str) -> 'Invoice': + def cancel( + cls, invoice_id: str, motive: str, substitution: Optional[str] = None + ) -> 'Invoice': """Cancel an invoice. Calls a DELETE request on invoice resource. @@ -189,7 +196,10 @@ def cancel(cls, invoice_id: str, motive: str) -> 'Invoice': Invoice: The cancelled invoice resource. """ - return cast('Invoice', cls._delete(invoice_id, **dict(motive=motive))) + data = dict(motive=motive) + if substitution: + data['substitution'] = substitution + return cast('Invoice', cls._delete(invoice_id, **data)) @property def customer(self) -> Customer: diff --git a/facturapi/types/general.py b/facturapi/types/general.py index 913db82..9e6b7fc 100644 --- a/facturapi/types/general.py +++ b/facturapi/types/general.py @@ -2,6 +2,7 @@ from pydantic import BaseModel +from ..types.enums import InvoiceRelation from .validators import sanitize_dict @@ -71,3 +72,8 @@ class SanitizedDict(dict): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) sanitize_dict(self) + + +class RelatedDocument(BaseModel): + relationship: InvoiceRelation + documents: List[str] = [] diff --git a/facturapi/types/queries.py b/facturapi/types/queries.py index 9902fe4..d26f768 100644 --- a/facturapi/types/queries.py +++ b/facturapi/types/queries.py @@ -75,3 +75,4 @@ def dict(self, *args, **kwargs) -> Dict[str, Any]: class InvoiceQuery(BaseQuery): motive: Optional[str] + substitution: Optional[str] diff --git a/facturapi/version.py b/facturapi/version.py index a8ade31..9cb01cb 100644 --- a/facturapi/version.py +++ b/facturapi/version.py @@ -1,2 +1,2 @@ -__version__ = '0.1.1' # pragma: no cover +__version__ = '0.1.2.dev4' # pragma: no cover CLIENT_VERSION = __version__