fix: customer creation from shopping cart (#25136)
This commit is contained in:
parent
446a6df662
commit
d3ee8c7731
@ -230,13 +230,20 @@ class Customer(TransactionBase):
|
|||||||
frappe.db.set(self, "customer_name", newdn)
|
frappe.db.set(self, "customer_name", newdn)
|
||||||
|
|
||||||
def set_loyalty_program(self):
|
def set_loyalty_program(self):
|
||||||
if self.loyalty_program: return
|
if self.loyalty_program:
|
||||||
|
return
|
||||||
|
|
||||||
loyalty_program = get_loyalty_programs(self)
|
loyalty_program = get_loyalty_programs(self)
|
||||||
if not loyalty_program: return
|
if not loyalty_program:
|
||||||
|
return
|
||||||
|
|
||||||
if len(loyalty_program) == 1:
|
if len(loyalty_program) == 1:
|
||||||
self.loyalty_program = loyalty_program[0]
|
self.loyalty_program = loyalty_program[0]
|
||||||
else:
|
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):
|
def create_onboarding_docs(self, args):
|
||||||
defaults = frappe.defaults.get_defaults()
|
defaults = frappe.defaults.get_defaults()
|
||||||
@ -340,7 +347,6 @@ def _set_missing_values(source, target):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_loyalty_programs(doc):
|
def get_loyalty_programs(doc):
|
||||||
''' returns applicable loyalty programs for a customer '''
|
''' returns applicable loyalty programs for a customer '''
|
||||||
from frappe.desk.treeview import get_children
|
|
||||||
|
|
||||||
lp_details = []
|
lp_details = []
|
||||||
loyalty_programs = frappe.get_all("Loyalty Program",
|
loyalty_programs = frappe.get_all("Loyalty Program",
|
||||||
@ -349,15 +355,33 @@ def get_loyalty_programs(doc):
|
|||||||
"ifnull(to_date, '2500-01-01')": [">=", today()]})
|
"ifnull(to_date, '2500-01-01')": [">=", today()]})
|
||||||
|
|
||||||
for loyalty_program in loyalty_programs:
|
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]
|
if (
|
||||||
customer_territories = [d.value for d in get_children("Territory", loyalty_program.customer_territory)] + [loyalty_program.customer_territory]
|
(not loyalty_program.customer_group
|
||||||
|
or doc.customer_group in get_nested_links(
|
||||||
if (not loyalty_program.customer_group or doc.customer_group in customer_groups)\
|
"Customer Group",
|
||||||
and (not loyalty_program.customer_territory or doc.territory in customer_territories):
|
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)
|
lp_details.append(loyalty_program.name)
|
||||||
|
|
||||||
return lp_details
|
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.whitelist()
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
def get_customer_list(doctype, txt, searchfield, start, page_len, filters=None):
|
def get_customer_list(doctype, txt, searchfield, start, page_len, filters=None):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user