-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Conversation
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() |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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)
def get_payment_success_url(self): | ||
return self.payment_success_url | ||
|
There was a problem hiding this comment.
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
"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", |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundand logic
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"], |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
erpnext/accounts/doctype/payment_request/test_payment_request.py
Outdated
Show resolved
Hide resolved
@ruthra-kumar now it's green :-) |
@ruthra-kumar Does this look good?
|
Bit held up with other stuff. Will look into this PR next week. |
@ruthra-kumar Hey, I hope we can get through this next step. Kindly remember, there are still 6 or so ahead, at a minimum. :-) |
Thanks a lot! The next one should be a lot smaller and easier! 🤝 |
Part of #40845
cc @ruthra-kumar