From 79ad995be49759884e6f4c47d8103b88f2245efc Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 30 Dec 2025 12:39:39 +0330 Subject: [PATCH] fix - add purchase_policy to organization --- .../api/v1/serializers/serializer.py | 8 +++---- .../0053_organization_purchase_policy.py | 18 ++++++++++++++++ ...054_remove_organization_purchase_policy.py | 17 +++++++++++++++ .../0055_organization_purchase_policy.py | 18 ++++++++++++++++ apps/authentication/models.py | 21 +++++++++---------- 5 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 apps/authentication/migrations/0053_organization_purchase_policy.py create mode 100644 apps/authentication/migrations/0054_remove_organization_purchase_policy.py create mode 100644 apps/authentication/migrations/0055_organization_purchase_policy.py diff --git a/apps/authentication/api/v1/serializers/serializer.py b/apps/authentication/api/v1/serializers/serializer.py index 3f9b346..70bf2c9 100644 --- a/apps/authentication/api/v1/serializers/serializer.py +++ b/apps/authentication/api/v1/serializers/serializer.py @@ -262,15 +262,15 @@ class OrganizationSerializer(serializers.ModelSerializer): 'field_of_activity', 'free_visibility_by_scope', 'service_area', # noqa - # 'purchase_policy' + 'purchase_policy' ] extra_kwargs = { 'service_area': { # noqa 'required': False }, - # 'purchase_policy': { - # 'purchase_policy': False - # } + 'purchase_policy': { + 'purchase_policy': False + } } def validate(self, attrs): diff --git a/apps/authentication/migrations/0053_organization_purchase_policy.py b/apps/authentication/migrations/0053_organization_purchase_policy.py new file mode 100644 index 0000000..9d2da8d --- /dev/null +++ b/apps/authentication/migrations/0053_organization_purchase_policy.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0 on 2025-12-30 08:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0052_remove_organization_purchase_policy'), + ] + + operations = [ + migrations.AddField( + model_name='organization', + name='purchase_policy', + field=models.CharField(choices=[('INTERNAL_ONLY', 'Internal Only'), ('CROSS_COOP', 'Cross Cooperative Allowed')], default='INTERNAL_ONLY', help_text='defines where ranchers can purchase from', max_length=20), + ), + ] diff --git a/apps/authentication/migrations/0054_remove_organization_purchase_policy.py b/apps/authentication/migrations/0054_remove_organization_purchase_policy.py new file mode 100644 index 0000000..dc4ae92 --- /dev/null +++ b/apps/authentication/migrations/0054_remove_organization_purchase_policy.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0 on 2025-12-30 08:56 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0053_organization_purchase_policy'), + ] + + operations = [ + migrations.RemoveField( + model_name='organization', + name='purchase_policy', + ), + ] diff --git a/apps/authentication/migrations/0055_organization_purchase_policy.py b/apps/authentication/migrations/0055_organization_purchase_policy.py new file mode 100644 index 0000000..5f0c56c --- /dev/null +++ b/apps/authentication/migrations/0055_organization_purchase_policy.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0 on 2025-12-30 09:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0054_remove_organization_purchase_policy'), + ] + + operations = [ + migrations.AddField( + model_name='organization', + name='purchase_policy', + field=models.CharField(choices=[('INTERNAL_ONLY', 'Internal Only'), ('CROSS_COOP', 'Cross Cooperative Allowed')], default='INTERNAL_ONLY', help_text='defines where ranchers can purchase from', max_length=20), + ), + ] diff --git a/apps/authentication/models.py b/apps/authentication/models.py index ea023b6..aab259d 100644 --- a/apps/authentication/models.py +++ b/apps/authentication/models.py @@ -147,17 +147,16 @@ class Organization(BaseModel): has_pos = models.BooleanField(default=False) additional_data = models.JSONField(default=dict) service_area = models.ManyToManyField(City, related_name='service_area') - - # PURCHASE_POLICIES = ( - # ('INTERNAL_ONLY', 'Internal Only'), - # ('CROSS_COOP', 'Cross Cooperative Allowed'), - # ) - # purchase_policy = models.CharField( - # max_length=20, - # choices=PURCHASE_POLICIES, - # default='INTERNAL_ONLY', - # help_text='defines where ranchers can purchase from' - # ) + PURCHASE_POLICIES = ( + ('INTERNAL_ONLY', 'Internal Only'), + ('CROSS_COOP', 'Cross Cooperative Allowed'), + ) + purchase_policy = models.CharField( + max_length=20, + choices=PURCHASE_POLICIES, + default='INTERNAL_ONLY', + help_text='defines where ranchers can purchase from' + ) def __str__(self): return f'{self.name}-{self.type}'