Always compute state
This commit is contained in:
parent
259ed388b4
commit
74f72ed8a1
|
@ -108,8 +108,7 @@ class Bill(models.Model):
|
|||
is_sent = models.BooleanField(_("sent"), default=False)
|
||||
due_on = models.DateField(_("due on"), null=True, blank=True)
|
||||
updated_on = models.DateField(_("updated on"), auto_now=True)
|
||||
# TODO allways compute total or what?
|
||||
total = models.DecimalField(max_digits=12, decimal_places=2, null=True)
|
||||
# total = models.DecimalField(max_digits=12, decimal_places=2, null=True)
|
||||
comments = models.TextField(_("comments"), blank=True)
|
||||
html = models.TextField(_("HTML"), blank=True)
|
||||
|
||||
|
@ -125,6 +124,10 @@ class Bill(models.Model):
|
|||
def get_class_type(cls):
|
||||
return cls.__name__.upper()
|
||||
|
||||
@cached_property
|
||||
def total(self):
|
||||
return self.compute_total()
|
||||
|
||||
@cached_property
|
||||
def seller(self):
|
||||
return Account.get_main().billcontact
|
||||
|
@ -253,10 +256,10 @@ class Bill(models.Model):
|
|||
payment = self.account.paymentsources.get_default()
|
||||
if not self.due_on:
|
||||
self.due_on = self.get_due_date(payment=payment)
|
||||
self.total = self.compute_total()
|
||||
total = self.compute_total()
|
||||
transaction = None
|
||||
if self.get_type() != self.PROFORMA:
|
||||
transaction = self.transactions.create(bill=self, source=payment, amount=self.total)
|
||||
transaction = self.transactions.create(bill=self, source=payment, amount=total)
|
||||
self.closed_on = timezone.now()
|
||||
self.is_open = False
|
||||
self.is_sent = False
|
||||
|
@ -441,12 +444,6 @@ class BillLine(models.Model):
|
|||
else:
|
||||
total += self.sublines.aggregate(sub_total=Sum('total'))['sub_total'] or 0
|
||||
return round(total, 2)
|
||||
|
||||
# def save(self, *args, **kwargs):
|
||||
# super(BillLine, self).save(*args, **kwargs)
|
||||
# if self.bill.is_open:
|
||||
# self.bill.total = self.bill.get_total()
|
||||
# self.bill.save(update_fields=['total'])
|
||||
|
||||
|
||||
class BillSubline(models.Model):
|
||||
|
@ -465,10 +462,3 @@ class BillSubline(models.Model):
|
|||
description = models.CharField(_("description"), max_length=256)
|
||||
total = models.DecimalField(max_digits=12, decimal_places=2)
|
||||
type = models.CharField(_("type"), max_length=16, choices=TYPES, default=OTHER)
|
||||
|
||||
# def save(self, *args, **kwargs):
|
||||
# # TODO cost of this shit
|
||||
# super(BillSubline, self).save(*args, **kwargs)
|
||||
# if self.line.bill.is_open:
|
||||
# self.line.bill.total = self.line.bill.get_total()
|
||||
# self.line.bill.save(update_fields=['total'])
|
||||
|
|
|
@ -176,10 +176,10 @@ commit.verbose_name = _("Commit")
|
|||
|
||||
def delete_selected(modeladmin, request, queryset):
|
||||
""" Has to have same name as admin.actions.delete_selected """
|
||||
related_transactions = helpers.pre_delete_processes(modelamdin, request, queryset)
|
||||
related_transactions = helpers.pre_delete_processes(modeladmin, request, queryset)
|
||||
response = actions.delete_selected(modeladmin, request, queryset)
|
||||
if response is None:
|
||||
helpers.post_delete_processes(modelamdin, request, related_transactions)
|
||||
helpers.post_delete_processes(modeladmin, request, related_transactions)
|
||||
return response
|
||||
delete_selected.short_description = actions.delete_selected.short_description
|
||||
|
||||
|
|
|
@ -94,8 +94,10 @@ class TransactionAdmin(SelectAccountAdminMixin, ExtendedModelAdmin):
|
|||
actions = change_view_actions + (actions.report,)
|
||||
filter_by_account_fields = ('bill', 'source')
|
||||
change_readonly_fields = ('amount', 'currency')
|
||||
readonly_fields = ('bill_link', 'display_state', 'process_link', 'account_link', 'source_link')
|
||||
list_select_related = ('source', 'bill__account')
|
||||
readonly_fields = (
|
||||
'bill_link', 'display_state', 'process_link', 'account_link', 'source_link'
|
||||
)
|
||||
list_select_related = ('source', 'bill__account', 'process')
|
||||
date_hierarchy = 'created_at'
|
||||
|
||||
bill_link = admin_link('bill')
|
||||
|
@ -174,7 +176,8 @@ class TransactionProcessAdmin(ChangeViewActionsMixin, admin.ModelAdmin):
|
|||
def delete_view(self, request, object_id, extra_context=None):
|
||||
queryset = self.model.objects.filter(id=object_id)
|
||||
related_transactions = helpers.pre_delete_processes(self, request, queryset)
|
||||
response = super(TransactionProcessAdmin, self).delete_view(request, object_id, extra_context)
|
||||
response = super(TransactionProcessAdmin, self).delete_view(
|
||||
request, object_id, extra_context)
|
||||
if isinstance(response, HttpResponseRedirect):
|
||||
helpers.post_delete_processes(self, request, related_transactions)
|
||||
return response
|
||||
|
|
Loading…
Reference in a new issue