Skip to content

Fix monthly revenue totals, tenant cache isolation, and floating points precision errork - #235

Open
AbdulhadeAhmad wants to merge 4 commits into
Base360-AI:mainfrom
AbdulhadeAhmad:main
Open

AbdulhadeAhmad wants to merge 4 commits into
Base360-AI:mainfrom
AbdulhadeAhmad:main

Conversation

@AbdulhadeAhmad

Copy link
Copy Markdown

Fixes the three revenue issues reported in the assignment:

  • Incorrect March totals: Filter reservations by the selected month using each property’s local time zone, including daylight-saving changes. Added a reporting-month selector and corrected the database connection configuration.
  • Cross-client revenue leakage: Include tenant, property, and reporting period in cache keys. Ignore legacy shared entries, verify cached ownership, and remove hardcoded revenue fallbacks.
  • Cents discrepancies: Sum amounts at full decimal precision, round the final total once using ROUND_HALF_UP, and return a decimal string for display without floating-point conversion.
    Also installs SQLAlchemy’s asyncio dependencies to resolve the missing greenlet error.

One more thing:
I also added __pycache__ to .gitignore because the app hot-reloads from the host's repo and generate these files which pollutes git's changes.

Comment on lines +14 to +18
const [period, setPeriod] = useState(() => {
const now = new Date();
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
});
const [year, month] = period.split('-').map(Number);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Partial or invalid text in <input type="month"> fallback inputs triggers API requests with invalid month/year parameters, resulting in 422 errors.
Severity: LOW

Suggested Fix

Validate that the input matches the expected YYYY-MM format (e.g. using a regular expression /^\d{4}-\d{2}$/) before updating period and triggering queries.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: frontend/src/components/Dashboard.tsx#L14-L18

Potential issue: On browsers lacking native `<input type="month">` support, the control
defaults to a plain text field where `validity.valid` evaluates to true for non-empty
text. Typing partial or invalid input like '2024-' or 'abc' updates `period`, resulting
in invalid `month` and `year` values such as 0 or `NaN`. These values trigger API
requests on each keystroke that fail with 422 errors and cause the UI to display 'Failed
to load revenue data'.

Did we get this right? 👍 / 👎 to inform future reviews.

@AbdulhadeAhmad

Copy link
Copy Markdown
Author

Here's my loom video:
https://www.loom.com/share/73b1e992f495403f8900ed69d3e183d7

When I recorded the video it was more than 18 minutes, so I cut some parts, sorry if that makes the video a little inconvenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant