def reset_mode_of_payments(self): if self.pos_profile: pos_profile = frappe.get_cached_doc('POS Profile', self.pos_profile) update_multi_mode_option(self, pos_profile) self.paid_amount = 0
def set_pos_fields(self, for_validate=False): """Set retail related fields from POS Profiles""" from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile if not self.pos_profile: pos_profile = get_pos_profile(self.company) or {} if not pos_profile: frappe.throw( _("No POS Profile found. Please create a New POS Profile first" )) self.pos_profile = pos_profile.get('name') profile = {} if self.pos_profile: profile = frappe.get_doc('POS Profile', self.pos_profile) if not self.get('payments') and not for_validate: update_multi_mode_option(self, profile) if self.is_return and not for_validate: add_return_modes(self, profile) if profile: if not for_validate and not self.customer: self.customer = profile.customer self.ignore_pricing_rule = profile.ignore_pricing_rule self.account_for_change_amount = profile.get( 'account_for_change_amount') or self.account_for_change_amount self.set_warehouse = profile.get('warehouse') or self.set_warehouse for fieldname in ('currency', 'letter_head', 'tc_name', 'company', 'select_print_heading', 'write_off_account', 'taxes_and_charges', 'write_off_cost_center', 'apply_discount_on', 'cost_center', 'tax_category', 'ignore_pricing_rule', 'company_address', 'update_stock'): if not for_validate: self.set(fieldname, profile.get(fieldname)) if self.customer: customer_price_list, customer_group, customer_currency = frappe.db.get_value( "Customer", self.customer, [ 'default_price_list', 'customer_group', 'default_currency' ]) customer_group_price_list = frappe.db.get_value( "Customer Group", customer_group, 'default_price_list') selling_price_list = customer_price_list or customer_group_price_list or profile.get( 'selling_price_list') if customer_currency != profile.get('currency'): self.set('currency', customer_currency) else: selling_price_list = profile.get('selling_price_list') if selling_price_list: self.set('selling_price_list', selling_price_list) # set pos values in items for item in self.get("items"): if item.get('item_code'): profile_details = get_pos_profile_item_details( profile.get("company"), frappe._dict(item.as_dict()), profile) for fname, val in iteritems(profile_details): if (not for_validate) or (for_validate and not item.get(fname)): item.set(fname, val) # fetch terms if self.tc_name and not self.terms: self.terms = frappe.db.get_value("Terms and Conditions", self.tc_name, "terms") # fetch charges if self.taxes_and_charges and not len(self.get("taxes")): self.set_taxes() if not self.account_for_change_amount: self.account_for_change_amount = frappe.get_cached_value( 'Company', self.company, 'default_cash_account') return profile
def set_pos_fields(self, for_validate=False): """Set retail related fields from POS Profiles""" from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details if not self.pos_profile: pos_profile = get_pos_profile(self.company) or {} if not pos_profile: frappe.throw(_("No POS Profile found. Please create a New POS Profile first")) self.pos_profile = pos_profile.get("name") profile = {} if self.pos_profile: profile = frappe.get_doc("POS Profile", self.pos_profile) if not self.get("payments") and not for_validate: update_multi_mode_option(self, profile) if self.is_return and not for_validate: add_return_modes(self, profile) if profile: if not for_validate and not self.customer: self.customer = profile.customer self.account_for_change_amount = ( profile.get("account_for_change_amount") or self.account_for_change_amount ) self.set_warehouse = profile.get("warehouse") or self.set_warehouse for fieldname in ( "currency", "letter_head", "tc_name", "company", "select_print_heading", "write_off_account", "taxes_and_charges", "write_off_cost_center", "apply_discount_on", "cost_center", "tax_category", "ignore_pricing_rule", "company_address", "update_stock", ): if not for_validate: self.set(fieldname, profile.get(fieldname)) if self.customer: customer_price_list, customer_group, customer_currency = frappe.db.get_value( "Customer", self.customer, ["default_price_list", "customer_group", "default_currency"] ) customer_group_price_list = frappe.db.get_value( "Customer Group", customer_group, "default_price_list" ) selling_price_list = ( customer_price_list or customer_group_price_list or profile.get("selling_price_list") ) if customer_currency != profile.get("currency"): self.set("currency", customer_currency) else: selling_price_list = profile.get("selling_price_list") if selling_price_list: self.set("selling_price_list", selling_price_list) # set pos values in items for item in self.get("items"): if item.get("item_code"): profile_details = get_pos_profile_item_details( profile.get("company"), frappe._dict(item.as_dict()), profile ) for fname, val in profile_details.items(): if (not for_validate) or (for_validate and not item.get(fname)): item.set(fname, val) # fetch terms if self.tc_name and not self.terms: self.terms = frappe.db.get_value("Terms and Conditions", self.tc_name, "terms") # fetch charges if self.taxes_and_charges and not len(self.get("taxes")): self.set_taxes() if not self.account_for_change_amount: self.account_for_change_amount = frappe.get_cached_value( "Company", self.company, "default_cash_account" ) return profile