# Path: netvisor/_compat.py
# PY2 = sys.version_info[0] == 2
# 
# Path: netvisor/schemas/common.py
# class DateSchema(FlattenElementSchema):
#     text = fields.Date(load_from='#text')
# 
# Path: netvisor/schemas/fields.py
# class Decimal(fields.Decimal):
#     def _deserialize(self, value, attr, data):
#         return super(Decimal, self)._deserialize(
#             value.replace(',', '.'),
#             attr,
#             data
#         )
# 
#     def serialize(self, attr, obj, accessor=None):
#         value = super(Decimal, self).serialize(attr, obj, accessor)
#         if value is missing:
#             return value
#         return str(value).replace('.', ',')
# 
# class List(fields.List):
#     def _deserialize(self, value, attr, data):
#         if not is_collection(value) and value is not None:
#             value = [value]
#         return super(List, self)._deserialize(value, attr, data)


from marshmallow import Schema, fields, post_load, pre_load
from ..._compat import string_types
from ..common import DateSchema
from ..fields import Decimal, List

    @pre_load
    def pre_load(self, data):
        if isinstance(data, string_types):
            return {
                '#text': data,
                '@substatus': None
            }
        else:
            return data


class SalesInvoiceSchema(Schema):
    netvisor_key = fields.Integer()
    number = fields.Integer(load_from='invoice_number')
    date = fields.Nested(DateSchema, load_from='invoicedate')
    status = fields.Nested(StatusSchema, load_from='invoice_status')
    customer_code = fields.String(allow_none=True)
    customer_name = fields.String()
    reference_number = fields.String()
    sum = Decimal(load_from='invoice_sum')
    open_sum = Decimal(load_from='open_sum')

    @post_load
    def preprocess_sales_invoice(self, input_data):
        input_data.update(input_data['status'])
        return input_data


class SalesInvoiceListSchema(Schema):

# Path: netvisor/_compat.py
# PY2 = sys.version_info[0] == 2
# 
# Path: netvisor/schemas/common.py
# class DateSchema(FlattenElementSchema):
#     text = fields.Date(load_from='#text')
# 
# Path: netvisor/schemas/fields.py
# class Decimal(fields.Decimal):
#     def _deserialize(self, value, attr, data):
#         return super(Decimal, self)._deserialize(
#             value.replace(',', '.'),
#             attr,
#             data
#         )
# 
#     def serialize(self, attr, obj, accessor=None):
#         value = super(Decimal, self).serialize(attr, obj, accessor)
#         if value is missing:
#             return value
#         return str(value).replace('.', ',')
# 
# class List(fields.List):
#     def _deserialize(self, value, attr, data):
#         if not is_collection(value) and value is not None:
#             value = [value]
#         return super(List, self)._deserialize(value, attr, data)


# Path: netvisor/schemas/sales_invoices/list.py
from marshmallow import Schema, fields, post_load, pre_load
from ..._compat import string_types
from ..common import DateSchema
from ..fields import Decimal, List


    @pre_load
    def pre_load(self, data):
        if isinstance(data, string_types):
            return {
                '#text': data,
                '@substatus': None
            }
        else:
            return data


class SalesInvoiceSchema(Schema):
    netvisor_key = fields.Integer()
    number = fields.Integer(load_from='invoice_number')
    date = fields.Nested(DateSchema, load_from='invoicedate')
    status = fields.Nested(StatusSchema, load_from='invoice_status')
    customer_code = fields.String(allow_none=True)
    customer_name = fields.String()
    reference_number = fields.String()
    sum = Decimal(load_from='invoice_sum')
    open_sum = Decimal(load_from='open_sum')

    @post_load
    def preprocess_sales_invoice(self, input_data):
        input_data.update(input_data['status'])
        return input_data


class SalesInvoiceListSchema(Schema):

    sales_invoices = List(