def set_case_properties(self): if self.child_age is None and self.preg_month is None: raise InvalidRow("Window not found") if self.window > 14: self.case_is_out_of_range = True name = self.case_property('name', EMPTY_FIELD) if getattr(self.report, 'show_html', True): url = reverse("case_details", args=[DOMAIN, self.case_property('_id', '')]) self.name = "<a href='%s'>%s</a>" % (url, name) else: self.name = name self.awc_name = self.case_property('awc_name', EMPTY_FIELD) self.block_name = self.case_property('block_name', EMPTY_FIELD) self.husband_name = self.case_property('husband_name', EMPTY_FIELD) self.bank_name = self.case_property('bank_name', EMPTY_FIELD) self.bank_branch_name = self.case_property('bank_branch_name', EMPTY_FIELD) self.ifs_code = self.case_property('ifsc', EMPTY_FIELD) self.village = self.case_property('village_name', EMPTY_FIELD) self.closed = self.case_property('closed', False) cash_html = '<span style="color: {color};">Rs. {amt}</span>' self.cash = cash_html.format( color="red" if self.cash_amt == 0 else "green", amt=self.cash_amt, ) account = self.case_property('bank_account_number', None) if isinstance(account, Decimal): account = int(account) self.account_number = unicode(account) if account else '' # fake cases will have accounts beginning with 111 if re.match(r'^111', self.account_number): raise InvalidRow("Account begins with 111, assuming test case")
def closed_in_reporting_month(self): if not self.closed: return False closed_datetime = self.case_property('closed_on', EMPTY_FIELD) if closed_datetime and not isinstance(closed_datetime, datetime.datetime): raise InvalidRow('Closed date is not of datetime.datetime type') closed_date = closed_datetime.date() return closed_date >= self.reporting_window_start and\ closed_date < self.reporting_window_end
class Beneficiary(OPMCaseRow): """ Constructor object for each row in the Beneficiary Payment Report """ method_map = [ # If you need to change any of these names, keep the key intact ('name', ugettext_lazy("List of Beneficiaries"), True, None), ('husband_name', ugettext_lazy("Husband Name"), True, None), ('awc_name', ugettext_lazy("AWC Name"), True, None), ('bank_name', ugettext_lazy("Bank Name"), True, None), ('bank_branch_name', ugettext_lazy("Bank Branch Name"), True, None), ('ifs_code', ugettext_lazy("IFS Code"), True, None), ('account_number', ugettext_lazy("Bank Account Number"), True, None), ('block_name', ugettext_lazy("Block Name"), True, None), ('village', ugettext_lazy("Village Name"), True, None), ('num_children_disp', ugettext_lazy("Number of Children"), True, DTSortType.NUMERIC), ('bp1_cash', ugettext_lazy("Birth Preparedness Form 1"), True, None), ('bp2_cash', ugettext_lazy("Birth Preparedness Form 2"), True, None), ('child_cash', ugettext_lazy("Child Followup Form"), True, None), ('year_end_bonus_cash', ugettext_lazy("Bonus Payment"), True, None), ('total_cash', ugettext_lazy("Amount to be paid to beneficiary"), True, None), ('case_id', ugettext_lazy('Case ID'), True, None), ('owner_id', ugettext_lazy("Owner ID"), False, None), ('closed_date', ugettext_lazy("Closed On"), True, None), ('vhnd_available_display', ugettext_lazy('VHND organised this month'), True, None), ('payment_last_month', ugettext_lazy('Payment last month'), True, DTSortType.NUMERIC), ('issues', ugettext_lazy("Issues"), True, None), ] def __init__(self, case, report, child_index=1, **kwargs): super(Beneficiary, self).__init__(case, report, child_index=child_index, **kwargs) # Show only cases that require payment if self.total_cash == 0: raise InvalidRow("Case does not require payment") if self.case_is_out_of_range: raise InvalidRow("Child age is greater than 36 months") self.payment_last_month = numeric_fn(self.last_month_row.total_cash if self.last_month_row else 0)
def status(self): if self.dod is not None: # if they delivered within the reporting month, or afterwards they are treated as pregnant if self.dod > self.reporting_window_start: return 'pregnant' else: return 'mother' elif self.edd is not None: # they haven't delivered, so they're pregnant return 'pregnant' else: # no dates, not valid raise InvalidRow("Case doesn't specify an EDD or DOD.")
def preg_month(self): if self.status == 'pregnant': if not self.edd: raise InvalidRow('No edd found for pregnant mother.') base_window_start = add_months_to_date(self.edd, -9) try: non_adjusted_month = len(months_between(base_window_start, self.reporting_window_start)) - 1 except AssertionError: self.case_is_out_of_range = True non_adjusted_month = 0 # the date to check one month after they first become eligible, # aka the end of their fourth month of pregnancy vhnd_date_to_check = add_months_to_date(self.preg_first_eligible_date, 1) month = self._adjust_for_vhnd_presence(non_adjusted_month, vhnd_date_to_check) if month < 4 or month > 9: self.case_is_out_of_range = True return month
def get_date_property(self, property): prop = self.case_property(property) if prop and not isinstance(prop, datetime.date): raise InvalidRow("{} must be a date!".format(property)) return prop