Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate order promotions in draft order #15459

Merged
merged 178 commits into from
Apr 16, 2024

Conversation

zedzior
Copy link
Member

@zedzior zedzior commented Feb 22, 2024

I want to merge this change, because it enables catalogue and order promotion calculations in draft orders.
Issue: #14586

It also prevents checkout/order from multiple catalogue discounts applied to single line.
Isssue: #15124

Impact

  • New migrations
  • New/Updated API fields or mutations
  • Deprecated API fields or mutations
  • Removed API types, fields, or mutations

Docs

  • Link to documentation:

Pull Request Checklist

  • Privileged queries and mutations are either absent or guarded by proper permission checks
  • Database queries are optimized and the number of queries is constant
  • Database migrations are either absent or optimized for zero downtime
  • The changes are covered by test cases
  • All new fields/inputs/mutations have proper labels added (ADDED_IN_X, PREVIEW_FEATURE, etc.)
  • All migrations have proper dependencies
  • All indexes are added concurrently in migrations
  • All RunSql and RunPython migrations have revert option defined

IKarbowiak and others added 30 commits January 12, 2024 12:12
* Refactor method for fetching variants for predicate

* Limit querysets used for filtering

* Fix failing tests
…5054)

* Add checkout_and_order_predicate field to promotion_rule graphql type.

* Add reward_type field.

* Add predicate types.

* Temporarily turn checkoutAndOrderPredicate field into JSON.

* Add input types.

* Validate new input fields.

* Cover validations with tests.

* Remove stuff from previous approach.

* Do not allow mixing predicates.

* Fix promotion rule validation

* Adjust clean_promotion_rule validator

* Extend PromotionCreate validation

* Unify promotion rule validations

* Rename PredicateType ORDER field to CHECKOUT_AND_ORDER

* Add more tests to PromotionRuleUpdate

* Update promotion/validators.py file

* Add docstrings to functions in promotion validators.py file

* Add tests for promotion validators

* Add validation for price based predicate and rule with mixed currencies

* Add mising test for PromotionRuleCreate

* Clear graphql/discount/utils.py

* Fix migrations and removed not needed changes

* Apply code review suggestions

* Refactor get_predicate_type function.

---------

Co-authored-by: IKarbowiak <iga.karbowiak@saleor.io>
* Add CheckoutDiscountedObjectWhere

* Add fetch_promotion_rules_for_checkout method

* Introduce PredicateObjectType

* Add schema of including checkout and order discount

* Extend discount models

* Include checkout and order promotion discount in checkoucalculations

* Adjust create or update checkout discount - remove CheckoutDiscount when the voucher is assigned and update CheckoutOrder if any exist

* Adjust checkout discount creation for checkout and order promotions

* Delete CheckoutDiscount when no rule applies anymore

* Add tests for CheckoutLinesAdd

* Fix failing tests

* Add test for generate_checkout_payload_for_tax_calculation

* Include checkout discounts in CheckoutInfo dataloader

* Add tests for checkout base calculations

* Add tests for webhooks

* Add tests for recalculate_checkout_discount

* Add tests for price_override

* Add tests for avatax

* Add test for calculate_checkout_total method for Avatax plugin

* Add test for checkout calculation

* Fix migrations

* Apply code review suggestions
* Adjsut CheckoutAddPromoCode

* Adjust checkoutRemovePromoCode

* Update test for recalculate_checkout_discount
* Rename checkoutAndOrder discount to order discount

* Rename occurrences in comments.

---------

Co-authored-by: zedzior <piotr.zabieglik@gmail.com>
* Add unique constrain on CheckoutDiscount model.

* Use get_or_create when creating CheckoutDiscount.

* Make it working.

* Add test.

* Add additional test.
* Adjust total_price filtering in CheckoutDiscountedObjectWhere

* Add filtering by subtotal_price in CheckoutDiscountedObjectWhere

* Apply code review suggestiins and change DiscountedObjectPredicateInput to DiscountedObjectWhereInput

* Fix failing CI

* Fix failing test
* Add CHECKOUT_AND_ORDER_RULES_LIMIT env variable

* Add limit check to promotion validators

* Add test for promotion_rule_create mutation.

