From dabd4eb584d05265631b79ea4b1ee2552dc4e6c1 Mon Sep 17 00:00:00 2001 From: Didrik Munther Date: Wed, 16 Aug 2023 00:11:54 +0200 Subject: [PATCH 1/2] Add ordering for products --- .../migrations/0027_add_account_order.py | 22 +++++++++++++++++++ accounting/models.py | 6 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 accounting/migrations/0027_add_account_order.py diff --git a/accounting/migrations/0027_add_account_order.py b/accounting/migrations/0027_add_account_order.py new file mode 100644 index 000000000..76080a6c0 --- /dev/null +++ b/accounting/migrations/0027_add_account_order.py @@ -0,0 +1,22 @@ +# Generated by Django 2.2.24 on 2023-08-16 00:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounting', '0026_rename_hidden_products_field'), + ] + + operations = [ + migrations.AlterModelOptions( + name='product', + options={'default_permissions': [], 'ordering': ['ordering', 'category'], 'permissions': [('base', 'View the Accounting tab'), ('export_orders', 'Export orders'), ('ths_customer_ids', 'Edit companies without THS customer IDs')], 'verbose_name_plural': 'Products'}, + ), + migrations.AddField( + model_name='product', + name='ordering', + field=models.IntegerField(default=0, help_text='Order the product. The higher the number, the higher the sorting.'), + ), + ] diff --git a/accounting/models.py b/accounting/models.py index bf8a8eaae..b57dbca3d 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -65,6 +65,10 @@ class Product(models.Model): revenue = models.ForeignKey(Revenue, blank=False, on_delete=models.CASCADE) result_center = models.PositiveIntegerField(blank=False, null=False) cost_unit = models.PositiveIntegerField(blank=False, null=False) + ordering = models.IntegerField( + default=0, + help_text="Order the product. The higher the number, the higher the sorting.", + ) category = models.ForeignKey( Category, blank=True, null=True, on_delete=models.CASCADE ) @@ -100,7 +104,7 @@ class Product(models.Model): class Meta: verbose_name_plural = "Products" - ordering = ["category", "name"] + ordering = ["ordering", "category"] default_permissions = [] permissions = [ ("base", "View the Accounting tab"), From bfbd9fbf0073ce048904529c1d36bf265a3316e7 Mon Sep 17 00:00:00 2001 From: Didrik Munther Date: Wed, 16 Aug 2023 00:12:32 +0200 Subject: [PATCH 2/2] Format code --- .../migrations/0027_add_account_order.py | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/accounting/migrations/0027_add_account_order.py b/accounting/migrations/0027_add_account_order.py index 76080a6c0..9db908edd 100644 --- a/accounting/migrations/0027_add_account_order.py +++ b/accounting/migrations/0027_add_account_order.py @@ -4,19 +4,30 @@ class Migration(migrations.Migration): - dependencies = [ - ('accounting', '0026_rename_hidden_products_field'), + ("accounting", "0026_rename_hidden_products_field"), ] operations = [ migrations.AlterModelOptions( - name='product', - options={'default_permissions': [], 'ordering': ['ordering', 'category'], 'permissions': [('base', 'View the Accounting tab'), ('export_orders', 'Export orders'), ('ths_customer_ids', 'Edit companies without THS customer IDs')], 'verbose_name_plural': 'Products'}, + name="product", + options={ + "default_permissions": [], + "ordering": ["ordering", "category"], + "permissions": [ + ("base", "View the Accounting tab"), + ("export_orders", "Export orders"), + ("ths_customer_ids", "Edit companies without THS customer IDs"), + ], + "verbose_name_plural": "Products", + }, ), migrations.AddField( - model_name='product', - name='ordering', - field=models.IntegerField(default=0, help_text='Order the product. The higher the number, the higher the sorting.'), + model_name="product", + name="ordering", + field=models.IntegerField( + default=0, + help_text="Order the product. The higher the number, the higher the sorting.", + ), ), ]