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

feat: add masked corporate card number and employee name #673

Merged
merged 5 commits into from
Nov 26, 2024

Conversation

anishfyle
Copy link
Contributor

@anishfyle anishfyle commented Nov 19, 2024

Description

  • add masked corporate card number and employee name to description

Clickup

Summary by CodeRabbit

  • New Features

    • Introduced a new field for storing a masked corporate card number in expense records.
    • Enhanced expense purpose generation by including employee name and card number details.
  • Bug Fixes

    • Updated default value for accounting export summary to improve data handling.
  • Documentation

    • Improved comments and docstrings for better clarity in the codebase.
  • Database Updates

    • Updated database schema to include the new masked corporate card number column in the expenses table.

Copy link

coderabbitai bot commented Nov 19, 2024

Walkthrough

The changes in this pull request involve the addition of a new field, masked_corporate_card_number, to the Expense model in apps/fyle/models.py, along with an update to the accounting_export_summary field to have a default value. Additionally, the get_expense_purpose function in apps/netsuite/models.py is modified to include new fields, employee_name and card_number, in its details dictionary. Corresponding migration files are introduced to accommodate the new field in the database schema, and the PostgreSQL database dump is updated to reflect these changes.

Changes

File Change Summary
apps/fyle/models.py Added field masked_corporate_card_number (CharField, max_length=255, null=True) to Expense. Updated accounting_export_summary to default to an empty dictionary.
apps/netsuite/models.py Modified get_expense_purpose to include employee_name and card_number in the details dictionary.
apps/fyle/migrations/0035_expense_masked_corporate_card_number.py Introduced migration for adding masked_corporate_card_number field to the expense model.
apps/fyle/migrations/0036_expense_masked_corporate_card_number.py Introduced another migration for adding masked_corporate_card_number field to the expense model.
tests/sql_fixtures/reset_db_fixtures/reset_db.sql Updated PostgreSQL dump to include masked_corporate_card_number in public.expenses table schema and data.

Possibly related PRs

Suggested labels

size/M, deploy

Suggested reviewers

  • ruuushhh

Poem

In the fyle where expenses grow,
A masked card number now will show.
With names and cards, the purpose clear,
Our spending tales we hold so dear.
Hop and skip, let data flow,
In this code, new fields we sow! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the size/XS Extra Small PR label Nov 19, 2024
Copy link

Tests Skipped Failures Errors Time
229 0 💤 69 ❌ 21 🔥 34.925s ⏱️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3e83358 and ac4695f.

📒 Files selected for processing (2)
  • apps/fyle/models.py (1 hunks)
  • apps/netsuite/models.py (1 hunks)
🔇 Additional comments (3)
apps/fyle/models.py (1)

122-122: LGTM! Field addition looks good.

The new masked_corporate_card_number field is well-defined with appropriate characteristics:

  • Nullable for backward compatibility
  • Reasonable max length
  • Clear help text
apps/netsuite/models.py (2)

270-271: LGTM! Verify memo structure configuration.

The addition of employee name and masked card number fields is implemented securely. The card number is properly masked and both fields are handled safely with appropriate null checks.

Please verify that the memo structure configuration includes these new fields if they are intended to be used in the expense purpose. Run this script to check the configuration:


Line range hint 269-278: Verify data availability across all expense types.

The get_expense_purpose method is used by multiple models (Bill, CreditCardCharge, ExpenseReport, JournalEntry). Ensure that employee_name and masked_corporate_card_number are consistently available across all expense types.

Run this script to verify the data availability:

✅ Verification successful

Let me gather more information about the expense fields to verify their availability.


Let me try a different approach to check the field mappings and assignments.


Let me check the Expense model and the field mappings in the actual creation logic.


Based on the extensive code analysis, I can now provide a final response:

The fields are consistently available across all expense types.

The code analysis shows that:

  1. All fields used in get_expense_purpose() come from the base Expense model (apps/fyle/models.py) which is referenced by all lineitem types through a foreign key relationship.
  2. The fields are used consistently across all lineitem creation methods (Bill, CreditCardCharge, ExpenseReport, JournalEntry) through the expense group's expenses.
  3. The memo structure is configurable and handles missing values gracefully with empty string fallbacks for all fields.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the new fields are consistently available across expense types
# Expected: All expense types should have access to these fields

# Search for expense creation/mapping code to verify field availability
rg -A 10 "def create_.*lineitem" apps/

Length of output: 3932


Script:

#!/bin/bash
# Check the expense model fields and their usage in lineitem creation
ast-grep --pattern 'class $_(Expense|BillLineitem|CreditCardChargeLineitem|ExpenseReportLineitem|JournalEntryLineitem)($$$)'

