예제 #1
0
def get_data(filters=None):
    data = []
    customer_details = get_customer_details(filters)

    items = get_selling_items(filters)
    item_stock_map = frappe.get_all(
        "Bin",
        fields=["item_code", "sum(actual_qty) AS available"],
        group_by="item_code")
    item_stock_map = {
        item.item_code: item.available
        for item in item_stock_map
    }

    for item in items:
        price_list_rate = get_price_list_rate_for(customer_details,
                                                  item.item_code) or 0.0
        available_stock = item_stock_map.get(item.item_code)

        data.append({
            "item_code": item.item_code,
            "item_name": item.item_name,
            "selling_rate": price_list_rate,
            "price_list": customer_details.get("price_list"),
            "available_stock": available_stock,
        })

    return data
예제 #2
0
def get_item_rate(customer, item_code, out):
    if out.get((customer, item_code)):
        return out.get((customer, item_code))
    default_price_list = frappe.db.sql("""
        select cu.name,
        COALESCE(cu.default_price_list,cug.default_price_list,sing.value) price_list
        from tabCustomer cu
        inner join `tabCustomer Group` cug on cug.name = cu.customer_group
        cross join tabSingles sing on sing.field = 'selling_price_list'
        and sing.doctype = 'Selling Settings'
        where cu.name=%s""", (customer, ),
                                       as_dict=True)

    customer_details = get_party_details(party=customer, party_type="Customer")
    customer_details.update({
        "company":
        get_default_company(),
        "price_list":
        [d["price_list"] for d in default_price_list if d.name == customer][0],
        "transaction_date":
        getdate()
    })
    rate = get_price_list_rate_for(customer_details, item_code) or 0.0
    out.setdefault((customer, item_code), rate)
    return rate
예제 #3
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
예제 #4
0
    def test_price_with_no_qty(self):
        # Check correct price when no quantity
        doc = frappe.copy_doc(test_records[2])
        args = {
            "price_list": doc.price_list,
            "customer": doc.customer,
            "uom": "_Test UOM",
            "transaction_date": '2017-04-18',
        }

        price = get_price_list_rate_for(args, doc.item_code)
        self.assertEqual(price, None)
예제 #5
0
    def test_lowest_price_when_no_date_provided(self):
        #Check lowest price when no date provided
        doc = frappe.copy_doc(test_records[1])

        args = {
            "price_list": doc.price_list,
            "uom": "_Test UOM",
            "qty": 7,
        }

        price = get_price_list_rate_for(args, doc.item_code)
        self.assertEqual(price, 10)
예제 #6
0
    def test_prices_at_invalid_date(self):
        #Check correct price at invalid date
        doc = frappe.copy_doc(test_records[3])

        args = {
            "price_list": doc.price_list,
            "qty": 7,
            "uom": "_Test UOM",
            "transaction_date": "01-15-2019"
        }

        price = get_price_list_rate_for(args, doc.item_code)
        self.assertEqual(price, None)
예제 #7
0
	def test_price_with_no_qty(self):
		# Check correct price when no quantity
		doc = frappe.copy_doc(test_records[2])
		args = {
			"price_list": doc.price_list,
			"min_qty": 30,
			"customer": doc.customer,
			"uom": "_Test UOM",
            "transaction_date": '2017-04-18',
		}

		price = get_price_list_rate_for(args, doc.item_code)
		self.assertEqual(price, None)
예제 #8
0
	def test_lowest_price_when_no_date_provided(self):
		#Check lowest price when no date provided
		doc = frappe.copy_doc(test_records[1])

		args = {
			"price_list": doc.price_list,
			"min_qty": doc.min_qty,
			"uom": "_Test UOM",
			"qty": 7,
		}

		price = get_price_list_rate_for(args, doc.item_code)
		self.assertEqual(price, 10)
예제 #9
0
    def test_prices_outside_of_date(self):
        #Check correct price when outside of the date
        doc = frappe.copy_doc(test_records[4])

        args = {
            "price_list": doc.price_list,
            "customer": "_Test Customer",
            "uom": "_Test UOM",
            "transaction_date": "2017-04-25",
            "qty": 7,
        }

        price = get_price_list_rate_for(args, doc.item_code)
        self.assertEqual(price, None)
예제 #10
0
    def test_prices_at_date(self):
        # Check correct price at first date
        doc = frappe.copy_doc(test_records[2])

        args = {
            "price_list": doc.price_list,
            "customer": "_Test Customer",
            "uom": "_Test UOM",
            "transaction_date": '2017-04-18',
            "qty": 7
        }

        price = get_price_list_rate_for(args, doc.item_code)
        self.assertEqual(price, 20)
예제 #11
0
    def test_price_in_a_qty(self):
        # Check correct price at this quantity
        doc = frappe.copy_doc(test_records[2])

        args = {
            "price_list": doc.price_list,
            "customer": doc.customer,
            "uom": "_Test UOM",
            "transaction_date": '2017-04-18',
            "qty": 10
        }

        price = get_price_list_rate_for(process_args(args), doc.item_code)
        self.assertEqual(price, 20.0)
예제 #12
0
	def test_prices_at_invalid_date(self):
		#Check correct price at invalid date
		doc = frappe.copy_doc(test_records[3])

		args = {
			"price_list": doc.price_list,
			"min_qty": doc.min_qty,
			"qty": 7,
			"uom": "_Test UOM",
			"transaction_date": "01-15-2019"
		}

		price = get_price_list_rate_for(args, doc.item_code)
		self.assertEqual(price, None)
예제 #13
0
	def test_prices_at_date(self):
		# Check correct price at first date
		doc = frappe.copy_doc(test_records[2])

		args = {
			"price_list": doc.price_list,
			"min_qty": doc.min_qty,
			"customer": "_Test Customer",
			"uom": "_Test UOM",
			"transaction_date": '2017-04-18',
			"qty": 7
		}

		price = get_price_list_rate_for(args, doc.item_code)
		self.assertEqual(price, 20)
예제 #14
0
	def test_price_in_a_qty(self):
		# Check correct price at this quantity
		doc = frappe.copy_doc(test_records[2])

		args = {
			"price_list": doc.price_list,
			"min_qty": doc.min_qty,
            "customer": doc.customer,
            "uom": "_Test UOM",
            "transaction_date": '2017-04-18',
            "qty": 10
		}

		price = get_price_list_rate_for(process_args(args), doc.item_code)
		self.assertEqual(price, 20.0)
예제 #15
0
	def test_prices_outside_of_date(self):
		#Check correct price when outside of the date
		doc = frappe.copy_doc(test_records[4])

		args = {
			"price_list": doc.price_list,
			"min_qty": doc.min_qty,
            "customer": "_Test Customer",
            "uom": "_Test UOM",
			"transaction_date": "2017-04-25",
			"qty": 7,
		}

		price = get_price_list_rate_for(args, doc.item_code)
		self.assertEqual(price, None)
예제 #16
0
    def test_empty_duplicate_validation(self):
        # Check if none/empty values are not compared during insert validation
        doc = frappe.copy_doc(test_records[2])
        doc.customer = None
        doc.price_list_rate = 21
        doc.insert()

        args = {
            "price_list": doc.price_list,
            "uom": "_Test UOM",
            "transaction_date": '2017-04-18',
            "qty": 7
        }

        price = get_price_list_rate_for(args, doc.item_code)
        frappe.db.rollback()

        self.assertEqual(price, 21)