Skip to content

Commit

Permalink
Added code field to product resource, which was added to oscar (#57)
Browse files Browse the repository at this point in the history
* Added code field to product resource, which was added to oscar

The code field can be used to store external id's

* Added tests

* Test against oscar from github

* Updated setup.py according to pypa instruction

https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html

* kltsie zegt bats
  • Loading branch information
specialunderwear authored Dec 4, 2024
1 parent 18e205a commit ca6469c
Show file tree
Hide file tree
Showing 8 changed files with 834 additions and 695 deletions.
1 change: 1 addition & 0 deletions oscar_odin/mappings/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def product_class(self, value) -> ProductClassModel:
"description": {constants.PRODUCT_DESCRIPTION},
"is_discountable": {constants.PRODUCT_IS_DISCOUNTABLE},
"priority": {constants.PRODUCT_PRIORITY},
"code": {constants.PRODUCT_CODE},
}

@classmethod
Expand Down
1 change: 1 addition & 0 deletions oscar_odin/mappings/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
PRODUCT_STRUCTURE = "Product.structure"
PRODUCT_IS_PUBLIC = "Product.is_public"
PRODUCT_UPC = "Product.upc"
PRODUCT_CODE = "Product.code"
PRODUCT_PARENT = "Product.parent"
PRODUCT_TITLE = "Product.title"
PRODUCT_SLUG = "Product.slug"
Expand Down
1 change: 1 addition & 0 deletions oscar_odin/resources/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class ProductResource(OscarCatalogueResource):
"""A product within Django Oscar."""

id: Optional[int]
code: Optional[str]
upc: Optional[str]
structure: str = StringField(choices=ProductModel.STRUCTURE_CHOICES)
title: str
Expand Down
1,502 changes: 822 additions & 680 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.8"
django-oscar = {version = "^4.0a1", allow-prereleases = true}
django-oscar = {git = "https://github.com/django-oscar/django-oscar.git", allow-prereleases = true}
coverage = { version = "^7.3", optional = true }
pylint = { version = "^3.0.2", optional = true }
black = { version = "^23.11.0", optional = true }
Expand Down
16 changes: 2 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
# this setup.py script is completely generated dynamically by poetry and
# is needed to be able to integrate this project in tools that are based on setuptools
from pathlib import Path
from setuptools import setup

from poetry.core.factory import Factory
from poetry.core.masonry.builders.sdist import SdistBuilder

# let poetry construct setupt.py
cwd_path = Path(".").resolve()
poetry = Factory().create_poetry()
sdist_builder = SdistBuilder(poetry)
setup_py = sdist_builder.build_setup()

# run setup in the current context
exec(setup_py, globals(), locals())
setup()
4 changes: 4 additions & 0 deletions tests/mappings/test_catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test_get_mapped_fields(self):
"attributes",
"categories",
"children",
"code",
"date_created",
"date_updated",
"description",
Expand Down Expand Up @@ -116,6 +117,7 @@ def test_get_mapped_fields(self):
"availability",
"categories",
"children",
"code",
"currency",
"date_created",
"date_updated",
Expand Down Expand Up @@ -148,6 +150,7 @@ def test_get_mapped_fields(self):
"attributes",
"categories",
"children",
"code",
"date_created",
"date_updated",
"description",
Expand Down Expand Up @@ -177,6 +180,7 @@ def test_get_mapped_fields(self):
sorted(demfields),
[
"Category.code",
"Product.code",
"Product.description",
"Product.is_discountable",
"Product.is_public",
Expand Down
2 changes: 2 additions & 0 deletions tests/reverse/test_catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_create_product_with_related_fields(self):

product_resource = ProductResource(
upc="1234323-2",
code="semek-mumtaz",
title="asdf2",
slug="asdf-asdfasdf2",
description="description",
Expand Down Expand Up @@ -125,6 +126,7 @@ def test_create_product_with_related_fields(self):

product_resource = ProductResource(
upc="1234323-2",
code="haind-berrit",
title="asdf2",
structure=Product.STANDALONE,
price=D("21.50"),
Expand Down

0 comments on commit ca6469c

Please sign in to comment.