Example #1
0
def put(bag):
    pg_db = PostgresDatabase()

    operation_data = {
        "type": "Operations",
        "branch_id": bag['branch_id'],
        "document_id": bag['document_id'],
        "product_id": bag['product_id'],
        "unit_id": bag['unit_id'],
        "quantity": bag['quantity'],
        "currency_id": bag['currency_id'],
        "purpose_id": bag.get('purpose_id', None),
        "quote_unit_price": bag['quote_unit_price'],
        "total_cost": bag['total_cost'],
        "additional_cost": bag.get('additional_cost', 0),
        "delivery_date": bag.get('delivery_date', None),
        "is_due": bag.get('is_due', False),
        "due_date": bag.get('due_date', None),
        "is_advance": bag.get('is_advance', None),
        "employee_id": bag.get('employee_id', None),
        "contractor_id": bag.get('contractor_id', None),
        "from_branch_id": bag.get('from_branch_id', None),
        "comment": bag.get('comment', None),
        "operation_status": bag.get('operation_status', 'active')
    }
    if '_id' in bag:
        operation_data['_id'] = bag['_id']
    if '_rev' in bag:
        operation_data['_rev'] = bag['_rev']
    _id, _rev = pg_db.store(operation_data, new_edits=True)
    return {"id": _id, "rev": _rev}
Example #2
0
    def commit(self, bag):
        pg_db = PostgresDatabase()
        bag['type'] = 'Document'
        bag['document_status'] = 'committed'
        _id, _rev = pg_db.store(bag)

        amount = 0
        for product in bag['data']['products']:
            operation_data = {
                "branch_id": bag['branch_id'],
                "document_id": _id,
                "product_id": product['product_id'],
                "unit_id": product['unit_id'],
                "quantity": product['quantity'],
                "currency_id": bag['data']['currency_id'],
                "purpose_id": bag['data'].get('purpose_id', None),
                "quote_unit_price": product['quote_unit_price'],
                "total_cost": product['total_cost'],
                "additional_cost": product.get('additional_cost', 0),
                "delivery_date": bag['data'].get('delivery_date', None),
                "is_due": bag['data'].get('is_due', False),
                "due_date": bag['data'].get('due_date', None),
                "is_advance": bag['data'].get('is_advance', None),
                "employee_id": bag['data'].get('employee_id', None),
                "contractor_id": bag['data'].get('contractor_id', None),
                "comment": u'{}\n{}'.format(bag['title'], bag.get('short_desc', u''))
            }

            controller.call('operation.put', operation_data)

            amount += product['total_cost'] + product.get('additional_cost', 0)

        payment_data = {
            "branch_id": bag['branch_id'],
            "document_id": _id,
            "amount": amount,
            "currency_id": bag['data']['currency_id'],
            "payment_date": datetime.now(),
            "payment_direction": 'we_give_them' if 'is_due' in bag['data'] and bag['data'][
                                                                                   'is_due'] is True else 'they_to_us',
            "archive": False,
            "payment_type": 'debt' if 'is_due' in bag['data'] and bag['data']['is_due'] is True else 'cash',
            "data": {
                "comment": u'{}\n{}'.format(bag['title'], bag.get('short_desc', u''))
            }
        }

        if 'is_advance' in bag['data'] and bag['data']['is_advance'] == True:
            payment_data['payment_direction'] = 'they_to_us'
            payment_data['payment_type'] = 'repayment'
            payment_data['data']['employee_id'] = bag['data']['employee_id']
        else:
            payment_data['data']['contractor_id'] = bag['data']['contractor_id']

        controller.call('accounting.put', payment_data)

        return {"id": _id, "rev": _rev}
Example #3
0
    def rollback(self, bag):
        pg_db = PostgresDatabase()
        document = orm_to_json(g.tran.query(db.Document).filter_by(_deleted='infinity', _id=bag[ID]).one())
        document['type'] = 'Document'
        document['document_status'] = 'canceled'
        _id, _rev = pg_db.store(document)

        for payment in g.tran.query(db.Payments).filter_by(_deleted='infinity', document_id=_id).all():
            payment = orm_to_json(payment)
            payment['payment_status'] = 'canceled'
            controller.call('accounting.put', payment)

        for operation in g.tran.query(db.Operations).filter_by(_deleted='infinity', document_id=_id).all():
            operation = orm_to_json(operation)
            operation['operation_status'] = 'canceled'
            controller.call('operation.put', operation)
