def apply_price_list_on_item(args): item_doc = frappe.get_doc("Item", args.item_code) item_details = get_price_list_rate(args, item_doc) item_details.update(get_pricing_rule_for_item(args, item_details.price_list_rate)) return item_details
def get_item_details(args): """ args = { "item_code": "", "warehouse": None, "customer": "", "conversion_rate": 1.0, "selling_price_list": None, "price_list_currency": None, "plc_conversion_rate": 1.0, "parenttype": "", "parent": "", "supplier": None, "transaction_date": None, "conversion_rate": 1.0, "buying_price_list": None, "is_subcontracted": "Yes" / "No", "transaction_type": "selling", "ignore_pricing_rule": 0/1 "project_name": "", } """ args = process_args(args) item_doc = frappe.get_doc("Item", args.item_code) item = item_doc validate_item_details(args, item) out = get_basic_details(args, item) get_party_item_code(args, item_doc, out) if out.get("warehouse"): out.update(get_available_qty(args.item_code, out.warehouse)) out.update(get_projected_qty(item.name, out.warehouse)) get_price_list_rate(args, item_doc, out) if args.transaction_type == "selling" and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args)) # update args with out, if key or value not exists for key, value in out.iteritems(): if args.get(key) is None: args[key] = value out.update(get_pricing_rule_for_item(args)) if args.get("parenttype") in ("Sales Invoice", "Delivery Note"): if item_doc.has_serial_no == 1 and not args.serial_no: out.serial_no = get_serial_nos_by_fifo(args, item_doc) if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days( args.transaction_date, item.lead_time_days) if args.get("is_subcontracted") == "Yes": out.bom = get_default_bom(args.item_code) return out
def get_price(item_code, template_item_code, price_list, qty=1): if price_list: cart_settings = get_shopping_cart_settings() price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={"price_list": price_list, "item_code": item_code}) if not price: price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={"price_list": price_list, "item_code": template_item_code}) if price: pricing_rule = get_pricing_rule_for_item(frappe._dict({ "item_code": item_code, "qty": qty, "transaction_type": "selling", "price_list": price_list, "customer_group": cart_settings.default_customer_group, "company": cart_settings.company, "conversion_rate": 1, "for_shopping_cart": True })) if pricing_rule: if pricing_rule.pricing_rule_for == "Discount Percentage": price[0].price_list_rate = flt(price[0].price_list_rate * (1.0 - (pricing_rule.discount_percentage / 100.0))) if pricing_rule.pricing_rule_for == "Price": price[0].price_list_rate = pricing_rule.price_list_rate return price[0]
def get_item_details(args): """ args = { "item_code": "", "warehouse": None, "customer": "", "conversion_rate": 1.0, "selling_price_list": None, "price_list_currency": None, "plc_conversion_rate": 1.0, "parenttype": "", "parent": "", "supplier": None, "transaction_date": None, "conversion_rate": 1.0, "buying_price_list": None, "is_subcontracted": "Yes" / "No", "transaction_type": "selling", "ignore_pricing_rule": 0/1 "project_name": "" } """ args = process_args(args) item_doc = frappe.get_doc("Item", args.item_code) item = item_doc validate_item_details(args, item) out = get_basic_details(args, item) get_party_item_code(args, item_doc, out) if out.get("warehouse"): out.update(get_available_qty(args.item_code, out.warehouse)) out.update(get_projected_qty(item.name, out.warehouse)) get_price_list_rate(args, item_doc, out) if args.transaction_type == "selling" and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args)) # update args with out, if key or value not exists for key, value in out.iteritems(): if args.get(key) is None: args[key] = value out.update(get_pricing_rule_for_item(args)) if args.get("parenttype") in ("Sales Invoice", "Delivery Note"): if item_doc.has_serial_no == 1 and not args.serial_no: out.serial_no = get_serial_nos_by_fifo(args, item_doc) if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days(args.transaction_date, item.lead_time_days) if args.get("is_subcontracted") == "Yes": out.bom = get_default_bom(args.item_code) return out
def get_item_price(item, company): """Gets the item price from the price list taking in the total number of assemblies being made and name of the company""" #Get the Item item_doc = frappe.get_doc("Item", item.item) args = { "doctype": item.doctype, "parent_type": item.parenttype, "name": item_doc.name, "item_code": item.item, "transaction_type": "buying", "supplier": item.supplier, "qty": item.qty, "price_list": item.price_list, "company": company } args = frappe._dict(args) #frappe.msgprint(str(args)) pr_price = 0 pr_result = get_pricing_rule_for_item(args) if pr_result.pricing_rule: #frappe.msgprint("Found pricing rule for " + item.item + ": " + pr_result.pricing_rule) pricing_rule = frappe.get_doc("Pricing Rule", pr_result.pricing_rule) pr_price = pricing_rule.price else: #Need to find the item price #frappe.msgprint("Could not find pricing rule for " + item.item ) pr_price = frappe.db.get_value("Item Price", { "price_list": item.price_list, "item_code": item.item }, "price_list_rate") or 0 return pr_price
def apply_price_list_on_item(args): item_details = frappe._dict() item_doc = frappe.get_doc("Item", args.item_code) get_price_list_rate(args, item_doc, item_details) item_details.discount_percentage = 0.0 item_details.update(get_pricing_rule_for_item(args)) return item_details
def get_item_price(item, company): """Gets the item price from the price list taking in the total number of assemblies being made and name of the company""" #Get the Item item_doc = frappe.get_doc("Item",item.item) args = { "doctype": item.doctype, "parent_type": item.parenttype, "name": item_doc.name, "item_code": item.item, "transaction_type": "buying", "supplier": item.supplier, "qty": item.qty, "price_list": item.price_list, "company": company } args = frappe._dict(args) #frappe.msgprint(str(args)) pr_price = 0 pr_result = get_pricing_rule_for_item(args) if pr_result.pricing_rule: #frappe.msgprint("Found pricing rule for " + item.item + ": " + pr_result.pricing_rule) pricing_rule = frappe.get_doc("Pricing Rule", pr_result.pricing_rule) pr_price = pricing_rule.price else: #Need to find the item price #frappe.msgprint("Could not find pricing rule for " + item.item ) pr_price = frappe.db.get_value("Item Price", {"price_list": item.price_list,"item_code": item.item}, "price_list_rate") or 0 return pr_price
def apply_price_list_on_item(args): item_details = frappe._dict() item_doc = frappe.get_doc("Item", args.item_code) get_price_list_rate(args, item_doc, item_details) item_details.discount_percentage = 0.0 item_details.update(get_pricing_rule_for_item(args)) return item_details
def get_taxes_charges(item, type, company): #Get the Item item_doc = frappe.get_doc("Item", item.item) total_qty = item.qty args = { "doctype": item.doctype, "parent_type": item.parenttype, "name": item_doc.name, "item_code": item.item, "transaction_type": "buying", "supplier": item.supplier, "qty": item.qty, "price_list": item.price_list, "company": company } #frappe.msgprint("{0}".format(args)) args = frappe._dict(args) pr_price = 0 # Get the pricing rule pr_result = get_pricing_rule_for_item(args) if pr_result.pricing_rule: pricing_rule = frappe.get_doc("Pricing Rule", pr_result.pricing_rule) # Find the supplier quotation associated with this pricing rule quotation = frappe.get_doc("Supplier Quotation", pricing_rule.from_supplier_quotation) # Get the master quote quantity based on our total quantity for this part qtylist = [] for item in quotation.items: if item.item_code == pricing_rule.item_code: qtylist.append(item.qty) qtylist.sort() count = 0 for i in qtylist: count = count + 1 if i == pricing_rule.min_qty: break if count > 0: # Loop through each charge type to find the one with the correct quantity and type applicable_charges = [] for tax_charge in quotation.taxes: desc_list = "{" + tax_charge.description + "}" args = frappe._dict(json.loads(desc_list)) if args.type == type: applicable_charges.append(args.qty) applicable_charges.sort() for tax_charge in quotation.taxes: desc_list = "{" + tax_charge.description + "}" args = frappe._dict(json.loads("{" + desc_list + "}")) if args.type == type and args.qty == applicable_charges[count - 1]: # We finally found the correct charge for freight return tax_charge.price else: #Need to find the item price return 0
def get_price(item_code, price_list, customer_group, company, qty=1): template_item_code = frappe.db.get_value("Item", item_code, "variant_of") if price_list: price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={"price_list": price_list, "item_code": item_code}) if template_item_code and not price: price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={"price_list": price_list, "item_code": template_item_code}) if price: pricing_rule = get_pricing_rule_for_item(frappe._dict({ "item_code": item_code, "qty": qty, "transaction_type": "selling", "price_list": price_list, "customer_group": customer_group, "company": company, "conversion_rate": 1, "for_shopping_cart": True, "currency": frappe.db.get_value("Price List", price_list, "currency") })) if pricing_rule: if pricing_rule.pricing_rule_for == "Discount Percentage": price[0].price_list_rate = flt(price[0].price_list_rate * (1.0 - (flt(pricing_rule.discount_percentage) / 100.0))) if pricing_rule.pricing_rule_for == "Rate": price[0].price_list_rate = pricing_rule.price_list_rate price_obj = price[0] if price_obj: price_obj["formatted_price"] = fmt_money(price_obj["price_list_rate"], currency=price_obj["currency"]) price_obj["currency_symbol"] = not cint(frappe.db.get_default("hide_currency_symbol")) \ and (frappe.db.get_value("Currency", price_obj.currency, "symbol", cache=True) or price_obj.currency) \ or "" uom_conversion_factor = frappe.db.sql("""select C.conversion_factor from `tabUOM Conversion Detail` C inner join `tabItem` I on C.parent = I.name and C.uom = I.sales_uom where I.name = %s""", item_code) uom_conversion_factor = uom_conversion_factor[0][0] if uom_conversion_factor else 1 price_obj["formatted_price_sales_uom"] = fmt_money(price_obj["price_list_rate"] * uom_conversion_factor, currency=price_obj["currency"]) if not price_obj["price_list_rate"]: price_obj["price_list_rate"] = 0 if not price_obj["currency"]: price_obj["currency"] = "" if not price_obj["formatted_price"]: price_obj["formatted_price"] = "" return price_obj
def get_taxes_charges(item, type, company): #Get the Item item_doc = frappe.get_doc("Item",item.item) total_qty = item.qty args = { "doctype": item.doctype, "parent_type": item.parenttype, "name": item_doc.name, "item_code": item.item, "transaction_type": "buying", "supplier": item.supplier, "qty": item.qty, "price_list": item.price_list, "company": company } #frappe.msgprint("{0}".format(args)) args = frappe._dict(args) pr_price = 0 # Get the pricing rule pr_result = get_pricing_rule_for_item(args) if pr_result.pricing_rule: pricing_rule = frappe.get_doc("Pricing Rule", pr_result.pricing_rule) # Find the supplier quotation associated with this pricing rule quotation = frappe.get_doc("Supplier Quotation", pricing_rule.from_supplier_quotation) # Get the master quote quantity based on our total quantity for this part qtylist = [] for item in quotation.items: if item.item_code == pricing_rule.item_code: qtylist.append(item.qty) qtylist.sort() count = 0 for i in qtylist: count = count + 1 if i == pricing_rule.min_qty: break if count > 0: # Loop through each charge type to find the one with the correct quantity and type applicable_charges = [] for tax_charge in quotation.taxes: desc_list = "{" + tax_charge.description + "}" args = frappe._dict(json.loads(desc_list)) if args.type == type: applicable_charges.append(args.qty) applicable_charges.sort() for tax_charge in quotation.taxes: desc_list = "{" + tax_charge.description + "}" args = frappe._dict(json.loads("{" + desc_list + "}")) if args.type == type and args.qty == applicable_charges[count-1]: # We finally found the correct charge for freight return tax_charge.price else: #Need to find the item price return 0
def get_plan_rate(self, plan, quantity=1, date=nowdate()): if plan.price_determination == "Fixed rate": return plan.fixed_rate elif plan.price_determination == "Based on price list": customer_doc = frappe.get_doc("Customer", self.customer) price_list = get_default_price_list(customer_doc) if not price_list: price_list = frappe.db.get_value("Price List", {"selling": 1}) price_list_rate = get_price_list_rate_for( { "company": self.company, "uom": plan.uom, "customer": self.customer, "price_list": price_list, "currency": self.currency, "min_qty": quantity, "transaction_date": date }, plan.item) rule = get_pricing_rule_for_item( frappe._dict({ "company": self.company, "uom": plan.uom, "item_code": plan.item, "stock_qty": quantity, "transaction_type": "selling", "price_list_rate": price_list_rate, "price_list_currency": frappe.db.get_value("Price List", price_list, "currency"), "price_list": price_list, "customer": self.customer, "currency": self.currency, "transaction_date": date, "warehouse": frappe.db.get_value("Warehouse", dict(is_group=1, parent_warehouse='')) })) if rule.get("price_list_rate"): price_list_rate = rule.get("price_list_rate") return price_list_rate or 0
def get_price(item_code, price_list, customer_group, company, qty=1): template_item_code = frappe.db.get_value("Item", item_code, "variant_of") if price_list: price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={"price_list": price_list, "item_code": item_code}) if template_item_code and not price: price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={"price_list": price_list, "item_code": template_item_code}) if price: pricing_rule = get_pricing_rule_for_item(frappe._dict({ "item_code": item_code, "qty": qty, "transaction_type": "selling", "price_list": price_list, "customer_group": customer_group, "company": company, "conversion_rate": 1, "for_shopping_cart": True })) if pricing_rule: if pricing_rule.pricing_rule_for == "Discount Percentage": price[0].price_list_rate = flt(price[0].price_list_rate * (1.0 - (flt(pricing_rule.discount_percentage) / 100.0))) if pricing_rule.pricing_rule_for == "Price": price[0].price_list_rate = pricing_rule.price_list_rate price_obj = price[0] if price_obj: price_obj["formatted_price"] = fmt_money(price_obj["price_list_rate"], currency=price_obj["currency"]) price_obj["currency_symbol"] = not cint(frappe.db.get_default("hide_currency_symbol")) \ and (frappe.db.get_value("Currency", price_obj.currency, "symbol") or price_obj.currency) \ or "" if not price_obj["price_list_rate"]: price_obj["price_list_rate"] = 0 if not price_obj["currency"]: price_obj["currency"] = "" if not price_obj["formatted_price"]: price_obj["formatted_price"] = "" return price_obj
def get_price(item_code, price_list, customer_group, company, qty=1): template_item_code = frappe.db.get_value("Item", item_code, "variant_of") if price_list: price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={"price_list": price_list, "item_code": item_code}) if template_item_code and not price: price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={"price_list": price_list, "item_code": template_item_code}) if price: pricing_rule = get_pricing_rule_for_item(frappe._dict({ "item_code": item_code, "qty": qty, "transaction_type": "selling", "price_list": price_list, "customer_group": customer_group, "company": company, "conversion_rate": 1, "for_shopping_cart": True })) if pricing_rule: if pricing_rule.pricing_rule_for == "Discount Percentage": price[0].price_list_rate = flt(price[0].price_list_rate * (1.0 - (flt(pricing_rule.discount_percentage) / 100.0))) if pricing_rule.pricing_rule_for == "Price": price[0].price_list_rate = pricing_rule.price_list_rate price_obj = price[0] if price_obj: price_obj["formatted_price"] = fmt_money(price_obj["price_list_rate"], currency=price_obj["currency"]) price_obj["currency_symbol"] = not cint(frappe.db.get_default("hide_currency_symbol")) \ and (frappe.db.get_value("Currency", price_obj.currency, "symbol") or price_obj.currency) \ or "" if not price_obj["price_list_rate"]: price_obj["price_list_rate"] = 0 if not price_obj["currency"]: price_obj["currency"] = "" if not price_obj["formatted_price"]: price_obj["formatted_price"] = "" return price_obj
def get_price(item_code, template_item_code, price_list, qty=1): if price_list: cart_settings = get_shopping_cart_settings() price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={ "price_list": price_list, "item_code": item_code }) if template_item_code and not price: price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"], filters={ "price_list": price_list, "item_code": template_item_code }) if price: pricing_rule = get_pricing_rule_for_item( frappe._dict({ "item_code": item_code, "qty": qty, "transaction_type": "selling", "price_list": price_list, "customer_group": cart_settings.default_customer_group, "company": cart_settings.company, "conversion_rate": 1, "for_shopping_cart": True })) if pricing_rule: if pricing_rule.pricing_rule_for == "Discount Percentage": price[0].price_list_rate = flt( price[0].price_list_rate * (1.0 - (flt(pricing_rule.discount_percentage) / 100.0))) if pricing_rule.pricing_rule_for == "Price": price[0].price_list_rate = pricing_rule.price_list_rate return price[0]
def get_item_price(item_code, member=None, qty=0, transaction_date=None, price_list='Standard Selling', no_pricing_rule=1): prices = frappe.db.sql(""" SELECT price_list_rate FROM `tabItem Price` WHERE price_list = '{price_list}' AND item_code = '{item_code}' """.format(item_code=item_code, price_list=price_list)) price_list_rate = prices[0][0] if prices \ else (frappe.db.get_value('Item', item_code, 'standard_rate') or 0) if cint(no_pricing_rule): return price_list_rate applied_pricing_rule = get_pricing_rule_for_item( frappe._dict({ 'doctype': 'Gym Subscription Item', 'transaction_type': 'selling', 'transaction_date': transaction_date or today(), 'qty': qty, 'item_code': item_code, 'customer': frappe.db.get_value('Gym Member', member, 'customer'), 'price_list': price_list, 'conversion_factor': 1, 'conversion_rate': 1.0, 'company': frappe.db.get_value('Gym Settings', None, 'default_company') or frappe.defaults.get_user_default('company'), })) return applied_pricing_rule.get('price_list_rate') or \ price_list_rate * (1 - flt( applied_pricing_rule.get('discount_percentage', 0) ) / 100)
def get_item_price(item, company): """Gets the item price from the price list taking in the total number of assemblies being made and name of the company""" # frappe.msgprint(str(item)) # Get the Item item_doc = frappe.get_doc("Item", item.item_code) total_qty = item.qty args = { "doctype": "Item", "name": item_doc.item_code, "item_code": item.item_code, "transaction_type": "buying", "supplier": item.supplier, "qty": item.qty, "price_list": item.price_list, "company": company, } # frappe.msgprint("{0}".format(args)) args = frappe._dict(args) pr_price = 0 pr_result = get_pricing_rule_for_item(args) # frappe.msgprint(str(pr_result)) if pr_result.pricing_rule: pricing_rule = frappe.get_doc("Pricing Rule", pr_result.pricing_rule) pr_price = pricing_rule.price else: # Need to find the item price pr_price = ( frappe.db.get_value( "Item Price", {"price_list": item.price_list, "item_code": item.item}, "price_list_rate" ) or 0 ) # frappe.msgprint("Price: {0}".format(pr_price)) # frappe.msgprint("Pricing Rule: {0}".format(pr_result.pricing_rule)) return pr_price
def get_item_price(item, company): """Gets the item price from the price list taking in the total number of assemblies being made and name of the company""" #frappe.msgprint(str(item)) #Get the Item item_doc = frappe.get_doc("Item", item.item_code) total_qty = item.qty args = { "doctype": "Item", "name": item_doc.item_code, "item_code": item.item_code, "transaction_type": "buying", "supplier": item.supplier, "qty": item.qty, "price_list": item.price_list, "company": company } #frappe.msgprint("{0}".format(args)) args = frappe._dict(args) pr_price = 0 pr_result = get_pricing_rule_for_item(args) #frappe.msgprint(str(pr_result)) if pr_result.pricing_rule: pricing_rule = frappe.get_doc("Pricing Rule", pr_result.pricing_rule) pr_price = pricing_rule.price else: #Need to find the item price pr_price = frappe.db.get_value("Item Price", { "price_list": item.price_list, "item_code": item.item }, "price_list_rate") or 0 #frappe.msgprint("Price: {0}".format(pr_price)) #frappe.msgprint("Pricing Rule: {0}".format(pr_result.pricing_rule)) return pr_price
def get_item_cost(item_code, cost_method, qty): item_price = 0 if cost_method == "Item Valuation Rate": # Get the item valuation method item_price == frappe.db.get_value("Bin",{"item_code": "item_code"}, "valuation_rate") elif cost_method == "Last Purchase Rate": last_purchase_details = get_last_purchase_details(item_code) item_price = last_purchase_details.base_rate elif cost_method == "Default Supplier": item = frappe.get_doc("Item", item_code) args = { "doctype": item.doctype, "name": item.name, "item_code": item.item_code, "transaction_type": "buying", "supplier": item.default_supplier, "qty": qty } args = frappe._dict(args) #frappe.msgprint(str(args)) pr_price = 0 pr_result = get_pricing_rule_for_item(args) if pr_result.pricing_rule: pricing_rule = frappe.get_doc("Pricing Rule", pr_result.pricing_rule) pr_price = pricing_rule.price else: #Need to find the item price price_list = frappe.db.get_value("Supplier", item.default_supplier, "default_price_list") item_price = frappe.db.get_value("Item Price", {"price_list": price_list,"item_code": item.item_code}, "price_list_rate") or 0 return item_price
def get_item_details(args): """ args = { "item_code": "", "warehouse": None, "customer": "", "conversion_rate": 1.0, "selling_price_list": None, "price_list_currency": None, "plc_conversion_rate": 1.0, "doctype": "", "name": "", "supplier": None, "transaction_date": None, "conversion_rate": 1.0, "buying_price_list": None, "is_subcontracted": "Yes" / "No", "ignore_pricing_rule": 0/1 "project": "" } """ args = process_args(args) item_doc = frappe.get_doc("Item", args.item_code) item = item_doc validate_item_details(args, item) out = get_basic_details(args, item) get_party_item_code(args, item_doc, out) if out.get("warehouse"): out.update(get_bin_details(args.item_code, out.warehouse)) if frappe.db.exists("Product Bundle", args.item_code): valuation_rate = 0.0 bundled_items = frappe.get_doc("Product Bundle", args.item_code) for bundle_item in bundled_items.items: valuation_rate += \ flt(get_valuation_rate(bundle_item.item_code, out.get("warehouse")).get("valuation_rate") \ * bundle_item.qty) out.update({ "valuation_rate": valuation_rate }) else: out.update(get_valuation_rate(args.item_code, out.get("warehouse"))) get_price_list_rate(args, item_doc, out) if args.customer and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args)) # update args with out, if key or value not exists for key, value in out.iteritems(): if args.get(key) is None: args[key] = value out.update(get_pricing_rule_for_item(args)) if args.get("doctype") in ("Sales Invoice", "Delivery Note"): if item_doc.has_serial_no == 1 and not args.serial_no: out.serial_no = get_serial_nos_by_fifo(args, item_doc) if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days(args.transaction_date, item.lead_time_days) if args.get("is_subcontracted") == "Yes": out.bom = get_default_bom(args.item_code) get_gross_profit(out) return out
def get_item_details(args, doc=None, for_validate=False, overwrite_warehouse=True): """ args = { "item_code": "", "warehouse": None, "customer": "", "conversion_rate": 1.0, "selling_price_list": None, "price_list_currency": None, "plc_conversion_rate": 1.0, "doctype": "", "name": "", "supplier": None, "transaction_date": None, "conversion_rate": 1.0, "buying_price_list": None, "is_subcontracted": "Yes" / "No", "ignore_pricing_rule": 0/1 "project": "" "set_warehouse": "" } """ args = process_args(args) for_validate = process_string_args(for_validate) overwrite_warehouse = process_string_args(overwrite_warehouse) item = frappe.get_cached_doc("Item", args.item_code) validate_item_details(args, item) out = get_basic_details(args, item, overwrite_warehouse) if isinstance(doc, string_types): doc = json.loads(doc) if doc and doc.get('doctype') == 'Purchase Invoice': args['bill_date'] = doc.get('bill_date') if doc: args['posting_date'] = doc.get('posting_date') args['transaction_date'] = doc.get('transaction_date') get_item_tax_template(args, item, out) out["item_tax_rate"] = get_item_tax_map(args.company, args.get("item_tax_template") if out.get("item_tax_template") is None \ else out.get("item_tax_template"), as_json=True) get_party_item_code(args, item, out) set_valuation_rate(out, args) update_party_blanket_order(args, out) get_price_list_rate(args, item, out) if args.customer and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args)) if (args.get("doctype") == "Material Request" and args.get("material_request_type") == "Material Transfer"): out.update(get_bin_details(args.item_code, args.get("from_warehouse"))) elif out.get("warehouse"): out.update(get_bin_details(args.item_code, out.warehouse)) # update args with out, if key or value not exists for key, value in iteritems(out): if args.get(key) is None: args[key] = value data = get_pricing_rule_for_item(args, out.price_list_rate, doc, for_validate=for_validate) out.update(data) update_stock(args, out) if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days( args.transaction_date, item.lead_time_days) if args.get("is_subcontracted") == "Yes": out.bom = args.get('bom') or get_default_bom(args.item_code) get_gross_profit(out) if args.doctype == 'Material Request': out.rate = args.rate or out.price_list_rate out.amount = flt(args.qty * out.rate) return out
def add_pricing_rules(mquotation, method=None): """This function adds all the items to pricing rules""" frappe.msgprint(_("Adding Pricing Rules")) quotation = frappe.get_doc("Supplier Quotation", mquotation) # Loop through all of the items in the price list for item_doc in quotation.items: # check to see if there are any pricing rules that fall into the specified quantity/supplier #frappe.msgprint(_("Checking pricing rules of {0} for previous prices".format(item_doc.item_code))) item = frappe.get_doc("Item", item_doc.item_code) args = { "doctype": item_doc.doctype, "parent_type": item_doc.parenttype, "name": item_doc.name, "item_code": item_doc.item_code, "transaction_type": "buying", "supplier": quotation.supplier, "qty": item_doc.qty, "price_list": quotation.buying_price_list, "company": quotation.company } args = frappe._dict(args) pr_result = get_pricing_rule_for_item(args) if not pr_result.pricing_rule: frappe.msgprint(_("There are no pricing rules for this item")) pr_title = item_doc.item_code + "-" + quotation.supplier + "-" + str( item_doc.qty) new_rule = frappe.get_doc({ "doctype": "Pricing Rule", "min_qty": item_doc.qty, "apply_on": "Item Code", "item_code": item_doc.item_code, "priority": 1, "buying": "1", "applicable_for": "Supplier", "company": quotation.company, "price_or_discount": "Price", "price": item_doc.rate, "supplier": quotation.supplier, "for_price_list": quotation.buying_price_list, "title": pr_title, "from_supplier_quotation": quotation.name }) new_rule.insert() else: frappe.msgprint( _("Pricing Rule {0} applies for this item".format( pr_result.pricing_rule))) # Check to see if the pricing rule matches quantity min exactly pricing_rule = frappe.get_doc("Pricing Rule", pr_result.pricing_rule) if item_doc.qty == pricing_rule.min_qty: # This pricing rule rate just needs to be changed frappe.msgprint(_("Updating Pricing Rule")) frappe.set_value("Pricing Rule", pricing_rule.name, "price", item_doc.rate) frappe.set_value("Pricing Rule", pricing_rule.name, "from_supplier_quotation", quotation.name) else: frappe.msgprint( _("Creating new rule and incrementing priority")) # This rule is lower in qty than the current rule. We need to add a new pricing rule and update the priorities for each of the higher quantity pricing rules pr_title = item_doc.item_code + "-" + quotation.supplier + "-" + str( item_doc.qty) new_rule = frappe.get_doc({ "doctype": "Pricing Rule", "min_qty": item_doc.qty, "apply_on": "Item Code", "item_code": item_doc.item_code, "priority": pricing_rule.priority, "buying": "1", "applicable_for": "Supplier", "company": quotation.company, "price_or_discount": "Price", "price": item_doc.rate, "supplier": quotation.supplier, "for_price_list": quotation.buying_price_list, "title": pr_title, "from_supplier_quotation": quotation.name }) new_rule.insert() # Run through each of the higher quantity pricing rules and increase their priority by one unfiltered_rules = get_pricing_rules(args) pricing_rules = filter( lambda x: (flt(item_doc.qty) <= flt(x.min_qty)), unfiltered_rules) for pr in pricing_rules: frappe.set_value("Pricing Rule", pr.name, "priority", str(int(pr.priority) + 1))
def get_price(item_code, price_list, customer_group, company, qty=1, uom=None): template_item_code, stock_uom = frappe.db.get_value( "Item", item_code, ["variant_of", "stock_uom"]) uom_condition = "" if uom: uom_condition = " AND uom = '{0}'".format(uom) elif stock_uom: uom_condition = " AND (uom = '{0}' OR ifnull(uom, '') = '')".format( stock_uom) if price_list: price = frappe.db.sql(""" SELECT price_list_rate, currency, uom FROM `tabItem Price` WHERE price_list=%s AND item_code = %s {conditions} AND CURDATE() BETWEEN IFNULL(valid_from, '2000-01-01') AND IFNULL(valid_upto, '2500-12-31')""". format(conditions=uom_condition), (price_list, item_code), as_dict=True) if template_item_code and not price: price = frappe.db.sql(""" SELECT price_list_rate, currency FROM `tabItem Price` WHERE price_list=%s AND item_code = %s {conditions} AND CURDATE() BETWEEN IFNULL(valid_from, '2000-01-01') AND IFNULL(valid_upto, '2500-12-31')""". format(conditions=uom_condition), (price_list, template_item_code), as_dict=True) if price: pricing_rule = get_pricing_rule_for_item( frappe._dict({ "item_code": item_code, "qty": qty, "transaction_type": "selling", "price_list": price_list, "customer_group": customer_group, "for_shopping_cart": 1, "company": company, "conversion_rate": 1, "currency": frappe.db.get_value("Price List", price_list, "currency") })) if pricing_rule: if pricing_rule.pricing_rule_for == "Discount Percentage": price[0].price_list_rate = flt( price[0].price_list_rate * (1.0 - (flt(pricing_rule.discount_percentage) / 100.0))) if pricing_rule.pricing_rule_for == "Rate": price[0].price_list_rate = pricing_rule.price_list_rate price_obj = price[0] if price_obj: price_obj["formatted_price"] = fmt_money( price_obj["price_list_rate"], currency=price_obj["currency"]) price_obj["currency_symbol"] = not cint(frappe.db.get_default("hide_currency_symbol")) \ and (frappe.db.get_value("Currency", price_obj.currency, "symbol", cache=True) or price_obj.currency) \ or "" if stock_uom and not uom: uom_conversion_factor = frappe.db.sql( """select C.conversion_factor from `tabUOM Conversion Detail` C inner join `tabItem` I on C.parent = I.name and C.uom = I.sales_uom where I.name = %s""", item_code) uom_conversion_factor = uom_conversion_factor[0][ 0] if uom_conversion_factor else 1 price_obj["formatted_price_sales_uom"] = fmt_money( price_obj["price_list_rate"] * uom_conversion_factor, currency=price_obj["currency"]) if not price_obj["price_list_rate"]: price_obj["price_list_rate"] = 0 if not price_obj["currency"]: price_obj["currency"] = "" if not price_obj["formatted_price"]: price_obj["formatted_price"] = "" return price_obj
def get_item_details(args): """ args = { "item_code": "", "warehouse": None, "customer": "", "conversion_rate": 1.0, "selling_price_list": None, "price_list_currency": None, "plc_conversion_rate": 1.0, "doctype": "", "name": "", "supplier": None, "transaction_date": None, "conversion_rate": 1.0, "buying_price_list": None, "is_subcontracted": "Yes" / "No", "ignore_pricing_rule": 0/1 "project": "" "set_warehouse": "" } """ args = process_args(args) item = frappe.get_cached_doc("Item", args.item_code) validate_item_details(args, item) out = get_basic_details(args, item) get_party_item_code(args, item, out) set_valuation_rate(out, args) update_party_blanket_order(args, out) get_price_list_rate(args, item, out) if args.customer and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args)) if out.get("warehouse"): out.update(get_bin_details(args.item_code, out.warehouse)) # update args with out, if key or value not exists for key, value in iteritems(out): if args.get(key) is None: args[key] = value out.update(get_pricing_rule_for_item(args)) update_stock(args, out) if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days(args.transaction_date, item.lead_time_days) if args.get("is_subcontracted") == "Yes": out.bom = args.get('bom') or get_default_bom(args.item_code) get_gross_profit(out) if args.doctype == 'Material Request': out.rate = args.rate or out.price_list_rate out.amount = flt(args.qty * out.rate) return out
def get_item_details(args): """ args = { "item_code": "", "warehouse": None, "customer": "", "conversion_rate": 1.0, "selling_price_list": None, "price_list_currency": None, "plc_conversion_rate": 1.0, "doctype": "", "name": "", "supplier": None, "transaction_date": None, "conversion_rate": 1.0, "buying_price_list": None, "is_subcontracted": "Yes" / "No", "ignore_pricing_rule": 0/1 "project": "" "set_warehouse": "" } """ args = process_args(args) item = frappe.get_cached_doc("Item", args.item_code) validate_item_details(args, item) out = get_basic_details(args, item) get_party_item_code(args, item, out) set_valuation_rate(out, args) update_party_blanket_order(args, out) get_price_list_rate(args, item, out) if args.customer and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args)) if out.get("warehouse"): out.update(get_bin_details(args.item_code, out.warehouse)) # update args with out, if key or value not exists for key, value in iteritems(out): if args.get(key) is None: args[key] = value out.update(get_pricing_rule_for_item(args)) update_stock(args, out) if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days(args.transaction_date, item.lead_time_days) if args.get("is_subcontracted") == "Yes": out.bom = args.get('bom') or get_default_bom(args.item_code) get_gross_profit(out) if args.doctype == 'Material Request': out.rate = args.rate or out.price_list_rate out.amount = flt(args.qty * out.rate) return out
def get_item_details(args): """ args = { "item_code": "", "warehouse": None, "customer": "", "conversion_rate": 1.0, "selling_price_list": None, "price_list_currency": None, "plc_conversion_rate": 1.0, "doctype": "", "name": "", "supplier": None, "transaction_date": None, "conversion_rate": 1.0, "buying_price_list": None, "is_subcontracted": "Yes" / "No", "ignore_pricing_rule": 0/1 "project": "" } """ args = process_args(args) item_doc = frappe.get_doc("Item", args.item_code) item = item_doc validate_item_details(args, item) out = get_basic_details(args, item) get_party_item_code(args, item_doc, out) if frappe.db.exists("Product Bundle", args.item_code): valuation_rate = 0.0 bundled_items = frappe.get_doc("Product Bundle", args.item_code) for bundle_item in bundled_items.items: valuation_rate += \ flt(get_valuation_rate(bundle_item.item_code, args.company, out.get("warehouse")).get("valuation_rate") \ * bundle_item.qty) out.update({"valuation_rate": valuation_rate}) else: out.update( get_valuation_rate(args.item_code, args.company, out.get("warehouse"))) update_party_blanket_order(args, out) get_price_list_rate(args, item_doc, out) if args.customer and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args)) if out.get("warehouse"): out.update(get_bin_details(args.item_code, out.warehouse)) # update args with out, if key or value not exists for key, value in iteritems(out): if args.get(key) is None: args[key] = value out.update(get_pricing_rule_for_item(args)) if (args.get("doctype") == "Delivery Note" or (args.get("doctype") == "Sales Invoice" and args.get('update_stock'))) \ and out.warehouse and out.stock_qty > 0: if out.has_batch_no and not args.get("batch_no"): out.batch_no = get_batch_no(out.item_code, out.warehouse, out.qty) actual_batch_qty = get_batch_qty(out.batch_no, out.warehouse, out.item_code) if actual_batch_qty: out.update(actual_batch_qty) if out.has_serial_no and args.get('batch_no'): reserved_so = get_so_reservation_for_item(args) out.batch_no = args.get('batch_no') out.serial_no = get_serial_no(out, args.serial_no, sales_order=reserved_so) elif out.has_serial_no: reserved_so = get_so_reservation_for_item(args) out.serial_no = get_serial_no(out, args.serial_no, sales_order=reserved_so) if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days( args.transaction_date, item.lead_time_days) if args.get("is_subcontracted") == "Yes": out.bom = args.get('bom') or get_default_bom(args.item_code) get_gross_profit(out) if args.doctype == 'Material Request': out.rate = args.rate or out.price_list_rate out.amount = flt(args.qty * out.rate) return out
def add_pricing_rules(mquotation, method=None): """This function adds all the items to pricing rules""" frappe.msgprint(_("Adding Pricing Rules")) quotation = frappe.get_doc("Supplier Quotation", mquotation) # Loop through all of the items in the price list for item_doc in quotation.items: # check to see if there are any pricing rules that fall into the specified quantity/supplier # frappe.msgprint(_("Checking pricing rules of {0} for previous prices".format(item_doc.item_code))) item = frappe.get_doc("Item", item_doc.item_code) args = { "doctype": item_doc.doctype, "parent_type": item_doc.parenttype, "name": item_doc.name, "item_code": item_doc.item_code, "transaction_type": "buying", "supplier": quotation.supplier, "qty": item_doc.qty, "price_list": quotation.buying_price_list, "company": quotation.company, } args = frappe._dict(args) pr_result = get_pricing_rule_for_item(args) if not pr_result.pricing_rule: frappe.msgprint(_("There are no pricing rules for this item")) pr_title = item_doc.item_code + "-" + quotation.supplier + "-" + str(item_doc.qty) new_rule = frappe.get_doc( { "doctype": "Pricing Rule", "min_qty": item_doc.qty, "apply_on": "Item Code", "item_code": item_doc.item_code, "priority": 1, "buying": "1", "applicable_for": "Supplier", "company": quotation.company, "price_or_discount": "Price", "price": item_doc.rate, "supplier": quotation.supplier, "for_price_list": quotation.buying_price_list, "title": pr_title, "from_supplier_quotation": quotation.name, } ) new_rule.insert() else: frappe.msgprint(_("Pricing Rule {0} applies for this item".format(pr_result.pricing_rule))) # Check to see if the pricing rule matches quantity min exactly pricing_rule = frappe.get_doc("Pricing Rule", pr_result.pricing_rule) if item_doc.qty == pricing_rule.min_qty: # This pricing rule rate just needs to be changed frappe.msgprint(_("Updating Pricing Rule")) frappe.set_value("Pricing Rule", pricing_rule.name, "price", item_doc.rate) frappe.set_value("Pricing Rule", pricing_rule.name, "from_supplier_quotation", quotation.name) else: frappe.msgprint(_("Creating new rule and incrementing priority")) # This rule is lower in qty than the current rule. We need to add a new pricing rule and update the priorities for each of the higher quantity pricing rules pr_title = item_doc.item_code + "-" + quotation.supplier + "-" + str(item_doc.qty) new_rule = frappe.get_doc( { "doctype": "Pricing Rule", "min_qty": item_doc.qty, "apply_on": "Item Code", "item_code": item_doc.item_code, "priority": pricing_rule.priority, "buying": "1", "applicable_for": "Supplier", "company": quotation.company, "price_or_discount": "Price", "price": item_doc.rate, "supplier": quotation.supplier, "for_price_list": quotation.buying_price_list, "title": pr_title, "from_supplier_quotation": quotation.name, } ) new_rule.insert() # Run through each of the higher quantity pricing rules and increase their priority by one unfiltered_rules = get_pricing_rules(args) pricing_rules = filter(lambda x: (flt(item_doc.qty) <= flt(x.min_qty)), unfiltered_rules) for pr in pricing_rules: frappe.set_value("Pricing Rule", pr.name, "priority", str(int(pr.priority) + 1))