* Add validation to promotion_create mutation; cover with test.

* Add TODO comment; fix linter.

* Check the number of all checkout and order rules in database, instead of rules asocciated with given promotion.

* Extend errors with rulesLimit and exceedBy fields.

* Rename checkoutAndOrder; fix tests.
* Get rid of total discount

* Fix failing test
* Add predicate_type to PromotionRule model

* Add predicateType to PromotionRuleCreateInput

* Update changelog

* Make predicateType in PromotionRuleCreateInput optional, set the default value

* Fix failing e2e

* Adjust promotion validations

* Fix setting default value for predicateType

* Set predicateType on PromotionRule in sale mutations

* Fix failing tests

* Add type to Promotion

* Get rif of MIXED_PROMOTION_PREDICATES error code

* Update promotion rule validators

* Replace promotion fixture with catalogue_promotion

* Update update_products_discounted_prices_for_promotion_task

* Drop commented line in PromotionCreate
* Create proper 'OrderDiscount' object, when converting checkout to order.

* Add voucher and voucher code to 'OrderDiscount' when discount type is VOUCHER.

* Add test.

* Fix linter.

* Simplify 'OrderDiscount' create.

* Apply review changes.

* Fix linter.
* Extend PromotionRule with gifts field

* Extend CheckoutLine and OrderLine with is_gift field

* Add GIFT RewardType

* Add gift_promotion_rule fixture
* Add missing labels

* Add atomic block for setting voucher on checkout and deleting the discount
* Add 'gifts' and 'giftsLimit' fields to 'PromotionRule' type.

* Add 'is_gift' field to 'OrderLine' and 'CheckoutLine' types.

* Add 'gifts' to promotion rule input; validate gift promotions.

* Make it working.

* Add tests to promotion rule create.

* Adjust promotion create mutation.

* Add test for promotion create mutation.

* Add tests to promotion rule update.

* Adjust validators.

* Add more tests to promotion rule update.

* Add dataloader.

* Fix tests.

* Test 'isGift' field.

* Rename 'gifts' to 'giftIds'.

* Adjust mutations after renaming.

* Restore previous name in case of inputs.

* Add PREVIEW_FEATURE flags.
@zedzior zedzior marked this pull request as ready for review April 8, 2024 12:15
@github-actions github-actions bot temporarily deployed to calculate-order-promotions-in-draft-order April 8, 2024 12:15 Inactive
@zedzior zedzior marked this pull request as draft April 8, 2024 15:04
@zedzior zedzior removed the request for review from a team April 8, 2024 15:04
@github-actions github-actions bot temporarily deployed to calculate-order-promotions-in-draft-order April 8, 2024 15:38 Inactive
@zedzior zedzior marked this pull request as ready for review April 8, 2024 16:02
@github-actions github-actions bot temporarily deployed to calculate-order-promotions-in-draft-order April 8, 2024 16:02 Inactive
@github-actions github-actions bot temporarily deployed to calculate-order-promotions-in-draft-order April 8, 2024 16:11 Inactive
@zedzior zedzior added merchant Merchant Experience team topics and removed test deployment Deploy test environment for pull request labels Apr 8, 2024
@zedzior zedzior requested review from kadewu and korycins April 8, 2024 16:43
korycins
korycins previously approved these changes Apr 9, 2024
saleor/discount/utils.py Show resolved Hide resolved
saleor/discount/utils.py Outdated Show resolved Hide resolved
saleor/order/calculations.py Show resolved Hide resolved
@zedzior zedzior dismissed stale reviews from korycins, yellowee, and IKarbowiak via 1a4a000 April 12, 2024 12:36
@zedzior zedzior merged commit eb0c3f2 into main Apr 16, 2024
7 checks passed
@zedzior zedzior deleted the calculate-order-promotions-in-draft-order branch April 16, 2024 09:14
zedzior added a commit that referenced this pull request May 14, 2024
* Calculate order promotions in draft order (#15459)

* Add `unique_type` to discount line models - migration compatibility (#15953)

* Add product name to gift line. (#15977)

* Fix subtotal discount propagation. (#15980)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merchant Merchant Experience team topics promotions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the order calculations to include the promotion discount
5 participants