Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checkout and order promotions (#14696)
* Refactor fetching variants for predicates (#14670) * Refactor method for fetching variants for predicate * Limit querysets used for filtering * Fix failing tests * Extend PromotionRule with checkout_and_order_predicate field (#14664) * Fix migrations * Allow defining `checkoutAndOrderPredicate` in promotion mutations (#15054) * 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> * Update changelog * Include promotion discounts in checkout calculations (#15052) * 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 * test_unable_to_have_promotion_rule_with_mixed_predicates_CORE_2125 (#15210) * Adjust voucher assignement (#15189) * Adjsut CheckoutAddPromoCode * Adjust checkoutRemovePromoCode * Update test for recalculate_checkout_discount * Rename checkoutAndOrder discount to order discount (#15207) * Rename checkoutAndOrder discount to order discount * Rename occurrences in comments. --------- Co-authored-by: zedzior <piotr.zabieglik@gmail.com> * Fix failing tests * Prevent race condition on `CheckoutDiscount` object creation. (#15212) * Add unique constrain on CheckoutDiscount model. * Use get_or_create when creating CheckoutDiscount. * Make it working. * Add test. * Add additional test. * Adjust checkout discounted object where filter (#15187) * 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 * Fix DiscountedObjectWhereInput - include AND, OR operators * Add rules limit for checkout and order promotions. (#15200) * 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. * Add order promotions when populating db with dummy data. (#15232) * test_apply_promotion_with_order_predicate_eq_amount_on_checkout (#15222) * Get rid of total discount (#15229) * Get rid of total discount * Fix failing test * Adjust promotion rule type (#15213) * 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 * Collapse migrations introduced for order predicate (#15252) * Do not re-calculate the promotions when catalogue predicate is empty (#15251) * Fix `OrderDiscount.type` when converting checkout to order. (#15248) * 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. * test_promotion_applied_on_checkout_with_specified_lte_gte_subtotal (#15261) * Checkout and order promotions adjustments (#15279) * Add missing labels * Add atomic block for setting voucher on checkout and deleting the discount * Get rid of list() on iterator() * Fix failing test * Fix filtering by order predicate (#15332) * Convert camel case to snake case. * Improve tests. * Correct predicates in tests. * Apply review comments. * Order promotions performance. (#15347) * Check if clear discounts is needed; call the function once * Update base_prices if needed only. * Fix tests. * Refactor. --------- Co-authored-by: Piotr Zabieglik <55899043+zedzior@users.noreply.github.com> Co-authored-by: Renata <renata.gajzlerowicz@gmail.com> Co-authored-by: zedzior <piotr.zabieglik@gmail.com> Co-authored-by: Maciej Korycinski <maciej.korycinski@saleor.io>
- Loading branch information