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

chore: clarify codepath around mute email and make invoice #41704

Merged
merged 1 commit into from
Jun 23, 2024

Conversation

blaggacao
Copy link
Collaborator

Part of #40845

cc @ruthra-kumar

Comment on lines 215 to +221
def make_invoice(self):
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
if hasattr(ref_doc, "order_type") and ref_doc.order_type == "Shopping Cart":
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice

si = make_sales_invoice(self.reference_name, ignore_permissions=True)
si.allocate_advances_automatically = True
si = si.insert(ignore_permissions=True)
si.submit()
si = make_sales_invoice(self.reference_name, ignore_permissions=True)
si.allocate_advances_automatically = True
si = si.insert(ignore_permissions=True)
si.submit()
Copy link
Collaborator Author

@blaggacao blaggacao May 31, 2024

Choose a reason for hiding this comment

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

shifting control to de caller for a more "atomic" make_invoice function (useful later)

ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)

if (
hasattr(ref_doc, "order_type") and ref_doc.order_type == "Shopping Cart"
) or self.flags.mute_email:
send_mail = False

if send_mail and self.payment_channel != "Phone":
if send_mail and not (self.mute_email or self.flags.mute_email):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Use state instead of "logic on the leaves" (of the code branches)

Comment on lines -415 to -417
def get_payment_success_url(self):
return self.payment_success_url

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there's no field payment_success_url

Comment on lines +491 to +494
"make_sales_invoice": args.order_type == "Shopping Cart",
"mute_email": args.mute_email
or args.order_type == "Shopping Cart"
or gateway_account.get("payment_channel", "Email") != "Email",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ensure intent is properly reflected in state

Comment on lines -589 to +579
if gateway_account:
return get_payment_gateway_account(gateway_account)

gateway_account = get_payment_gateway_account({"is_default": 1})

return gateway_account
return get_payment_gateway_account(gateway_account)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

redundand logic

Comment on lines -597 to +586
def get_payment_gateway_account(args):
def get_payment_gateway_account(filter):
return frappe.db.get_value(
"Payment Gateway Account",
args,
["name", "payment_gateway", "payment_account", "message"],
filter,
["name", "payment_gateway", "payment_account", "payment_channel", "message"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

linter

self.assertEqual(pr.mute_email, False)
self.assertEqual(pr.mute_email, True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Finally, make the test semantically more correct.

@blaggacao
Copy link
Collaborator Author

@ruthra-kumar now it's green :-)

@ruthra-kumar ruthra-kumar self-assigned this May 31, 2024
@blaggacao
Copy link
Collaborator Author

@ruthra-kumar Does this look good?

  • All previous tests remain green; including the specifically added ones to stabilize this refactoring
  • The test semantic improves, correctly asserting the pr.mute_email state, now

@ruthra-kumar
Copy link
Member

@blaggacao

Bit held up with other stuff. Will look into this PR next week.

@blaggacao
Copy link
Collaborator Author

blaggacao commented Jun 17, 2024

@ruthra-kumar Hey, I hope we can get through this next step. Kindly remember, there are still 6 or so ahead, at a minimum. :-)

@ruthra-kumar ruthra-kumar merged commit 73d56c4 into frappe:develop Jun 23, 2024
13 checks passed
@blaggacao blaggacao deleted the payments/pr-2 branch June 23, 2024 13:23
@blaggacao
Copy link
Collaborator Author

Thanks a lot! The next one should be a lot smaller and easier! 🤝

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants