def get_pos_data(): doc = frappe.new_doc('Sales Invoice') doc.update_stock = 1 doc.is_pos = 1 pos_profile = get_pos_profile(doc.company) or {} if pos_profile.get('name'): pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name')) else: frappe.msgprint('<a href="#Form/POS Profile/New POS Profile">' + _("Welcome to POS: Create your POS Profile") + '</a>') update_pos_profile_data(doc, pos_profile) update_multi_mode_option(doc, pos_profile) default_print_format = pos_profile.get('print_format') or "Point of Sale" print_template = frappe.db.get_value('Print Format', default_print_format, 'html') return { 'doc': doc, 'default_customer': pos_profile.get('customer'), 'items': get_items(doc, pos_profile), 'customers': get_customers(pos_profile, doc), 'pricing_rules': get_pricing_rules(doc), 'print_template': print_template, 'write_off_account': pos_profile.get('write_off_account'), 'meta': { 'invoice': frappe.get_meta('Sales Invoice'), 'items': frappe.get_meta('Sales Invoice Item'), 'taxes': frappe.get_meta('Sales Taxes and Charges') } }
def get_pos_data(): doc = frappe.new_doc('Sales Invoice') doc.update_stock = 1 doc.is_pos = 1 pos_profile = get_pos_profile(doc.company) or {} if pos_profile.get('name'): pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name')) else: frappe.msgprint(_("Warning Message: Create POS Profile")) update_pos_profile_data(doc, pos_profile) update_multi_mode_option(doc, pos_profile) print_template = frappe.db.get_value( 'Print Format', pos_profile.get('print_format'), 'html') or '' return { 'doc': doc, 'items': get_items(doc, pos_profile), 'customers': get_customers(pos_profile, doc), 'pricing_rules': get_pricing_rules(doc), 'mode_of_payment': get_mode_of_payment(doc), 'print_template': print_template, 'meta': { 'invoice': frappe.get_meta('Sales Invoice'), 'items': frappe.get_meta('Sales Invoice Item'), 'taxes': frappe.get_meta('Sales Taxes and Charges') } }
def get_pos_data(): doc = frappe.new_doc('Sales Invoice') doc.is_pos = 1 pos_profile = get_pos_profile(doc.company) or {} if not doc.company: doc.company = pos_profile.get('company') doc.update_stock = pos_profile.get('update_stock') if pos_profile.get('name'): pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name')) company_data = get_company_data(doc.company) update_pos_profile_data(doc, pos_profile, company_data) update_multi_mode_option(doc, pos_profile) default_print_format = pos_profile.get('print_format') or "Point of Sale" print_template = frappe.db.get_value('Print Format', default_print_format, 'html') return { 'doc': doc, 'default_customer': pos_profile.get('customer'), 'items': get_items(doc, pos_profile), 'customers': get_customers(pos_profile, doc, company_data.default_currency), 'pricing_rules': get_pricing_rules(doc), 'print_template': print_template, 'meta': { 'invoice': frappe.get_meta('Sales Invoice'), 'items': frappe.get_meta('Sales Invoice Item'), 'taxes': frappe.get_meta('Sales Taxes and Charges') } }
def get_pos_data(): doc = frappe.new_doc('Sales Invoice') doc.update_stock = 1; doc.is_pos = 1; pos_profile = get_pos_profile(doc.company) or {} if pos_profile.get('name'): pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name')) else: frappe.msgprint('<a href="#Form/POS Profile/New POS Profile">' + _("Welcome to POS: Create your POS Profile") + '</a>'); update_pos_profile_data(doc, pos_profile) update_multi_mode_option(doc, pos_profile) default_print_format = pos_profile.get('print_format') or "Point of Sale" print_template = frappe.db.get_value('Print Format', default_print_format, 'html') return { 'doc': doc, 'items': get_items(doc, pos_profile), 'customers': get_customers(pos_profile, doc), 'pricing_rules': get_pricing_rules(doc), 'print_template': print_template, 'write_off_account': pos_profile.get('write_off_account'), 'meta': { 'invoice': frappe.get_meta('Sales Invoice'), 'items': frappe.get_meta('Sales Invoice Item'), 'taxes': frappe.get_meta('Sales Taxes and Charges') } }
def pos_profile_data(): pos_profile = get_pos_profile( frappe.defaults.get_user_default('company')) return dict(has_pos=pos_profile is not None, pos=None if pos_profile is None else frappe.get_doc( "POS Profile", pos_profile.name))
def get_pos_data(): doc = frappe.new_doc('Sales Invoice') doc.update_stock = 1; doc.is_pos = 1; pos_profile = get_pos_profile(doc.company) or {} if pos_profile.get('name'): pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name')) else: frappe.msgprint(_("Warning Message: Create POS Profile")) update_pos_profile_data(doc, pos_profile) update_multi_mode_option(doc, pos_profile) print_template = frappe.db.get_value('Print Format', pos_profile.get('print_format'), 'html') or '' return { 'doc': doc, 'items': get_items(doc, pos_profile), 'customers': get_customers(pos_profile, doc), 'pricing_rules': get_pricing_rules(doc), 'mode_of_payment': get_mode_of_payment(doc), 'print_template': print_template, 'meta': { 'invoice': frappe.get_meta('Sales Invoice'), 'items': frappe.get_meta('Sales Invoice Item'), 'taxes': frappe.get_meta('Sales Taxes and Charges') } }
def _make_sales_invoice(items_list=None, pos=None, self_customer=None): if not len(items_list) > 0 or not doc.customer: return default_tax_template = frappe.db.get_value("Company", company, "default_maintenance_tax_template") if not default_tax_template: url = frappe.utils.get_url_to_form("Company", company) frappe.throw(_("Please Setup Default Maintenance Tax Template in <a href='{0}'>{1}</a>".format(url,company))) if self_customer: invoice_customer = self_consumption_customer else: invoice_customer = doc.customer is_pos = 0 pos_profile = "" naming_series = "" if pos: user_pos_profile = get_pos_profile(company) is_pos = 1 pos_profile = user_pos_profile.name naming_series = user_pos_profile.naming_series default_tax_template = user_pos_profile.taxes_and_charges or default_tax_template invoice_doc = frappe.get_doc(dict( is_pos = is_pos, pos_profile = pos_profile, naming_series = naming_series, doctype = "Sales Invoice", customer = invoice_customer, company = company, posting_date = today(), due_date = today(), ignore_pricing_rule = 1, items = items_list, update_stock = 1, remarks = user_remarks, cost_center = cost_center, lease = lease, taxes_and_charges=default_tax_template, job_card = doc.name )).insert(ignore_permissions=True) invoice_doc.reload() if invoice_doc.taxes_and_charges and not pos: getTax(invoice_doc) invoice_doc.calculate_taxes_and_totals() invoice_doc.run_method("set_missing_values") invoice_doc.run_method("calculate_taxes_and_totals") invoice_doc.save() if invoice_doc: invoice_url = frappe.utils.get_url_to_form(invoice_doc.doctype, invoice_doc.name) si_msgprint = "Sales invoice Created <a href='{0}'>{1}</a>".format(invoice_url,invoice_doc.name) frappe.flags.ignore_account_permission = True if submit_maintenance_invoice == 1 and not pos: invoice_doc.submit() if pos: make_sales_pos_payment(invoice_doc,user_pos_profile.name) si_msgprint = "POS " + si_msgprint frappe.msgprint(_(si_msgprint)) for item_row in doc.materials_billed: if item_row.item and item_row.quantity and item_row.invoiced == 1 and not item_row.sales_invoice: item_row.sales_invoice = invoice_doc.name frappe.db.set_value("Issue Materials Billed",item_row.name,"sales_invoice",invoice_doc.name) frappe.db.commit()
def add_order(self, client=None): # last_user = self.current_user self.validate_transaction() from erpnext.stock.get_item_details import get_pos_profile # from erpnext.controllers.accounts_controller import get_default_taxes_and_charges company = frappe.defaults.get_user_default('company') pos_profile = get_pos_profile(company) order = frappe.new_doc("Table Order") if pos_profile: order.pos_profile = None if pos_profile is None else pos_profile.name order.customer = frappe.db.get_value('POS Profile', pos_profile.name, 'customer') taxes_and_charges = frappe.db.get_value('POS Profile', pos_profile.name, 'taxes_and_charges') # if taxes_and_charges is None: # taxes = get_default_taxes_and_charges("Sales Taxes and Charges Template", company=company) # taxes_and_charges = taxes.get("taxes_and_charges") order.taxes_and_charges = taxes_and_charges else: frappe.throw(_("POS Profile is required to use Point-of-Sale")) order.selling_price_list = frappe.db.get_value('Price List', dict(enabled=1)) order.table = self.name order.company = company order.save() order.send_notifications(dict(action="Add", client=client))
def get_pop_data(): doc = frappe.new_doc('Farmer Quotation') doc.is_pop = 1 pos_profile = get_pos_profile(doc.company) or {} if not doc.company: doc.company = pos_profile.get('company') doc.update_stock = 0 #pos_profile.get('update_stock') if pos_profile.get('name'): pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name')) company_data = get_company_data(doc.company) update_pos_profile_data(doc, pos_profile, company_data) default_print_format = "Point of Purchase" #pos_profile.get('print_format') or print_template = frappe.db.get_value('Print Format', default_print_format, 'html') return { 'doc': doc, 'items': get_items_list(), 'item_uoms': get_items_uoms(), 'farmers': get_farmers_list(), 'print_template': print_template, 'meta': get_meta() }
def set_pos_fields(self, for_validate=False): """Set retail related fields from POS Profiles""" if cint(self.is_pos) != 1: return from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile pos = get_pos_profile(self.company) if not self.get('payments') and not for_validate: pos_profile = frappe.get_doc('POS Profile', pos.name) if pos else None update_multi_mode_option(self, pos_profile) if not self.account_for_change_amount: self.account_for_change_amount = frappe.db.get_value( 'Company', self.company, 'default_cash_account') if pos: if not for_validate and not self.customer: self.customer = pos.customer self.mode_of_payment = pos.mode_of_payment # self.set_customer_defaults() if pos.get('account_for_change_amount'): self.account_for_change_amount = pos.get( 'account_for_change_amount') for fieldname in ('territory', 'naming_series', 'currency', 'taxes_and_charges', 'letter_head', 'tc_name', 'selling_price_list', 'company', 'select_print_heading', 'cash_bank_account', 'write_off_account', 'write_off_cost_center', 'apply_discount_on'): if (not for_validate) or (for_validate and not self.get(fieldname)): self.set(fieldname, pos.get(fieldname)) if not for_validate: self.update_stock = cint(pos.get("update_stock")) # set pos values in items for item in self.get("items"): if item.get('item_code'): for fname, val in get_pos_profile_item_details( pos, frappe._dict(item.as_dict()), pos).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() return pos
def get_pos_data(): doc = frappe.new_doc('Sales Invoice') doc.is_pos = 1; pos_profile = get_pos_profile(doc.company) or {} if not doc.company: doc.company = pos_profile.get('company') doc.update_stock = pos_profile.get('update_stock') if pos_profile.get('name'): pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name')) company_data = get_company_data(doc.company) update_pos_profile_data(doc, pos_profile, company_data) update_multi_mode_option(doc, pos_profile) default_print_format = pos_profile.get('print_format') or "Point of Sale" print_template = frappe.db.get_value('Print Format', default_print_format, 'html') customers = get_customers_list(pos_profile) return { 'doc': doc, 'default_customer': pos_profile.get('customer'), 'items': get_items_list(pos_profile), 'item_groups': get_item_groups(pos_profile), 'customers': customers, 'address': get_customers_address(customers), 'serial_no_data': get_serial_no_data(pos_profile, doc.company), 'batch_no_data': get_batch_no_data(), 'tax_data': get_item_tax_data(), 'price_list_data': get_price_list_data(doc.selling_price_list), 'bin_data': get_bin_data(pos_profile), 'pricing_rules': get_pricing_rule_data(doc), 'print_template': print_template, 'pos_profile': pos_profile, 'meta': get_meta() }
def test_pos_profile(self): make_pos_profile() pos_profile = get_pos_profile("_Test Company") or {} if pos_profile: doc = frappe.get_doc("POS Profile", pos_profile.get("name")) doc.append('item_groups', {'item_group': '_Test Item Group'}) doc.append('customer_groups', {'customer_group': '_Test Customer Group'}) doc.save() items = get_items_list(doc) customers = get_customers_list(doc) products_count = frappe.db.sql( """ select count(name) from tabItem where item_group = '_Test Item Group'""", as_list=1) customers_count = frappe.db.sql( """ select count(name) from tabCustomer where customer_group = '_Test Customer Group'""" ) self.assertEquals(len(items), products_count[0][0]) self.assertEquals(len(customers), customers_count[0][0]) frappe.db.sql("delete from `tabPOS Profile`")
def set_pos_fields(self, for_validate=False): """Set retail related fields from POS Profiles""" if cint(self.is_pos) != 1: return 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 {} self.pos_profile = pos_profile.get('name') pos = {} if self.pos_profile: pos = frappe.get_doc('POS Profile', self.pos_profile) if not self.get('payments') and not for_validate: update_multi_mode_option(self, pos) if not self.account_for_change_amount: self.account_for_change_amount = frappe.db.get_value('Company', self.company, 'default_cash_account') if pos: self.allow_print_before_pay = pos.allow_print_before_pay if not for_validate and not self.customer: self.customer = pos.customer if pos.get('account_for_change_amount'): self.account_for_change_amount = pos.get('account_for_change_amount') for fieldname in ('territory', 'naming_series', 'currency', 'taxes_and_charges', 'letter_head', 'tc_name', 'selling_price_list', 'company', 'select_print_heading', 'cash_bank_account', 'write_off_account', 'write_off_cost_center', 'apply_discount_on'): if (not for_validate) or (for_validate and not self.get(fieldname)): self.set(fieldname, pos.get(fieldname)) if not for_validate: self.update_stock = cint(pos.get("update_stock")) # set pos values in items for item in self.get("items"): if item.get('item_code'): for fname, val in get_pos_profile_item_details(pos, frappe._dict(item.as_dict()), pos).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() return pos
def set_pos_fields(self, for_validate=False): """Set retail related fields from POS Profiles""" if cint(self.is_pos) != 1: return from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile pos = get_pos_profile(self.company) if pos: if not for_validate and not self.customer: self.customer = pos.customer self.mode_of_payment = pos.mode_of_payment # self.set_customer_defaults() for fieldname in ( "territory", "naming_series", "currency", "taxes_and_charges", "letter_head", "tc_name", "selling_price_list", "company", "select_print_heading", "cash_bank_account", "write_off_account", "write_off_cost_center", ): if (not for_validate) or (for_validate and not self.get(fieldname)): self.set(fieldname, pos.get(fieldname)) if not for_validate: self.update_stock = cint(pos.get("update_stock")) # set pos values in items for item in self.get("items"): if item.get("item_code"): for fname, val in get_pos_profile_item_details(pos, frappe._dict(item.as_dict()), pos).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() return pos
def get_pos_data(): print ("Get POS DATA ") print ("Get POS DATA ") print ("Get POS DATA ") doc = frappe.new_doc('Sales Invoice') doc.is_pos = 1; pos_profile = get_pos_profile(doc.company) or {} if not doc.company: doc.company = pos_profile.get('company') doc.update_stock = pos_profile.get('update_stock') if pos_profile.get('name'): pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name')) company_data = get_company_data(doc.company) update_pos_profile_data(doc, pos_profile, company_data) update_multi_mode_option(doc, pos_profile) default_print_format = pos_profile.get('print_format') or "Point of Sale" print_template = frappe.db.get_value('Print Format', default_print_format, 'html') #TO DELETE print("Doc ", doc) print("default_customer ", pos_profile.get('customer')) #print("items ", get_items_list(pos_profile)) print("customers ", get_customers_list(pos_profile)) print("serial_no_data ", get_serial_no_data(pos_profile, doc.company)) print("batch_no_data ", get_batch_no_data()) print("tax_data ", get_item_tax_data()) print("price_list_data ", get_price_list_data(doc.selling_price_list)) print ("bin_data ", get_bin_data(pos_profile)) print("pricing_rules ", get_pricing_rule_data(doc)) print("print_template ", print_template) print("pos_profile ", pos_profile) return { 'doc': doc, 'default_customer': pos_profile.get('customer'), 'items': get_items_list(pos_profile), 'customers': get_customers_list(pos_profile), 'serial_no_data': get_serial_no_data(pos_profile, doc.company), 'batch_no_data': get_batch_no_data(), 'tax_data': get_item_tax_data(), 'price_list_data': get_price_list_data(doc.selling_price_list), 'bin_data': get_bin_data(pos_profile), 'pricing_rules': get_pricing_rule_data(doc), 'print_template': print_template, 'pos_profile': pos_profile, 'meta': get_meta() }
def get_stock_availability(item_code, company, is_pos): warehouse = "" if int(is_pos) == 1: user_pos_profile = get_pos_profile(company) warehouse = user_pos_profile.warehouse if not warehouse: warehouse = frappe.db.get_single_value('Stock Settings', 'default_warehouse') latest_sle = frappe.db.sql("""select sum(actual_qty) as actual_qty from `tabStock Ledger Entry` where item_code = %s and warehouse = %s limit 1""", (item_code, warehouse), as_dict=1) sle_qty = latest_sle[0].actual_qty or 0 if latest_sle else 0 return sle_qty
def validate_warehouse(self): pos_profile = get_pos_profile(self.company) or {} print ("POS Perfil ",pos_profile) if not pos_profile: frappe.throw(_("Este usuario nao tem perfil para vendas\n Deve configurar no POS (Ponto de Venda).")) validated = False for d in self.get('servicos'): print (unicode(d.servico_produto).encode('utf-8')) artigo = frappe.get_doc("Item", d.servico_produto) d.warehouse = pos_profile['warehouse'] or artigo.default_warehouse d.income_account = pos_profile['income_account'] or artigo.income_account d.cost_center = pos_profile['cost_center'] or artigo.selling_cost_center
def get_extended_pos_data(company): pos_profile = get_pos_profile(company) if not pos_profile.warehouse: frappe.throw(_("Warehouse missing in POS Profile")) query_date = today() return { "sales_persons": _get_sales_persons(), "group_discounts": get_brand_discounts(), "customers_details": _get_customers_details(pos_profile, query_date), "loyalty_programs": _get_loyalty_programs(company), "gift_cards": _get_gift_cards(query_date), "territories": _get_territories(), "customer_groups": _get_customer_groups(), "batch_details": _get_batch_details(pos_profile.warehouse), "branch_details": _get_branch_details(), }
def get_pos_data(): doc = frappe.new_doc('Sales Invoice') doc.is_pos = 1 pos_profile = get_pos_profile(doc.company) or {} if not pos_profile: frappe.throw(_("POS Profile is required to use Point-of-Sale")) if not doc.company: doc.company = pos_profile.get('company') doc.update_stock = pos_profile.get('update_stock') if pos_profile.get('name'): pos_profile = frappe.get_doc('POS Profile', pos_profile.get('name')) pos_profile.validate() company_data = get_company_data(doc.company) update_pos_profile_data(doc, pos_profile, company_data) update_multi_mode_option(doc, pos_profile) default_print_format = pos_profile.get('print_format') or "Point of Sale" print_template = frappe.db.get_value('Print Format', default_print_format, 'html') items_list = get_items_list(pos_profile, doc.company) customers = get_customers_list(pos_profile) doc.plc_conversion_rate = update_plc_conversion_rate(doc, pos_profile) return { 'doc': doc, 'default_customer': pos_profile.get('customer'), 'items': items_list, 'item_groups': get_item_groups(pos_profile), 'customers': customers, 'address': get_customers_address(customers), 'contacts': get_contacts(customers), 'serial_no_data': get_serial_no_data(pos_profile, doc.company), 'batch_no_data': get_batch_no_data(), 'barcode_data': get_barcode_data(items_list), 'tax_data': get_item_tax_data(), 'price_list_data': get_price_list_data(doc.selling_price_list, doc.plc_conversion_rate), 'customer_wise_price_list': get_customer_wise_price_list(), 'bin_data': get_bin_data(pos_profile), 'pricing_rules': get_pricing_rule_data(doc), 'print_template': print_template, 'pos_profile': pos_profile, 'meta': get_meta() }
def _make_sales_invoice(items_list=None, pos=None, self_customer=None): if not len(items_list) > 0 or not doc.customer: return if self_customer: invoice_customer = self_consumption_customer else: invoice_customer = doc.customer is_pos = 0 pos_profile = "" naming_series = "" if pos: user_pos_profile = get_pos_profile(company) is_pos = 1 pos_profile = user_pos_profile.name naming_series = user_pos_profile.naming_series invoice_doc = frappe.get_doc(dict( is_pos = is_pos, pos_profile = pos_profile, naming_series = naming_series, doctype = "Sales Invoice", customer = invoice_customer, company = company, posting_date = today(), due_date = today(), ignore_pricing_rule = 1, items = items_list, update_stock = 1, remarks = user_remarks, cost_center = cost_center, lease = lease, job_card = doc.name )).insert(ignore_permissions=True) if invoice_doc: invoice_url = frappe.utils.get_url_to_form(invoice_doc.doctype, invoice_doc.name) si_msgprint = "Sales invoice Created <a href='{0}'>{1}</a>".format(invoice_url,invoice_doc.name) frappe.flags.ignore_account_permission = True if submit_maintenance_invoice == 1 and not pos: invoice_doc.submit() if pos: make_sales_pos_payment(invoice_doc) si_msgprint = "POS " + si_msgprint frappe.msgprint(_(si_msgprint)) for item_row in doc.materials_billed: if item_row.item and item_row.quantity and item_row.invoiced == 1 and not item_row.sales_invoice: item_row.sales_invoice = invoice_doc.name
def test_pos_profile(self): make_pos_profile() pos_profile = get_pos_profile("_Test Company") or {} if pos_profile: doc = frappe.get_doc("POS Profile", pos_profile.get("name")) doc.set('item_groups', [{'item_group': '_Test Item Group'}]) doc.set('customer_groups', [{'customer_group': '_Test Customer Group'}]) doc.save() items = get_items_list(doc, doc.company) customers = get_customers_list(doc) products_count = frappe.db.sql(""" select count(name) from tabItem where item_group = '_Test Item Group' and disabled = 0 and has_variants = 0 and is_sales_item = 1""", as_list=1) customers_count = frappe.db.sql(""" select count(name) from tabCustomer where customer_group = '_Test Customer Group' and disabled = 0""") self.assertEqual(len(items), products_count[0][0]) self.assertEqual(len(customers), customers_count[0][0]) frappe.db.sql("delete from `tabPOS Profile`")
def test_pos_profile(self): make_pos_profile() pos_profile = get_pos_profile("_Test Company") or {} if pos_profile: doc = frappe.get_doc("POS Profile", pos_profile.get("name")) doc.append('item_groups', {'item_group': '_Test Item Group'}) doc.append('customer_groups', {'customer_group': '_Test Customer Group'}) doc.save() items = get_items_list(doc, doc.company) customers = get_customers_list(doc) products_count = frappe.db.sql(""" select count(name) from tabItem where item_group = '_Test Item Group'""", as_list=1) customers_count = frappe.db.sql(""" select count(name) from tabCustomer where customer_group = '_Test Customer Group'""") self.assertEqual(len(items), products_count[0][0]) self.assertEqual(len(customers), customers_count[0][0]) frappe.db.sql("delete from `tabPOS Profile`")
def get_perfil_pos(): pos_profile = get_pos_profile(doc.company) or {} if not pos_profile: alert("Este usuario nao tem perfil para vendas\n Deve configurar no POS (Ponto de Venda).") return { # 'doc': doc, # 'default_customer': pos_profile.get('customer'), # 'items': get_items_list(pos_profile), # 'customers': get_customers_list(pos_profile), # 'serial_no_data': get_serial_no_data(pos_profile, doc.company), # 'batch_no_data': get_batch_no_data(), # 'tax_data': get_item_tax_data(), # 'price_list_data': get_price_list_data(doc.selling_price_list), # 'bin_data': get_bin_data(pos_profile), # 'pricing_rules': get_pricing_rule_data(doc), # 'print_template': print_template, 'pos_profile': pos_profile # 'meta': get_meta() }
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
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