Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mirumee/saleor into invoice-model
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszszymanski129 committed Mar 5, 2020
2 parents 88fc279 + e486a4d commit b06bae4
Show file tree
Hide file tree
Showing 25 changed files with 225 additions and 123 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ All notable, unreleased changes to this project will be documented in this file.
- Unify saleor metadata - #5178 by @fowczarek
- Add compiled versions of emails to the repository - #5260 by @tomaszszymanski129
- Add required prop to fields where applicable - #5293 by @dominik-zeglen

- Drop get_absolute_url methods - #5299 by @IKarbowiak
- Add --force flag to cleardb command - #5302 by @maarcingebala
- Require non-empty message in orderAddNote mutation - #5316 by @maarcingebala

## 2.9.0

Expand Down
10 changes: 8 additions & 2 deletions saleor/core/management/commands/cleardb.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ def add_arguments(self, parser):
action="store_true",
help="Delete staff user accounts (doesn't delete superuser accounts).",
)
parser.add_argument(
"--force",
action="store_true",
help="Allows running the cleardb command in DEBUG=False mode.",
)

def handle(self, **options):
if not settings.DEBUG:
raise CommandError("Cannot clear the database in DEBUG=True mode.")
force = options.get("force", False)
if not settings.DEBUG and not force:
raise CommandError("Cannot clear the database in DEBUG=False mode.")

Checkout.objects.all().delete()
self.stdout.write("Removed checkouts")
Expand Down
13 changes: 13 additions & 0 deletions saleor/core/utils/random_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,19 @@ def create_vouchers():
else:
yield "Value voucher already exists"

voucher, created = Voucher.objects.get_or_create(
code="VCO9KV98LC",
defaults={
"type": VoucherType.ENTIRE_ORDER,
"discount_value_type": DiscountValueType.PERCENTAGE,
"discount_value": 5,
},
)
if created:
yield "Voucher #%d" % voucher.id
else:
yield "Value voucher already exists"


