예제 #1
0
    def test_ingress(self):
        with self.sessionmanager:
            init_prod_cant = self.prod_api.get_producto('1',
                                                        bodega_id=1).cantidad
            t = TransMetadata(origin=None,
                              dest=1,
                              user=0,
                              trans_type=TransType.INGRESS,
                              ref='hello world')
            items = [
                Item(self.prod_api.get_producto('1'), 10),
                Item(self.prod_api.get_producto('2'), 10)
            ]
            transfer = Transferencia(t, items)
            trans = self.trans_api.save(transfer)
            self.assertEquals(t.status, Status.NEW)

        with self.sessionmanager:
            trans = self.trans_api.commit(trans)
            self.assertEquals(trans.meta.status, Status.COMITTED)

        with self.sessionmanager:
            post_prod_cant = self.prod_api.get_producto('1',
                                                        bodega_id=1).cantidad
            self.assertEquals(Decimal(10), post_prod_cant - init_prod_cant)

        with self.sessionmanager:
            trans = self.trans_api.delete(trans)
        with self.sessionmanager:
            last_cant = self.prod_api.get_producto('1', bodega_id=1).cantidad
            self.assertEquals(trans.meta.status, Status.DELETED)
            self.assertEquals(init_prod_cant, last_cant)
def main():
    with sessionmanager as session:
        all_trans = session.query(NTransferencia)
        for t in all_trans:
            content = requests.get("http://192.168.0.22/app/api/ingreso/{}".format(t.id))
            transfer = Transferencia.deserialize(content.json())
            value = get_value(transfer)
            t.value = value
        session.commit()
def main():
    with sessionmanager as session:
        all_trans = session.query(NTransferencia)
        for t in all_trans:
            content = requests.get(
                'http://192.168.0.22/app/api/ingreso/{}'.format(t.id))
            transfer = Transferencia.deserialize(content.json())
            value = get_value(transfer)
            t.value = value
        session.commit()
예제 #4
0
 def forward_request(self, work):
     print 'work', work['work'], type(work['work'])
     work = work['work']
     work = WorkObject.deserialize(json.loads(work))
     if work.objtype == WorkObject.INV:
         if work.action == WorkObject.DELETE:
             work.content = InvMovementMeta(uid=work.objid)
         else:
             work.content = InvMetadata.deserialize(work.content)
     elif work.objtype == WorkObject.INV_TRANS:
         work.content = Invoice.deserialize(work.content)
     elif work.objtype == WorkObject.TRANS:
         work.content = Transferencia.deserialize(work.content)
     else:
         print 'ERROR'
         return -1 # RETRY
     r = self.exec_work(work)
     if r.status_code == 200:
         return -2  # OK
     else:
         return -1  # RETRY
예제 #5
0
def main():
    start = datetime.date(2015, 9, 1)
    end = datetime.date(2016, 6, 12)

    with dbapi.session:
        for x in transapi.search_metadata_by_date_range(start, end):
            raw = requests.get('http://192.168.0.23/app/api/ingreso/{}'.format(x.uid))
            t = Transferencia.deserialize(json.loads(raw.text))
            total = 0
            for i in t.items:
                if i.prod.uid is None:
                    pass
                prod = dbapi.get(i.prod.uid, ProdItemGroup)
                if prod is None:
                    print i.prod.uid
                    continue
                if prod.base_price_usd is None:
                    continue
                total += prod.base_price_usd * i.cant
            t.meta.value = total

            dbapi.db_session.query(NTransferencia).filter_by(id=t.meta.uid).update({'value': total})
예제 #6
0
def crear_ingreso():
    json_content = request.body.read()
    json_dict = json_loads(json_content)
    ingreso = Transferencia.deserialize(json_dict)
    ingreso = transapi.save(ingreso)
    return {'codigo': ingreso.meta.uid}
예제 #7
0
def crear_ingreso():
    json_content = request.body.read()
    json_dict = json_loads(json_content)
    ingreso = Transferencia.deserialize(json_dict)
    ingreso = transapi.save(ingreso)
    return {'codigo': ingreso.meta.uid}