def main(): with sessionmanager as session: all_client = get_all_client() meta_item = defaultdict(list) bodega_id = 1 tax_percent = 12 for meta, item, prod in query_all_fully_joined(session, date(2015, 6, 1), date(2015, 6, 30), bodega_id): meta_item[meta].append((item, prod)) for m, i in meta_item.items(): almacen_id = bodega_id codigo = m.codigo if codigo < 0: codigo = abs(codigo) almacen_id = 3 store = prodapi.store.get(almacen_id) meta = InvMetadata( almacen_id=almacen_id, almacen_name=store.nombre, almacen_ruc=store.ruc, codigo=str(codigo), user=m.vendedor_id, client=all_client[m.cliente_id], timestamp=datetime.combine(m.fecha, time()), payment_format=newpayformat(m.pago), total=money_to_cent(m.total), tax_percent=tax_percent, ) meta.status = Status.DELETED if m.eliminado else Status.COMITTED meta.subtotal = int(meta.total / (1 + tax_percent / 100.0)) meta.tax = meta.total - meta.subtotal def make_item(ix): p = Product().merge_from(ix[1]) p.precio1 = money_to_cent(ix[0].precio) return Item(p, ix[0].cantidad) items = map(make_item, i) inv = Invoice(meta, items) invapi.save(inv) print len(meta_item) print 'end'
def decode_db_row_with_client(db_raw): m = InvMetadata.from_db_instance(db_raw[0]) m.client.nombres = decode_str(db_raw.nombres) m.client.apellidos = decode_str(db_raw.apellidos) if not m.almacen_name: alm = dbapi.get(m.almacen_id, Store) m.almacen_name = alm.nombre return m
def main(): with sessionmanager as session: all_client = get_all_client() meta_item = defaultdict(list) bodega_id = 1 tax_percent = 12 for meta, item, prod in query_all_fully_joined( session, date(2015, 6, 1), date(2015, 6, 30), bodega_id): meta_item[meta].append((item, prod)) for m, i in meta_item.items(): almacen_id = bodega_id codigo = m.codigo if codigo < 0: codigo = abs(codigo) almacen_id = 3 store = prodapi.store.get(almacen_id) meta = InvMetadata( almacen_id=almacen_id, almacen_name=store.nombre, almacen_ruc=store.ruc, codigo=str(codigo), user=m.vendedor_id, client=all_client[m.cliente_id], timestamp=datetime.combine(m.fecha, time()), payment_format=newpayformat(m.pago), total=money_to_cent(m.total), tax_percent=tax_percent, ) meta.status = Status.DELETED if m.eliminado else Status.COMITTED meta.subtotal = int(meta.total / (1 + tax_percent/100.0)) meta.tax = meta.total - meta.subtotal def make_item(ix): p = Product().merge_from(ix[1]) p.precio1 = money_to_cent(ix[0].precio) return Item(p, ix[0].cantidad) items = map(make_item, i) inv = Invoice(meta, items) invapi.save(inv) print len(meta_item) print 'end'
def old_to_new_invoice(old_inv, all_client): meta_item = defaultdict(list) for meta, item, prod in old_inv: meta_item[meta.id].append((meta, item, prod)) print 'total record', len(meta_item) for m, i in meta_item.items(): m = i[0][0] almacen_id = m.bodega_id codigo = m.codigo if codigo < 0: codigo = abs(codigo) almacen_id = 3 tax_percent = 12 if almacen_id != 2 else 0 store = prodapi.store.get(almacen_id) meta = InvMetadata( almacen_id=almacen_id, almacen_name=store.nombre, almacen_ruc=store.ruc, codigo=str(codigo), user=m.vendedor_id, client=all_client[m.cliente_id], timestamp=datetime.combine(m.fecha, time(1, 0, 0)), payment_format=newpayformat(m.pago), total=money_to_cent(m.total), tax_percent=tax_percent, ) meta.status = Status.DELETED if m.eliminado else Status.COMITTED meta.subtotal = int(meta.total / (1 + tax_percent / 100.0)) meta.tax = meta.total - meta.subtotal def make_item(ix): p = Product().merge_from(ix[2]) p.precio1 = money_to_cent(ix[1].precio) return Item(p, ix[1].cantidad) items = map(make_item, i) inv = Invoice(meta, items) yield inv
def old_to_new_invoice(old_inv, all_client): meta_item = defaultdict(list) for meta, item, prod in old_inv: meta_item[meta.id].append((meta, item, prod)) print "total record", len(meta_item) for m, i in meta_item.items(): m = i[0][0] almacen_id = m.bodega_id codigo = m.codigo if codigo < 0: codigo = abs(codigo) almacen_id = 3 tax_percent = 12 if almacen_id != 2 else 0 store = prodapi.store.get(almacen_id) meta = InvMetadata( almacen_id=almacen_id, almacen_name=store.nombre, almacen_ruc=store.ruc, codigo=str(codigo), user=m.vendedor_id, client=all_client[m.cliente_id], timestamp=datetime.combine(m.fecha, time(1, 0, 0)), payment_format=newpayformat(m.pago), total=money_to_cent(m.total), tax_percent=tax_percent, ) meta.status = Status.DELETED if m.eliminado else Status.COMITTED meta.subtotal = int(meta.total / (1 + tax_percent / 100.0)) meta.tax = meta.total - meta.subtotal def make_item(ix): p = Product().merge_from(ix[2]) p.precio1 = money_to_cent(ix[1].precio) return Item(p, ix[1].cantidad) items = map(make_item, i) inv = Invoice(meta, items) yield inv
def test_inv(self): with self.sessionmanager: init_prod_cant = self.prod_api.get_producto('1', bodega_id=1).cantidad client = Client() client.codigo = '123' t = InvMetadata(client=client, codigo='123', user='******', total=123, subtotal=123, tax=123, discount=0, bodega_id=1, almacen_id=1) inv = Invoice() inv.meta = t inv.items = [Item(self.prod_api.get_producto('1'), 5)] invoice = self.inv_api.save(inv) self.assertEquals( self.inv_api.get_doc(invoice.meta.uid).meta.codigo, '123') x = self.inv_api.commit(invoice) self.assertEquals(Status.COMITTED, x.meta.status) new_inv = self.prod_api.get_producto('1', bodega_id=1).cantidad self.assertEquals(-5, new_inv - init_prod_cant) x = self.inv_api.delete(invoice) self.assertEquals(Status.DELETED, x.meta.status) new_inv = self.prod_api.get_producto('1', bodega_id=1).cantidad self.assertEquals(0, new_inv - init_prod_cant) today = datetime.datetime.now() yesterday = today - datetime.timedelta(days=1) searched = list( self.inv_api.search_metadata_by_date_range(start=yesterday, end=today)) print searched self.assertEquals(1, len(searched))
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
def make_one_inv(day, codigo, items): invmeta = InvMetadata() invmeta.codigo = codigo invmeta.timestamp = day invmeta.status = Status.NEW invmeta.bodega_id = 1 invmeta.almacen_ruc = '0992584092001' invmeta.almacen_id = 3 invmeta.payment_format = 'EFECTIVO' invmeta.subtotal = sum((int(i.cant * i.prod.precio1) for i in items)) invmeta.tax = int(invmeta.subtotal * 0.12) invmeta.tax_percent = int(invmeta.subtotal * 0.12) invmeta.total = invmeta.subtotal + invmeta.tax invmeta.discount = 0 invmeta.client = Client() invmeta.client.name = 'QUINAL SA' invmeta.client.codigo = '0992337168001' inv = Invoice(invmeta, items) return inv