def make_supply_point_product(supply_point_case, product_uuid, owner_id=None): domain = supply_point_case.domain id = uuid.uuid4().hex user_id = get_commtrack_user_id(domain) owner_id = owner_id or get_owner_id(supply_point_case) or user_id username = const.COMMTRACK_USERNAME product_name = Product.get(product_uuid).name caseblock = CaseBlock(case_id=id, create=True, version=V2, case_name=product_name, user_id=user_id, owner_id=owner_id, case_type=const.SUPPLY_POINT_PRODUCT_CASE_TYPE, update={"product": product_uuid}, index={ const.PARENT_CASE_REF: (const.SUPPLY_POINT_CASE_TYPE, supply_point_case._id), }) casexml = ElementTree.tostring(caseblock.as_xml()) submit_case_blocks(casexml, domain, username, user_id, xmlns=const.COMMTRACK_SUPPLY_POINT_PRODUCT_XMLNS) return SupplyPointProductCase.get(id)
def make_supply_point_product(supply_point_case, product_uuid, owner_id=None): domain = supply_point_case.domain id = uuid.uuid4().hex user_id = const.get_commtrack_user_id(domain) owner_id = owner_id or get_owner_id(supply_point_case) or user_id username = const.COMMTRACK_USERNAME product_name = Product.get(product_uuid).name caseblock = CaseBlock( case_id=id, create=True, version=V2, case_name=product_name, user_id=user_id, owner_id=owner_id, case_type=const.SUPPLY_POINT_PRODUCT_CASE_TYPE, update={ "product": product_uuid }, index={ const.PARENT_CASE_REF: (const.SUPPLY_POINT_CASE_TYPE, supply_point_case._id), } ) casexml = ElementTree.tostring(caseblock.as_xml()) submit_case_blocks(casexml, domain, username, user_id, xmlns=const.COMMTRACK_SUPPLY_POINT_PRODUCT_XMLNS) sppc = SupplyPointProductCase.get(id) sppc.bind_to_location(supply_point_case.location) sppc.save() return sppc
def requisition_case_id(self): # for somewhat obscure reasons, the case_id is the id of the # supply_point_product case, so we add a new field for this. # though for newly created requisitions it's just empty if self.base_action_type == RequisitionActions.REQUEST: return None if self.base_action_type == RequisitionActions.RECEIPTS: # for receipts the id should point to the most recent open requisition # (or none) try: product_stock_case = SupplyPointProductCase.get(self.case_id) return RequisitionCase.open_for_product_case( self.domain, product_stock_case.location_[-1], self.case_id )[0] except IndexError: # there was no open requisition. this is ok return None assert False, "%s is an unexpected action type!" % self.base_action_type
def requisition_case_id(self): # for somewhat obscure reasons, the case_id is the id of the # supply_point_product case, so we add a new field for this. # though for newly created requisitions it's just empty if self.base_action_type == RequisitionActions.REQUEST: return None if self.base_action_type == RequisitionActions.RECEIPTS: # for receipts the id should point to the most recent open requisition # (or none) try: product_stock_case = SupplyPointProductCase.get(self.case_id) return RequisitionCase.open_for_product_case( self.domain, product_stock_case.location_[-1], self.case_id)[0] except IndexError: # there was no open requisition. this is ok return None assert False, "%s is an unexpected action type!" % self.base_action_type