diff --git a/pola/company/migrations/0033_brand_website_url.py b/pola/company/migrations/0033_brand_website_url.py new file mode 100644 index 00000000000..f3310983d16 --- /dev/null +++ b/pola/company/migrations/0033_brand_website_url.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.16 on 2024-06-21 10:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('company', '0032_alter_brand_logotype'), + ] + + operations = [ + migrations.AddField( + model_name='brand', + name='website_url', + field=models.CharField(default='example.pl', max_length=128, verbose_name='URL marki'), + ), + ] diff --git a/pola/company/models.py b/pola/company/models.py index e8cbaa19bc8..f3a3ab03ce9 100644 --- a/pola/company/models.py +++ b/pola/company/models.py @@ -312,6 +312,9 @@ class Brand(TimeStampedModel): region_name='eu-central-1', ), ) + website_url = models.CharField( + max_length=128, null=False, blank=False, verbose_name=_("URL marki"), default="example.pl" + ) def __str__(self): return self.common_name or self.name diff --git a/pola/logic.py b/pola/logic.py index 9e76ce5d4b5..aac1073bc7e 100644 --- a/pola/logic.py +++ b/pola/logic.py @@ -112,7 +112,8 @@ def get_result_from_code(code, multiple_company_supported=False, report_as_objec def serialize_brand(brand): logotype_url = brand.logotype.url if brand.logotype else None - return {'name': str(brand), 'logotype_url': logotype_url} + website_url = brand.website_url if brand.website_url else None + return {'name': str(brand), 'logotype_url': logotype_url, 'website_url': website_url} def handle_companies_when_multiple_companies_are_not_supported( diff --git a/pola/rpc_api/openapi-v1.yaml b/pola/rpc_api/openapi-v1.yaml index e0758dd7eaa..a76b101e980 100644 --- a/pola/rpc_api/openapi-v1.yaml +++ b/pola/rpc_api/openapi-v1.yaml @@ -167,6 +167,8 @@ components: logotype_url: type: string nullable: true + website_url: + type: string required: - name - logotype_url diff --git a/pola/rpc_api/tests/test_views_v3.py b/pola/rpc_api/tests/test_views_v3.py index b35f0ef9bb1..ea772132153 100644 --- a/pola/rpc_api/tests/test_views_v3.py +++ b/pola/rpc_api/tests/test_views_v3.py @@ -200,7 +200,9 @@ def test_should_return_200_when_one_comand_in_brand_and_product(self): self.maxDiff = None self.assertEqual( { - 'all_company_brands': [{'logotype_url': None, 'name': p.brand.common_name}], + 'all_company_brands': [ + {'logotype_url': None, 'name': p.brand.common_name, 'website_url': p.brand.website_url} + ], 'altText': None, 'card_type': 'type_white', 'code': '5900049011829', diff --git a/pola/rpc_api/tests/test_views_v4.py b/pola/rpc_api/tests/test_views_v4.py index 054bb330776..110583e99e9 100644 --- a/pola/rpc_api/tests/test_views_v4.py +++ b/pola/rpc_api/tests/test_views_v4.py @@ -175,6 +175,7 @@ def test_should_return_200_when_product_with_brand_and_image(self): 'all_company_brands': [ { 'name': b.common_name, + 'website_url': 'example.pl', } ], 'product_id': p.pk, diff --git a/pola/tests/test_logic.py b/pola/tests/test_logic.py index 39ddae7f462..ce28a17be00 100644 --- a/pola/tests/test_logic.py +++ b/pola/tests/test_logic.py @@ -404,7 +404,8 @@ def test_display_brand_when_enabled_on_company(self): company = CompanyFactory.create(description='test-description', display_brands_in_description=True) product = ProductFactory.create(code=current_ean, company=company, brand=None) BrandFactory.create(common_name="brand-1", company=company) - BrandFactory.create(common_name="brand-2", company=company) + BrandFactory.create(common_name="brand-2", company=company, website_url="test.pl") + BrandFactory.create(common_name="brand-3", company=company, website_url="moja_domena_testowa_123.com") with mock.patch("pola.logic.get_by_code", return_value=product): response = get_result_from_code(current_ean) @@ -412,13 +413,14 @@ def test_display_brand_when_enabled_on_company(self): expected_response = ( { 'all_company_brands': [ - {'logotype_url': None, 'name': 'brand-2'}, - {'logotype_url': None, 'name': 'brand-1'}, + {'logotype_url': None, 'name': 'brand-3', 'website_url': 'moja_domena_testowa_123.com'}, + {'logotype_url': None, 'name': 'brand-2', 'website_url': 'test.pl'}, + {'logotype_url': None, 'name': 'brand-1', 'website_url': 'example.pl'}, ], 'altText': None, 'card_type': 'type_grey', 'code': TEST_EAN13, - 'description': ('test-description\n' 'Ten producent psoiada marki: brand-1, brand-2.'), + 'description': ('test-description\n' 'Ten producent psoiada marki: brand-1, brand-2, brand-3.'), 'is_friend': False, 'name': company.official_name, 'plCapital': None,