0% found this document useful (0 votes)
9 views7 pages

Python Assessment

The document outlines a Python function, `generate_monthly_bill`, which generates a monthly bill based on a predefined list of items, filtering for active items within a specified month. It includes requirements for active item detection, grouping logic, amount calculation, and total revenue computation. The output format is specified as a dictionary containing line items and total revenue.

Uploaded by

clopileta8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Python Assessment

The document outlines a Python function, `generate_monthly_bill`, which generates a monthly bill based on a predefined list of items, filtering for active items within a specified month. It includes requirements for active item detection, grouping logic, amount calculation, and total revenue computation. The output format is specified as a dictionary containing line items and total revenue.

Uploaded by

clopileta8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Python Assessment: Monthly Bill Generator

Objective

Given a predefined `item_list`, write a function that, for a given month and year (e.g., `"2024-11"`),
generates a bill by calculating charges for active items and grouping them appropriately.

✅ Function Signature

def generate_monthly_bill(item_list: list, target_month: str) -> dict:

"""

Generates a bill for the given month based on the item list.

Parameters:

item_list (list): List of dictionaries with item details.

target_month (str): Month in "YYYY-MM" format (e.g., "2024-11").

Returns:

dict: A dictionary with grouped line items and total revenue.

"""

🧩 Requirements

1. Active Item Detection

- Include only items whose date range intersects with the selected month.

2. Grouping Logic

- Group items if the following fields match:

- `item_code`

- `rate`

- Billing Period (intersection of item’s start/stop and selected month)

3. Amount Calculation
- Calculate the billable amount for each item based on its active days in the selected month.

4. Total Revenue

- The total revenue should be the sum of all grouped amounts.

📦 Output Format

"line_items": [

"item_code": "Executive Desk (4*2)",

"rate": 1080.0,

"qty": 25,

"amount": 27000.0,

"billing_period": "2024-11-01 to 2024-11-30"

},

...

],

"total_revenue": 72000.0

🧩 Hints

- Be mindful of inconsistent data types in fields like `rate`, `qty`, and `amount`.

- Pay close attention to how many days in the month an item is active.

item_list = [
{

"idx": 1,

"item_code": "Executive Desk (4*2)",

"sales_description": "Dedicated Executive Desk",

"qty": 10,

"rate": "1000",

"amount": "10000",

"start_date": "2023-11-01",

"stop_date": "2024-10-17",

},

"idx": 2,

"item_code": "Executive Desk (4*2)",

"qty": "10",

"rate": "1080",

"amount": "10800",

"start_date": "2024-10-18",

"stop_date": "2025-10-31",

},

"idx": 3,

"item_code": "Executive Desk (4*2)",

"qty": 15,

"rate": "1080",

"amount": "16200",

"start_date": "2024-11-01",

"stop_date": "2025-10-31",

},

"idx": 4,
"item_code": "Executive Desk (4*2)",

"qty": 5,

"rate": "1000",

"amount": "5000",

"start_date": "2024-11-01",

"stop_date": "2025-10-31",

},

"idx": 5,

"item_code": "Manager Cabin",

"qty": 5,

"rate": 5000,

"amount": 25000,

"start_date": "2024-11-01",

"stop_date": "2025-10-31",

},

"idx": 6,

"item_code": "Manager Cabin",

"qty": 7,

"rate": "5000",

"amount": 35000,

"start_date": "2024-12-15",

"stop_date": "2025-10-31",

},

"idx": 7,

"item_code": "Manager Cabin",

"qty": 10,

"rate": 4600,

"amount": 46000,
"start_date": "2023-11-01",

"stop_date": "2024-10-17",

},

"idx": 8,

"item_code": "Parking (2S)",

"qty": 10,

"rate": 1000,

"amount": 10000,

"start_date": "2024-11-01",

"stop_date": "2025-10-31",

},

"idx": 9,

"item_code": "Parking (2S)",

"qty": 10,

"rate": 0,

"amount": 0,

"start_date": "2024-11-01",

"stop_date": "2025-10-31",

},

"idx": 10,

"item_code": "Executive Desk (4*2)",

"qty": "8",

"rate": "1100",

"amount": "8800",

"start_date": "2024-11-15",

"stop_date": "2025-01-31",

},

{
"idx": 11,

"item_code": "Manager Cabin",

"qty": "3",

"rate": "5200",

"amount": "15600",

"start_date": "2024-10-10",

"stop_date": "2024-11-10",

},

"idx": 12,

"item_code": "Conference Table",

"qty": 1,

"rate": "20000",

"amount": "20000",

"start_date": "2024-11-05",

"stop_date": "2024-11-20",

},

"idx": 13,

"item_code": "Parking (2S)",

"qty": 5,

"rate": "1000",

"amount": "5000",

"start_date": "2024-11-15",

"stop_date": "2025-02-28",

},

"idx": 14,

"item_code": "Reception Desk",

"qty": 2,

"rate": "7000",
"amount": "14000",

"start_date": "2024-11-01",

"stop_date": "2025-03-31",

},

"idx": 15,

"item_code": "Reception Desk",

"qty": 1,

"rate": "7000",

"amount": "7000",

"start_date": "2024-11-10",

"stop_date": "2024-11-25",

},

"idx": 16,

"item_code": "Breakout Area",

"qty": 3,

"rate": "3000",

"amount": "9000",

"start_date": "2024-01-01",

"stop_date": "2024-01-31",

You might also like