Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Merge branch 'master' of github.com:mirumee/saleor into feature/invoices

Tomasz Szymanski9b3b5a48dce7
diff --cc .isort.cfg
index 833333f5c4,0c968f353d..d901976150
--- a/.isort.cfg
+++ b/.isort.cfg
@@@ -1,2 -1,2 +1,2 @@@
[settings]
- known_third_party = PIL,babel,braintree,celery,dj_database_url,dj_email_url,django,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphene_federation,graphql,graphql_jwt,graphql_relay,html_to_draftjs,i18naddress,jaeger_client,jwt,markdown,measurement,mptt,oauthlib,opentracing,phonenumber_field,phonenumbers,prices,promise,pytest,pytz,razorpay,requests,sentry_sdk,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield,weasyprint
-known_third_party = PIL,babel,braintree,celery,dj_database_url,dj_email_url,django,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_federation,graphql,graphql_jwt,graphql_relay,html_to_draftjs,i18naddress,jaeger_client,jwt,markdown,measurement,mptt,oauthlib,opentracing,phonenumber_field,phonenumbers,prices,promise,pytest,pytz,razorpay,requests,sentry_sdk,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield
++known_third_party = PIL,babel,braintree,celery,dj_database_url,dj_email_url,django,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_federation,graphql,graphql_jwt,graphql_relay,html_to_draftjs,i18naddress,jaeger_client,jwt,markdown,measurement,mptt,oauthlib,opentracing,phonenumber_field,phonenumbers,prices,promise,pytest,pytz,razorpay,requests,sentry_sdk,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield,weasyprint
diff --cc locale/en/LC_MESSAGES/django.po
index 5a619315e2,c823b36da0..c3834ac6b6
--- a/locale/en/LC_MESSAGES/django.po
+++ b/locale/en/LC_MESSAGES/django.po
@@@ -8,7 -8,7 +8,7 @@@ msgid "
msgstr ""
"Project-Id-Version: master\n"
"Report-Msgid-Bugs-To: \n"
- "POT-Creation-Date: 2020-04-20 03:17-0500\n"
-"POT-Creation-Date: 2020-04-14 04:02-0500\n"
++"POT-Creation-Date: 2020-04-26 05:00-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
@@@ -32,91 -32,6 +32,91 @@@ msgid "
"%(street_address_2)s"
msgstr ""
- #: templates/invoice.html:158
++#: templates/invoice.html:160
+msgctxt "Invoice PDF header"
+msgid "INVOICE INFORMATION"
+msgstr ""
+
- #: templates/invoice.html:162
- msgctxt "Invoice PDF header"
++#: templates/invoice.html:164
++msgctxt "Invoice PDF header: order number"
+msgid "Order:"
+msgstr ""
+
- #: templates/invoice.html:169
++#: templates/invoice.html:171
+msgctxt "Invoice PDF header"
+msgid "Date:"
+msgstr ""
+
- #: templates/invoice.html:175
++#: templates/invoice.html:177
+msgctxt "Invoice PDF amount (price)"
+msgid "Amount:"
+msgstr ""
+
- #: templates/invoice.html:185
++#: templates/invoice.html:187
+msgctxt "Invoice PDF"
+msgid "BILLING ADDRESS"
+msgstr ""
+
- #: templates/invoice.html:214
++#: templates/invoice.html:216
+msgctxt "Invoice PDF"
+msgid "SHIPMENT ADDRESS"
+msgstr ""
+
- #: templates/invoice.html:245
++#: templates/invoice.html:247
+msgctxt "Invoice PDF"
+msgid "PAYMENT METHOD"
+msgstr ""
+
- #: templates/invoice.html:253
++#: templates/invoice.html:255
+msgctxt "Invoice PDF"
+msgid "SHIPMENT METHOD"
+msgstr ""
+
- #: templates/invoice.html:263
++#: templates/invoice.html:265
+msgctxt "Invoice PDF table header"
+msgid "ITEMS ORDERED"
+msgstr ""
+
- #: templates/invoice.html:269
++#: templates/invoice.html:271
+msgctxt "Invoice PDF table"
+msgid "Products"
+msgstr ""
+
- #: templates/invoice.html:272
++#: templates/invoice.html:274
+msgctxt "Invoice PDF table"
+msgid "Price"
+msgstr ""
+
- #: templates/invoice.html:275
++#: templates/invoice.html:277
+msgctxt "Invoice PDF table"
+msgid "Quantity"
+msgstr ""
+
- #: templates/invoice.html:278
++#: templates/invoice.html:280
+msgctxt "Invoice PDF table"
+msgid "Total Price"
+msgstr ""
+
- #: templates/invoice.html:302
++#: templates/invoice.html:304
+msgctxt "Invoice PDF summary"
+msgid "Subtotal"
+msgstr ""
+
- #: templates/invoice.html:315
++#: templates/invoice.html:317
+msgctxt "Invoice PDF summary"
+msgid "Delivery Cost"
+msgstr ""
+
- #: templates/invoice.html:328
++#: templates/invoice.html:330
+msgctxt "Invoice PDF summary"
+msgid "Tax"
+msgstr ""
+
- #: templates/invoice.html:341
++#: templates/invoice.html:343
+msgctxt "Invoice PDF summary"
+msgid "Grand Total"
+msgstr ""
+
#: templates/read_only/read_only_splash.html:48
msgid "Be aware pirate! <br> Saleor runs in <span>read only mode!</span>"
msgstr ""
diff --cc saleor/graphql/api.py
index 307b53cbf4,b4e2290d3d..eec086d372
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@@ -7,10 -8,10 +8,10 @@@ from .discount.schema import DiscountMu
from .giftcard.schema import GiftCardMutations, GiftCardQueries
from .menu.schema import MenuMutations, MenuQueries
from .meta.schema import MetaMutations
-from .order.schema import OrderMutations, OrderQueries
+from .order.schema import InvoiceMutations, OrderMutations, OrderQueries
from .page.schema import PageMutations, PageQueries
from .payment.schema import PaymentMutations, PaymentQueries
+ from .plugins.schema import PluginsMutations, PluginsQueries
from .product.schema import ProductMutations, ProductQueries
from .shipping.schema import ShippingMutations, ShippingQueries
from .shop.schema import ShopMutations, ShopQueries
@@@ -46,9 -49,8 +49,9 @@@ class Mutation
CheckoutMutations,
CoreMutations,
DiscountMutations,
- ExtensionsMutations,
+ PluginsMutations,
GiftCardMutations,
+ InvoiceMutations,
MenuMutations,
MetaMutations,
OrderMutations,
diff --cc saleor/graphql/core/enums.py
index a2ee8be9af,1475216878..58c3111e12
--- a/saleor/graphql/core/enums.py
+++ b/saleor/graphql/core/enums.py
@@@ -94,9 -92,11 +92,12 @@@ GiftCardErrorCode = graphene.Enum.from_
MenuErrorCode = graphene.Enum.from_enum(menu_error_codes.MenuErrorCode)
MetadataErrorCode = graphene.Enum.from_enum(core_error_codes.MetadataErrorCode)
OrderErrorCode = graphene.Enum.from_enum(order_error_codes.OrderErrorCode)
+InvoiceErrorCode = graphene.Enum.from_enum(order_error_codes.InvoiceErrorCode)
PageErrorCode = graphene.Enum.from_enum(page_error_codes.PageErrorCode)
PaymentErrorCode = graphene.Enum.from_enum(payment_error_codes.PaymentErrorCode)
+ PermissionGroupErrorCode = graphene.Enum.from_enum(
+ account_error_codes.PermissionGroupErrorCode
+ )
ProductErrorCode = graphene.Enum.from_enum(product_error_codes.ProductErrorCode)
ShopErrorCode = graphene.Enum.from_enum(core_error_codes.ShopErrorCode)
ShippingErrorCode = graphene.Enum.from_enum(shipping_error_codes.ShippingErrorCode)
diff --cc saleor/graphql/core/types/common.py
index 0d1a4ff414,fd09845d86..a72c3b35a4
--- a/saleor/graphql/core/types/common.py
+++ b/saleor/graphql/core/types/common.py
@@@ -4,11 -4,11 +4,12 @@@ from ....product.templatetags.product_i
from ...translations.enums import LanguageCodeEnum
from ..enums import (
AccountErrorCode,
+ AppErrorCode,
CheckoutErrorCode,
DiscountErrorCode,
- ExtensionsErrorCode,
GiftCardErrorCode,
+ InvoiceErrorCode,
+ JobStatusEnum,
MenuErrorCode,
MetadataErrorCode,
OrderErrorCode,
@@@ -70,10 -117,20 +118,24 @@@ class OrderError(Error)
code = OrderErrorCode(description="The error code.", required=True)
+class InvoiceError(Error):
+ code = InvoiceErrorCode(description="The error code.", required=True)
+
+
+ class PermissionGroupError(Error):
+ code = PermissionGroupErrorCode(description="The error code.", required=True)
+ permissions = graphene.List(
+ graphene.NonNull(PermissionEnum),
+ description="List of permissions which causes the error.",
+ required=False,
+ )
+ users = graphene.List(
+ graphene.NonNull(graphene.ID),
+ description="List of user IDs which causes the error.",
+ required=False,
+ )
+
+
class ProductError(Error):
code = ProductErrorCode(description="The error code.", required=True)
diff --cc saleor/graphql/core/utils/error_codes.py
index 759bbfb320,6aff742585..1d351371b1
--- a/saleor/graphql/core/utils/error_codes.py
+++ b/saleor/graphql/core/utils/error_codes.py
@@@ -4,11 -5,11 +5,11 @@@ from ....app.error_codes import AppErro
from ....checkout.error_codes import CheckoutErrorCode
from ....core.error_codes import ShopErrorCode
from ....discount.error_codes import DiscountErrorCode
- from ....extensions.error_codes import ExtensionsErrorCode
from ....giftcard.error_codes import GiftCardErrorCode
from ....menu.error_codes import MenuErrorCode
-from ....order.error_codes import OrderErrorCode
+from ....order.error_codes import InvoiceErrorCode, OrderErrorCode
from ....payment.error_codes import PaymentErrorCode
+ from ....plugins.error_codes import PluginErrorCode
from ....product.error_codes import ProductErrorCode
from ....shipping.error_codes import ShippingErrorCode
@@@ -42,11 -43,11 +43,12 @@@ DJANGO_FORM_FIELDS_ERROR_CODES =
SALEOR_ERROR_CODE_ENUMS = [
AccountErrorCode,
+ AppErrorCode,
CheckoutErrorCode,
DiscountErrorCode,
- ExtensionsErrorCode,
+ PluginErrorCode,
GiftCardErrorCode,
+ InvoiceErrorCode,
MenuErrorCode,
OrderErrorCode,
PaymentErrorCode,
diff --cc saleor/graphql/order/schema.py
index eabd3bef19,3abce46c9c..ab94e8f052
--- a/saleor/graphql/order/schema.py
+++ b/saleor/graphql/order/schema.py
@@@ -25,11 -25,9 +25,11 @@@ from .mutations.fulfillments import
FulfillmentUpdateMeta,
FulfillmentUpdatePrivateMeta,
FulfillmentUpdateTracking,
+ OrderFulfill,
)
from .mutations.orders import (
+ CreateInvoice,
+ DeleteInvoice,
OrderAddNote,
OrderCancel,
OrderCapture,
diff --cc saleor/graphql/schema.graphql
index c23dc8ead3,dc3214043b..9d474b51e2
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@@ -1320,20 -1435,9 +1435,20 @@@ type CountryDisplay
vat: VAT
}
+type CreateInvoice {
- errors: [Error!]!
++ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
+ invoiceErrors: [InvoiceError!]!
+ invoice: Invoice
+}
+
+input CreateInvoiceInput {
+ number: String!
+ url: String!
+}
+
type CreateToken {
token: String
- errors: [Error!]!
+ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
accountErrors: [AccountError!]!
user: User
}
@@@ -1431,14 -1535,8 +1546,14 @@@ input DateTimeRangeInput
scalar Decimal
+type DeleteInvoice {
- errors: [Error!]!
++ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
+ invoiceErrors: [InvoiceError!]!
+ invoice: Invoice
+}
+
type DeleteMetadata {
- errors: [Error!]!
+ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
metadataErrors: [MetadataError!]!
item: ObjectWithMetadata
}
@@@ -3851,25 -3953,14 +3995,25 @@@ enum ReportingPeriod
THIS_MONTH
}
+type RequestDeleteInvoice {
- errors: [Error!]!
++ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
+ invoiceErrors: [InvoiceError!]!
+ invoice: Invoice
+}
+
type RequestEmailChange {
- errors: [Error!]!
+ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
user: User
accountErrors: [AccountError!]!
}
+type RequestInvoice {
- errors: [Error!]!
++ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
+ invoiceErrors: [InvoiceError!]!
+}
+
type RequestPasswordReset {
- errors: [Error!]!
+ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
accountErrors: [AccountError!]!
}
@@@ -3991,12 -4084,6 +4137,12 @@@ type SelectedAttribute
values: [AttributeValue]!
}
+type SendInvoiceEmail {
- errors: [Error!]!
++ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
+ invoiceErrors: [InvoiceError!]!
+ invoice: Invoice
+}
+
input SeoInput {
title: String
description: String
@@@ -4620,19 -4730,8 +4789,19 @@@ input TranslationInput
scalar UUID
+type UpdateInvoice {
- errors: [Error!]!
++ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
+ invoiceErrors: [InvoiceError!]!
+ invoice: Invoice
+}
+
+input UpdateInvoiceInput {
+ number: String
+ url: String
+}
+
type UpdateMetadata {
- errors: [Error!]!
+ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
metadataErrors: [MetadataError!]!
item: ObjectWithMetadata
}
diff --cc saleor/order/error_codes.py
index 088558c3dd,e16f113cc9..16db8a7a75
--- a/saleor/order/error_codes.py
+++ b/saleor/order/error_codes.py
@@@ -22,10 -22,5 +22,12 @@@ class OrderErrorCode(Enum)
UNIQUE = "unique"
VOID_INACTIVE_PAYMENT = "void_inactive_payment"
ZERO_QUANTITY = "zero_quantity"
+ INSUFFICIENT_STOCK = "insufficient_stock"
+ DUPLICATED_INPUT_ITEM = "duplicated_input_item"
+
+
+class InvoiceErrorCode(Enum):
+ REQUIRED = "required"
+ NOT_READY = "not_ready"
+ URL_OR_NUMBER_NOT_SET = "url_or_number_not_set"
+ NOT_FOUND = "not_found"
diff --cc saleor/order/migrations/0084_auto_20200426_0504.py
index 85329ee79e,0000000000..0e3d5a92a1
mode 100644,000000..100644
--- a/saleor/order/migrations/0084_auto_20200426_0504.py
+++ b/saleor/order/migrations/0084_auto_20200426_0504.py
@@@ -1,54 -1,0 +1,54 @@@
- # Generated by Django 3.0.4 on 2020-04-08 09:40
++# Generated by Django 3.0.5 on 2020-04-26 10:04
+
+import django.contrib.postgres.fields.jsonb
+from django.db import migrations, models
+
+import saleor.core.utils.json_serializer
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
- ("order", "0081_auto_20200406_0456"),
++ ("order", "0083_merge_20200421_0529"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="invoice",
+ name="metadata",
+ field=django.contrib.postgres.fields.jsonb.JSONField(
+ blank=True,
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ null=True,
+ ),
+ ),
+ migrations.AddField(
+ model_name="invoice",
+ name="private_metadata",
+ field=django.contrib.postgres.fields.jsonb.JSONField(
+ blank=True,
+ default=dict,
+ encoder=saleor.core.utils.json_serializer.CustomJsonEncoder,
+ null=True,
+ ),
+ ),
+ migrations.AddField(
+ model_name="invoice",
+ name="status",
+ field=models.CharField(default="pending", max_length=32),
+ ),
+ migrations.AlterField(
+ model_name="invoice", name="created", field=models.DateTimeField(null=True),
+ ),
+ migrations.AlterField(
+ model_name="invoice",
+ name="number",
+ field=models.CharField(max_length=255, null=True),
+ ),
+ migrations.AlterField(
+ model_name="invoice",
+ name="url",
+ field=models.URLField(max_length=2048, null=True),
+ ),
+ ]
diff --cc tests/api/test_order.py
index 9f5beada95,0f3087c693..c5c1f73196
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@@ -12,9 -11,7 +12,8 @@@ from prices import Money, TaxedMone
from saleor.account.models import CustomerEvent
from saleor.core.permissions import OrderPermissions
from saleor.core.taxes import zero_taxed_money
- from saleor.extensions.manager import ExtensionsManager
from saleor.graphql.core.enums import ReportingPeriod
+from saleor.graphql.order.enums import InvoiceStatus
from saleor.graphql.order.mutations.orders import (
clean_order_cancel,
clean_order_capture,
@@@ -24,13 -21,15 +23,15 @@@
from saleor.graphql.order.utils import validate_draft_order
from saleor.graphql.payment.types import PaymentChargeStatusEnum
from saleor.order import OrderStatus, events as order_events
-from saleor.order.error_codes import OrderErrorCode
-from saleor.order.models import Order, OrderEvent
+from saleor.order.error_codes import InvoiceErrorCode, OrderErrorCode
+from saleor.order.models import Invoice, Order, OrderEvent
from saleor.payment import ChargeStatus, CustomPaymentChoices, PaymentError
from saleor.payment.models import Payment
+ from saleor.plugins.manager import PluginsManager
from saleor.shipping.models import ShippingMethod
- from saleor.warehouse.models import Stock
+ from saleor.warehouse.models import Allocation, Stock
+ from ..utils import get_available_quantity_for_stock
from .utils import assert_no_permission, get_graphql_content
diff --cc tests/test_emails.py
index 761517ae61,3dc57c8ec7..47e620fee1
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@@ -11,8 -11,7 +11,8 @@@ import saleor.account.emails as account
import saleor.order.emails as emails
from saleor.core.emails import get_email_context, prepare_url
from saleor.core.utils import build_absolute_uri
+from saleor.order.models import Invoice, InvoiceStatus
- from saleor.order.utils import add_variant_to_order
+ from saleor.order.utils import add_variant_to_draft_order
def test_get_email_context(site_settings):