def fill_header(self): self.item = FiscalYear.get_current(self.getparam("year")) new_begin = convert_date(self.getparam("begin"), self.item.begin) new_end = convert_date(self.getparam("end"), self.item.end) if (new_begin >= self.item.begin) and (new_end <= self.item.end): self.item.begin = new_begin self.item.end = new_end img = XferCompImage('img') img.set_value(self.current_image()) if not img.value.startswith('/static/'): img.type = 'jpg' img.set_location(0, 0, 1, 5) self.add_component(img) if self.item.last_fiscalyear is not None: lbl = XferCompLabelForm('year_1') lbl.set_location(1, 0, 3) lbl.description = _('year N-1') lbl.set_value(six.text_type(self.item.last_fiscalyear)) self.add_component(lbl) select_year = XferCompSelect(self.field_id) select_year.set_location(1, 1, 3) select_year.set_select_query(FiscalYear.objects.all()) select_year.description = _('year N') select_year.set_value(self.item.id) select_year.set_needed(True) select_year.set_action(self.request, self.__class__.get_action(), close=CLOSE_NO, modal=FORMTYPE_REFRESH) self.add_component(select_year) self.filter = Q(entry__year=self.item) self.lastfilter = Q(entry__year=self.item.last_fiscalyear)
def fillresponse(self): text = _( "{[b]}Do you want that those %d old selected adherent(s) has been renew?{[/b]}{[br/]}Same subscription(s) will be applicated.{[br/]}No validated bill will be created for each subscritpion.") % len(self.items) if self.confirme(text): dateref = convert_date(self.getparam("dateref", ""), Season.current_season().date_ref) for item in self.items: item.renew(dateref)
def change_bill(self): if len(self.subscriptiontype.articles.all()) == 0: return self.status = int(self.status) if self.status in (1, 2): if (self.status == 2) and (self.bill is not None) and (self.bill.bill_type == 0) and (self.bill.status == 1): self.bill = self.bill.convert_to_bill() create_bill = (self.bill is None) if self.status == 1: bill_type = 0 else: bill_type = 1 if create_bill: self.bill = Bill.objects.create(bill_type=bill_type, date=self.season.date_ref, third=get_or_create_customer(self.adherent_id)) if (self.bill.status == 0): self.bill.bill_type = bill_type if hasattr(self, 'xfer'): self.bill.date = convert_date(self.xfer.getparam('dateref'), self.season.date_ref) elif hasattr(self, 'dateref'): self.bill.date = convert_date(self.dateref, self.season.date_ref) else: self.bill.date = self.season.date_ref if (self.bill.date < self.season.begin_date) or (self.bill.date > self.season.end_date): self.bill.date = self.season.date_ref cost_acc = CostAccounting.objects.filter(is_default=True) if len(cost_acc) > 0: self.bill.cost_accounting = cost_acc[0] cmt = ["{[b]}%s{[/b]}" % _("subscription"), "{[i]}%s{[/i]}: %s" % (_('subscription type'), six.text_type(self.subscriptiontype))] self.bill.comment = "{[br/]}".join(cmt) self.bill.save() self.bill.detail_set.all().delete() for art in self.subscriptiontype.articles.all(): Detail.create_for_bill(self.bill, art) if hasattr(self, 'send_email_param'): self.sendemail(self.send_email_param) if (self.status == 3) and (self.bill is not None): if self.bill.status == 0: self.bill.delete() self.bill = None elif self.bill.status == 1: new_assetid = self.bill.cancel() if new_assetid is not None: self.bill = Bill.objects.get(id=new_assetid)
def add_test_expenses(simple=True, with_payoff=False): expense1 = Expense(date=convert_date('2015-05-07'), comment='opq 666', expensetype=0, third_id=2) expense1.editor.before_save(None) expense1.save() ExpenseDetail.objects.create(expense=expense1, set_id=2, designation='set 2', expense_account='604', price='100') expense1.valid() if not simple: expense2 = Expense(date=convert_date('2015-08-28'), comment='creation', expensetype=0, third_id=2) expense2.editor.before_save(None) expense2.save() ExpenseDetail.objects.create(expense=expense2, set_id=3, designation='set 1', expense_account='602', price='75') expense2.valid() if with_payoff: pay = Payoff(supporting_id=expense1.id, date='2015-05-11', mode=0, amount=35.0) pay.editor.before_save(None) pay.save() pay = Payoff(supporting_id=expense2.id, date='2015-08-30', mode=0, amount=75.0) pay.editor.before_save(None) pay.save()
def _add_test_expenses(expense_account1, expense_account2, simple, with_payoff): expense1 = Expense(date=convert_date('2015-05-07'), comment='opq 666', expensetype=0, third_id=2) expense1.editor.before_save(None) expense1.save() ExpenseDetail.objects.create(expense=expense1, set_id=2, designation='set 2', expense_account=expense_account1, price='100') expense1.valid() if not simple: expense2 = Expense(date=convert_date('2015-08-28'), comment='creation', expensetype=0, third_id=2) expense2.editor.before_save(None) expense2.save() ExpenseDetail.objects.create(expense=expense2, set_id=3, designation='set 1', expense_account=expense_account2, price='75') expense2.valid() if with_payoff: pay = Payoff(supporting_id=expense1.id, date='2015-05-11', mode=0, amount=35.0) pay.editor.before_save(None) pay.save() pay = Payoff(supporting_id=expense2.id, date='2015-08-30', mode=0, amount=75.0) pay.editor.before_save(None) pay.save()
def fill_header(self): self.item = FiscalYear.get_current(self.getparam("year")) new_begin = convert_date(self.getparam("begin"), self.item.begin) new_end = convert_date(self.getparam("end"), self.item.end) if (new_begin >= self.item.begin) and (new_end <= self.item.end): self.item.begin = new_begin self.item.end = new_end img = XferCompImage('img') img.set_value(self.icon_path()) img.set_location(0, 0, 1, 3) self.add_component(img) select_year = XferCompSelect(self.field_id) select_year.set_location(1, 0, 4) select_year.set_select_query(FiscalYear.objects.all()) select_year.set_value(self.item.id) select_year.set_needed(True) select_year.set_action(self.request, self.__class__.get_action(), close=CLOSE_NO, modal=FORMTYPE_REFRESH) self.add_component(select_year) self.filter = Q(entry__year=self.item) if self.item.status != 2: self.fill_from_model(1, 1, False, ['begin']) self.fill_from_model(3, 1, False, ['end']) begin_filter = self.get_components('begin') begin_filter.set_action(self.request, self.__class__.get_action(), close=CLOSE_NO, modal=FORMTYPE_REFRESH) end_filter = self.get_components('end') end_filter.set_action(self.request, self.__class__.get_action(), close=CLOSE_NO, modal=FORMTYPE_REFRESH) self.filter &= Q(entry__date_value__gte=self.item.begin) self.filter &= Q(entry__date_value__lte=self.item.end) self.fill_filterCode() lbl = XferCompLabelForm("result") lbl.set_value_center(self.item.total_result_text) lbl.set_location(0, 6, 6) self.add_component(lbl) self.fill_filterheader() self.define_gridheader()
def _import_subscription(self, type_name, dateformat): working_subscription = None current_season = Season.current_season() type_option = 0 if '#' in type_name: type_name, type_option = type_name.split('#') try: type_obj = SubscriptionType.objects.filter(name=type_name) if len(type_obj) > 0: type_obj = type_obj[0] if type_obj.duration == 1: type_option = int(type_option) - 1 period_list = current_season.period_set.all() begin_date = period_list[type_option].begin_date end_date = period_list[type_option].end_date elif type_obj.duration == 2: type_option = int(type_option) - 1 mounths = current_season.get_months() begin_date = convert_date(mounths[type_option][0] + '-01') end_date = same_day_months_after( begin_date, 1) - timedelta(days=1) elif type_obj.duration == 3: try: begin_date = datetime.strptime( type_option, dateformat).date() except (TypeError, ValueError): begin_date = date.today() end_date = same_day_months_after( begin_date, 12) - timedelta(days=1) else: begin_date = current_season.begin_date end_date = current_season.end_date try: working_subscription = Subscription.objects.get( adherent=self, season=current_season, subscriptiontype=type_obj, begin_date=begin_date, end_date=end_date) except ObjectDoesNotExist: working_subscription = Subscription() working_subscription.adherent = self working_subscription.season = current_season working_subscription.subscriptiontype = type_obj working_subscription.begin_date = begin_date working_subscription.end_date = end_date working_subscription.save() if isinstance(working_subscription, tuple): working_subscription = working_subscription[0] except: logging.getLogger('diacamma.member').exception("import_data") return working_subscription
def set_periode(self, dateref): self.dateref = dateref self.season = Season.get_from_date(dateref) if self.subscriptiontype.duration == 0: # periodic self.begin_date = self.season.begin_date self.end_date = self.season.end_date elif self.subscriptiontype.duration == 1: # periodic period = self.season.get_period_from_date(dateref) self.begin_date = period.begin_date self.end_date = period.end_date elif self.subscriptiontype.duration == 2: # monthly self.begin_date = convert_date('%4d-%02d-01' % (dateref.year, dateref.month)) self.end_date = same_day_months_after(self.begin_date, 1) - timedelta(days=1) elif self.subscriptiontype.duration == 3: # calendar self.begin_date = dateref self.end_date = same_day_months_after(self.begin_date, 12) - timedelta(days=1)
def fillresponse(self, send_email=True): cmd_manager = CommandManager(self.getparam('CMD_FILE', ''), self.items) if self.getparam('SAVE') is None: dlg = self.create_custom(self.model) img = XferCompImage('img') img.set_value(self.icon_path()) img.set_location(0, 0, 1, 4) dlg.add_component(img) lab = XferCompLabelForm('lbl_title') lab.set_value_as_title(self.caption) lab.set_location(1, 0, 2) dlg.add_component(lab) grid = XferCompGrid('AdhCmd') for fname, ftitle in cmd_manager.get_fields(): grid.add_header(fname, ftitle) for cmd_id, cmd_item in cmd_manager.get_content_txt(): for head_name, value in cmd_item.items(): grid.set_value(cmd_id, head_name, value) grid.set_location(1, 2, 2) grid.add_action(self.request, AdherentCommandModify.get_action(TITLE_MODIFY, "images/edit.png"), close=CLOSE_NO, unique=SELECT_SINGLE) grid.add_action(self.request, AdherentCommandDelete.get_action(TITLE_DELETE, "images/delete.png"), close=CLOSE_NO, unique=SELECT_SINGLE) dlg.params['CMD_FILE'] = cmd_manager.file_name dlg.add_component(grid) if len(grid.records) > 0: lab = XferCompLabelForm('lbl_send_email') lab.set_value_as_name(_('Send quotition by email for each adherent.')) lab.set_location(1, 3) dlg.add_component(lab) chk = XferCompCheck('send_email') chk.set_value(send_email) chk.set_location(2, 3) dlg.add_component(chk) dlg.add_action(AdherentCommand.get_action(TITLE_OK, "images/ok.png"), close=CLOSE_YES, params={'SAVE': 'YES'}) dlg.add_action(WrapAction(TITLE_CLOSE, 'images/close.png')) else: dateref = convert_date(self.getparam("dateref", ""), Season.current_season().date_ref) if send_email: param_email = self.request.META.get('HTTP_REFERER', self.request.build_absolute_uri()), self.language else: param_email = None nb_sub, nb_bill = cmd_manager.create_subscription(dateref, param_email) if send_email: msg = _('%(nbsub)d new subscription and %(nbbill)d quotation have been sent.') % {'nbsub': nb_sub, 'nbbill': nb_bill} else: msg = _('%d new subscription have been prepared.') % nb_sub self.message(msg)
def get_filter(self): team = self.getparam("team", ()) activity = self.getparam("activity", ()) genre = self.getparam("genre", 0) age = self.getparam("age", ()) status = self.getparam("status", -1) dateref = convert_date(self.getparam("dateref", ""), Season.current_season().date_ref) if self.getparam('is_renew', False): date_one_year = same_day_months_after(dateref, -12) date_six_month = same_day_months_after(dateref, -6) date_three_month = same_day_months_after(dateref, -3) current_filter = Q(subscription__subscriptiontype__duration=0) & Q( subscription__end_date__gte=date_one_year) current_filter |= Q(subscription__subscriptiontype__duration=1) & Q( subscription__end_date__gte=date_six_month) current_filter |= Q(subscription__subscriptiontype__duration=2) & Q( subscription__end_date__gte=date_three_month) current_filter |= Q(subscription__subscriptiontype__duration=3) & Q( subscription__end_date__gte=date_one_year) exclude_filter = Q(subscription__begin_date__lte=dateref) & Q( subscription__end_date__gte=dateref) else: current_filter = Q(subscription__begin_date__lte=dateref) & Q( subscription__end_date__gte=dateref) exclude_filter = Q() if len(team) > 0: current_filter &= Q(subscription__license__team__in=team) if len(activity) > 0: current_filter &= Q(subscription__license__activity__in=activity) if len(age) > 0: age_filter = Q() for age_item in Age.objects.filter(id__in=age): age_filter |= Q(birthday__gte="%d-01-01" % (dateref.year - age_item.maximum)) & Q( birthday__lte="%d-12-31" % (dateref.year - age_item.minimum)) current_filter &= age_filter if genre != 0: current_filter &= Q(genre=genre) if status == -1: current_filter &= Q(subscription__status__in=(1, 2)) else: current_filter &= Q(subscription__status=status) return (current_filter, exclude_filter)
def fillresponse_header(self): row = self.get_max_row() + 1 team = self.getparam("team", ()) activity = self.getparam("activity", ()) genre = self.getparam("genre", 0) age = self.getparam("age", ()) status = self.getparam("status", -1) dateref = convert_date( self.getparam("dateref", ""), Season.current_season().date_ref) if Params.getvalue("member-age-enable"): lbl = XferCompLabelForm('lblage') lbl.set_value_as_name(_("Age")) lbl.set_location(0, row) self.add_component(lbl) sel = XferCompCheckList('age') sel.set_select_query(Age.objects.all()) sel.set_value(age) sel.set_location(1, row, 1, 2) self.add_component(sel) if Params.getvalue("member-team-enable"): lbl = XferCompLabelForm('lblteam') lbl.set_value_as_name(Params.getvalue("member-team-text")) lbl.set_location(2, row) self.add_component(lbl) sel = XferCompCheckList('team') sel.set_select_query(Team.objects.all()) sel.set_value(team) sel.set_location(3, row, 1, 2) self.add_component(sel) if Params.getvalue("member-activite-enable"): lbl = XferCompLabelForm('lblactivity') lbl.set_value_as_name(Params.getvalue("member-activite-text")) lbl.set_location(4, row) self.add_component(lbl) sel = XferCompCheckList('activity') sel.set_select_query(Activity.objects.all()) sel.set_value(activity) sel.set_location(5, row, 1, 2) self.add_component(sel) lbl = XferCompLabelForm('lbldateref') lbl.set_value_as_name(_("reference date")) lbl.set_location(6, row) self.add_component(lbl) dtref = XferCompDate('dateref') dtref.set_value(dateref) dtref.set_needed(True) dtref.set_location(7, row, 2) self.add_component(dtref) if Params.getvalue("member-filter-genre"): lbl = XferCompLabelForm('lblgenre') lbl.set_value_as_name(_("genre")) lbl.set_location(6, row + 1) self.add_component(lbl) sel = XferCompSelect('genre') list_genre = list(self.item.get_field_by_name('genre').choices) list_genre.insert(0, (0, '---')) sel.set_select(list_genre) sel.set_location(7, row + 1) sel.set_value(genre) self.add_component(sel) lbl = XferCompLabelForm('lblstatus') lbl.set_value_as_name(_("status")) lbl.set_location(6, row + 2) self.add_component(lbl) sel = XferCompSelect('status') list_status = list(Subscription.get_field_by_name('status').choices) del list_status[0] del list_status[-2] del list_status[-1] list_status.insert(0, (-1, '%s & %s' % (_('building'), _('valid')))) sel.set_select(list_status) sel.set_location(7, row + 2) sel.set_value(status) self.add_component(sel) btn = XferCompButton('btndateref') btn.set_location(8, row + 1, 1, 2) btn.set_action(self.request, self.get_action(_('Refresh'), ''), modal=FORMTYPE_REFRESH, close=CLOSE_NO) self.add_component(btn)
def set_context(self, xfer): if xfer is not None: self.date_ref = convert_date(xfer.getparam("dateref"))