# Generated by Django 2.2.5 on 2019-10-02 08:05

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [("invoices", "0018_auto_20190916_1110")]

    operations = [
        migrations.RunSQL(
            """
UPDATE invoices_invoice i
SET
third_party_costs=COALESCE(
    (
        SELECT SUM(third_party_costs)
        FROM invoices_service s
        WHERE
            s.invoice_id=i.id
            AND s.third_party_costs IS NOT NULL
    ),
    0
)
WHERE i.type='services';
                """
        )
    ]
