fix: customer creation from shopping cart (#25136)

This commit is contained in:
Sagar Vora 2021-04-01 18:18:19 +05:30 committed by GitHub
parent 446a6df662
commit d3ee8c7731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -230,13 +230,20 @@ class Customer(TransactionBase):
frappe.db.set(self, "customer_name", newdn)
def set_loyalty_program(self):
if self.loyalty_program: return
if self.loyalty_program:
return
loyalty_program = get_loyalty_programs(self)
if not loyalty_program: return
if not loyalty_program:
return
if len(loyalty_program) == 1:
self.loyalty_program = loyalty_program[0]
else:
frappe.msgprint(_("Multiple Loyalty Program found for the Customer. Please select manually."))
frappe.msgprint(
_("Multiple Loyalty Programs found for Customer {}. Please select manually.")
.format(frappe.bold(self.customer_name))
)
def create_onboarding_docs(self, args):
defaults = frappe.defaults.get_defaults()
@ -340,7 +347,6 @@ def _set_missing_values(source, target):
@frappe.whitelist()
def get_loyalty_programs(doc):
''' returns applicable loyalty programs for a customer '''
from frappe.desk.treeview import get_children
lp_details = []
loyalty_programs = frappe.get_all("Loyalty Program",
@ -349,15 +355,33 @@ def get_loyalty_programs(doc):
"ifnull(to_date, '2500-01-01')": [">=", today()]})
for loyalty_program in loyalty_programs:
customer_groups = [d.value for d in get_children("Customer Group", loyalty_program.customer_group)] + [loyalty_program.customer_group]
customer_territories = [d.value for d in get_children("Territory", loyalty_program.customer_territory)] + [loyalty_program.customer_territory]
if (not loyalty_program.customer_group or doc.customer_group in customer_groups)\
and (not loyalty_program.customer_territory or doc.territory in customer_territories):
if (
(not loyalty_program.customer_group
or doc.customer_group in get_nested_links(
"Customer Group",
loyalty_program.customer_group,
doc.flags.ignore_permissions
))
and (not loyalty_program.customer_territory
or doc.territory in get_nested_links(
"Territory",
loyalty_program.customer_territory,
doc.flags.ignore_permissions
))
):
lp_details.append(loyalty_program.name)
return lp_details
def get_nested_links(link_doctype, link_name, ignore_permissions=False):
from frappe.desk.treeview import _get_children
links = [link_name]
for d in _get_children(link_doctype, link_name, ignore_permissions):
links.append(d.value)
return links
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def get_customer_list(doctype, txt, searchfield, start, page_len, filters=None):
@ -572,4 +596,4 @@ def get_customer_primary_contact(doctype, txt, searchfield, start, page_len, fil
""", {
'customer': customer,
'txt': '%%%s%%' % txt
})
})