easybill_client/generated/async/easybill_generated_async/models/document_position.py
claudi caacb339dd Add unit tests for authentication and webhook parsing
- Implement tests for basic and bearer authentication headers in `test_auth.py`.
- Create tests for the `EasybillWebhookParser` in `test_webhooks.py`, covering JSON and form-encoded payloads, as well as a generic parse and acknowledgement method.
2026-04-17 10:20:12 +02:00

256 lines
14 KiB
Python

# coding: utf-8
"""
easybill REST API
The first version of the easybill REST API. [CHANGELOG](https://api.easybill.de/rest/v1/CHANGELOG.md) ## Authentication You can choose between two available methods: `Basic Auth` or `Bearer Token`. In each HTTP request, one of the following HTTP headers is required: ``` # Basic Auth Authorization: Basic base64_encode('<email>:<api_key>') # Bearer Token Authorization: Bearer <api_key> ``` ## Limitations ### Request Limit * PLUS: 10 requests per minute * BUSINESS: 60 requests per minute If the limit is exceeded, you will receive the HTTP error: `429 Too Many Requests` ### Result Limit All result lists are limited to 100 by default. This limit can be increased by the query parameter `limit` to a maximum of 1000. ## Query filter Many list resources can be filtered. In `/documents` you can filter e.g. by number with `/documents?number=111028654`. If you want to filter multiple numbers, you can either enter them separated by commas `/documents?number=111028654,222006895` or as an array `/documents?number[]=111028654&number[]=222006895`. **Warning**: The maximum size of an HTTP request line in bytes is 4094. If this limit is exceeded, you will receive the HTTP error: `414 Request-URI Too Large` ### Escape commas in query You can escape commans in query `name=Patrick\\, Peter` if you submit the header `X-Easybill-Escape: true` in your request. ## Property login_id This is the login of your admin or employee account. ## Date and Date-Time format Please use the timezone `Europe/Berlin`. * **date** = *Y-m-d* = `2016-12-31` * **date-time** = *Y-m-d H:i:s* = `2016-12-31 03:13:37` Date or datetime can be `null` because the attributes have been added later and the entry is older.
The version of the OpenAPI document: 1.96.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python
class DocumentPosition(BaseModel):
"""
DocumentPosition
""" # noqa: E501
number: Optional[StrictStr] = 'null'
description: Optional[StrictStr] = 'null'
document_note: Optional[StrictStr] = Field(default=None, description="This field can be used in the document text areas with the liquid placeholder {{document.item_notes}}. Every note is only displayed once for every kind of product. This is useful if you want to add something like an instruction.")
quantity: Optional[Union[StrictFloat, StrictInt]] = 1.0
quantity_str: Optional[Annotated[str, Field(strict=True, max_length=10)]] = Field(default=None, description="Use quantity_str if you want to set a quantity like: 1:30 h or 3x5 m. quantity_str overwrites quantity.")
unit: Optional[StrictStr] = 'null'
type: Optional[StrictStr] = 'POSITION'
position: Optional[StrictInt] = Field(default=None, description="Automatic by default (first item: 1, second item: 2, ...)")
single_price_net: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Price in cents, despite being of type float (e.g. 150 = 1.50€, but also 150.0 = 1.50€)")
single_price_gross: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Price in cents, despite being of type float (e.g. 150 = 1.50€, but also 150.0 = 1.50€)")
vat_percent: Optional[Union[StrictFloat, StrictInt]] = 0.0
discount: Optional[Union[StrictFloat, StrictInt]] = None
discount_type: Optional[StrictStr] = null
position_id: Optional[StrictInt] = Field(default=None, description="If set, values are copied from the referenced position")
total_price_net: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Price in cents, despite being of type float (e.g. 150 = 1.50€, but also 150.0 = 1.50€)")
total_price_gross: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Price in cents, despite being of type float (e.g. 150 = 1.50€, but also 150.0 = 1.50€)")
total_vat: Optional[Union[StrictFloat, StrictInt]] = None
serial_number_id: Optional[StrictStr] = None
serial_number: Optional[StrictStr] = None
booking_account: Optional[StrictStr] = 'null'
export_cost_1: Optional[StrictStr] = 'null'
export_cost_2: Optional[StrictStr] = 'null'
cost_price_net: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Price in cents, despite being of type float (e.g. 150 = 1.50€, but also 150.0 = 1.50€)")
cost_price_total: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Price in cents, despite being of type float (e.g. 150 = 1.50€, but also 150.0 = 1.50€)")
cost_price_charge: Optional[Union[StrictFloat, StrictInt]] = None
cost_price_charge_type: Optional[StrictStr] = None
item_type: Optional[StrictStr] = Field(default='UNDEFINED', alias="itemType")
id: Optional[StrictInt] = None
__properties: ClassVar[List[str]] = ["number", "description", "document_note", "quantity", "quantity_str", "unit", "type", "position", "single_price_net", "single_price_gross", "vat_percent", "discount", "discount_type", "position_id", "total_price_net", "total_price_gross", "total_vat", "serial_number_id", "serial_number", "booking_account", "export_cost_1", "export_cost_2", "cost_price_net", "cost_price_total", "cost_price_charge", "cost_price_charge_type", "itemType", "id"]
@field_validator('type')
def type_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
return value
if value not in set(['POSITION', 'POSITION_NOCALC', 'TEXT']):
raise ValueError("must be one of enum values ('POSITION', 'POSITION_NOCALC', 'TEXT')")
return value
@field_validator('discount_type')
def discount_type_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
return value
if value not in set(['PERCENT', 'AMOUNT', 'QUANTITY', 'FIX']):
raise ValueError("must be one of enum values ('PERCENT', 'AMOUNT', 'QUANTITY', 'FIX')")
return value
@field_validator('cost_price_charge_type')
def cost_price_charge_type_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
return value
if value not in set(['PERCENT', 'AMOUNT']):
raise ValueError("must be one of enum values ('PERCENT', 'AMOUNT')")
return value
@field_validator('item_type')
def item_type_validate_enum(cls, value):
"""Validates the enum"""
if value is None:
return value
if value not in set(['PRODUCT', 'SERVICE', 'UNDEFINED']):
raise ValueError("must be one of enum values ('PRODUCT', 'SERVICE', 'UNDEFINED')")
return value
model_config = ConfigDict(
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
return json.dumps(to_jsonable_python(self.to_dict()))
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of DocumentPosition from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
* OpenAPI `readOnly` fields are excluded.
"""
excluded_fields: Set[str] = set([
"total_price_net",
"total_price_gross",
"total_vat",
"serial_number_id",
"serial_number",
"cost_price_total",
"cost_price_charge",
"cost_price_charge_type",
"id",
])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# set to None if number (nullable) is None
# and model_fields_set contains the field
if self.number is None and "number" in self.model_fields_set:
_dict['number'] = None
# set to None if description (nullable) is None
# and model_fields_set contains the field
if self.description is None and "description" in self.model_fields_set:
_dict['description'] = None
# set to None if unit (nullable) is None
# and model_fields_set contains the field
if self.unit is None and "unit" in self.model_fields_set:
_dict['unit'] = None
# set to None if single_price_net (nullable) is None
# and model_fields_set contains the field
if self.single_price_net is None and "single_price_net" in self.model_fields_set:
_dict['single_price_net'] = None
# set to None if discount (nullable) is None
# and model_fields_set contains the field
if self.discount is None and "discount" in self.model_fields_set:
_dict['discount'] = None
# set to None if discount_type (nullable) is None
# and model_fields_set contains the field
if self.discount_type is None and "discount_type" in self.model_fields_set:
_dict['discount_type'] = None
# set to None if position_id (nullable) is None
# and model_fields_set contains the field
if self.position_id is None and "position_id" in self.model_fields_set:
_dict['position_id'] = None
# set to None if booking_account (nullable) is None
# and model_fields_set contains the field
if self.booking_account is None and "booking_account" in self.model_fields_set:
_dict['booking_account'] = None
# set to None if export_cost_1 (nullable) is None
# and model_fields_set contains the field
if self.export_cost_1 is None and "export_cost_1" in self.model_fields_set:
_dict['export_cost_1'] = None
# set to None if export_cost_2 (nullable) is None
# and model_fields_set contains the field
if self.export_cost_2 is None and "export_cost_2" in self.model_fields_set:
_dict['export_cost_2'] = None
# set to None if cost_price_net (nullable) is None
# and model_fields_set contains the field
if self.cost_price_net is None and "cost_price_net" in self.model_fields_set:
_dict['cost_price_net'] = None
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of DocumentPosition from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"number": obj.get("number") if obj.get("number") is not None else 'null',
"description": obj.get("description") if obj.get("description") is not None else 'null',
"document_note": obj.get("document_note"),
"quantity": obj.get("quantity") if obj.get("quantity") is not None else 1.0,
"quantity_str": obj.get("quantity_str"),
"unit": obj.get("unit") if obj.get("unit") is not None else 'null',
"type": obj.get("type") if obj.get("type") is not None else 'POSITION',
"position": obj.get("position"),
"single_price_net": obj.get("single_price_net"),
"single_price_gross": obj.get("single_price_gross"),
"vat_percent": obj.get("vat_percent") if obj.get("vat_percent") is not None else 0.0,
"discount": obj.get("discount"),
"discount_type": obj.get("discount_type") if obj.get("discount_type") is not None else null,
"position_id": obj.get("position_id"),
"total_price_net": obj.get("total_price_net"),
"total_price_gross": obj.get("total_price_gross"),
"total_vat": obj.get("total_vat"),
"serial_number_id": obj.get("serial_number_id"),
"serial_number": obj.get("serial_number"),
"booking_account": obj.get("booking_account") if obj.get("booking_account") is not None else 'null',
"export_cost_1": obj.get("export_cost_1") if obj.get("export_cost_1") is not None else 'null',
"export_cost_2": obj.get("export_cost_2") if obj.get("export_cost_2") is not None else 'null',
"cost_price_net": obj.get("cost_price_net"),
"cost_price_total": obj.get("cost_price_total"),
"cost_price_charge": obj.get("cost_price_charge"),
"cost_price_charge_type": obj.get("cost_price_charge_type"),
"itemType": obj.get("itemType") if obj.get("itemType") is not None else 'UNDEFINED',
"id": obj.get("id")
})
return _obj