Skip to content

Krit-m/discount-module

Repository files navigation

Introduction

The codes and documentation in this repository are part of the coding test - take home assignment for Playtorium job application of Krittaphat Maiklad.

Requirement

  • 'json' python library

Instruction

  • Use 'discountCalculator.py' as the main program. Functions for campaign check and discount calculations are created in the 'modules' folder.

  • The module receive input from the file 'shoppingList.json', which includes items in the shopping cart and discount campaigns chosen to be used. Items' categories are supposed to be specified in this list.

    The terms used in json input and the module for discount categories and types are as following:

    - Coupon : "coupon"
    - On Top : "onTop"
    - Seasonal: "seasonal"

    - Fixed amount : "fixed"
    - Percentage discount : "percent"
    - Percentage discount by item category : "byItem"
    - Discount by points : "byPoints"
    - Special campaigns: "special"

    The terms for parameters are as following:

    - Amount, percentage, or Customer points: "amount"
    (for any campaigns with only one numerical parameter)

    -Item category: "item"
    (for percentage discount by item category)

    - Every X THB: "forEvery"
    - Discount Y THB: "discount"
    (for special campaigns)

    In addition, I've added the 'currentPromotion.json' file as another input. This implementation aims to reflect the real life condition, in which some promotions might be usable only during a specific period of time. (Therefore, this input should only be edited by the store.) The file contains names (or code) referring to the promotional campaigns. Campaigns in 'shoppingList.json' with different names than the ones in this file are considered unusable.

  • Upon starting the program, the validity of each discount campaign is checked. A campaign in the list with any of the following properties is counted as 'Invalid':
    • Does not have a name, or its name is not included in 'currentPromotion'. For example, campaign 'HappyNewYear' is not used.
    • Discount category (coupon, on top, or seasonal) and type (i.e. fixed amount or percentage discount) are unmatched. For example; "category" : "coupon", "type" : "byItem"
    • Missing a required parameter or parameter value does not match. For example, string value for "amount".
    • "amount" is not a positive integer, or higher than 100 for percentage discounts.
    • "byItem" campaign, in cases that its specified item category does not match any items in the cart.
    • "special" campaign, with "discount" value higher than "forEvery"

  • The program does not stop working when encounter an invalid campaign. It will continue the discount calculation with any valid campaigns remain. The program will be interrupted and return a NOTICE message under 2 circumstances:
    • There are no valid campaigns left in the list.
    • There are 2 or more valid campaigns of a same category in the list.

  • Discount calculations are performed in order by category (coupon > on top > seasonal), regardless of campaigns' order in the list. (Even if you put an 'on top' before a 'coupon' in the list, 'coupon' will be used first.)

  • Names and types of campaigns used are shown in the terminal, along with the discounted total price.
    • For 'byItem', the item category is included in the output.
    • For 'byPoints', the amount of point used is stated in the output

Other assumptions made

  • For every discount campaigns in which the discount would be applied to the 'total price', the discount is applied in a certain percentage to EVERY ITEM in the cart, so that the total price is deducted to the desired amount.

    The reason of this decision is to avoid conflicts in cases that a fixed amount discount, which is a coupon, is applied before 'percentage discount by item category', an on top discount that might not be applied to all the items. This way, all items' price are reduced by 'fixed amount' equally before going through 'percentage discount by item category'.

  • If the 'fixed amount' coupon have higher amount than the total price, the total will be cut down to 0 baht, not a price of negative number. Also, other campaigns in the list are not used. However, if the shopping list include other 2 or more campaigns of a same category, the list will not pass the validity step.

  • If point input for 'discount by points' is higher than 20 percent of the total price, following the point rule, the module will use only '20% of total price' points for discount. (Please note that the amount of point actually being used is shown in the output.)
    I assume that since this module only 'calculate' the discount, it will not consume customer's point without approval.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages