def _search_or_create_bill(self): high_contact = self.contact.get_final_child() new_third = get_or_create_customer(high_contact.get_ref_contact().id) bill_list = Bill.objects.filter( third=new_third, bill_type=1, status=0).annotate(participant_count=Count('participant')).filter( participant_count__gte=1).order_by('-date') if len(bill_list) > 0: self.bill = bill_list[0] if self.bill is None: self.bill = Bill.objects.create(bill_type=1, date=date.today(), third=new_third) return high_contact
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)