Example #4
0
def put(bag):
    pg_db = PostgresDatabase()

    accounting_data = {
        "type":
        "Payments",
        "branch_id":
        bag['branch_id'],
        "document_id":
        bag.get('document_id', None),
        "amount":
        bag['amount'],
        "currency_id":
        bag['currency_id'],
        "payment_date":
        bag['payment_date'] if 'payment_date' in bag else datetime.now(),
        "payment_direction":
        bag['payment_direction'],
        "payment_status":
        bag.get('payment_status', 'active'),
        "payment_type":
        bag['payment_type'],
        "data": {}
    }
    if '_id' in bag:
        accounting_data['_id'] = bag['_id']
    if '_rev' in bag:
        accounting_data['_rev'] = bag['_rev']
    if 'employee_id' in bag['data']:
        accounting_data['data']['employee_id'] = bag['data']['employee_id']
    if 'contractor_id' in bag['data']:
        accounting_data['data']['contractor_id'] = bag['data']['contractor_id']
    if 'branch_id' in bag['data']:
        accounting_data['data']['branch_id'] = bag['data']['branch_id']
    if 'comment' in bag['data']:
        accounting_data['data']['comment'] = bag['data']['comment']
    _id, _rev = pg_db.store(accounting_data, new_edits=True)
    return {"id": _id, "rev": _rev}
Example #5
0
    def commit(self, bag):
        pg_db = PostgresDatabase()
        bag['type'] = 'Document'
        bag['document_status'] = 'committed'
        _id, _rev = pg_db.store(bag)

        amount = 0
        for product in bag['data']['products']:
            operation_data = {
                "branch_id": bag['branch_id'],
                "document_id": _id,
                "product_id": product['product_id'],
                "unit_id": product['unit_id'],
                "quantity": product['quantity'] * -1,
                "currency_id": bag['data']['currency_id'],
                "quote_unit_price": product['quote_unit_price'],
                "total_cost": product['total_cost'],
                "additional_cost": product.get('additional_cost', 0),
                "delivery_date": bag['data'].get('delivery_date', None),
                "from_branch_id": bag['data']['from_branch_id'],
                "comment": u'{}\n{}'.format(bag['title'], bag.get('short_desc', u''))
            }

            controller.call('operation.put', operation_data)

            operation_data = {
                "branch_id": bag['from_branch_id'],
                "document_id": _id,
                "product_id": product['product_id'],
                "unit_id": product['unit_id'],
                "quantity": product['quantity'],
                "currency_id": bag['data']['currency_id'],
                "quote_unit_price": product['quote_unit_price'],
                "total_cost": product['total_cost'],
                "additional_cost": product.get('additional_cost', 0),
                "delivery_date": bag['data'].get('delivery_date', None),
                "from_branch_id": bag['data']['branch_id'],
                "comment": u'{}\n{}'.format(bag['title'], bag.get('short_desc', u''))
            }

            controller.call('operation.put', operation_data)

            amount += product['total_cost'] + product.get('additional_cost', 0)

        payment_data = {
            "branch_id": bag['branch_id'],
            "documents_id": [_id],
            "amount": amount,
            "currency_id": bag['data']['currency_id'],
            "payment_date": datetime.now(),
            "payment_direction": 'they_to_us',
            "archive": False,
            "payment_type": 'cash',
            "data": {
                "branch_id": bag['data']['branch_id'],
                "comment": u'{}\n{}'.format(bag['title'], bag.get('short_desc', u''))
            }
        }

        controller.call('accounting.put', payment_data)

        payment_data = {
            "branch_id": bag['data']['branch_id'],
            "document_id": _id,
            "amount": amount,
            "currency_id": bag['data']['currency_id'],
            "payment_date": datetime.now(),
            "payment_direction": 'we_give_them',
            "archive": False,
            "payment_type": 'cash',
            "data": {
                "branch_id": bag['branch_id'],
                "comment": u'{}\n{}'.format(bag['title'], bag.get('short_desc', u''))
            }
        }

        controller.call('accounting.put', payment_data)

        return {"id": _id, "rev": _rev}