def create_gift_card():
user = random.choice(
Expand Down
6 changes: 0 additions & 6 deletions saleor/data_feeds/google_merchant.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"title",
"product_type",
"google_product_category",
"link",
"image_link",
"condition",
"availability",
Expand Down Expand Up @@ -71,10 +70,6 @@ def item_guid(item: ProductVariant):
return item.sku


def item_link(item: ProductVariant, current_site):
return add_domain(current_site.domain, item.get_absolute_url(), not settings.DEBUG)


def item_title(item: ProductVariant):
return item.display_product()

Expand Down Expand Up @@ -197,7 +192,6 @@ def item_attributes(
"item_group_id": item_group_id(item),
"availability": item_availability(item),
"google_product_category": item_google_product_category(item, category_paths),
"link": item_link(item, current_site),
}

image_link = item_image_link(item, current_site)
Expand Down
12 changes: 11 additions & 1 deletion saleor/graphql/management/commands/get_graphql_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ class Command(BaseCommand):
help = "Writes SDL for GraphQL API schema to stdout"

def handle(self, *args, **options):
self.stdout.write(print_schema(schema))
"""Support multiple interface notation in schema for Apollo tooling.
In `graphql-core` V2 separator for interaces is `,`.
Apollo tooling to generate TypeScript types using `&` as interfaces separator.
https://github.com/graphql-python/graphql-core/pull/258
"""
printed_schema = print_schema(schema)
for line in printed_schema.splitlines():
if "implements" in line:
line = line.replace(",", " &")
self.stdout.write(f"{line}\n")
23 changes: 21 additions & 2 deletions saleor/graphql/order/mutations/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ def perform_mutation(cls, _root, info, **data):


class OrderAddNoteInput(graphene.InputObjectType):
message = graphene.String(description="Note message.", name="message")
message = graphene.String(
description="Note message.", name="message", required=True
)


class OrderAddNote(BaseMutation):
Expand All @@ -278,11 +280,28 @@ class Meta:
error_type_class = OrderError
error_type_field = "order_errors"

@classmethod
def clean_input(cls, _info, _instance, data):
message = data["input"]["message"].strip()
if not message:
raise ValidationError(
{
"message": ValidationError(
"Message can't be empty.", code=OrderErrorCode.REQUIRED,
)
}
)
data["input"]["message"] = message
return data

@classmethod
def perform_mutation(cls, _root, info, **data):
order = cls.get_node_or_error(info, data.get("id"), only_type=Order)
cleaned_input = cls.clean_input(info, order, data)
event = events.order_note_added_event(
order=order, user=info.context.user, message=data.get("input")["message"]
order=order,
user=info.context.user,
message=cleaned_input["input"]["message"],
)
return OrderAddNote(order=order, event=event)

Expand Down
15 changes: 9 additions & 6 deletions saleor/graphql/product/types/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ def __resolve_reference(root, _info, **_kwargs):
@key(fields="id")
class Product(CountableDjangoObjectType):
url = graphene.String(
description="The storefront URL for the product.", required=True
description="The storefront URL for the product.",
required=True,
deprecation_reason="DEPRECATED: Will be removed in Saleor 2.11.",
)
thumbnail = graphene.Field(
Image,
Expand Down Expand Up @@ -469,7 +471,7 @@ def resolve_thumbnail(root: models.Product, info, *, size=255):

@staticmethod
def resolve_url(root: models.Product, *_args):
return root.get_absolute_url()
return ""

@staticmethod
@gql_optimizer.resolver_hints(
Expand Down Expand Up @@ -754,8 +756,10 @@ class Category(CountableDjangoObjectType):
products = PrefetchingConnectionField(
Product, description="List of products in the category."
)
# Deprecated. To remove in #5022
url = graphene.String(description="The storefront's URL for the category.")
url = graphene.String(
description="The storefront's URL for the category.",
deprecation_reason="DEPRECATED: Will be removed in Saleor 2.11.",
)
children = PrefetchingConnectionField(
lambda: Category, description="List of children of the category."
)
Expand Down Expand Up @@ -805,10 +809,9 @@ def resolve_children(root: models.Category, info, **_kwargs):
qs = root.children.all()
return gql_optimizer.query(qs, info)

# Deprecated. To remove in #5022
@staticmethod
def resolve_url(root: models.Category, _info):
return root.get_absolute_url()
return ""

@staticmethod
def resolve_products(root: models.Category, info, **_kwargs):
Expand Down
34 changes: 17 additions & 17 deletions saleor/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type AssignNavigation {
menuErrors: [MenuError!]!
}

type Attribute implements Node, ObjectWithMetadata {
type Attribute implements Node & ObjectWithMetadata {
id: ID!
productTypes(before: String, after: String, first: Int, last: Int): ProductTypeCountableConnection!
productVariantTypes(before: String, after: String, first: Int, last: Int): ProductTypeCountableConnection!
Expand Down Expand Up @@ -499,7 +499,7 @@ input CatalogueInput {
collections: [ID]
}

type Category implements Node, ObjectWithMetadata {
type Category implements Node & ObjectWithMetadata {
seoTitle: String
seoDescription: String
id: ID!
Expand All @@ -515,7 +515,7 @@ type Category implements Node, ObjectWithMetadata {
meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `metadata` field instead. ")
ancestors(before: String, after: String, first: Int, last: Int): CategoryCountableConnection
products(before: String, after: String, first: Int, last: Int): ProductCountableConnection
url: String
url: String @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11.")
children(before: String, after: String, first: Int, last: Int): CategoryCountableConnection
backgroundImage(size: Int): Image
translation(languageCode: LanguageCodeEnum!): CategoryTranslation
Expand Down Expand Up @@ -632,7 +632,7 @@ type CategoryUpdatePrivateMeta {
category: Category
}

type Checkout implements Node, ObjectWithMetadata {
type Checkout implements Node & ObjectWithMetadata {
created: DateTime!
lastChange: DateTime!
user: User
Expand Down Expand Up @@ -847,7 +847,7 @@ type ChoiceValue {
verbose: String
}

type Collection implements Node, ObjectWithMetadata {
type Collection implements Node & ObjectWithMetadata {
seoTitle: String
seoDescription: String
id: ID!
Expand Down Expand Up @@ -1422,7 +1422,7 @@ type DeletePrivateMetadata {
item: ObjectWithMetadata
}

type DigitalContent implements Node, ObjectWithMetadata {
type DigitalContent implements Node & ObjectWithMetadata {
useDefaultSettings: Boolean!
automaticFulfillment: Boolean!
productVariant: ProductVariant!
Expand Down Expand Up @@ -1619,7 +1619,7 @@ enum ExtensionsErrorCode {
UNIQUE
}

type Fulfillment implements Node, ObjectWithMetadata {
type Fulfillment implements Node & ObjectWithMetadata {
id: ID!
fulfillmentOrder: Int!
status: FulfillmentStatus!
Expand Down Expand Up @@ -2428,7 +2428,7 @@ interface ObjectWithMetadata {
meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `metadata` field instead. ")
}

type Order implements Node, ObjectWithMetadata {
type Order implements Node & ObjectWithMetadata {
id: ID!
created: DateTime!
status: OrderStatus!
Expand All @@ -2444,8 +2444,8 @@ type Order implements Node, ObjectWithMetadata {
voucher: Voucher
giftCards: [GiftCard]
discount: Money
discountName: String!
translatedDiscountName: String!
discountName: String
translatedDiscountName: String
displayGrossPrices: Boolean!
customerNote: String!
weight: Weight
Expand Down Expand Up @@ -2489,7 +2489,7 @@ type OrderAddNote {
}

input OrderAddNoteInput {
message: String
message: String!
}

type OrderBulkCancel {
Expand Down Expand Up @@ -3122,7 +3122,7 @@ input PriceRangeInput {
lte: Float
}

type Product implements Node, ObjectWithMetadata {
type Product implements Node & ObjectWithMetadata {
id: ID!
seoTitle: String
seoDescription: String
Expand All @@ -3141,7 +3141,7 @@ type Product implements Node, ObjectWithMetadata {
metadata: [MetadataItem]!
privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")
meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `metadata` field instead. ")
url: String!
url: String! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11.")
thumbnail(size: Int): Image
pricing: ProductPricingInfo
isAvailable: Boolean
Expand Down Expand Up @@ -3381,7 +3381,7 @@ type ProductTranslation implements Node {
language: LanguageDisplay!
}

type ProductType implements Node, ObjectWithMetadata {
type ProductType implements Node & ObjectWithMetadata {
id: ID!
name: String!
slug: String!
Expand Down Expand Up @@ -3524,7 +3524,7 @@ type ProductUpdatePrivateMeta {
product: Product
}

type ProductVariant implements Node, ObjectWithMetadata {
type ProductVariant implements Node & ObjectWithMetadata {
id: ID!
name: String!
sku: String!
Expand Down Expand Up @@ -3886,7 +3886,7 @@ input SeoInput {
description: String
}

type ServiceAccount implements Node, ObjectWithMetadata {
type ServiceAccount implements Node & ObjectWithMetadata {
id: ID!
created: DateTime
isActive: Boolean
Expand Down Expand Up @@ -4531,7 +4531,7 @@ type UpdatePrivateMetadata {

scalar Upload

type User implements Node, ObjectWithMetadata {
type User implements Node & ObjectWithMetadata {
id: ID!
lastLogin: DateTime
email: String!
Expand Down
5 changes: 0 additions & 5 deletions saleor/menu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ def get_ordering_queryset(self):
def linked_object(self):
return self.category or self.collection or self.page

def get_url(self):
linked_object = self.linked_object
# Deprecated. To remove in #5022
return linked_object.get_absolute_url() if linked_object else self.url

def is_public(self):
return not self.linked_object or getattr(
self.linked_object, "is_published", True
Expand Down
6 changes: 1 addition & 5 deletions saleor/menu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

def get_menu_item_as_dict(menu_item):
data = {}
if menu_item.linked_object:
# Deprecated. To remove in #5022
data["url"] = menu_item.linked_object.get_absolute_url()
else:
data["url"] = menu_item.url or ""
data["url"] = menu_item.url or ""
data["name"] = menu_item.name
data["translations"] = {
translated.language_code: {"name": translated.name}
Expand Down
23 changes: 23 additions & 0 deletions saleor/order/migrations/0079_auto_20200304_0752.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions saleor/order/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class Order(ModelWithMetadata):
default=0,
)
discount = MoneyField(amount_field="discount_amount", currency_field="currency")
discount_name = models.CharField(max_length=255, default="", blank=True)
translated_discount_name = models.CharField(max_length=255, default="", blank=True)
discount_name = models.CharField(max_length=255, blank=True, null=True)
translated_discount_name = models.CharField(max_length=255, blank=True, null=True)
display_gross_prices = models.BooleanField(default=True)
customer_note = models.TextField(blank=True, default="")
weight = MeasurementField(
Expand Down Expand Up @@ -219,11 +219,6 @@ def __repr__(self):
def __str__(self):
return "#%d" % (self.id,)

# Deprecated. To remove in #5022
@staticmethod
def get_absolute_url():
return ""

def get_last_payment(self):
return max(self.payments.all(), default=None, key=attrgetter("pk"))

Expand Down
Loading

0 comments on commit b06bae4

Please sign in to comment.