def create_bill(self): if self.article is not None: high_contact = self._search_or_create_bill() bill_comment = [ "{[b]}%s{[/b]}: %s" % (self.event.event_type_txt, self.event.date_txt) ] bill_comment.append("{[i]}%s{[/i]}" % self.event.comment) if (self.bill.third.contact.id == high_contact.id) and (self.event.event_type == 1) and ( self.comment is not None) and (self.comment != ''): bill_comment.append(self.comment) self.bill.comment = "{[br/]}".join(bill_comment) self.bill.save() self.bill.detail_set.all().delete() participant_list = list(self.bill.participant_set.all()) if self not in participant_list: participant_list.append(self) for participant in participant_list: detail_comment = [participant.article.designation] if participant.bill.third.contact.id != participant.contact.id: detail_comment.append( _("Participant: %s") % six.text_type(participant.contact)) if (participant.event.event_type == 1) and (participant.comment is not None) and ( participant.comment != ''): detail_comment.append(participant.comment) Detail.create_for_bill( participant.bill, participant.article, reduce=participant.reduce, designation="{[br/]}".join(detail_comment)) self.save()
def create_bill(self): if self.bill is not None: self.bill.delete() self.bill = None self.save() if self.article is not None: self.bill = Bill.objects.create( bill_type=1, date=date.today(), third=get_or_create_customer(self.contact_id)) cost_acc = CostAccounting.objects.filter(is_default=True) if len(cost_acc) > 0: self.bill.cost_accounting = cost_acc[0] self.bill.comment = "{[b]}%s{[/b]}: %s" % ( self.event.event_type_txt, self.event.date_txt) self.bill.save() Detail.create_for_bill(self.bill, self.article) self.save()
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)