def raise_supply_point_events(xform, cases): supply_points = [ SupplyPointCase.wrap(c._doc) for c in cases if c.type == SUPPLY_POINT_CASE_TYPE ] case_updates = get_case_updates(xform) for sp in supply_points: created = any( filter( lambda update: update.id == sp._id and update.creates_case(), case_updates)) supply_point_modified.send(sender=None, supply_point=sp, created=created)
def raise_events(xform, cases): supply_points = [SupplyPointCase.wrap(c._doc) for c in cases if c.type == const.SUPPLY_POINT_CASE_TYPE] case_updates = get_case_updates(xform) for sp in supply_points: created = any(filter(lambda update: update.id == sp._id and update.creates_case(), case_updates)) supply_point_modified.send(sender=None, supply_point=sp, created=created) requisition_cases = [RequisitionCase.wrap(c._doc) for c in cases if c.type == const.REQUISITION_CASE_TYPE] if requisition_cases and requisition_cases[0].requisition_status == RequisitionStatus.APPROVED: requisition_approved.send(sender=None, requisitions=requisition_cases) if requisition_cases and requisition_cases[0].requisition_status == RequisitionStatus.RECEIVED: requisition_receipt.send(sender=None, requisitions=requisition_cases) if requisition_cases and requisition_cases[0].requisition_status == RequisitionStatus.REQUESTED: requisition_modified.send(sender=None, cases=requisition_cases)
def get_data(self): # todo: this will probably have to paginate eventually if self.all_relevant_forms: sp_ids = get_relevant_supply_point_ids( self.domain, self.active_location, ) supply_points = ( SupplyPointCase.wrap(doc) for doc in iter_docs(SupplyPointCase.get_db(), sp_ids)) form_xmlnses = [ form['xmlns'] for form in self.all_relevant_forms.values() ] for supply_point in supply_points: # todo: get locations in bulk loc = supply_point.location transactions = StockTransaction.objects.filter( case_id=supply_point._id, ).exclude(report__date__lte=self.start_date).exclude( report__date__gte=self.end_date).order_by('-report__date') matched = False for trans in transactions: if XFormInstance.get( trans.report.form_id).xmlns in form_xmlnses: yield { 'loc_id': loc._id, 'loc_path': loc.path, 'name': loc.name, 'type': loc.location_type, 'reporting_status': 'reporting', 'geo': loc._geopoint, } matched = True break if not matched: yield { 'loc_id': loc._id, 'loc_path': loc.path, 'name': loc.name, 'type': loc.location_type, 'reporting_status': 'nonreporting', 'geo': loc._geopoint, }
def get_data(self): # todo: this will probably have to paginate eventually if self.all_relevant_forms: sp_ids = get_relevant_supply_point_ids( self.domain, self.active_location, ) supply_points = (SupplyPointCase.wrap(doc) for doc in iter_docs(SupplyPointCase.get_db(), sp_ids)) form_xmlnses = [form['xmlns'] for form in self.all_relevant_forms.values()] for supply_point in supply_points: # todo: get locations in bulk loc = supply_point.location transactions = StockTransaction.objects.filter( case_id=supply_point._id, ).exclude( report__date__lte=self.start_date ).exclude( report__date__gte=self.end_date ).order_by('-report__date') matched = False for trans in transactions: if XFormInstance.get(trans.report.form_id).xmlns in form_xmlnses: yield { 'loc_id': loc._id, 'loc_path': loc.path, 'name': loc.name, 'type': loc.location_type, 'reporting_status': 'reporting', 'geo': loc._geopoint, } matched = True break if not matched: yield { 'loc_id': loc._id, 'loc_path': loc.path, 'name': loc.name, 'type': loc.location_type, 'reporting_status': 'nonreporting', 'geo': loc._geopoint, }
def get_supply_points(supply_point_ids): supply_points = [] for doc in iter_docs(SupplyPointCase.get_db(), supply_point_ids): supply_points.append(SupplyPointCase.wrap(doc)) return supply_points
def raise_supply_point_events(xform, cases): supply_points = [SupplyPointCase.wrap(c._doc) for c in cases if c.type == const.SUPPLY_POINT_CASE_TYPE] case_updates = get_case_updates(xform) for sp in supply_points: created = any(filter(lambda update: update.id == sp._id and update.creates_case(), case_updates)) supply_point_modified.send(sender=None, supply_point=sp, created=created)
def test_get_supply_point_case_by_location(self): actual = get_supply_point_case_by_location(self.locations[0]) expected = SupplyPointCase.wrap(self.supply_points[0].to_json()) self.assertEqual(type(actual), type(expected)) self.assertEqual(actual.to_json(), expected.to_json())
def get_supply_points(supply_point_ids): supply_points = [] for doc in iter_docs(SupplyPointCase.get_db(), supply_point_ids): supply_points.append(SupplyPointCase.wrap(doc)) return supply_points
def test_get_supply_point_case_by_location(self): actual = get_supply_point_case_by_location(self.locations[0]) expected = SupplyPointCase.wrap(self.supply_points[0].to_json()) self.assertEqual(type(actual), type(expected)) self.assertEqual(actual.to_json(), expected.to_json())