def __json__(self, request): return dict( id=self.id, task_id=self.task_id, description=self.description, amount=integer_to_amount(self.amount, 5), tva=integer_to_amount(self.tva, 2), )
def get_val(self, line): if hasattr(line, 'ht'): val = integer_to_amount(line.ht) else: val = integer_to_amount(line.total) # Le total_ht s'affiche en bas de page en mode calculée self.ht += integer_to_amount(line.total_ht) return val
def write_table_footer(self, columns, lines): """ Write table footer (total, ht, tva, km) :param list columns: The columns as described in the static vars here above :param list lines: The lines presented in this table """ for column in columns: cell = self.get_column_cell(column) cell.style = FOOTER_CELL if not column.static: value = column.ht cell.value = value if value == 0 and not column.force_visible: col_width = 0 else: col_width = 13 self.set_col_width(column.start_letter, col_width) elif column.key == 'description': cell.value = "Totaux" elif column.key == 'total_ht': cell.value = integer_to_amount( sum( [ getattr(line, 'total_ht', 0) for line in lines ] ) ) elif column.key == 'tva': cell.value = integer_to_amount( sum( [ getattr(line, 'total_tva', 0) for line in lines ] ) ) elif column.key == 'km': cell.value = integer_to_amount( sum( [getattr(line, 'km', 0) for line in lines] ) ) elif column.key == 'total': cell.value = integer_to_amount( sum( [line.total for line in lines] ) ) self.index += 4
def __json__(self, request): res = BaseExpenseLine.__json__(self, request) res.update( dict( ht=integer_to_amount(self.ht, 2), tva=integer_to_amount(self.tva, 2) ) ) return res
def __json__(self, request): """ Return the datas used by the json renderer to represent this task """ return dict( id=self.id, name=self.name, created_at=self.created_at.isoformat(), updated_at=self.updated_at.isoformat(), phase_id=self.phase_id, business_type_id=self.business_type_id, status=self.status, status_comment=self.status_comment, status_person_id=self.status_person_id, # status_date=self.status_date.isoformat(), date=self.date.isoformat(), owner_id=self.owner_id, description=self.description, ht=integer_to_amount(self.ht, 5), tva=integer_to_amount(self.tva, 5), ttc=integer_to_amount(self.ttc, 5), company_id=self.company_id, project_id=self.project_id, customer_id=self.customer_id, project_index=self.project_index, company_index=self.company_index, official_number=self.official_number, internal_number=self.internal_number, display_units=self.display_units, expenses_ht=integer_to_amount(self.expenses_ht, 5), address=self.address, workplace=self.workplace, payment_conditions=self.payment_conditions, notes=self.notes, status_history=[ status.__json__(request) for status in self.statuses ], discounts=[ discount.__json__(request) for discount in self.discounts ], payments=[ payment.__json__(request) for payment in self.payments ], mentions=[mention.id for mention in self.mentions], line_groups=[ group.__json__(request) for group in self.line_groups ], attachments=[ file_.__json__(request) for file_ in self.files ], file_requirements=[ file_req.__json__(request) for file_req in self.file_requirements ] )
def __json__(self, request): return dict( id=self.id, order=self.order, index=self.order, description=self.description, cost=integer_to_amount(self.amount, 5), amount=integer_to_amount(self.amount, 5), date=self.date.isoformat(), task_id=self.task_id, )
def __json__(self, request): """ Return the datas used by the json renderer to represent this task """ return dict( id=self.id, name=self.name, created_at=self.created_at.isoformat(), updated_at=self.updated_at.isoformat(), phase_id=self.phase_id, status=self.status, status_comment=self.status_comment, status_person_id=self.status_person_id, # status_date=self.status_date.isoformat(), date=self.date.isoformat(), owner_id=self.owner_id, description=self.description, ht=integer_to_amount(self.ht, 5), tva=integer_to_amount(self.tva, 5), ttc=integer_to_amount(self.ttc, 5), company_id=self.company_id, project_id=self.project_id, customer_id=self.customer_id, project_index=self.project_index, company_index=self.company_index, official_number=self.official_number, internal_number=self.internal_number, display_units=self.display_units, expenses_ht=integer_to_amount(self.expenses_ht, 5), address=self.address, workplace=self.workplace, payment_conditions=self.payment_conditions, status_history=[ status.__json__(request) for status in self.statuses ], discounts=[ discount.__json__(request) for discount in self.discounts ], payments=[ payment.__json__(request) for payment in self.payments ], mentions=[mention.id for mention in self.mentions], line_groups=[ group.__json__(request) for group in self.line_groups ], attachments=[ file_.__json__(request) for file_ in self.files ], file_requirements=[ file_req.__json__(request) for file_req in self.file_requirements ] )
def __json__(self, request): result = dict( id=self.id, order=self.order, cost=integer_to_amount(self.cost, 5), tva=integer_to_amount(self.tva, 2), description=self.description, quantity=self.quantity, unity=self.unity, group_id=self.group_id, product_id=self.product_id, ) return result
def get_turnover(self, year): """ Retrieve the annual turnover for the current company :param int year: The current year """ ca = self._autonomie_service.get_turnover(self, year) return math_utils.integer_to_amount(ca, precision=5)
def __json__(self, request): return dict( id=self.id, created_at=self.created_at, updated_at=self.updated_at, mode=self.mode, amount=math_utils.integer_to_amount(self.amount), bank_remittance_id=self.bank_remittance_id, label=self.bank_remittance_id, date=self.date, exported=self.exported, task_id=self.task_id, bank_id=self.bank_id, bank=self.bank.label, tva_id=self.tva_id, tva=math_utils.integer_to_amount(self.tva.value, 2), user_id=self.user_id, )
def __json__(self, request): return dict( id=self.id, value=integer_to_amount(self.value, 2), label=self.name, name=self.name, default=self.default, products=[product.__json__(request) for product in self.products], )
def __json__(self, request): res = BaseExpenseLine.__json__(self, request) res.update( dict( km=integer_to_amount(self.km), start=self.start, end=self.end, vehicle=self.vehicle, )) return res
def get_cell_val(self, line, column): """ return the value for a given cell for the current line """ if line.type_object is None: val = "" elif column.has_key('key'): val = getattr(line, column['key'], '') formatter = column.get('formatter') if val and formatter: val = formatter(val) elif column['code'] == line.type_object.code: if hasattr(line, 'ht'): val = integer_to_amount(line.ht) else: val = integer_to_amount(line.total) else: val = "" return val
def __json__(self, request): res = BaseExpenseLine.__json__(self, request) res.update( dict( km=integer_to_amount(self.km), start=self.start, end=self.end, vehicle=self.vehicle, ) ) return res
def serialize(self, node, appstruct): if appstruct is colander.null: return colander.null try: return str(integer_to_amount(self.num(appstruct), self.precision)) except Exception: raise colander.Invalid( node, u"\"{val}\" n'est pas un montant valide".format(val=appstruct), )
def write_total(self): """ write the final total """ cell = self.get_merged_cells('A', 'D') cell.value = u"Total des frais professionnel à payer" cell.style = LARGE_FOOTER_CELL cell = self.get_merged_cells('E', 'E') cell.value = integer_to_amount(self.model.total) cell.style = LARGE_FOOTER_CELL self.index += 2
def write_total(self): """ write the final total """ cell = self.get_merged_cells('A', 'D') cell.value = u"Total des dépenses professionnelles à payer" cell.style = LARGE_FOOTER_CELL cell = self.get_merged_cells('E', 'E') cell.value = integer_to_amount(self.model.total) cell.style = LARGE_FOOTER_CELL self.index += 2
def write_table(self, columns, lines): """ write a table with headers and content :param columns: list of dict :params lines: list of models to be written """ self.write_table_header(columns) for line in lines: for column in columns: cell = self.get_column_cell(column) cell.value = self.get_cell_val(line, column) if column.has_key('number_format'): cell.style.number_format.format_code = \ column['number_format'] self.index += 1 for column in columns: cell = self.get_column_cell(column) cell.style.font.bold = True self.set_color(cell, Color.footer) cell.style.number_format.format_code = '0.00' if column.has_key('code'): val = sum([line.ht for line in lines \ if line.type_object \ and line.type_object.code==column['code']]) cell.value = integer_to_amount(val) if val == 0: self.set_col_width(column['letter'], 0) else: self.set_col_width(column['letter'], 13) elif column.get('key') == 'description': cell.value = "Totaux" elif column.get('key') == 'tva': cell.value = integer_to_amount( sum([getattr(line, 'tva', 0) for line in lines])) cell.style.number_format.format_code = '0.00' elif column.get('key') == 'total': cell.value = integer_to_amount( sum([line.total for line in lines])) cell.style.number_format.format_code = '0.00' self.index += 4
def __json__(self, request): """ Json repr of our model """ return dict( id=self.id, label=self.label, ref=self.ref, description=self.description, tva=integer_to_amount(self.tva, 2), value=self.value, unity=self.unity, category_id=self.category_id, category=self.category.title, )
def write_total(self): """ write the final total """ cell = self.get_merged_cells('A', 'D') cell.value = u"Total des frais professionnel à payer" cell.style.font.bold = True cell.style.font.size = 16 self.set_color(cell, Color.footer) cell = self.get_merged_cells('E', 'E') cell.style.font.bold = True cell.style.font.size = 16 cell.value = integer_to_amount(self.model.total) cell.style.number_format.format_code = '0.00' self.set_color(cell, Color.footer) self.index += 2
def __json__(self, request): """ Build a Json representation of this object :rtype: dict """ return dict( id=self.id, created_at=self.created_at, updated_at=self.updated_at, mode=self.mode, amount=math_utils.integer_to_amount(self.amount, 5), bank_remittance_id=self.bank_remittance_id, date=self.date, exporter=self.exported, task_id=self.task_id, bank_id=self.bank_id, tva_id=self.tva_id, user_id=self.user_id, )
def write_table(self, columns, lines): """ write a table with headers and content :param columns: list of dict :params lines: list of models to be written """ self.write_table_header(columns) for line in lines: got_value = False for column in columns: cell = self.get_column_cell(column) if column.static: # On récupère les valeurs pour les colonnes fixes value = self.get_formatted_cell_val( line, column, ) else: # On récupère les valeurs pour les colonnes spécifiques à # chaque type de données # Première passe on essaye de remplir les colonnes pour la # ligne de dépense données en fonction de l'id du type de # dépense associé value = self.get_cell_val(line, column, by_id=True) if value: got_value = True cell.value = value if column.style: cell.style = column.style # Deuxième passe, on a rempli aucune case pour cette ligne on va # essayer de remplir les colonnes en recherchant le type de dépense # par code if not got_value: for column in columns: cell = self.get_column_cell(column) if not column.static and not got_value: value = self.get_cell_val( line, column, by_id=False, ) if value: got_value = True cell.value = value if column.style: cell.style = column.style self.index += 1 for column in columns: cell = self.get_column_cell(column) cell.style = FOOTER_CELL if not column.static: value = column.ht cell.value = value if value == 0 and not column.force_visible: col_width = 0 else: col_width = 13 self.set_col_width(column.start_letter, col_width) elif column.key == 'description': cell.value = "Totaux" elif column.key == 'tva': cell.value = integer_to_amount( sum( [ getattr(line, 'total_tva', 0) for line in lines ] ) ) elif column.key == 'total': cell.value = integer_to_amount( sum( [line.total for line in lines] ) ) self.index += 4
def write_table(self, columns, lines): """ write a table with headers and content :param columns: list of dict :params lines: list of models to be written """ self.write_table_header(columns) for line in lines: got_value = False for column in columns: cell = self.get_column_cell(column) if column.static: # On récupère les valeurs pour les colonnes fixes value = self.get_formatted_cell_val( line, column, ) else: # On récupère les valeurs pour les colonnes spécifiques à # chaque type de données # Première passe on essaye de remplir les colonnes pour la # ligne de frais données en fonction de l'id du type de # frais associé value = self.get_cell_val(line, column, by_id=True) if value: got_value = True cell.value = value if column.style: cell.style = column.style # Deuxième passe, on a rempli aucune case pour cette ligne on va # essayer de remplir les colonnes en recherchant le type de frais # par code if not got_value: for column in columns: cell = self.get_column_cell(column) if not column.static and not got_value: value = self.get_cell_val( line, column, by_id=False, ) if value: got_value = True cell.value = value if column.style: cell.style = column.style self.index += 1 for column in columns: cell = self.get_column_cell(column) cell.style = FOOTER_CELL if not column.static: value = column.ht cell.value = value if value == 0 and not column.force_visible: col_width = 0 else: col_width = 13 self.set_col_width(column.start_letter, col_width) elif column.key == 'description': cell.value = "Totaux" elif column.key == 'tva': cell.value = integer_to_amount( sum( [ getattr(line, 'total_tva', 0) for line in lines ] ) ) elif column.key == 'total': cell.value = integer_to_amount( sum( [line.total for line in lines] ) ) self.index += 4