def __init__(self, dados): super(MyPDF, self).__init__() self.oficina = DadosOficina() self.dados = dados if (dados['tipo'] == tupla_tipo_historico[0][0]): self.tipo = tupla_tipo_historico[0][1] else: self.tipo = tupla_tipo_historico[1][1] self.numero_ordem = str(dados['numero_ordem']) self.cliente = dados['cliente']['nome'] self.endereco = dados['cliente']['endereco'] self.endereco += ' - ' + dados['cliente']['complemento'] self.endereco += ' - ' + dados['cliente']['bairro'] self.endereco += ' - ' + dados['cliente']['cidade'] self.endereco += ' - ' + dados['cliente']['estado'] self.telefone = dados['cliente']['telefone'] self.celular = dados['cliente']['celular'] self.telefone_comercial = dados['cliente']['telefone_comercial'] self.cpf = dados['cliente']['cpf'] self.tecnico = '' if self.dados.get('tecnico'): self.tecnico = dados['tecnico']['nome'] veiculo = '' ano = '' if self.dados.get('veiculo'): veiculo += dados['veiculo']['placa'] ano = str(dados['veiculo']['ano']) if self.dados.get('modelo'): veiculo += ' - ' + dados['modelo']['nome'] if self.dados.get('montadora'): veiculo += ' - ' + dados['montadora']['nome'] veiculo += ' - Ano: ' + ano veiculo += ' - Km: ' + '%.0f' % (to_float_or_zero( dados['vistoria']['kilometragem'])) self.veiculo = veiculo self.data = format_date(from_str_to_datetime_or_none(dados['data'])) self.falhas = [] self.servicos = [] self.pecas = [] self.sub_total_servicos = 0 self.sub_total_pecas = 0 for item in dados['items']: if item['tipo'] == 'F': self.falhas.append(item) elif item['tipo'] == 'P': self.pecas.append(item) self.sub_total_pecas += item['quantidade'] * item['valor'] elif item['tipo'] == 'S': self.servicos.append(item) self.sub_total_servicos += item['quantidade'] * item['valor'] self.total = self.sub_total_servicos + self.sub_total_pecas self.observacoes = dados['observacao']
def as_dict(self): return {"id": self.id, "username": self.username, "email": self.email, "created_time": format_date(self.created_time), "first_name": self.user_detail.first_name, "last_name": self.user_detail.last_name, "gender": self.user_detail.gender, "dob": self.get_dob(), "phone": self.user_detail.phone, "bio": self.user_detail.bio, "url": self.user_detail.url }
def as_dict(self): return { "id": self.id, "username": self.username, "email": self.email, "created_time": format_date(self.created_time), "first_name": self.user_detail.first_name, "last_name": self.user_detail.last_name, "gender": self.user_detail.gender, "dob": self.get_dob(), "phone": self.user_detail.phone, "bio": self.user_detail.bio, "url": self.user_detail.url }
def to_json(self, include_logistic=False, replace_entries_to_refunded=False): if not self.is_paid: self.update_amount() self.reload() entries_json = [] if replace_entries_to_refunded and self.has_refund_entries(): for e in self.refund_entries: entries_json.append(e.to_json()) else: for e in self.entries: entries_json.append(e.to_json()) refund_entries_json = [] for e in self.refund_entries: refund_entries_json.append(e.to_json()) result = dict( id=str(self.id), short_id=str(self.sid), status=self.status, customer_id=str(self.customer_id), amount=self.amount, cn_shipping=self.cn_shipping, coin=self.coin, lucky_money=self.lucky_money, discount=self.discount, final=self.final, estimated_tax=self.estimated_tax, payment_status='PAID' if self.is_paid else 'UNPAID', payment_ref_number=[ p.ref_number for p in Payment.objects(order=self) ], created_at=format_date(self.created_at), entries=entries_json, refund_entries=refund_entries_json, refund_amount=self.refund_amount, real_tax=self.real_tax, ) if self.address: result.update({'address': self.address.to_json()}) if include_logistic: result.update(logistics=[l.to_json() for l in self.logistics]) return result
def gen_raw_users(qty): id_list = [] rows = [] for i in range(qty): uid = shortuuid.uuid() sex = 'W' if random.randint(0, 1) == 0 else 'M' name = utils.rand_elem(female_names) if sex == "W" else utils.rand_elem(male_names) birth_date = utils.format_date(rand_user_birth_date()) user_dict = { '_id': uid, 'surname': utils.rand_elem(surnames), 'name': name, 'birth_date': {'$date': birth_date+"T00:00:00Z"}, 'sex': sex } rows.append(user_dict) id_list.append(uid) return id_list, rows
def get_single_line_chart_hist(json, is_new_stats): stats = defaultdict(lambda: defaultdict(list)) for stats_type in json: last_value = 0 for date in json[stats_type]: date_obj = utils.parse_date(date) date_str = utils.format_date(date_obj) stats[stats_type]["labels"].append(date_str) stats[stats_type]["total"] = json[stats_type][date] curr_value = json[stats_type][date] if is_new_stats: new_value = curr_value - last_value last_value = curr_value else: new_value = curr_value stats[stats_type]["data"].append(new_value) return stats