Ejemplo n.º 1
0
 def create(data):
     product = Product(
         name = data["name"],
         stock = data["stock"],
         income = Account.create(data["income"]),
         profit = Account.create(data["profit"]),
         id_ = data["id"],
         purchases = [],
         fixedprice = data["fixedprice"]
     )
     for p in data["purchases"]:
         product.add_purchase(Purchase.create(p))
     return product
Ejemplo n.º 2
0
    def create(data, filepath=None):
        version = data["version"]

        if version >= 1 and version <= 2:
            inventory = Inventory.create(data["inventory"])
            accounts = Accounts.create(data["accounts"])
            usage = Usage.create(data["usage"], inventory, accounts)
            comment = data["comment"]
            cash_in_hand = Account.create(data["cash_in_hand"])
            date = data["date"]
            if date is not None:
                date = dateutils.fromtuple(date)

            if version >= 2:
                id_ = data["id"]
                title = data["title"]
            else:
                id_ = uuid4().hex
                title = None
        else:
            raise VersionError("Unknown document version: " % (repr(version),))

        return Document(
            usage = usage,
            accounts = accounts,
            inventory = inventory,
            date = date,
            comment = comment,
            filepath = filepath,
            version = version,
            cash_in_hand = cash_in_hand,
            title = title,
            id_ = id_
        )