Compare commits

...

2 Commits

Author SHA1 Message Date
Raphael Michel
5e3f9178f5 Bump version to 4.4.0 2021-10-29 15:37:30 +02:00
Raphael Michel
03ea47715d Fix check_order_transactions on SQLite 2021-10-29 15:37:22 +02:00
2 changed files with 8 additions and 5 deletions

View File

@@ -19,4 +19,4 @@
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see # You should have received a copy of the GNU Affero General Public License along with this program. If not, see
# <https://www.gnu.org/licenses/>. # <https://www.gnu.org/licenses/>.
# #
__version__ = "4.4.0.dev0" __version__ = "4.4.0"

View File

@@ -43,7 +43,7 @@ class Command(BaseCommand):
order=OuterRef('pk') order=OuterRef('pk')
).order_by().values('order').annotate(p=Sum('price')).values('p'), ).order_by().values('order').annotate(p=Sum('price')).values('p'),
output_field=models.DecimalField(decimal_places=2, max_digits=10) output_field=models.DecimalField(decimal_places=2, max_digits=10)
), Value(Decimal(0)), output_field=models.DecimalField(decimal_places=2, max_digits=10) ), Value(0), output_field=models.DecimalField(decimal_places=2, max_digits=10)
), ),
fee_total=Coalesce( fee_total=Coalesce(
Subquery( Subquery(
@@ -51,7 +51,7 @@ class Command(BaseCommand):
order=OuterRef('pk') order=OuterRef('pk')
).order_by().values('order').annotate(p=Sum('value')).values('p'), ).order_by().values('order').annotate(p=Sum('value')).values('p'),
output_field=models.DecimalField(decimal_places=2, max_digits=10) output_field=models.DecimalField(decimal_places=2, max_digits=10)
), Value(Decimal(0)), output_field=models.DecimalField(decimal_places=2, max_digits=10) ), Value(0), output_field=models.DecimalField(decimal_places=2, max_digits=10)
), ),
tx_total=Coalesce( tx_total=Coalesce(
Subquery( Subquery(
@@ -59,12 +59,12 @@ class Command(BaseCommand):
order=OuterRef('pk') order=OuterRef('pk')
).order_by().values('order').annotate(p=Sum(F('price') * F('count'))).values('p'), ).order_by().values('order').annotate(p=Sum(F('price') * F('count'))).values('p'),
output_field=models.DecimalField(decimal_places=2, max_digits=10) output_field=models.DecimalField(decimal_places=2, max_digits=10)
), Value(Decimal(0)), output_field=models.DecimalField(decimal_places=2, max_digits=10) ), Value(0), output_field=models.DecimalField(decimal_places=2, max_digits=10)
), ),
).annotate( ).annotate(
correct_total=Case( correct_total=Case(
When(Q(status=Order.STATUS_CANCELED) | Q(status=Order.STATUS_EXPIRED) | Q(require_approval=True), When(Q(status=Order.STATUS_CANCELED) | Q(status=Order.STATUS_EXPIRED) | Q(require_approval=True),
then=Value(Decimal(0))), then=Value(0)),
default=F('position_total') + F('fee_total'), default=F('position_total') + F('fee_total'),
output_field=models.DecimalField(decimal_places=2, max_digits=10) output_field=models.DecimalField(decimal_places=2, max_digits=10)
), ),
@@ -73,6 +73,9 @@ class Command(BaseCommand):
tx_total=F('correct_total') tx_total=F('correct_total')
).select_related('event') ).select_related('event')
for o in qs: for o in qs:
if abs(o.tx_total - o.correct_total) < Decimal('0.00001') and abs(o.position_total + o.fee_total - o.total) < Decimal('0.00001'):
# Ignore SQLite which treats Decimals like floats…
continue
print(f"Error in order {o.full_code}: status={o.status}, sum(positions)+sum(fees)={o.position_total + o.fee_total}, " print(f"Error in order {o.full_code}: status={o.status}, sum(positions)+sum(fees)={o.position_total + o.fee_total}, "
f"order.total={o.total}, sum(transactions)={o.tx_total}, expected={o.correct_total}") f"order.total={o.total}, sum(transactions)={o.tx_total}, expected={o.correct_total}")