def boot_session(bootinfo): """boot session - send website info if guest""" bootinfo.custom_css = frappe.db.get_value('Style Settings', None, 'custom_css') or '' bootinfo.website_settings = frappe.get_doc('Website Settings') if frappe.session['user']!='Guest': update_page_info(bootinfo) load_country_and_currency(bootinfo) bootinfo.sysdefaults.territory = get_root_of('Territory') bootinfo.sysdefaults.customer_group = get_root_of('Customer Group') bootinfo.notification_settings = frappe.get_doc("Notification Control", "Notification Control") # if no company, show a dialog box to create a new company bootinfo.customer_count = frappe.db.sql("""select count(*) from tabCustomer""")[0][0] if not bootinfo.customer_count: bootinfo.setup_complete = frappe.db.sql("""select name from tabCompany limit 1""") and 'Yes' or 'No' bootinfo.docs += frappe.db.sql("""select name, default_currency, cost_center, default_terms, default_letter_head, default_bank_account, enable_perpetual_inventory from `tabCompany`""", as_dict=1, update={"doctype":":Company"})
def setup_pos_profile(): company_abbr = frappe.get_cached_value('Company', erpnext.get_default_company(), "abbr") pos = frappe.new_doc('POS Profile') pos.user = frappe.db.get_global('demo_accounts_user') pos.name = "Demo POS Profile" pos.naming_series = 'SINV-' pos.update_stock = 0 pos.write_off_account = 'Cost of Goods Sold - ' + company_abbr pos.write_off_cost_center = 'Main - ' + company_abbr pos.customer_group = get_root_of('Customer Group') pos.territory = get_root_of('Territory') pos.append( 'payments', { 'mode_of_payment': frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name'), 'amount': 0.0, 'default': 1 }) pos.insert()
def boot_session(bootinfo): """boot session - send website info if guest""" bootinfo.custom_css = frappe.db.get_value('Style Settings', None, 'custom_css') or '' bootinfo.website_settings = frappe.get_doc('Website Settings') if frappe.session['user']!='Guest': update_page_info(bootinfo) load_country_and_currency(bootinfo) bootinfo.sysdefaults.territory = frappe.db.get_single_value('Selling Settings', 'territory') or get_root_of('Territory') bootinfo.sysdefaults.customer_group = frappe.db.get_single_value('Selling Settings', 'customer_group') or get_root_of('Customer Group') bootinfo.notification_settings = frappe.get_doc("Notification Control", "Notification Control") # if no company, show a dialog box to create a new company bootinfo.customer_count = frappe.db.sql("""select count(*) from tabCustomer""")[0][0] if not bootinfo.customer_count: bootinfo.setup_complete = frappe.db.sql("""select name from tabCompany limit 1""") and 'Yes' or 'No' bootinfo.docs += frappe.db.sql("""select name, default_currency, cost_center, default_terms, default_letter_head, default_bank_account, enable_perpetual_inventory from `tabCompany`""", as_dict=1, update={"doctype":":Company"})
def set_defaults_for_tests(): from frappe.utils.nestedset import get_root_of selling_settings = frappe.get_single("Selling Settings") selling_settings.customer_group = get_root_of("Customer Group") selling_settings.territory = get_root_of("Territory") selling_settings.save()
def set_defaults_for_tests(): defaults = { "customer_group": get_root_of("Customer Group"), "territory": get_root_of("Territory"), } frappe.db.set_single_value("Selling Settings", defaults) for key, value in defaults.items(): frappe.db.set_default(key, value) frappe.db.set_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing", 0)
def make_rfq(item, supplier, contact): # make rfq rfq = frappe.get_doc( { "doctype": "Request for Quotation", "transaction_date": nowdate(), "status": "Draft", "company": frappe.db.get_single_value("Marketplace Settings", "company"), "message_for_supplier": "Please supply the specified items at the best possible rates", "suppliers": [{"supplier": supplier.name, "contact": contact.name}], "items": [ { "item_code": item.item_code, "qty": 1, "schedule_date": nowdate(), "warehouse": item.default_warehouse or get_root_of("Warehouse"), "description": item.description, "uom": item.stock_uom, } ], } ).insert() rfq.save() rfq.submit() return rfq
def validate(self): if not self.parent_territory: self.parent_territory = get_root_of("Territory") for d in self.get('targets') or []: if not flt(d.target_qty) and not flt(d.target_amount): frappe.throw(_("Either target qty or target amount is mandatory"))
def make_rfq(item, supplier, contact): # make rfq rfq = frappe.get_doc({ 'doctype': 'Request for Quotation', 'transaction_date': nowdate(), 'status': 'Draft', 'company': frappe.db.get_single_value('Marketplace Settings', 'company'), 'message_for_supplier': 'Please supply the specified items at the best possible rates', 'suppliers': [ { 'supplier': supplier.name, 'contact': contact.name } ], 'items': [ { 'item_code': item.item_code, 'qty': 1, 'schedule_date': nowdate(), 'warehouse': item.default_warehouse or get_root_of("Warehouse"), 'description': item.description, 'uom': item.stock_uom } ] }).insert() rfq.save() rfq.submit() return rfq
def execute(): frappe.reload_doc("accounts", "doctype", "pricing_rule") frappe.db.auto_commit_on_many_writes = True default_item_group = get_root_of("Item Group") for d in frappe.db.sql("""select * from `tabCustomer Discount` where ifnull(parent, '') != ''""", as_dict=1): if not d.discount: continue frappe.get_doc({ "doctype": "Pricing Rule", "apply_on": "Item Group", "item_group": d.item_group or default_item_group, "applicable_for": "Customer", "customer": d.parent, "price_or_discount": "Discount Percentage", "discount_percentage": d.discount, "selling": 1 }).insert() frappe.db.auto_commit_on_many_writes = False frappe.delete_doc("DocType", "Customer Discount")
def get_children(doctype, parent=None, company=None, is_root=False): condition = "" var_dict = { "name": get_root_of("Department"), "parent": parent, "company": company, } if company == parent: condition = "name=%(name)s" elif company: condition = "parent_department=%(parent)s and company=%(company)s" else: condition = "parent_department = %(parent)s" return frappe.db.sql( """ select name as value, is_group as expandable from `tab{doctype}` where {condition} order by name""".format( doctype=doctype, condition=condition ), var_dict, as_dict=1, )
def update_warehouses(self): self.shipstation_warehouses = [] root_warehouse = get_root_of("Warehouse") if not frappe.db.exists("Warehouse", {"warehouse_name": "Shipstation Warehouses"}): ss_warehouse_doc = frappe.new_doc("Warehouse") ss_warehouse_doc.update({ "warehouse_name": "Shipstation Warehouses", "parent_warehouse": root_warehouse, "is_group": True }) ss_warehouse_doc.insert() parent_warehouse = frappe.get_doc( "Warehouse", {"warehouse_name": "Shipstation Warehouses"}) warehouses = self.client().list_warehouses() for warehouse in warehouses: if frappe.db.exists( "Warehouse", {"shipstation_warehouse_id": warehouse.warehouse_id}): warehouse_doc = frappe.get_doc( "Warehouse", {"shipstation_warehouse_id": warehouse.warehouse_id}) else: warehouse_doc = frappe.new_doc("Warehouse") warehouse_doc.update({ "shipstation_warehouse_id": warehouse.warehouse_id, "warehouse_name": warehouse.warehouse_name, "parent_warehouse": parent_warehouse.name }) warehouse_doc.insert() self.append("shipstation_warehouses", {"warehouse": warehouse_doc.name}) self.save()
def get_customer(user=None): if not user: user = frappe.session.user customer = frappe.db.get_value("Contact", {"email_id": user}, "customer") if customer: return frappe.get_doc("Customer", customer) else: customer = frappe.new_doc("Customer") fullname = get_fullname(user) customer.update({ "customer_name": fullname, "customer_type": "Individual", "customer_group": get_shopping_cart_settings().default_customer_group, "territory": get_root_of("Territory") }) customer.insert(ignore_permissions=True) contact = frappe.new_doc("Contact") contact.update({ "customer": customer.name, "first_name": fullname, "email_id": user }) contact.insert(ignore_permissions=True) return customer
def on_update_address(doc, method): #save territory root_territory = get_root_of("Territory") if doc.country: insert_territory(doc.country, root_territory, 1) if doc.state: insert_territory(doc.state, doc.country, 1) if doc.county: insert_territory(doc.county, doc.state, 1) if doc.post_office: insert_territory(doc.post_office, doc.county, 0) #save India Zipcode if doc.post_office and doc.postal_code and doc.county and doc.state: if not frappe.db.exists("India Zipcode", { "pincode": doc.postal_code, "officename": doc.post_office }): zipcode = frappe.get_doc({ "doctype": "India Zipcode", "officename": doc.post_office, "pincode": doc.postal_code, "taluk": doc.taluk, "districtname": doc.county, "statename": doc.state, }) zipcode.flags.ignore_permissions = True zipcode.insert()
def create_delete_custom_fields(self): if self.enable_sync: custom_fields = {} # create for doctype in ["Customer", "Sales Order", "Item", "Address"]: df = dict( fieldname="woocommerce_id", label="Woocommerce ID", fieldtype="Data", read_only=1, print_hide=1, ) create_custom_field(doctype, df) for doctype in ["Customer", "Address"]: df = dict( fieldname="woocommerce_email", label="Woocommerce Email", fieldtype="Data", read_only=1, print_hide=1, ) create_custom_field(doctype, df) if not frappe.get_value("Item Group", {"name": _("WooCommerce Products")}): item_group = frappe.new_doc("Item Group") item_group.item_group_name = _("WooCommerce Products") item_group.parent_item_group = get_root_of("Item Group") item_group.insert()
def make_rfq(item, supplier, contact): # make rfq rfq = frappe.get_doc({ 'doctype': 'Request for Quotation', 'transaction_date': nowdate(), 'status': 'Draft', 'company': frappe.db.get_single_value('Hub Settings', 'company'), 'message_for_supplier': 'Please supply the specified items at the best possible rates', 'suppliers': [ { 'supplier': supplier.name, 'contact': contact.name } ], 'items': [ { 'item_code': item.item_code, 'qty': 1, 'schedule_date': nowdate(), 'warehouse': item.default_warehouse or get_root_of("Warehouse"), 'description': item.description, 'uom': item.stock_uom } ] }).insert() rfq.save() rfq.submit() return rfq
def autoname(self): root = get_root_of("Department") if root and self.department_name != root: self.name = get_abbreviated_name(self.department_name, self.company) else: self.name = self.department_name
def get_price_list(self, billing_territory): price_list = self.get_name_from_territory(billing_territory, "price_lists", "selling_price_list") if not (price_list and price_list[0]): price_list = self.get_name_from_territory(self.default_territory or get_root_of("Territory"), "price_lists", "selling_price_list") return price_list and price_list[0] or None
def get_party(user=None): if not user: user = frappe.session.user contact_name = frappe.db.get_value("Contact", {"user": user}) if not contact_name: contact_name = get_contact_name(user) party = None if contact_name: contact = frappe.get_doc('Contact', contact_name) if contact.links: party_doctype = contact.links[0].link_doctype party = contact.links[0].link_name cart_settings = frappe.get_doc("Shopping Cart Settings") debtors_account = '' if cart_settings.enable_checkout: debtors_account = get_debtors_account(cart_settings) if party: return frappe.get_doc(party_doctype, party) else: if not cart_settings.enabled: frappe.local.flags.redirect_location = "/contact" raise frappe.Redirect customer = frappe.new_doc("Customer") fullname = get_fullname(user) customer.update({ "customer_name": fullname, "customer_type": "Individual", "customer_group": get_shopping_cart_settings().default_customer_group, "territory": get_root_of("Territory") }) if debtors_account: customer.update({ "accounts": [{ "company": cart_settings.company, "account": debtors_account }] }) customer.flags.ignore_mandatory = True customer.insert(ignore_permissions=True) contact = frappe.new_doc("Contact") contact.update({"first_name": fullname}) contact.add_email(user, is_primary=True) contact.append('links', dict(link_doctype='Customer', link_name=customer.name)) contact.flags.ignore_mandatory = True contact.insert(ignore_permissions=True) return customer
def create_or_update_customer(biotrack_customer): name = biotrack_customer.get("name") ubi = biotrack_customer.get("ubi") location = biotrack_customer.get("location") transactionid = biotrack_customer.get("transactionid") test = frappe.db.get_value("Customer", biotrack_customer.get("name"), ["name", "external_transaction_id"]) if test: name_test, external_transaction_id = test if not (frappe.flags.force_sync or False) and external_transaction_id == transactionid: return False customer = frappe.get_doc('Customer', name_test) else: customer = frappe.get_doc({ "doctype": "Customer", "customer_name": name, "territory": get_root_of("Territory"), "customer_type": _("Company") }) customer_group = detect_group(biotrack_customer) customer.update({ "customer_group": customer_group.name if customer_group else None, "territory": get_root_of("Territory"), "ubi": ubi, "license_no": location, "external_transaction_id": transactionid }) customer.flags.ignore_mandatory = True customer.save() if customer: create_customer_address(customer, biotrack_customer) frappe.db.commit() return True
def validate(self): if not self.parent_sales_person: self.parent_sales_person = get_root_of("Sales Person") for d in self.get('targets') or []: if not flt(d.target_qty) and not flt(d.target_amount): frappe.throw( _("Either target qty or target amount is mandatory.")) self.validate_employee_id()
def setup_pos_profile(): company_abbr = frappe.db.get_value("Company", erpnext.get_default_company(), "abbr") pos = frappe.new_doc('POS Profile') pos.user = frappe.db.get_global('demo_accounts_user') pos.naming_series = 'SINV-' pos.update_stock = 0 pos.write_off_account = 'Cost of Goods Sold - '+ company_abbr pos.write_off_cost_center = 'Main - '+ company_abbr pos.customer_group = get_root_of('Customer Group') pos.territory = get_root_of('Territory') pos.append('payments', { 'mode_of_payment': frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name'), 'amount': 0.0, 'default': 1 }) pos.insert()
def get_party(user=None): if not user: user = frappe.session.user contact_name = frappe.db.get_value("Contact", {"email_id": user}) party = None if contact_name: contact = frappe.get_doc('Contact', contact_name) if contact.links: party_doctype = contact.links[0].link_doctype party = contact.links[0].link_name cart_settings = frappe.get_doc("Shopping Cart Settings") debtors_account = '' if cart_settings.enable_checkout: debtors_account = get_debtors_account(cart_settings) if party: return frappe.get_doc(party_doctype, party) else: if not cart_settings.enabled: frappe.local.flags.redirect_location = "/contact" raise frappe.Redirect customer = frappe.new_doc("Customer") fullname = get_fullname(user) customer.update({ "customer_name": fullname, "customer_type": "Individual", "customer_group": get_shopping_cart_settings().default_customer_group, "territory": get_root_of("Territory") }) if debtors_account: customer.update({ "accounts": [{ "company": cart_settings.company, "account": debtors_account }] }) customer.flags.ignore_mandatory = True customer.insert(ignore_permissions=True) contact = frappe.new_doc("Contact") contact.update({ "first_name": fullname, "email_id": user }) contact.append('links', dict(link_doctype='Customer', link_name=customer.name)) contact.flags.ignore_mandatory = True contact.insert(ignore_permissions=True) return customer
def guess_territory(): territory = None geoip_country = frappe.session.get("session_country") if geoip_country: territory = frappe.db.get_value("Territory", geoip_country) return territory or \ frappe.db.get_value("Shopping Cart Settings", None, "territory") or \ get_root_of("Territory")
def guess_territory(): territory = None geoip_country = frappe.session.get("session_country") if geoip_country: territory = frappe.db.get_value("Territory", geoip_country) return (territory or frappe.db.get_value("E Commerce Settings", None, "territory") or get_root_of("Territory"))
def get_tax_template(posting_date, args): """Get matching tax rule""" args = frappe._dict(args) conditions = [ """(from_date is null or from_date <= '{0}') and (to_date is null or to_date >= '{0}')""".format(posting_date) ] conditions.append("ifnull(tax_category, '') = {0}".format( frappe.db.escape(cstr(args.get("tax_category"))))) if "tax_category" in args.keys(): del args["tax_category"] for key, value in iteritems(args): if key == "use_for_shopping_cart": conditions.append( "use_for_shopping_cart = {0}".format(1 if value else 0)) elif key == "customer_group": if not value: value = get_root_of("Customer Group") customer_group_condition = get_customer_group_condition(value) conditions.append("ifnull({0}, '') in ('', {1})".format( key, customer_group_condition)) else: conditions.append("ifnull({0}, '') in ('', {1})".format( key, frappe.db.escape(cstr(value)))) tax_rule = frappe.db.sql( """select * from `tabTax Rule` where {0}""".format(" and ".join(conditions)), as_dict=True, ) if not tax_rule: return None for rule in tax_rule: rule.no_of_keys_matched = 0 for key in args: if rule.get(key): rule.no_of_keys_matched += 1 rule = sorted( tax_rule, key=functools.cmp_to_key( lambda b, a: cmp(a.no_of_keys_matched, b.no_of_keys_matched ) or cmp(a.priority, b.priority)), )[0] tax_template = rule.sales_tax_template or rule.purchase_tax_template doctype = "{0} Taxes and Charges Template".format(rule.tax_type) if frappe.db.get_value(doctype, tax_template, "disabled") == 1: return None return tax_template
def get_items(start, page_length, price_list, item_group, search_value=""): serial_no = "" batch_no = "" item_code = search_value if not frappe.db.exists('Item Group', item_group): item_group = get_root_of('Item Group') if search_value: # search serial no serial_no_data = frappe.db.get_value('Serial No', search_value, ['name', 'item_code']) if serial_no_data: serial_no, item_code = serial_no_data if not serial_no: batch_no_data = frappe.db.get_value('Batch', search_value, ['name', 'item']) if batch_no_data: batch_no, item_code = batch_no_data item_code, condition = get_conditions(item_code, serial_no, batch_no) lft, rgt = frappe.db.get_value('Item Group', item_group, ['lft', 'rgt']) # locate function is used to sort by closest match from the beginning of the value res = frappe.db.sql( """select i.name as item_code, i.item_name, i.image as item_image, item_det.price_list_rate, item_det.currency from `tabItem` i LEFT JOIN (select item_code, price_list_rate, currency from `tabItem Price` where price_list=%(price_list)s) item_det ON (item_det.item_code=i.name or item_det.item_code=i.variant_of) where i.disabled = 0 and i.has_variants = 0 and i.is_sales_item = 1 and i.item_group in (select name from `tabItem Group` where lft >= {lft} and rgt <= {rgt}) and {condition} limit {start}, {page_length}""".format(start=start, page_length=page_length, lft=lft, rgt=rgt, condition=condition), { 'item_code': item_code, 'price_list': price_list }, as_dict=1) res = {'items': res} if serial_no: res.update({'serial_no': serial_no}) if batch_no: res.update({'batch_no': batch_no}) return res
def get_party(user=None): if not user: user = frappe.session.user party = frappe.db.get_value("Contact", {"email_id": user}, ["customer", "supplier"], as_dict=1) if party: party_doctype = 'Customer' if party.customer else 'Supplier' party = party.customer or party.supplier cart_settings = frappe.get_doc("Shopping Cart Settings") debtors_account = '' if cart_settings.enable_checkout: debtors_account = get_debtors_account(cart_settings) if party: return frappe.get_doc(party_doctype, party) else: if not cart_settings.enabled: return None customer = frappe.new_doc("Customer") fullname = get_fullname(user) customer.update({ "customer_name": fullname, "customer_type": "Individual", "customer_group": get_shopping_cart_settings().default_customer_group, "territory": get_root_of("Territory") }) if debtors_account: customer.update({ "accounts": [{ "company": cart_settings.company, "account": debtors_account }] }) customer.flags.ignore_mandatory = True customer.insert(ignore_permissions=True) contact = frappe.new_doc("Contact") contact.update({ "customer": customer.name, "first_name": fullname, "email_id": user }) contact.flags.ignore_mandatory = True contact.insert(ignore_permissions=True) return customer
def set_missing_customer_details(self): if not self.customer_group: self.customer_group = frappe.db.get_single_value( 'Selling Settings', 'customer_group') or get_root_of('Customer Group') if not self.territory: self.territory = frappe.db.get_single_value( 'Selling Settings', 'territory') or get_root_of('Territory') if not self.default_price_list: self.default_price_list = frappe.db.get_single_value( 'Selling Settings', 'selling_price_list') if not self.customer_group or not self.territory or not self.default_price_list: frappe.msgprint( _('Please set defaults for Customer Group, Territory and Selling Price List in Selling Settings'), alert=True) if not self.default_currency: self.default_currency = get_default_currency() if not self.language: self.language = frappe.db.get_single_value( 'System Settings', 'language')
def autoname(self): root = get_root_of("Department") # if root and self.department_name != root: # self.name = get_abbreviated_name(self.department_name, self.company) # else: # self.name = self.department_name #-----------------28th November 2019--------------- # if root and self.department_name != root: self.name = self.department_name
def execute(): # store data from original single document shopify_settings = frappe.get_doc("Shopify Settings") shopify_data = shopify_settings.as_dict(no_default_fields=True) shopify_password = shopify_settings.get_password("password") frappe.reload_doc("shopify_integration", "doctype", "shopify_settings") frappe.reload_doc("shopify_integration", "doctype", "shopify_payout") setup_custom_fields() # get shop name url = urlparse(shopify_data.get("shopify_url")) subdomain = url.hostname.split(".")[0] if subdomain: shop_name = frappe.unscrub(subdomain.replace("-", " ")) else: shop_name = "Shopify" # create new Shopify Settings document new_shop = frappe.new_doc("Shopify Settings") new_shop.update(shopify_data) new_shop.update({ "shop_name": shop_name, "password": shopify_password, "item_group": get_root_of("Item Group") }) new_shop.insert(ignore_permissions=True) # update Shopify Payout and linked Shopify documents for payout in frappe.get_all("Shopify Payout"): frappe.db.set_value("Shopify Payout", payout.name, "shop_name", new_shop.name) payout_doc = frappe.get_doc("Shopify Payout", payout.name) for transaction in payout_doc.transactions: if transaction.sales_order: frappe.db.set_value("Sales Order", transaction.sales_order, "shopify_settings", new_shop.name) if transaction.sales_invoice: frappe.db.set_value("Sales Invoice", transaction.sales_invoice, "shopify_settings", new_shop.name) if transaction.delivery_note: frappe.db.set_value("Delivery Note", transaction.delivery_note, "shopify_settings", new_shop.name) # # ref: https://github.com/ParsimonyGit/shipstation_integration/ # update the "Is Shopify Store" check in Shipstation stores if "shipstation_integration" in frappe.get_installed_apps(): mws_setup_marketplaces = frappe.get_all( "Shipstation Store", filters={"marketplace_name": "Shopify"}) for marketplace in mws_setup_marketplaces: frappe.db.set_value("Shipstation Store", marketplace.name, "is_shopify_store", True)
def validate_price_lists(self): territory_name_map = self.validate_overlapping_territories("price_lists", "selling_price_list") # validate that a Shopping Cart Price List exists for the root territory # as a catch all! from frappe.utils.nestedset import get_root_of root_territory = get_root_of("Territory") if root_territory not in territory_name_map.keys(): msgprint(_("Please specify a Price List which is valid for Territory") + ": " + root_territory, raise_exception=ShoppingCartSetupError)
def create_price_lists(args): for pl_type, pl_name in (("Selling", _("Standard Selling")), ("Buying", _("Standard Buying"))): frappe.get_doc({ "doctype": "Price List", "price_list_name": pl_name, "enabled": 1, "buying": 1 if pl_type == "Buying" else 0, "selling": 1 if pl_type == "Selling" else 0, "currency": args["currency"], "territories": [{ "territory": get_root_of("Territory") }] }).insert()
def create_price_list(pl_name, buying=0, selling=0): price_list = frappe.get_doc({ "doctype": "Price List", "price_list_name": pl_name, "enabled": 1, "buying": buying, "selling": selling, "currency": frappe.db.get_default("currency"), "territories": [{ "territory": get_root_of("Territory") }] }) price_list.insert()
def create_territories(): """create two default territories, one for home country and one named Rest of the World""" from frappe.utils.nestedset import get_root_of country = frappe.db.get_default("country") root_territory = get_root_of("Territory") for name in (country, _("Rest Of The World")): if name and not frappe.db.exists("Territory", name): frappe.get_doc({ "doctype": "Territory", "territory_name": name.replace("'", ""), "parent_territory": root_territory, "is_group": "No" }).insert()
def create_price_lists(args): for pl_type, pl_name in (("Selling", _("Standard Selling")), ("Buying", _("Standard Buying"))): frappe.get_doc({ "doctype": "Price List", "price_list_name": pl_name, "enabled": 1, "buying": 1 if pl_type == "Buying" else 0, "selling": 1 if pl_type == "Selling" else 0, "currency": args["currency"], "valid_for_territories": [{ "territory": get_root_of("Territory") }] }).insert()
def setup_pos_profile(): company_abbr = frappe.get_cached_value("Company", erpnext.get_default_company(), "abbr") pos = frappe.new_doc("POS Profile") pos.user = frappe.db.get_global("demo_accounts_user") pos.name = "Demo POS Profile" pos.naming_series = "SINV-" pos.update_stock = 0 pos.write_off_account = "Cost of Goods Sold - " + company_abbr pos.write_off_cost_center = "Main - " + company_abbr pos.customer_group = get_root_of("Customer Group") pos.territory = get_root_of("Territory") pos.append( "payments", { "mode_of_payment": frappe.db.get_value("Mode of Payment", {"type": "Cash"}, "name"), "amount": 0.0, "default": 1, }, ) pos.insert()