def get_context(context): context.no_cache = 1 context.show_sidebar = True context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name) if hasattr(context.doc, "set_indicator"): context.doc.set_indicator() if show_attachments(): context.attachments = get_attachments(frappe.form_dict.doctype, frappe.form_dict.name) context.parents = frappe.form_dict.parents context.title = frappe.form_dict.name context.payment_ref = frappe.db.get_value("Payment Request", {"reference_name": frappe.form_dict.name}, "name") context.enabled_checkout = frappe.get_doc("Shopping Cart Settings").enable_checkout default_print_format = frappe.db.get_value('Property Setter', dict(property='default_print_format', doc_type=frappe.form_dict.doctype), "value") if default_print_format: context.print_format = default_print_format else: context.print_format = "Standard" if not frappe.has_website_permission(context.doc): frappe.throw(_("Not Permitted"), frappe.PermissionError) # check for the loyalty program of the customer customer_loyalty_program = frappe.db.get_value("Customer", context.doc.customer, "loyalty_program") if customer_loyalty_program: from erpnext.accounts.doctype.loyalty_program.loyalty_program import get_loyalty_program_details_with_points loyalty_program_details = get_loyalty_program_details_with_points(context.doc.customer, customer_loyalty_program) context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points"))
def get_points_earned(self): def get_returned_amount(): returned_amount = frappe.db.sql(""" select sum(grand_total) from `tabSales Invoice` where docstatus=1 and is_return=1 and ifnull(return_against, '')=%s """, self.name) return abs(flt(returned_amount[0][0])) if returned_amount else 0 lp_details = get_loyalty_program_details_with_points(self.customer, company=self.company, loyalty_program=self.loyalty_program, expiry_date=self.posting_date, include_expired_entry=True) if lp_details and getdate(lp_details.from_date) <= getdate(self.posting_date) and \ (not lp_details.to_date or getdate(lp_details.to_date) >= getdate(self.posting_date)): returned_amount = get_returned_amount() eligible_amount = flt(self.grand_total) - cint(self.loyalty_amount) - returned_amount points_earned = cint(eligible_amount/lp_details.collection_factor) return points_earned or 0
def get_context(context): context.no_cache = 1 context.show_sidebar = True context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name) if hasattr(context.doc, "set_indicator"): context.doc.set_indicator() if show_attachments(): context.attachments = get_attachments(frappe.form_dict.doctype, frappe.form_dict.name) context.parents = frappe.form_dict.parents context.title = frappe.form_dict.name context.payment_ref = frappe.db.get_value( "Payment Request", {"reference_name": frappe.form_dict.name}, "name") context.enabled_checkout = frappe.get_doc( "E Commerce Settings").enable_checkout default_print_format = frappe.db.get_value( 'Property Setter', dict(property='default_print_format', doc_type=frappe.form_dict.doctype), "value") if default_print_format: context.print_format = default_print_format else: context.print_format = "Standard" if not frappe.has_website_permission(context.doc): frappe.throw(_("Not Permitted"), frappe.PermissionError) # check for the loyalty program of the customer customer_loyalty_program = frappe.db.get_value("Customer", context.doc.customer, "loyalty_program") if customer_loyalty_program: from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( get_loyalty_program_details_with_points, ) loyalty_program_details = get_loyalty_program_details_with_points( context.doc.customer, customer_loyalty_program) context.available_loyalty_points = int( loyalty_program_details.get("loyalty_points"))
def get_points_earned(self): def get_returned_amount(): returned_amount = frappe.db.sql( """ select sum(grand_total) from `tabSales Invoice` where docstatus=1 and is_return=1 and ifnull(return_against, '')=%s """, self.name) return abs(flt(returned_amount[0][0])) if returned_amount else 0 lp_details = get_loyalty_program_details_with_points( self.customer, company=self.company, loyalty_program=self.loyalty_program, expiry_date=self.posting_date, include_expired_entry=True) if lp_details and getdate(lp_details.from_date) <= getdate(self.posting_date) and \ (not lp_details.to_date or getdate(lp_details.to_date) >= getdate(self.posting_date)): returned_amount = get_returned_amount() eligible_amount = flt(self.grand_total) - cint( self.loyalty_amount) - returned_amount points_earned = cint(eligible_amount / lp_details.collection_factor) return points_earned or 0