def test_wetmill(self): self.season = self.rwanda_2010 self.report = Report.get_for_wetmill_season(self.nasho, self.season, self.viewer) self.scorecard = Scorecard.get_for_wetmill_season( self.nasho, self.season, self.viewer) # login with view report permission user self.login(self.viewer) response = self.client.get( reverse('public-wetmill', args=[self.nasho.id])) # nasho should be in the response self.assertContains(response, "Nasho") # check if the finalized report is inside the finalized list of report within the context # shouldn't be. self.assertFalse(self.report in response.context['finalized_reports']) self.assertFalse( self.report in response.context['finalized_scorecards']) # finalize on of this wetmills reports self.report.is_finalized = True self.report.save() # finalize the scorecard for this wetmill self.scorecard.is_finalized = True self.scorecard.save() response = self.client.get( reverse('public-wetmill', args=[self.nasho.id])) # nasho should be in the response self.assertContains(response, "Nasho") # check if the finalized report is inside the finalized list of report within the context self.assertTrue(self.report in response.context['finalized_reports']) self.assertTrue( self.scorecard in response.context['finalized_scorecards']) self.assertIsNone(response.context['last_scorecard']) self.assertIsNone(response.context['last_report']) # finalize the season self.season.is_finalized = True self.season.save() # get the page again response = self.client.get( reverse('public-wetmill', args=[self.nasho.id])) self.assertTrue(self.report in response.context['finalized_reports']) self.assertTrue( self.scorecard in response.context['finalized_scorecards']) self.assertEquals(self.scorecard, response.context['last_scorecard']) self.assertEquals(self.report, response.context['last_report'])
def setUp(self): super(PDFTestCase, self).setUp() self.report = Report.get_for_wetmill_season(self.nasho, self.rwanda_2010, self.admin) self.report.farmers = 100 self.report.capacity = Decimal("10000") self.report.save() self.season = self.rwanda_2010 self.nasho.set_csp_for_season(self.season, self.rtc)
def render(self, wetmill, report_season, actor, now): """ Renders this template for the passed in actor """ total_wetmills = len(self.get_wetmills(wetmill.country, report_season)) context = dict(wetmill=wetmill, actor=actor, total_wetmills=total_wetmills) # if we have a finalized report, and the season is finalized if report_season and report_season.is_finalized: report = Report.get_for_wetmill_season(wetmill, report_season) if report and report.is_finalized: self.add_report_context(context, report) t = Template(self.text) return t.render(Context(context)).strip()
def test_counts(self): self.season = self.rwanda_2010 self.report = Report.get_for_wetmill_season(self.nasho, self.season, self.viewer) self.report.farmers = 800 self.report.is_finalized = True self.report.save() self.season.is_finalized = True self.season.save() self.assertEquals(800, get_total_farmers()) self.assertEquals(800, get_total_farmers(self.rwanda)) self.assertEquals(0, get_total_farmers(self.kenya)) self.assertEquals(3, get_total_wetmills()) self.assertEquals(1, get_total_wetmills(self.kenya))
def setup_ethiopia_season(self): self.birr = Currency.objects.create(name="Ethiopian Birr", has_decimals=True, abbreviation='Birr', created_by=self.admin, modified_by=self.admin) self.ethiopia = Country.objects.create(name="Ethiopia", currency=self.birr, country_code='ET', calling_code='254', created_by=self.admin, modified_by=self.admin) self.ethiopia_2009 = Season.objects.create( country=self.ethiopia, name="2009", has_local_sales=True, default_adjustment=Decimal("0.20"), exchange_rate=Decimal("17.00"), farmer_income_baseline=Decimal("100"), fob_price_baseline="1.15", has_members=True, created_by=self.admin, modified_by=self.admin) self.illubabor = Province.objects.create(country=self.ethiopia, name="Illubabor", order=0, created_by=self.admin, modified_by=self.admin) self.camp_cooperative = Wetmill.objects.create(country=self.ethiopia, province=self.illubabor, name="Camp Cooperative", created_by=self.admin, modified_by=self.admin) self.report = Report.get_for_wetmill_season(self.camp_cooperative, self.ethiopia_2009, self.admin) self.report.working_capital = Decimal("307938") self.report.working_capital_repaid = Decimal("0") self.season = self.ethiopia_2009
def render(self, wetmill, actor, now): """ Renders this template for the passed in actor """ total_wetmills = len(self.get_wetmills()) context = dict(wetmill=wetmill, actor=actor, total_wetmills=total_wetmills) # if we have a finalized report, and the season is finalized if self.report_season and self.report_season.is_finalized: report = Report.get_for_wetmill_season(wetmill, self.report_season) if report and report.is_finalized: self.add_report_context(context, report) # if we are an SMS message, insert those variables if self.sms_season: self.add_sms_context(context, wetmill, now) t = Template(self.text) return t.render(Context(context)).strip()
def generate_report(self, wetmill, multiplier): from reports.models import Report, ExpenseEntry, Production, CashUseEntry, FarmerPaymentEntry self.season.exchange_rate = Decimal("600") self.season.save() report = Report.get_for_wetmill_season(wetmill, self.season, self.admin) for expense in (self.expense_cherry_advance, self.expense_taxes): ExpenseEntry.objects.create(report=report, expense=expense, value=Decimal("10000") * multiplier, exchange_rate=None, created_by=self.admin, modified_by=self.admin) ExpenseEntry.objects.create(report=report, expense=self.expense_capex_interest, value=Decimal("3") * multiplier, exchange_rate=Decimal("500"), created_by=self.admin, modified_by=self.admin) Production.objects.create(report=report, grade=self.cherry, volume=Decimal("1000"), created_by=self.admin, modified_by=self.admin) Production.objects.create(report=report, grade=self.parchment, volume=Decimal("500"), created_by=self.admin, modified_by=self.admin) Production.objects.create(report=report, grade=self.green15, volume=Decimal("300"), created_by=self.admin, modified_by=self.admin) Production.objects.create(report=report, grade=self.green13, volume=Decimal("200"), created_by=self.admin, modified_by=self.admin) CashUseEntry.objects.create(report=report, cash_use=self.cu_dividend, value=Decimal("10000") * multiplier, created_by=self.admin, modified_by=self.admin) FarmerPaymentEntry.objects.create(report=report, farmer_payment=self.fp_dividend, member_per_kilo=Decimal("100") * multiplier, created_by=self.admin, modified_by=self.admin) CashUseEntry.objects.create(report=report, cash_use=self.cu_second_payment, value=Decimal("15000") * multiplier, created_by=self.admin, modified_by=self.admin) FarmerPaymentEntry.objects.create( report=report, farmer_payment=self.fp_second_payment, member_per_kilo=Decimal("150") * multiplier, non_member_per_kilo=Decimal("150") * multiplier, created_by=self.admin, modified_by=self.admin) report.is_finalized = True report.save() return report