コード例 #1
0
ファイル: models.py プロジェクト: gmimano/commcaretest
    def to_xml(self, E=None, **kwargs):
        if not E:
            E = XML()

        tx_type = 'balance' if self.action in (
            StockActions.STOCKONHAND,
            StockActions.STOCKOUT,
        ) else 'transfer'

        attr = {}
        if self.timestamp:
            attr['date'] = dateparse.json_format_datetime(self.timestamp)

        attr['section-id'] = 'stock'
        if tx_type == 'balance':
            attr['entity-id'] = self.case_id
        elif tx_type == 'transfer':
            here, there = ('dest', 'src') if self.action == StockActions.RECEIPTS else ('src', 'dest')
            attr[here] = self.case_id
            # no 'there' for now
            if self.subaction:
                attr['type'] = self.subaction

        return getattr(E, tx_type)(
            E.entry(
                id=self.product_id,
                quantity=str(self.quantity if self.action != StockActions.STOCKOUT else 0),
            ),
            **attr
        )
コード例 #2
0
ファイル: models.py プロジェクト: elbowink/commcare-hq
    def to_xml(self, E=None, **kwargs):
        if not E:
            E = XML()

        return E.entry(
            id=self.product_id,
            quantity=str(self.quantity if self.action != StockActions.STOCKOUT else 0),
        )
コード例 #3
0
ファイル: helpers.py プロジェクト: ye-man/commcare-hq
    def to_xml(self, E=None, **kwargs):
        if not E:
            E = XML()

        return E.entry(
            id=self.product_id,
            quantity=str(self.quantity if self.action != StockActions.STOCKOUT
                         else 0),
        )
コード例 #4
0
ファイル: sms.py プロジェクト: puttarajubr/commcare-hq
def to_instance(data):
    """convert the parsed sms stock report into an instance like what would be
    submitted from a commcare phone"""
    E = XML()
    M = XML(const.META_XMLNS, 'jrm')

    deviceID = get_device_id(data)
    timestamp = json_format_datetime(data['timestamp'])

    transactions = data['transactions']
    category = set(tx.category for tx in transactions).pop()
    stock_blocks = convert_transactions_to_blocks(E, transactions)

    if category == 'stock':
        root = E.stock_report(
            M.meta(
                M.userID(data['user']._id),
                M.deviceID(deviceID),
                M.timeStart(timestamp),
                M.timeEnd(timestamp)
            ),
            E.location(data['location']._id),
            *stock_blocks
        )
        return etree.tostring(root, encoding='utf-8', pretty_print=True)
    else:
        return requisition_case_xml(data, stock_blocks)
コード例 #5
0
ファイル: sms.py プロジェクト: dszafranek/commcare-hq
def to_instance(data):
    """convert the parsed sms stock report into an instance like what would be
    submitted from a commcare phone"""
    E = XML()
    M = XML(const.META_XMLNS, 'jrm')

    deviceID = ''
    if data.get('phone'):
        deviceID = 'sms:%s' % data['phone']
    timestamp = json_format_datetime(data['timestamp'])

    transactions = data['transactions']
    category = set(tx.category for tx in transactions).pop()
    factory = {
        'stock': E.stock_report,
        'requisition': E.requisition,
    }[category]

    root = factory(
        M.meta(
            M.userID(data['user']._id),
            M.deviceID(deviceID),
            M.timeStart(timestamp),
            M.timeEnd(timestamp)
        ),
        E.location(data['location']._id),
        *[tx.to_xml() for tx in transactions]
    )

    return root
コード例 #6
0
ファイル: sms.py プロジェクト: xbryanc/commcare-hq
def to_instance(data):
    """convert the parsed sms stock report into an instance like what would be
    submitted from a commcare phone"""
    E = XML()
    M = XML(const.META_XMLNS, 'jrm')

    deviceID = get_device_id(data)
    timestamp = json_format_datetime(data['timestamp'])

    transactions = data['transactions']
    category = set(tx.category for tx in transactions).pop()
    stock_blocks = convert_transactions_to_blocks(E, transactions)

    if category == 'stock':
        root = E.stock_report(
            M.meta(M.userID(data['user']._id), M.deviceID(deviceID),
                   M.timeStart(timestamp), M.timeEnd(timestamp)),
            E.location(data['location']._id), *stock_blocks)
        return etree.tostring(root, encoding='utf-8', pretty_print=True)
    else:
        raise RequisitionsHaveBeenRemoved()