def show(self, xfer): xfer.move_components('lbl_body', 0, 2) xfer.move_components('body', 0, 2) obj_recipients = xfer.get_components('recipients') new_recipients = XferCompGrid('recipient_list') new_recipients.set_location(obj_recipients.col, obj_recipients.row, obj_recipients.colspan) new_recipients.add_header("model", _('model')) new_recipients.add_header("filter", _('filter')) compid = 0 for model_title, filter_desc in self.item.recipients_description: new_recipients.set_value(compid, "model", model_title) new_recipients.set_value(compid, "filter", filter_desc) compid += 1 if compid > 0: nb_contact = len(self.item.get_contacts()) contact_nb = XferCompLabelForm('contact_nb') contact_nb.set_location(obj_recipients.col, obj_recipients.row + 1, obj_recipients.colspan) contact_nb.set_value(_("Message defined for %d contacts") % nb_contact) xfer.add_component(contact_nb) lbl = XferCompLabelForm('sep_body') lbl.set_location(obj_recipients.col - 1, obj_recipients.row + 2, 4) lbl.set_value("{[hr/]}") xfer.add_component(lbl) xfer.remove_component('recipients') new_recipients.add_action_notified(xfer, 'recipient_list') xfer.add_component(new_recipients) return LucteriosEditor.show(self, xfer)
def fillresponse(self, payer="", reference=""): self.fill_header(payer, reference) grid = XferCompGrid('entry') grid.define_page(self) grid.add_header('bill', _('bill')) grid.add_header('payer', _('payer'), horderable=1) grid.add_header('amount', _('amount'), horderable=1) grid.add_header('date', _('date'), horderable=1) grid.add_header('reference', _('reference'), horderable=1) payoff_nodeposit = DepositDetail.get_payoff_not_deposit( payer, reference, grid.order_list) for payoff in payoff_nodeposit: payoffid = payoff['id'] grid.set_value(payoffid, 'bill', payoff['bill']) grid.set_value(payoffid, 'payer', payoff['payer']) grid.set_value(payoffid, 'amount', payoff['amount']) grid.set_value(payoffid, 'date', payoff['date']) grid.set_value(payoffid, 'reference', payoff['reference']) grid.set_location(0, 2, 4) grid.add_action(self.request, DepositDetailSave.get_action(_("select"), "images/ok.png"), close=CLOSE_YES, unique=SELECT_MULTI) self.add_component(grid) self.add_action(WrapAction(TITLE_CANCEL, 'images/cancel.png'))
class FiscalYearLedger(FiscalYearReport): caption = _("Ledger") add_filtering = True def __init__(self, **kwargs): FiscalYearReport.__init__(self, **kwargs) self.last_account = None self.last_third = None self.last_total = 0 self.line_idx = 1 def define_gridheader(self): self.grid = XferCompGrid('report_%d' % self.item.id) self.grid.add_header('entry.num', _('numeros')) self.grid.add_header('entry.date_entry', _('date entry')) self.grid.add_header('entry.date_value', _('date value')) self.grid.add_header('entry.designation', _('name')) self.grid.add_header('debit', _('debit')) self.grid.add_header('credit', _('credit')) def _add_total_account(self): if self.last_account is not None: self.grid.set_value(self.line_idx, 'entry.designation', get_spaces( 30) + "{[i]}%s{[/i]}" % _('total')) self.grid.set_value(self.line_idx, 'debit', "{[i]}%s{[/i]}" % format_devise( max((0, -1 * self.last_account.credit_debit_way() * self.last_total)), 0)) self.grid.set_value(self.line_idx, 'credit', "{[i]}%s{[/i]}" % format_devise( max((0, self.last_account.credit_debit_way() * self.last_total)), 0)) self.line_idx += 1 self.grid.set_value(self.line_idx, 'entry.designation', '{[br/]}') self.line_idx += 1 self.last_total = 0 def calcul_table(self): self.line_idx = 1 self.last_account = None self.last_third = None self.last_total = 0 for line in EntryLineAccount.objects.filter(self.filter).order_by('account__code', 'entry__date_value', 'third'): if self.last_account != line.account: self._add_total_account() self.last_account = line.account self.last_third = None self.grid.set_value(self.line_idx, 'entry.designation', get_spaces( 15) + "{[u]}{[b]}%s{[/b]}{[/u]}" % six.text_type(self.last_account)) self.line_idx += 1 if self.last_third != line.third: self.grid.set_value(self.line_idx, 'entry.designation', get_spaces( 8) + "{[b]}%s{[/b]}" % six.text_type(line.entry_account)) self.line_idx += 1 self.last_third = line.third for header in self.grid.headers: self.grid.set_value( self.line_idx, header.name, line.evaluate('#' + header.name)) self.last_total += line.amount self.line_idx += 1 self._add_total_account()
def show(self, xfer): xfer.move_components('body', 0, 2) obj_recipients = xfer.get_components('recipients') new_recipients = XferCompGrid('recipient_list') new_recipients.tab = obj_recipients.tab new_recipients.set_location(obj_recipients.col, obj_recipients.row, obj_recipients.colspan) new_recipients.add_header("model", _('model')) new_recipients.add_header("filter", _('filter')) compid = 0 for model_title, filter_desc in self.item.recipients_description: new_recipients.set_value(compid, "model", model_title) new_recipients.set_value(compid, "filter", filter_desc) compid += 1 if compid == 0: xfer.remove_component('contact_nb') if not will_mail_send() or (len(self.item.get_contacts(False)) == 0): xfer.remove_component('contact_noemail') xfer.remove_component('recipients') new_recipients.add_action_notified(xfer, 'recipient_list') xfer.tab = new_recipients.tab xfer.add_component(new_recipients) old_documents = xfer.get_components('documents') xfer.remove_component('documents') new_documents = XferCompGrid('document') new_documents.tab = old_documents.tab new_documents.set_location(old_documents.col, old_documents.row, old_documents.colspan) new_documents.set_model(self.item.documents.all(), ["name", "description", "date_modification"], xfer) new_documents.add_action(xfer.request, DocumentShow.get_action( TITLE_EDIT, "images/show.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_SINGLE) if self.item.status == 0: new_documents.add_action(xfer.request, MessageRemoveDoc.get_action( _("Remove"), "images/delete.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_MULTI) new_documents.add_action(xfer.request, MessageInsertDoc.get_action( _("Insert"), "images/add.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_NONE) xfer.tab = new_documents.tab xfer.add_component(new_documents) return LucteriosEditor.show(self, xfer)
class FiscalYearTrialBalance(FiscalYearReport): caption = _("Trial balance") add_filtering = True def define_gridheader(self): self.grid = XferCompGrid('report_%d' % self.item.id) self.grid.add_header('designation', _('name')) self.grid.add_header('total_debit', _('debit sum')) self.grid.add_header('total_credit', _('credit sum')) self.grid.add_header('solde_debit', _('debit')) self.grid.add_header('solde_credit', _('credit')) def _get_balance_values(self): balance_values = {} data_line_positifs = list(EntryLineAccount.objects.filter(self.filter & Q(amount__gt=0)).values( 'account').annotate(data_sum=Sum('amount'))) data_line_negatifs = list(EntryLineAccount.objects.filter(self.filter & Q(amount__lt=0)).values( 'account').annotate(data_sum=Sum('amount'))) for data_line in data_line_positifs + data_line_negatifs: if abs(data_line['data_sum']) > 0.0001: account = ChartsAccount.objects.get( id=data_line['account']) if account.code not in balance_values.keys(): balance_values[account.code] = [ six.text_type(account), 0, 0] if (account.credit_debit_way() * data_line['data_sum']) > 0.0001: balance_values[account.code][ 2] = account.credit_debit_way() * data_line['data_sum'] else: balance_values[account.code][ 1] = -1 * account.credit_debit_way() * data_line['data_sum'] return balance_values def calcul_table(self): line_idx = 1 balance_values = self._get_balance_values() keys = list(balance_values.keys()) keys.sort() for key in keys: self.grid.set_value( line_idx, 'designation', balance_values[key][0]) self.grid.set_value( line_idx, 'total_debit', format_devise(balance_values[key][1], 5)) self.grid.set_value( line_idx, 'total_credit', format_devise(balance_values[key][2], 5)) diff = balance_values[key][1] - balance_values[key][2] self.grid.set_value( line_idx, 'solde_debit', format_devise(max(0, diff), 0)) if abs(diff) < 0.0001: self.grid.set_value( line_idx, 'solde_credit', format_devise(0, 5)) else: self.grid.set_value( line_idx, 'solde_credit', format_devise(max(0, -1 * diff), 0)) line_idx += 1
def show(self, xfer): obj_body = xfer.get_components('body') obj_body.value = "{[div style='border:1px solid black;background-color:#EEE;padding:5px;']}%s{[div]}" % obj_body.value xfer.move_components('body', 0, 2) obj_recipients = xfer.get_components('recipients') new_recipients = XferCompGrid('recipient_list') new_recipients.tab = obj_recipients.tab new_recipients.set_location(obj_recipients.col, obj_recipients.row, obj_recipients.colspan) new_recipients.add_header("model", _('model')) new_recipients.add_header("filter", _('filter')) compid = 0 for model_title, filter_desc in self.item.recipients_description: new_recipients.set_value(compid, "model", model_title) new_recipients.set_value(compid, "filter", filter_desc) compid += 1 if compid == 0: xfer.remove_component('contact_nb') if not will_mail_send() or (len(self.item.get_contacts(False)) == 0): xfer.remove_component('contact_noemail') xfer.remove_component('recipients') new_recipients.add_action_notified(xfer, 'recipient_list') xfer.tab = new_recipients.tab xfer.add_component(new_recipients) old_documents = xfer.get_components('attachments') xfer.remove_component('attachments') if xfer.item.is_dynamic: xfer.remove_component('__tab_3') xfer.remove_component('doc_in_link') xfer.remove_component('empty') else: new_documents = XferCompGrid('attachments') new_documents.tab = old_documents.tab new_documents.set_location(old_documents.col, old_documents.row, old_documents.colspan) new_documents.set_model(self.item.attachments.all(), ["name", "description", "date_modification"], xfer) new_documents.add_action(xfer.request, DocumentShow.get_action(TITLE_EDIT, "images/show.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_SINGLE) if self.item.status == 0: new_documents.add_action(xfer.request, MessageRemoveDoc.get_action(_("Remove"), "images/delete.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_MULTI) new_documents.add_action(xfer.request, MessageInsertDoc.get_action(_("Insert"), "images/add.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_NONE) xfer.tab = new_documents.tab xfer.add_component(new_documents) contact_nb = xfer.get_components('contact_nb') if (contact_nb is not None) and (self.item.nb_total > 0): xfer.tab = contact_nb.tab xfer.fill_from_model(contact_nb.col, contact_nb.row + 1, True, [((_('statistic'), 'statistic'),)]) return LucteriosEditor.show(self, xfer)
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 _show_initial_csv(self): tbl = XferCompGrid('CSV') for fieldname in self.spamreader.fieldnames: if fieldname != '': tbl.add_header(fieldname, fieldname) row_idx = 1 for row in self.spamreader: if row[self.spamreader.fieldnames[0]] is not None: for fieldname in self.spamreader.fieldnames: if fieldname != '': tbl.set_value(row_idx, fieldname, row[fieldname]) row_idx += 1 tbl.set_location(1, 1, 2) self.add_component(tbl) lbl = XferCompLabelForm('nb_line') lbl.set_value(_("Total number of items: %d") % (row_idx - 1)) lbl.set_location(1, 2, 2) self.add_component(lbl)
def fillresponse(self, field_id): self.items = self.model.objects.filter( id__in=self.getparam(field_id, ())) if len(self.items) < 2: raise LucteriosException( IMPORTANT, _("Impossible: you must to select many records!")) if self.item.id is None: self.item = self.items[0] if self.getparam("CONFIRME") is None: dlg = self.create_custom() lbl = XferCompLabelForm('title') lbl.set_value_as_title(self.caption) lbl.set_location(1, 0) dlg.add_component(lbl) grid = XferCompGrid(self.field_id) grid.add_header('value', _('designation')) grid.add_header('select', _('is main?'), 'bool') for item in self.items: grid.set_value(item.id, 'value', six.text_type(item)) grid.set_value(item.id, 'select', item.id == self.item.id) grid.set_location(1, 1) grid.add_action(self.request, self.get_action(_("Edit"), "images/show.png"), { 'modal': FORMTYPE_MODAL, 'close': CLOSE_NO, 'unique': SELECT_SINGLE, 'params': {"CONFIRME": 'OPEN'}}) grid.add_action(self.request, self.get_action( _("Select"), "images/ok.png"), {'modal': FORMTYPE_REFRESH, 'close': CLOSE_NO, 'unique': SELECT_SINGLE}) dlg.add_component(grid) dlg.add_action(self.get_action(_('Ok'), "images/ok.png"), {'close': CLOSE_YES, 'modal': FORMTYPE_MODAL, 'params': {'CONFIRME': 'YES', self.field_id: self.item.id}}) dlg.add_action(WrapAction(_("Cancel"), "images/cancel.png"), {}) elif self.getparam("CONFIRME") == 'YES': alias_objects = [] for item in self.items: if item.id != self.item.id: alias_objects.append(item.get_final_child()) self.item.get_final_child().merge_objects(alias_objects) self.redirect_action(ActionsManage.get_act_changed(self.model.__name__, 'show', '', ''), { 'params': {field_id: self.item.id}}) else: self.redirect_action(ActionsManage.get_act_changed(self.model.__name__, 'show', '', ''), { 'params': {field_id: self.item.id}})
def fillresponse(self, field_id): self.items = self.model.objects.filter(id__in=self.getparam(field_id, ())).distinct() if len(self.items) < 2: raise LucteriosException(IMPORTANT, _("Impossible: you must to select many records!")) item_id = self.getparam('mrg_' + self.field_id, 0) if item_id != 0: self.item = self.model.objects.get(id=item_id) if (self.item is None) or (self.item.id is None): self.item = self.items[0] if self.getparam("CONFIRME") is None: dlg = self.create_custom() lbl = XferCompLabelForm('title') lbl.set_value_as_title(self.caption) lbl.set_location(1, 0) dlg.add_component(lbl) grid = XferCompGrid('mrg_' + self.field_id) grid.add_header('value', _('designation')) grid.add_header('select', _('is main?'), 'B') for item in self.items: grid.set_value(item.id, 'value', six.text_type(item)) grid.set_value(item.id, 'select', item.id == self.item.id) grid.set_location(1, 1) grid.add_action(self.request, self.get_action(_("Edit"), "images/show.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_SINGLE, params={"CONFIRME": 'OPEN'}) grid.add_action(self.request, self.get_action(_("Select"), "images/ok.png"), modal=FORMTYPE_REFRESH, close=CLOSE_NO, unique=SELECT_SINGLE) dlg.add_component(grid) dlg.add_action(self.get_action(_('Ok'), "images/ok.png"), close=CLOSE_YES, modal=FORMTYPE_MODAL, params={'CONFIRME': 'YES', 'mrg_' + self.field_id: self.item.id}) dlg.add_action(WrapAction(_("Cancel"), "images/cancel.png")) elif self.getparam("CONFIRME") == 'YES': alias_objects = [] for item in self.items: if item.id != self.item.id: alias_objects.append(item.get_final_child()) self.item.get_final_child().merge_objects(alias_objects) self.redirect_action(ActionsManage.get_action_url(self.model.get_long_name(), 'Show', self), params={field_id: self.item.id}) else: self.redirect_action(ActionsManage.get_action_url(self.model.get_long_name(), 'Show', self), params={field_id: self.item.id})
def show(self, xfer): xfer.move_components('body', 0, 2) obj_recipients = xfer.get_components('recipients') new_recipients = XferCompGrid('recipient_list') new_recipients.tab = obj_recipients.tab new_recipients.set_location(obj_recipients.col, obj_recipients.row, obj_recipients.colspan) new_recipients.add_header("model", _('model')) new_recipients.add_header("filter", _('filter')) compid = 0 for model_title, filter_desc in self.item.recipients_description: new_recipients.set_value(compid, "model", model_title) new_recipients.set_value(compid, "filter", filter_desc) compid += 1 if compid == 0: xfer.remove_component('contact_nb') if not will_mail_send() or (len(self.item.get_contacts(False)) == 0): xfer.remove_component('contact_noemail') xfer.remove_component('recipients') new_recipients.add_action_notified(xfer, 'recipient_list') xfer.tab = new_recipients.tab xfer.add_component(new_recipients) old_documents = xfer.get_components('documents') xfer.remove_component('documents') new_documents = XferCompGrid('document') new_documents.tab = old_documents.tab new_documents.set_location(old_documents.col, old_documents.row, old_documents.colspan) new_documents.set_model(self.item.documents.all(), ["name", "description", "date_modification"], xfer) new_documents.add_action(xfer.request, DocumentShow.get_action(TITLE_EDIT, "images/show.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_SINGLE) if self.item.status == 0: new_documents.add_action(xfer.request, MessageRemoveDoc.get_action(_("Remove"), "images/delete.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_MULTI) new_documents.add_action(xfer.request, MessageInsertDoc.get_action(_("Insert"), "images/add.png"), modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_NONE) xfer.tab = new_documents.tab xfer.add_component(new_documents) return LucteriosEditor.show(self, xfer)
def fill_articles(self): articles_result = self.item.get_statistics_article() grid = XferCompGrid("articles") grid.add_header("article", _("article")) grid.add_header("amount", _("amount")) grid.add_header("number", _("number")) grid.add_header("mean", _("mean")) grid.add_header("ratio", _("ratio (%)")) index = 0 for art_val in articles_result: grid.set_value(index, "article", art_val[0]) grid.set_value(index, "amount", art_val[1]) grid.set_value(index, "number", art_val[2]) grid.set_value(index, "mean", art_val[3]) grid.set_value(index, "ratio", art_val[4]) index += 1 grid.set_location(0, 1, 3) grid.set_size(400, 800) self.add_component(grid)
def fillresponse(self): grid = XferCompGrid('grid') grid.set_location(0, 0) grid.add_header('col1', "Integer", 'N0') grid.add_header('col2', "Float", 'N3') grid.add_header('col3', "Boolean", 'B') grid.add_header('col4', "String", None, 0, "{[b]}%s{[/b]}") grid.set_value(1, "col1", 2500) grid.set_value(1, "col2", 7.54) grid.set_value(1, "col3", True) grid.set_value(1, "col4", "foo") grid.set_value(5, "col1", 4) grid.set_value(5, "col2", 789.644) grid.set_value(5, "col3", False) grid.set_value(5, "col4", "string") # grid.add_action(self.return_action('Reopen', ''),-1, {'modal':FORMTYPE_REFRESH}) self.add_component(grid)
def fill_tasks(self): self.new_tab(_('Tasks')) grid = XferCompGrid('tasks') grid.no_pager = True grid.add_header('name', _('name')) grid.add_header('trigger', _('trigger')) grid.add_header('nextdate', _('next date'), 'datetime') for job_desc in LucteriosScheduler.get_list(): grid.set_value(job_desc[0], 'name', job_desc[1]) grid.set_value(job_desc[0], 'trigger', '%s' % job_desc[2]) grid.set_value(job_desc[0], 'nextdate', job_desc[3]) grid.set_location(0, self.get_max_row() + 1, 2) grid.set_size(200, 500) self.add_component(grid)
def fill_customers(self): costumer_result = self.item.get_statistics_customer() grid = XferCompGrid("customers") grid.add_header("customer", _("customer")) grid.add_header("amount", _("amount")) grid.add_header("ratio", _("ratio (%)")) index = 0 for cust_val in costumer_result: grid.set_value(index, "customer", cust_val[0]) grid.set_value(index, "amount", cust_val[1]) grid.set_value(index, "ratio", cust_val[2]) index += 1 grid.set_location(0, 1, 3) grid.set_size(400, 800) self.add_component(grid)
def fillresponse(self): XferListEditor.fillresponse(self) self.new_tab(_('Tasks')) grid = XferCompGrid('tasks') grid.no_pager = True grid.add_header('name', _('name')) grid.add_header('trigger', _('trigger')) grid.add_header('nextdate', _('next date'), 'datetime') for job_desc in LucteriosScheduler.get_list(): grid.set_value(job_desc[0], 'name', job_desc[1]) grid.set_value(job_desc[0], 'trigger', '%s' % job_desc[2]) grid.set_value(job_desc[0], 'nextdate', job_desc[3]) grid.set_location(0, self.get_max_row() + 1, 2) grid.set_size(200, 500) self.add_component(grid)
def fillresponse(self): grid = XferCompGrid('grid') grid.set_location(0, 0) grid.add_header('col1', "Integer", 'int') grid.add_header('col2', "Float", 'float') grid.add_header('col3', "Boolean", 'bool') grid.add_header('col4', "String", 'str') grid.set_value(1, "col1", 25) grid.set_value(1, "col2", 7.54) grid.set_value(1, "col3", True) grid.set_value(1, "col4", "foo") grid.set_value(5, "col1", 0) grid.set_value(5, "col2", 789.644) grid.set_value(5, "col3", False) grid.set_value(5, "col4", "string") # grid.add_action(self.get_action('Reopen', ''),-1, {'modal':FORMTYPE_REFRESH}) self.add_component(grid)
def fillresponse(self): grid = XferCompGrid('grid') grid.set_location(0, 0) grid.add_header('col1', "Integer", 'int') grid.add_header('col2', "Float", 'float') grid.add_header('col3', "Boolean", 'bool') grid.add_header('col4', "String", 'str') grid.set_value(1, "col1", 25) grid.set_value(1, "col2", 7.54) grid.set_value(1, "col3", True) grid.set_value(1, "col4", "foo") grid.set_value(5, "col1", 0) grid.set_value(5, "col2", 789.644) grid.set_value(5, "col3", False) grid.set_value(5, "col4", "string") # grid.add_action(self.get_action('Reopen', ''),-1, {'modal':FORMTYPE_REFRESH}) self.add_component(grid)
class FiscalYearIncomeStatement(FiscalYearReport): caption = _("Income statement") def define_gridheader(self): self.grid = XferCompGrid('report_%d' % self.item.id) self.grid.add_header('left', _('Expense')) self.grid.add_header('left_n', self.item.get_identify()) self.grid.add_header('left_b', _('Budget')) if self.lastfilter is not None: self.grid.add_header( 'left_n_1', self.item.last_fiscalyear.get_identify()) self.grid.add_header('space', '') self.grid.add_header('right', _('Revenue')) self.grid.add_header('right_n', self.item.get_identify()) self.grid.add_header('right_b', _('Budget')) if self.lastfilter is not None: self.grid.add_header( 'right_n_1', self.item.last_fiscalyear.get_identify()) def fill_filterheader(self): if self.item.last_fiscalyear is not None: self.lastfilter = Q(entry__year=self.item.last_fiscalyear) lbl = XferCompLabelForm('sep_last') lbl.set_value("{[br/]}{[br/]}") lbl.set_location(2, 11, 3) self.add_component(lbl) lbl = XferCompLabelForm('lbllast_year') lbl.set_value_as_name(self.item.last_fiscalyear.get_identify()) lbl.set_location(1, 12) self.add_component(lbl) lbl = XferCompLabelForm('last_year') lbl.set_value(six.text_type(self.item.last_fiscalyear)) lbl.set_location(2, 12, 4) self.add_component(lbl) lbl = XferCompLabelForm('last_result') lbl.set_value(self.item.last_fiscalyear.total_result_text) lbl.set_location(2, 13, 4) self.add_component(lbl) def calcul_table(self): self.budgetfilter_right = Q(year=self.item) & Q(code__regex=current_system_account().get_revenue_mask()) self.budgetfilter_left = Q(year=self.item) & Q(code__regex=current_system_account().get_expence_mask()) self._add_left_right_accounting(Q(account__type_of_account=4), Q(account__type_of_account=3), True)
class ManageAccounting(CondominiumReport): def fill_header(self): CondominiumReport.fill_header(self) self.next_year = self.item.next_fiscalyear.first() if self.next_year is not None: lbl = XferCompLabelForm('yearn1') lbl.set_location(1, 2, 3) lbl.set_value(six.text_type(self.next_year)) lbl.description = _('year N+1') self.add_component(lbl) self.next_year_again = self.next_year.next_fiscalyear.first() if self.next_year_again is not None: lbl = XferCompLabelForm('yearn2') lbl.set_location(1, 3, 3) lbl.description = _('year N+2') lbl.set_value(six.text_type(self.next_year_again)) self.add_component(lbl) else: self.next_year_again = None def define_gridheader(self): self.grid = XferCompGrid('report_%d' % self.item.id) self.grid.add_header('design', _('Designation')) if self.item.last_fiscalyear is not None: self.grid.add_header('year_n_1', _('year N-1')) self.grid.add_header('budget_n', _('budget N')) self.grid.add_header('year_n', _('year N')) if self.next_year is not None: self.grid.add_header('budget_n1', _('budget N+1')) if self.next_year_again is not None: self.grid.add_header('budget_n2', _('budget N+2')) self.grid.set_location(0, 10, 6) self.grid.no_pager = True self.add_component(self.grid) def fill_part_of_grid(self, current_filter, query_budget, index_begin, title, sign_value=None): data_line, total1, total2, totalb = convert_query_to_account( self.filter & current_filter, self.lastfilter & current_filter, query_budget=query_budget, sign_value=sign_value) add_cell_in_grid(self.grid, index_begin, 'design', get_spaces(5) + '{[u]}%s{[/u]}' % title) line_idx = index_begin + 1 for data_item in data_line: add_cell_in_grid(self.grid, line_idx, 'design', data_item[0]) add_cell_in_grid(self.grid, line_idx, 'year_n', format_devise(data_item[1], 5)) add_cell_in_grid(self.grid, line_idx, 'budget_n', format_devise(data_item[3], 5)) if self.next_year is not None: add_cell_in_grid(self.grid, line_idx, 'budget_n1', format_devise(data_item[4], 5)) if self.next_year_again is not None: add_cell_in_grid(self.grid, line_idx, 'budget_n2', format_devise(data_item[5], 5)) if self.item.last_fiscalyear is not None: add_cell_in_grid(self.grid, line_idx, 'year_n_1', format_devise(data_item[2], 5)) line_idx += 1 add_cell_in_grid(self.grid, line_idx, 'design', '') line_idx += 1 add_cell_in_grid(self.grid, line_idx, 'design', get_spaces(5) + "{[u]}%s{[/u]}" % _('total')) add_cell_in_grid(self.grid, line_idx, 'year_n', "{[u]}%s{[/u]}" % format_devise(total1, 5)) add_cell_in_grid(self.grid, line_idx, 'budget_n', "{[u]}%s{[/u]}" % format_devise(totalb[0], 5)) if self.next_year is not None: add_cell_in_grid(self.grid, line_idx, 'budget_n1', "{[u]}%s{[/u]}" % format_devise(totalb[1], 5)) if self.next_year_again is not None: add_cell_in_grid(self.grid, line_idx, 'budget_n2', "{[u]}%s{[/u]}" % format_devise(totalb[2], 5)) if self.item.last_fiscalyear is not None: add_cell_in_grid(self.grid, line_idx, 'year_n_1', "{[u]}%s{[/u]}" % format_devise(total2, 5)) line_idx += 1 add_cell_in_grid(self.grid, line_idx, 'design', '') return line_idx, total1, total2, totalb
class FinancialStatus(CondominiumReport): caption = _("Financial status") def define_gridheader(self): self.grid = XferCompGrid('report_%d' % self.item.id) self.grid.add_header('left', _('Designation')) if self.item.last_fiscalyear is not None: self.grid.add_header('left_n_1', _('year N-1')) self.grid.add_header('left_n', _('year N')) self.grid.add_header('space', '') self.grid.add_header('right', _('Designation')) if self.item.last_fiscalyear is not None: self.grid.add_header('right_n_1', _('year N-1')) self.grid.add_header('right_n', _('year N')) self.grid.set_location(0, 10, 6) self.grid.no_pager = True self.add_component(self.grid) def fill_part_of_grid(self, side, current_filter, index_begin, title, sign_value=None, with_third=False): data_line, total1, total2, _totalb = convert_query_to_account( self.filter & current_filter, self.lastfilter & current_filter, sign_value=sign_value, with_third=with_third) add_cell_in_grid(self.grid, index_begin, side, get_spaces(5) + '{[u]}%s{[/u]}' % title) line_idx = index_begin + 1 line_idx = fill_grid(self.grid, line_idx, side, data_line) add_cell_in_grid(self.grid, line_idx, side, '') line_idx += 1 return line_idx, total1, total2 def fill_body(self): line__tresor, total1_tresor, total2_tresor = self.fill_part_of_grid( 'left', Q(account__code__regex=current_system_account().get_cash_mask()), 0, _('Tresory')) line__capital, total1_capital, total2_capital = self.fill_part_of_grid( 'right', Q(account__type_of_account=2), 0, _('Provision and advance')) line_idx = max(line__tresor, line__capital) add_item_in_grid(self.grid, line_idx, 'left', (_('total'), total1_tresor, total2_tresor, None), get_spaces(5) + "{[u]}%s{[/u]}") add_item_in_grid(self.grid, line_idx, 'right', (_('total'), total1_capital, total2_capital, None), get_spaces(5) + "{[u]}%s{[/u]}") add_cell_in_grid(self.grid, line_idx + 1, 'left', '') add_cell_in_grid(self.grid, line_idx + 1, 'right', '') last_ids = [] try: last_ids.append( EntryAccount.objects.filter( year=self.item).order_by('-id')[0].id) except IndexError: last_ids.append(0) if self.item.last_fiscalyear is not None: try: last_ids.append( EntryAccount.objects.filter( year=self.item.last_fiscalyear).order_by('-id')[0].id) except IndexError: last_ids.append(0) current_filter = Q(account__type_of_account__in=(0, 1)) & ~Q( account__code__regex=current_system_account().get_cash_mask()) current_filter &= ( ~Q(entry__year__status=2) | ~(Q(entry__journal=5) & Q(entry__id__in=tuple(last_ids)))) line__creance, total1_creance, total2_creance = self.fill_part_of_grid( 'left', current_filter, line_idx + 2, _('Créance'), sign_value=-1, with_third=True) line__dette, total1_dette, total2_dette = self.fill_part_of_grid( 'right', current_filter, line_idx + 2, _('Dettes'), sign_value=1, with_third=True) line_idx = max(line__creance, line__dette) add_item_in_grid(self.grid, line_idx, 'left', (_('total'), total1_creance, total2_creance, None), get_spaces(5) + "{[u]}%s{[/u]}") add_item_in_grid(self.grid, line_idx, 'right', (_('total'), total1_dette, total2_dette, None), get_spaces(5) + "{[u]}%s{[/u]}") add_cell_in_grid(self.grid, line_idx + 1, 'left', '') add_cell_in_grid(self.grid, line_idx + 1, 'right', '') add_item_in_grid(self.grid, line_idx + 2, 'left', (_('total'), total1_tresor + total1_creance, total2_tresor + total2_creance, None), get_spaces(5) + "{[b]}%s{[/b]}") add_item_in_grid(self.grid, line_idx + 2, 'right', (_('total'), total1_capital + total1_dette, total2_capital + total2_dette, None), get_spaces(5) + "{[b]}%s{[/b]}")
def fillresponse(self, season): if season is None: working_season = Season.current_season() else: working_season = Season.objects.get(id=season) img = XferCompImage('img') img.set_value(self.icon_path()) img.set_location(0, 0) self.add_component(img) lab = XferCompLabelForm('lbl_season') lab.set_value_as_name(_('season')) lab.set_location(1, 0) self.add_component(lab) sel = XferCompSelect('season') sel.set_needed(True) sel.set_select_query(Season.objects.all()) sel.set_value(working_season.id) sel.set_location(2, 0) sel.set_action(self.request, self.get_action('', ''), modal=FORMTYPE_REFRESH, close=CLOSE_NO) self.add_component(sel) stat_result = working_season.get_statistic() if len(stat_result) == 0: lab = XferCompLabelForm('lbl_season') lab.set_color('red') lab.set_value_as_infocenter(_('no subscription!')) lab.set_location(1, 1, 2) self.add_component(lab) else: tab_iden = 0 for stat_title, stat_city, stat_type in stat_result: tab_iden += 1 if (len(stat_city) > 0) and (len(stat_type) > 0): self.new_tab(stat_title) lab = XferCompLabelForm("lbltown_%d" % tab_iden) lab.set_underlined() lab.set_value(_("Result by city")) lab.set_location(0, 1) self.add_component(lab) grid = XferCompGrid("town_%d" % tab_iden) grid.add_header("city", _("city")) grid.add_header("MajW", _("women major")) grid.add_header("MajM", _("men major")) grid.add_header("MinW", _("women minor")) grid.add_header("MinM", _("men minor")) grid.add_header("ratio", _("total (%)")) cmp = 0 for stat_val in stat_city: for stat_key in stat_val.keys(): grid.set_value(cmp, stat_key, stat_val[stat_key]) cmp += 1 grid.set_location(0, 2) self.add_component(grid) lab = XferCompLabelForm("lbltype_%d" % tab_iden) lab.set_underlined() lab.set_value(_("Result by type")) lab.set_location(0, 3) self.add_component(lab) grid = XferCompGrid("type_%d" % tab_iden) grid.add_header("type", _("type")) grid.add_header("MajW", _("women major")) grid.add_header("MajM", _("men major")) grid.add_header("MinW", _("women minor")) grid.add_header("MinM", _("men minor")) grid.add_header("ratio", _("total (%)")) cmp = 0 for stat_val in stat_type: for stat_key in stat_val.keys(): if (stat_key == 'type') and not isinstance(stat_val['type'], six.text_type): grid.set_value(cmp, stat_key, six.text_type( SubscriptionType.objects.get(id=stat_val['type']))) else: grid.set_value( cmp, stat_key, stat_val[stat_key]) cmp += 1 grid.set_location(0, 4) self.add_component(grid) self.add_action(AdherentStatisticPrint.get_action(TITLE_PRINT, "images/print.png"), close=CLOSE_NO, params={'classname': self.__class__.__name__}) self.add_action(WrapAction(TITLE_CLOSE, 'images/close.png'))
class CostAccountingReport(FiscalYearReport): icon = "costAccounting.png" model = CostAccounting field_id = 'costaccounting' def fillresponse(self): for self.item in self.items: self.new_tab(six.text_type(self.item)) self.fill_header() self.calcul_table() self.fill_body() self.fill_buttons() def define_gridheader(self): self.grid = XferCompGrid('report_%d' % self.item.id) self.grid.add_header('left', _('Expenses')) self.grid.add_header('left_n', _('Value')) self.grid.add_header('left_b', _('Budget')) if self.lastfilter is not None: self.grid.add_header('left_n_1', _('Last')) self.grid.add_header('space', '') self.grid.add_header('right', _('Revenues')) self.grid.add_header('right_n', _('Value')) self.grid.add_header('right_b', _('Budget')) if self.lastfilter is not None: self.grid.add_header('right_n_1', _('Last')) def fill_filterheader(self): pass def fill_header(self): img = XferCompImage('img') img.set_value(self.icon_path()) img.set_location(0, 0, 1, 3) self.add_component(img) lbl = XferCompLabelForm('lblname') lbl.set_value_as_name( self.model._meta.verbose_name) lbl.set_location(1, 2) self.add_component(lbl) lbl = XferCompLabelForm('name') lbl.set_value(self.item) lbl.set_location(2, 2, 4) self.add_component(lbl) self.filltab_from_model(1, 6, True, [( (_('total revenue'), 'total_revenue'), (_('total expense'), 'total_expense'))]) self.filter = Q(entry__costaccounting=self.item) self.fill_filterCode() self.fill_filterheader() self.define_gridheader()
class FiscalYearBalanceSheet(FiscalYearReport): caption = _("Balance sheet") def fill_filterheader(self): if self.item.last_fiscalyear is not None: self.lastfilter = Q(entry__year=self.item.last_fiscalyear) lbl = XferCompLabelForm('sep_last') lbl.set_value("{[br/]}{[br/]}") lbl.set_location(2, 11, 3) self.add_component(lbl) lbl = XferCompLabelForm('lbllast_year') lbl.set_value_as_name(self.item.last_fiscalyear.get_identify()) lbl.set_location(1, 12) self.add_component(lbl) lbl = XferCompLabelForm('last_year') lbl.set_value(six.text_type(self.item.last_fiscalyear)) lbl.set_location(2, 12, 4) self.add_component(lbl) lbl = XferCompLabelForm('last_result') lbl.set_value(self.item.last_fiscalyear.total_result_text) lbl.set_location(2, 13, 4) self.add_component(lbl) def define_gridheader(self): self.grid = XferCompGrid('report_%d' % self.item.id) self.grid.add_header('left', _('Assets')) self.grid.add_header('left_n', self.item.get_identify()) if self.lastfilter is not None: self.grid.add_header( 'left_n_1', self.item.last_fiscalyear.get_identify()) self.grid.add_header('space', '') self.grid.add_header('right', _('Liabilities')) self.grid.add_header('right_n', self.item.get_identify()) if self.lastfilter is not None: self.grid.add_header( 'right_n_1', self.item.last_fiscalyear.get_identify()) def calcul_table(self): self._add_left_right_accounting( Q(account__type_of_account=0), Q(account__type_of_account__in=(1, 2)), False)
def fillresponse(self, modelname, quotechar="'", delimiter=";", encoding="utf-8", dateformat="%d/%m/%Y", step=0): def add_item_if_not_null(new_item): if new_item is not None: self.items_imported[new_item.id] = new_item if modelname is not None: self.model = apps.get_model(modelname) self.quotechar = quotechar self.delimiter = delimiter self.encoding = encoding self.dateformat = dateformat img = XferCompImage('img') img.set_value(self.icon_path()) img.set_location(0, 0, 1, 6) self.add_component(img) if step == 0: lbl = self._select_csv_parameters() step = 1 elif step == 1: lbl = XferCompLabelForm('modelname') lbl.set_value(self.model._meta.verbose_name.title()) lbl.set_location(1, 0) lbl.description = _('model') self.add_component(lbl) self._read_csv() self.new_tab(_("Fields")) self._select_fields() self.new_tab(_("Current content")) self._show_initial_csv() step = 2 elif step == 2: lbl = XferCompLabelForm('modelname') lbl.set_value(self.model._meta.verbose_name.title()) lbl.set_location(1, 0) lbl.description = _('model') self.add_component(lbl) fields_description, csv_readed = self._read_csv_and_convert() tbl = XferCompGrid('CSV') for field_description in fields_description: tbl.add_header(field_description[0], field_description[1], field_description[2], formatstr=field_description[3]) row_idx = 1 for row in csv_readed: for field_description in fields_description: tbl.set_value(row_idx, field_description[0], row[field_description[0]]) row_idx += 1 tbl.set_location(1, 1, 2) self.add_component(tbl) lbl = XferCompLabelForm('nb_line') lbl.set_value(_("Total number of items: %d") % (row_idx - 1)) lbl.set_location(1, 2, 2) self.add_component(lbl) step = 3 elif step == 3: fields_description, csv_readed = self._read_csv_and_convert() self.model.initialize_import() self.items_imported = {} for rowdata in csv_readed: add_item_if_not_null(self.model.import_data(rowdata, dateformat)) add_item_if_not_null(self.model.finalize_import()) lbl = XferCompLabelForm('result') lbl.set_value_as_header(_("%d items are been imported") % len(self.items_imported)) lbl.set_location(1, 2, 2) self.add_component(lbl) step = 4 if step < 4: if step > 1: self.add_action(self.get_action(_('Back'), "images/left.png"), close=CLOSE_NO, modal=FORMTYPE_REFRESH, params={'step': step - 2}) self.add_action(self.get_action(_('Ok'), "images/ok.png"), close=CLOSE_NO, modal=FORMTYPE_REFRESH, params={'step': step}) self.add_action(WrapAction(_("Cancel"), "images/cancel.png")) else: self.add_action(WrapAction(_("Close"), "images/close.png"))