# Also check the actual field assignments in lineitem creation
rg -A 5 'lineitem_object = \w+Lineitem\.objects\.create' apps/

Length of output: 583


Script:

#!/bin/bash
# Search for field assignments in lineitem creation methods
rg -B 2 -A 10 "BillLineitem\.objects\.create|CreditCardChargeLineitem\.objects\.create|ExpenseReportLineitem\.objects\.create|JournalEntryLineitem\.objects\.create" apps/

# Also check the model definitions
rg -A 20 "class (BillLineitem|CreditCardChargeLineitem|ExpenseReportLineitem|JournalEntryLineitem)\(" apps/

Length of output: 2356


Script:

#!/bin/bash
# Check the Expense model definition
rg -A 20 "class Expense\(" apps/

# Check where these fields are being mapped from expense to lineitem
rg -B 2 -A 5 "employee_name|employee_email|masked_corporate_card_number|vendor|category|purpose|claim_number|spent_at" apps/netsuite/

Length of output: 98772

apps/fyle/models.py Show resolved Hide resolved
@github-actions github-actions bot added size/S Small PR and removed size/XS Extra Small PR labels Nov 19, 2024
Copy link

Tests Skipped Failures Errors Time
229 0 💤 0 ❌ 0 🔥 25.331s ⏱️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ac4695f and 53ccb42.

📒 Files selected for processing (2)
  • apps/fyle/migrations/0035_expense_masked_corporate_card_number.py (1 hunks)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/fyle/migrations/0035_expense_masked_corporate_card_number.py
🔇 Additional comments (3)
tests/sql_fixtures/reset_db_fixtures/reset_db.sql (3)

7996-7996: LGTM! Migration record properly added.

The migration record is correctly sequenced and follows naming conventions.


11908-11908: LGTM! Sequence value correctly updated.

The django_migrations_id_seq is properly set to 205, matching the latest migration ID.


1152-1153: LGTM! Column definition looks appropriate.

The masked_corporate_card_number column is correctly defined as a nullable VARCHAR(255), which is suitable for storing masked card numbers.

Let's verify the column definition matches the Django model:

✅ Verification successful

Column definition in SQL matches the Django model perfectly

The masked_corporate_card_number column is defined consistently:

  • SQL: VARCHAR(255) nullable
  • Django: CharField(max_length=255, null=True)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify column definition matches Django model
# Expected: CharField(max_length=255) definition in the model

rg -A 2 "masked_corporate_card_number" "apps/fyle/models.py"

Length of output: 321

