-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging development into delete_users_view
- Loading branch information
Showing
17 changed files
with
470 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ | |
|
||
13/10/2023 | ||
- python manage.py set_mediafiles_names | ||
|
||
29/04/2024 | ||
- python manage.py precursor_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from dateutil.relativedelta import relativedelta | ||
from django.contrib.admin.models import CHANGE, ADDITION | ||
from django.core.management.base import BaseCommand | ||
from django.db.models import Count, Min | ||
from django.utils.timezone import now | ||
|
||
from laboratory.models import ObjectLogChange, PrecursorReport, \ | ||
Laboratory | ||
from laboratory.task_utils import save_object_report_precursor, \ | ||
build_precursor_report_from_reports | ||
from laboratory.tasks import add_consecutive | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
help = 'Create the report or precursors' | ||
|
||
def get_change_log(self): | ||
PrecursorReport.objects.all().delete() | ||
|
||
actual_date = now() | ||
ObjectLogChange.objects.filter(subject="Update", diff_value__lte=0).update(type_action=CHANGE) | ||
ObjectLogChange.objects.filter(subject="Update", diff_value__gte=0).update(type_action=ADDITION) | ||
labs = Laboratory.objects.annotate(changelog_count=Count('objectlogchange'), | ||
update_time_min=Min('objectlogchange__update_time'), | ||
).filter( | ||
changelog_count__gt=0) | ||
|
||
for lab in labs: | ||
current_time=lab.update_time_min | ||
previos_report=None | ||
while current_time<actual_date: | ||
current_time=current_time+relativedelta(months=+1) | ||
print("Running on %s for %d of %d" % ( | ||
str(lab), | ||
current_time.year, | ||
current_time.month | ||
)) | ||
report = PrecursorReport.objects.create( | ||
month=current_time.month, | ||
year=current_time.year, | ||
laboratory=lab, | ||
consecutive=add_consecutive(lab) | ||
) | ||
save_object_report_precursor(report) | ||
build_precursor_report_from_reports(report, previos_report) | ||
previos_report=report | ||
|
||
|
||
|
||
def handle(self, *args, **options): | ||
self.get_change_log() |
38 changes: 38 additions & 0 deletions
38
src/laboratory/migrations/0139_precursorreportvalues_precursorreport_report_values.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 4.1.13 on 2024-04-15 17:55 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import laboratory.catalog | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('laboratory', '0138_alter_shelfobjectequipmentcharacteristics_available_to_use_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PrecursorReportValues', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('quantity', models.FloatField(default=0.0)), | ||
('previous_balance', models.CharField(blank=True, max_length=200)), | ||
('new_income', models.FloatField(default=0.0)), | ||
('bills', models.CharField(blank=True, max_length=200)), | ||
('providers', models.CharField(blank=True, max_length=200)), | ||
('stock', models.FloatField(default=0.0)), | ||
('month_expense', models.FloatField(default=0.0)), | ||
('final_balance', models.FloatField(default=0.0)), | ||
('reason_to_spend', models.TextField(blank=True)), | ||
('measurement_unit', laboratory.catalog.GTForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='laboratory.catalog', verbose_name='measurement unit')), | ||
('object', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='laboratory.object')), | ||
('precursor_report', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='laboratory.precursorreport')), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='precursorreport', | ||
name='report_values', | ||
field=models.ManyToManyField(through='laboratory.PrecursorReportValues', to='laboratory.object'), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
src/laboratory/migrations/0140_alter_precursorreportvalues_previous_balance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.1.13 on 2024-04-22 17:32 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('laboratory', '0139_precursorreportvalues_precursorreport_report_values'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='previous_balance', | ||
field=models.FloatField(default=0.0), | ||
), | ||
] |
75 changes: 75 additions & 0 deletions
75
src/laboratory/migrations/0141_alter_precursorreportvalues_bills_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Generated by Django 4.1.13 on 2024-05-07 23:00 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import laboratory.catalog | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('laboratory', '0140_alter_precursorreportvalues_previous_balance'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='bills', | ||
field=models.CharField(blank=True, max_length=200, verbose_name='Bills'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='final_balance', | ||
field=models.FloatField(default=0.0, verbose_name='Final balance'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='measurement_unit', | ||
field=laboratory.catalog.GTForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='laboratory.catalog', verbose_name='Measurement unit'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='month_expense', | ||
field=models.FloatField(default=0.0, verbose_name='Month expense'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='new_income', | ||
field=models.FloatField(default=0.0, verbose_name='New income'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='object', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='laboratory.object', verbose_name='Object'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='precursor_report', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='laboratory.precursorreport', verbose_name='Report'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='previous_balance', | ||
field=models.FloatField(default=0.0, verbose_name='Previous balance'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='providers', | ||
field=models.CharField(blank=True, max_length=200, verbose_name='Providers'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='quantity', | ||
field=models.FloatField(default=0.0, verbose_name='Quantity'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='reason_to_spend', | ||
field=models.TextField(blank=True, verbose_name='Reason to spend'), | ||
), | ||
migrations.AlterField( | ||
model_name='precursorreportvalues', | ||
name='stock', | ||
field=models.FloatField(default=0.0, verbose_name='Stock'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.