def get_calculated_remains(storage_id): remains = dumps( get_data_of_model(Remain, filters=Remain.storage == storage_id)) acts = dumps( get_data_of_model(Act, filters=(and_(Act.storage == storage_id, Act.is_active == True, Act.is_upload == False)))) acts = map(lambda act: act['id'], acts) acts_strings = dumps( get_data_of_model(ActTable, filters=ActTable.act.in_(acts))) return calculate_remains(remains, acts_strings)
def get_acts_for_storage(count, act_type, upload_start, upload_end, start_date, end_date): ''' Get data of acts for storage. :param storage_id: ID ''' filters = [] if upload_start: filters.append(Act.upload_date >= upload_start) if upload_end: filters.append(Act.upload_date <= upload_end) if start_date: filters.append(Act.act_date >= start_date) if end_date: filters.append(Act.act_date <= end_date) return dumps( get_data_of_model(Act, limit=count, order_by=Act.id.desc(), filters=and_(*filters) if filters else None))
def get_table_of_acts(act_id): ''' Get data of table from act. :param act_id: ID of act. ''' return dumps(get_data_of_model(ActTable, filters=ActTable.act == act_id))
def get_storages_for_subdivision(): ''' Get data of storages for subdivision. :param subdivision_id: ID of subdivision. ''' return dumps(get_data_of_model(Storage))
def delete_storekeeper(storekeeper_name): session = create_session(DATABASES['main'].metadata.bind) session.query(Storekeeper).filter( Storekeeper.name == storekeeper_name).delete() session.commit() return [ str(storekeeper.name) for storekeeper in get_data_of_model(Storekeeper) ]
def genereate_acts(subdivision_id): ''' From active acts with type is 1 generate acts with type 0. ''' new_acts = [] new_acts_rows = [] acts = _get_active_acts(subdivision_id) session = create_session(DATABASES['main'].metadata.bind) act_rows = dumps(get_data_of_model(ActTable, filters=ActTable.act.in_(_get_act_ids(acts)))) for act in dumps(acts): new_act = _get_act_from_act_list(act, new_acts) if not new_act: new_act = _create_new_act(act) new_acts.append(new_act) for act_row in _get_act_rows(act, act_rows): new_row = ActTable(act_relation=new_act, date_of_write_off=act['date'], **_get_new_row(act_row)) new_acts_rows.append(new_row) session.add_all(new_acts) session.add_all(new_acts_rows) session.commit()
def _append_data_for_model(self, model, filters): for out_value in get_data_of_model(model, filters=filters.get( model.__tablename__), session=self.out_session): self._append_value(out_value, model)
def get_subdivisions(): ''' Get data of subdivisions. ''' return dumps(get_data_of_model(Subdivision))
def get_storekeepers(): return [ str(storekeeper.name) for storekeeper in get_data_of_model(Storekeeper) ]
def get_main_things(): ''' Get data of main things. ''' return dumps(get_data_of_model(MainThing))
def _get_active_acts(subdivision_id): return get_data_of_model(Act, filters=(and_(Act.subdivision == subdivision_id, Act.is_active == True, Act.is_upload == False, Act.act_type == 1)))