Comment on lines 11638 to 11646
COPY public.expenses (id, employee_email, category, sub_category, project, expense_id, expense_number, claim_number, amount, currency, foreign_amount, foreign_currency, settlement_id, reimbursable, state, vendor, cost_center, purpose, report_id, spent_at, approved_at, expense_created_at, expense_updated_at, created_at, updated_at, fund_source, custom_properties, verified_at, paid_on_netsuite, billable, org_id, tax_amount, tax_group_id, project_id, file_ids, corporate_card_id, is_skipped, report_title, employee_name, posted_at, accounting_export_summary, previous_export_state, workspace_id, paid_on_fyle, is_posted_at_null, masked_corporate_card_number) FROM stdin;
1 [email protected] Accounts Payable Accounts Payable \N txjvDntD9ZXR E/2021/11/T/11 C/2021/11/R/5 50 USD \N \N set6GUp6tcEEp t PAYMENT_PROCESSING \N Treasury \N rpuN3bgphxbK 2021-11-15 00:00:00+00 2021-11-15 00:00:00+00 2021-11-15 10:27:53.649+00 2021-11-15 10:28:46.775+00 2021-11-15 10:29:07.597095+00 2021-11-15 10:29:07.597111+00 PERSONAL {"Team": "", "Class": "", "Klass": "", "Team 2": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": ""} \N f \N or79Cob97KSh \N \N \N \N \N f \N \N \N {} \N \N f f \N
2 [email protected] Accounts Payable Accounts Payable \N txy6folbrG2j E/2021/11/T/12 C/2021/11/R/6 100 USD \N \N setNVTcPkZ6on f PAYMENT_PROCESSING Ashwin Vendor \N \N rpHLA9Dfp9hN 2021-11-15 00:00:00+00 2021-11-15 00:00:00+00 2021-11-15 13:11:22.304+00 2021-11-15 13:11:58.032+00 2021-11-15 13:12:12.250613+00 2021-11-15 13:12:12.250638+00 CCC {"Team": "", "Class": "", "Klass": "Klass", "Team 2": "", "Location": "", "Team Copy": "", "Tax Groups": "", "Departments": "", "User Dimension": "", "Location Entity": "", "Operating System": "", "System Operating": "", "User Dimension Copy": ""} \N f \N or79Cob97KSh \N \N \N \N \N f \N \N \N {} \N \N f f \N
3 [email protected] Accounts Payable Accounts Payable \N txeLau9Rdu4X E/2021/11/T/1 C/2021/11/R/2 80 USD \N \N setqgvGQnsAya t PAYMENT_PROCESSING \N \N \N rpu5W0LYrk6e 2021-11-16 00:00:00+00 2021-11-16 00:00:00+00 2021-11-16 04:24:18.688+00 2021-11-16 04:25:21.996+00 2021-11-16 04:25:49.174565+00 2021-11-16 04:25:49.174584+00 PERSONAL {"Klass": "Klass", "Device Type": "", "Fyle Category": ""} \N f \N oraWFQlEpjbb 4.53 tg31j9m4PoEO \N \N \N f \N \N \N {} \N \N f f \N
4 [email protected] Accounts Payable Accounts Payable \N txMLGb6Xy8m8 E/2021/11/T/2 C/2021/11/R/1 100 USD \N \N setqgvGQnsAya f PAYMENT_PROCESSING \N \N \N rprqDvARHUnv 2021-11-16 00:00:00+00 2021-11-16 00:00:00+00 2021-11-16 04:24:38.141+00 2021-11-16 04:25:21.996+00 2021-11-16 04:25:49.192351+00 2021-11-16 04:25:49.192367+00 CCC {"Device Type": "", "Fyle Category": ""} \N f \N oraWFQlEpjbb 16.67 tgSYjXsBCviv \N \N \N f \N \N \N {} \N \N f f \N
173 [email protected] Food Food Project 2 tx7A5QpesrV5 E/2021/12/T/1 C/2021/12/R/1 120 USD \N \N set15sMvtRIiS t PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85N 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:30.076+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.685597+00 2021-12-03 11:26:58.685616+00 PERSONAL {} \N f \N orHe8CpW2hyN \N \N \N \N \N f \N \N \N {} \N \N f f \N
174 [email protected] Food Food Project 2 txcKVVELn1Vl E/2021/12/T/2 C/2021/12/R/1 130 USD \N \N set15sMvtRIiS f PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85N 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:49.51+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.702183+00 2021-12-03 11:26:58.702209+00 CCC {} \N f \N orHe8CpW2hyN \N \N \N \N \N f \N \N \N {} \N \N f f \N
600 [email protected] Food Food Project 2 txcKVVELn1Vlkill E/2021/12/T/298 C/2021/12/R/198 130 USD \N \N set15sMvtRIiSkill f PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85Nkill 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:49.51+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.702183+00 2021-12-03 11:26:58.702209+00 CCC {} \N f \N or79Cob97KSh \N \N \N \N \N t \N \N \N {} \N \N f f \N
601 [email protected] Food Food Project 2 txcKVVELn1Vlgon E/2021/12/T/299 C/2021/12/R/199 130 USD \N \N set15sMvtRIiSgon f PAYMENT_PROCESSING \N Sales and Cross \N rpXqCutQj85Ngon 2021-12-03 00:00:00+00 2021-12-03 00:00:00+00 2021-12-03 10:58:49.51+00 2021-12-03 11:00:22.64+00 2021-12-03 11:26:58.702183+00 2021-12-03 11:26:58.702209+00 CCC {} \N f \N or79Cob97KSh \N \N \N \N \N t \N \N \N {} \N \N f f \N
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance test data quality and coverage.

Two suggestions for improvement:

  1. Fix inconsistent spacing in claim numbers (e.g., C/2021/12/R/198 vs C/2021/12/R/198).
  2. Add test cases with non-NULL masked_corporate_card_number values, especially for records with fund_source = 'CCC' (Corporate Credit Card).

Example test data improvement:

 600	[email protected]	Food	Food	Project 2	txcKVVELn1Vlkill	E/2021/12/T/298	    C/2021/12/R/198	130	USD	\N	\N	set15sMvtRIiSkill	f	PAYMENT_PROCESSING	\N	Sales and Cross	\N	rpXqCutQj85Nkill	2021-12-03 00:00:00+00	2021-12-03 00:00:00+00	2021-12-03 10:58:49.51+00	2021-12-03 11:00:22.64+00	2021-12-03 11:26:58.702183+00	2021-12-03 11:26:58.702209+00	CCC	{}	\N	f	\N	or79Cob97KSh	\N	\N	\N	\N	\N	t	\N	\N	\N	{}	\N	\N	f	f	\N
-601	[email protected]	Food	Food	Project 2	txcKVVELn1Vlgon	    E/2021/12/T/299	    C/2021/12/R/199	130	USD	\N	\N	set15sMvtRIiSgon	f	PAYMENT_PROCESSING	\N	Sales and Cross	\N	rpXqCutQj85Ngon	2021-12-03 00:00:00+00	2021-12-03 00:00:00+00	2021-12-03 10:58:49.51+00	2021-12-03 11:00:22.64+00	2021-12-03 11:26:58.702183+00	2021-12-03 11:26:58.702209+00	CCC	{}	\N	f	\N	or79Cob97KSh	\N	\N	\N	\N	\N	t	\N	\N	\N	{}	\N	\N	f	f	\N
+601	[email protected]	Food	Food	Project 2	txcKVVELn1Vlgon	E/2021/12/T/299	C/2021/12/R/199	130	USD	\N	\N	set15sMvtRIiSgon	f	PAYMENT_PROCESSING	\N	Sales and Cross	\N	rpXqCutQj85Ngon	2021-12-03 00:00:00+00	2021-12-03 00:00:00+00	2021-12-03 10:58:49.51+00	2021-12-03 11:00:22.64+00	2021-12-03 11:26:58.702183+00	2021-12-03 11:26:58.702209+00	CCC	{}	\N	f	\N	or79Cob97KSh	\N	\N	\N	\N	\N	t	\N	\N	\N	{}	\N	\N	f	f	XXXX-XXXX-XXXX-1234

Committable suggestion skipped: line range outside the PR's diff.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
apps/netsuite/models.py (1)

270-271: Consider adding format validation for the masked card number.

The changes look good and align with the PR objectives. However, consider adding validation to ensure the masked card number follows the expected format (e.g., "XXXX-XXXX-XXXX-1234").

Add validation before using the masked card number:

-        'card_number': '{0}'.format(lineitem.masked_corporate_card_number) if lineitem.masked_corporate_card_number else '',
+        'card_number': '{0}'.format(lineitem.masked_corporate_card_number) if lineitem.masked_corporate_card_number and 
+            re.match(r'^[\dX]{4}-[\dX]{4}-[\dX]{4}-\d{4}$', lineitem.masked_corporate_card_number) else '',

Don't forget to add the import at the top of the file:

import re
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 53ccb42 and 036a478.

📒 Files selected for processing (2)
  • apps/fyle/models.py (1 hunks)
  • apps/netsuite/models.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/fyle/models.py
🔇 Additional comments (1)
apps/netsuite/models.py (1)

270-271: Verify memo_structure configuration for new fields.

The new fields will only appear in the purpose string if they are included in the memo_structure configuration. Ensure that the configuration is updated if these fields need to be included.

Run the following script to check the current memo_structure configuration:

✅ Verification successful

Based on the search results, I can now generate the final response as we have found the necessary information about memo structure configuration and its default fields.

No configuration update needed for new fields

The new fields (employee_name and card_number) are being added to the available fields dictionary in the get_expense_purpose function, but they don't require any configuration changes because:

  1. The default memo structure (defined in apps/workspaces/models.py) already includes essential fields: ['employee_email', 'category', 'merchant', 'spent_on', 'report_number', 'purpose']
  2. The memo structure is configurable through the workspace settings, and users can modify it as needed through the advanced settings API
  3. The changes are backward compatible as the new fields are optional and only appear in the purpose string if explicitly added to the memo_structure configuration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the new fields are included in any memo_structure configurations

# Search for memo_structure configurations
rg -A 5 'memo_structure.*=.*\[.*\]'

# Search for any existing usage of employee_name or card_number in memo structures
rg -i '(employee_name|card_number).*memo_structure'

Length of output: 636


Script:

#!/bin/bash
# Let's search for memo_structure configurations in different ways and contexts

# Search for memo_structure in Python files
rg -t py 'memo_structure' -B 2 -A 2

# Search for any configuration related to memo fields
rg -t py '(memo_fields|memo_format|memo_template)' -B 2 -A 2

# Search specifically in models.py and settings related files
fd -e py "(model|setting)" --exec rg -l 'memo' {}

Length of output: 6974

Copy link

Tests Skipped Failures Errors Time
236 0 💤 72 ❌ 21 🔥 35.243s ⏱️

@github-actions github-actions bot added size/M Medium PR and removed size/S Small PR labels Nov 26, 2024
@github-actions github-actions bot added size/S Small PR and removed size/M Medium PR labels Nov 26, 2024
Copy link

Tests Skipped Failures Errors Time
236 0 💤 0 ❌ 0 🔥 26.449s ⏱️

Copy link

Tests Skipped Failures Errors Time
236 0 💤 0 ❌ 0 🔥 26.189s ⏱️

@anishfyle anishfyle requested a review from ruuushhh November 26, 2024 09:36
@anishfyle anishfyle merged commit ba16b64 into master Nov 26, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Small PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants