Beispiel #1
0
	def set_missing_values(source, target):
		from erpnext.controllers.accounts_controller import get_default_taxes_and_charges
		quotation = frappe.get_doc(target)

		company_currency = frappe.get_cached_value('Company',  quotation.company,  "default_currency")

		if quotation.quotation_to == 'Customer' and quotation.party_name:
			party_account_currency = get_party_account_currency("Customer", quotation.party_name, quotation.company)
		else:
			party_account_currency = company_currency

		quotation.currency = party_account_currency or company_currency

		if company_currency == quotation.currency:
			exchange_rate = 1
		else:
			exchange_rate = get_exchange_rate(quotation.currency, company_currency,
				quotation.transaction_date, args="for_selling")

		quotation.conversion_rate = exchange_rate

		# get default taxes
		taxes = get_default_taxes_and_charges("Sales Taxes and Charges Template", company=quotation.company)
		if taxes.get('taxes'):
			quotation.update(taxes)

		quotation.run_method("set_missing_values")
		quotation.run_method("calculate_taxes_and_totals")
		if not source.with_items:
			quotation.opportunity = source.name
Beispiel #2
0
	def set_missing_values(source, target):
		from erpnext.controllers.accounts_controller import get_default_taxes_and_charges
		quotation = frappe.get_doc(target)

		company_currency = frappe.db.get_value("Company", quotation.company, "default_currency")
		party_account_currency = get_party_account_currency("Customer", quotation.customer,
			quotation.company) if quotation.customer else company_currency

		quotation.currency = party_account_currency or company_currency

		if company_currency == quotation.currency:
			exchange_rate = 1
		else:
			exchange_rate = get_exchange_rate(quotation.currency, company_currency,
				quotation.transaction_date)

		quotation.conversion_rate = exchange_rate

		# get default taxes
		taxes = get_default_taxes_and_charges("Sales Taxes and Charges Template")
		if taxes:
			quotation.extend("taxes", taxes)

		quotation.run_method("set_missing_values")
		quotation.run_method("calculate_taxes_and_totals")
		if not source.with_items:
			quotation.opportunity = source.name
def create_supplier_quotation(doc):
    if isinstance(doc, basestring):
        doc = json.loads(doc)

    validate_duplicate_supplier_quotation(doc)

    try:
        sq_doc = frappe.get_doc(
            {
                "doctype": "Supplier Quotation",
                "supplier": doc.get("supplier"),
                "terms": doc.get("terms"),
                "company": doc.get("company"),
                "currency": doc.get("currency")
                or get_party_account_currency("Supplier", doc.get("supplier"), doc.get("company")),
                "buying_price_list": doc.get("buying_price_list")
                or frappe.db.get_value("Buying Settings", None, "buying_price_list"),
            }
        )
        add_items(sq_doc, doc.get("supplier"), doc.get("items"))
        sq_doc.flags.ignore_permissions = True
        sq_doc.run_method("set_missing_values")
        sq_doc.save()
        frappe.msgprint(_("Supplier Quotation {0} created").format(sq_doc.name))
        return sq_doc.name
    except Exception:
        return
 def postprocess(source, target_doc):
     target_doc.supplier = for_supplier
     args = get_party_details(for_supplier, party_type="Supplier", ignore_permissions=True)
     target_doc.currency = args.currency or get_party_account_currency("Supplier", for_supplier, source.company)
     target_doc.buying_price_list = args.buying_price_list or frappe.db.get_value(
         "Buying Settings", None, "buying_price_list"
     )
     set_missing_values(source, target_doc)
Beispiel #5
0
def get_customers(pos_profile, doc):
	filters = {'disabled': 0}
	customer_list = []
	customers = frappe.get_all("Customer", fields=["*"], filters = filters)

	for customer in customers:
		customer_currency = get_party_account_currency('Customer', customer.name, doc.company) or doc.currency
		if customer_currency == doc.currency:
			customer_list.append(customer)
	return customer_list
Beispiel #6
0
	def validate_currency(self):
		if self.get("currency"):
			party_type, party = self.get_party()
			if party_type and party:
				party_account_currency = get_party_account_currency(party_type, party, self.company)

				if (party_account_currency
						and party_account_currency != self.company_currency
						and self.currency != party_account_currency):
					frappe.throw(_("Accounting Entry for {0}: {1} can only be made in currency: {2}")
								 .format(party_type, party, party_account_currency), InvalidCurrency)
Beispiel #7
0
def run_purchase(current_date):
	# make material requests for purchase items that have negative projected qtys
	if can_make("Material Request"):
		report = "Items To Be Requested"
		for row in query_report.run(report)["result"][:how_many("Material Request")]:
			make_material_request(current_date, row[0], -row[-1])

	# get supplier details
	supplier = get_random("Supplier")
	
	company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency")
	party_account_currency = get_party_account_currency("Supplier", supplier, "Wind Power LLC")
	if company_currency == party_account_currency:
		exchange_rate = 1
	else:
		exchange_rate = get_exchange_rate(party_account_currency, company_currency)

	# make supplier quotations
	if can_make("Supplier Quotation"):
		from erpnext.stock.doctype.material_request.material_request import make_supplier_quotation
		
		report = "Material Requests for which Supplier Quotations are not created"
		for row in query_report.run(report)["result"][:how_many("Supplier Quotation")]:
			if row[0] != "'Total'":
				sq = frappe.get_doc(make_supplier_quotation(row[0]))
				sq.transaction_date = current_date
				sq.fiscal_year = cstr(current_date.year)
				sq.supplier = supplier
				sq.currency = party_account_currency or company_currency
				sq.conversion_rate = exchange_rate
				sq.insert()
				sq.submit()
				frappe.db.commit()

	# make purchase orders
	if can_make("Purchase Order"):
		from erpnext.stock.doctype.material_request.material_request import make_purchase_order
		report = "Requested Items To Be Ordered"
		for row in query_report.run(report)["result"][:how_many("Purchase Order")]:
			if row[0] != "'Total'":
				po = frappe.get_doc(make_purchase_order(row[0]))
				po.supplier = supplier
				po.currency = party_account_currency or company_currency
				po.conversion_rate = exchange_rate
				po.transaction_date = current_date
				po.fiscal_year = cstr(current_date.year)
				po.insert()
				po.submit()
				frappe.db.commit()

	if can_make("Subcontract"):
		make_subcontract(current_date)
Beispiel #8
0
def make_quotation():
    # get open opportunites
    opportunity = get_random("Opportunity", {"status": "Open", "with_items": 1})

    if opportunity:
        from erpnext.crm.doctype.opportunity.opportunity import make_quotation

        qtn = frappe.get_doc(make_quotation(opportunity))
        qtn.insert()
        frappe.db.commit()
        qtn.submit()
        frappe.db.commit()
    else:
        # make new directly

        # get customer, currency and exchange_rate
        customer = get_random("Customer")

        company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency")
        party_account_currency = get_party_account_currency("Customer", customer, "Wind Power LLC")
        if company_currency == party_account_currency:
            exchange_rate = 1
        else:
            exchange_rate = get_exchange_rate(party_account_currency, company_currency)

        qtn = frappe.get_doc(
            {
                "creation": frappe.flags.current_date,
                "doctype": "Quotation",
                "quotation_to": "Customer",
                "customer": customer,
                "currency": party_account_currency or company_currency,
                "conversion_rate": exchange_rate,
                "order_type": "Sales",
                "transaction_date": frappe.flags.current_date,
            }
        )

        add_random_children(
            qtn,
            "items",
            rows=3,
            randomize={"qty": (1, 5), "item_code": ("Item", {"has_variants": "0", "is_fixed_asset": 0})},
            unique="item_code",
        )

        qtn.insert()
        frappe.db.commit()
        qtn.submit()
        frappe.db.commit()
Beispiel #9
0
	def validate_supplier(self):
		prevent_po = frappe.db.get_value("Supplier", self.supplier, 'prevent_pos')
		if prevent_po:
			standing = frappe.db.get_value("Supplier Scorecard", self.supplier, 'status')
			if standing:
				frappe.throw(_("Purchase Orders are not allowed for {0} due to a scorecard standing of {1}.")
					.format(self.supplier, standing))

		warn_po = frappe.db.get_value("Supplier", self.supplier, 'warn_pos')
		if warn_po:
			standing = frappe.db.get_value("Supplier Scorecard",self.supplier, 'status')
			frappe.msgprint(_("{0} currently has a {1} Supplier Scorecard standing, and Purchase Orders to this supplier should be issued with caution.").format(self.supplier, standing), title=_("Caution"), indicator='orange')

		self.party_account_currency = get_party_account_currency("Supplier", self.supplier, self.company)
Beispiel #10
0
	def set_missing_values(source, target):
		quotation = frappe.get_doc(target)

		company_currency = frappe.db.get_value("Company", quotation.company, "default_currency")
		party_account_currency = get_party_account_currency("Customer", quotation.customer, quotation.company)

		if company_currency == party_account_currency:
			exchange_rate = 1
		else:
			exchange_rate = get_exchange_rate(party_account_currency, company_currency)

		quotation.currency = party_account_currency or company_currency
		quotation.conversion_rate = exchange_rate

		quotation.run_method("set_missing_values")
		quotation.run_method("calculate_taxes_and_totals")
Beispiel #11
0
	def validate_currency(self):
		company_currency = get_company_currency(self.company)
		account_currency = get_account_currency(self.account)

		if not self.account_currency:
			self.account_currency = company_currency

		if account_currency != self.account_currency:
			frappe.throw(_("Accounting Entry for {0} can only be made in currency: {1}")
				.format(self.account, (account_currency or company_currency)), InvalidAccountCurrency)

		if self.party_type and self.party:
			party_account_currency = get_party_account_currency(self.party_type, self.party, self.company)

			if party_account_currency != self.account_currency:
				frappe.throw(_("Accounting Entry for {0}: {1} can only be made in currency: {2}")
					.format(self.party_type, self.party, party_account_currency), InvalidAccountCurrency)

			validate_party_gle_currency(self.party_type, self.party, self.company)
def create_supplier_quotation(doc):
	if isinstance(doc, string_types):
		doc = json.loads(doc)

	try:
		sq_doc = frappe.get_doc({
			"doctype": "Supplier Quotation",
			"supplier": doc.get('supplier'),
			"terms": doc.get("terms"),
			"company": doc.get("company"),
			"currency": doc.get('currency') or get_party_account_currency('Supplier', doc.get('supplier'), doc.get('company')),
			"buying_price_list": doc.get('buying_price_list') or frappe.db.get_value('Buying Settings', None, 'buying_price_list')
		})
		add_items(sq_doc, doc.get('supplier'), doc.get('items'))
		sq_doc.flags.ignore_permissions = True
		sq_doc.run_method("set_missing_values")
		sq_doc.save()
		frappe.msgprint(_("Supplier Quotation {0} created").format(sq_doc.name))
		return sq_doc.name
	except Exception:
		return None
Beispiel #13
0
def work():
	frappe.set_user(frappe.db.get_global('demo_purchase_user'))

	if random.random() < 0.3:
		report = "Items To Be Requested"
		for row in query_report.run(report)["result"][:random.randint(1, 5)]:
			item_code, qty = row[0], abs(row[-1])

			mr = make_material_request(item_code, qty)

	if random.random() < 0.3:
		for mr in frappe.get_all('Material Request',
			filters={'material_request_type': 'Purchase', 'status': 'Open'},
			limit=random.randint(1,6)):
			if not frappe.get_all('Request for Quotation',
				filters={'material_request': mr.name}, limit=1):
				rfq = make_request_for_quotation(mr.name)
				rfq.transaction_date = frappe.flags.current_date
				add_suppliers(rfq)
				rfq.save()
				rfq.submit()

	# Make suppier quotation from RFQ against each supplier.
	if random.random() < 0.3:
		for rfq in frappe.get_all('Request for Quotation',
			filters={'status': 'Open'}, limit=random.randint(1, 6)):
			if not frappe.get_all('Supplier Quotation',
				filters={'request_for_quotation': rfq.name}, limit=1):
				rfq = frappe.get_doc('Request for Quotation', rfq.name)

				for supplier in rfq.suppliers:
					supplier_quotation = make_quotation_from_rfq(rfq.name, supplier.supplier)
					supplier_quotation.save()
					supplier_quotation.submit()

	# get supplier details
	supplier = get_random("Supplier")

	company_currency = frappe.db.get_value("Company", "Wind Power LLC", "default_currency")
	party_account_currency = get_party_account_currency("Supplier", supplier, "Wind Power LLC")
	if company_currency == party_account_currency:
		exchange_rate = 1
	else:
		exchange_rate = get_exchange_rate(party_account_currency, company_currency)

	# make supplier quotations
	if random.random() < 0.2:
		from erpnext.stock.doctype.material_request.material_request import make_supplier_quotation

		report = "Material Requests for which Supplier Quotations are not created"
		for row in query_report.run(report)["result"][:random.randint(1, 3)]:
			if row[0] != "'Total'":
				sq = frappe.get_doc(make_supplier_quotation(row[0]))
				sq.transaction_date = frappe.flags.current_date
				sq.supplier = supplier
				sq.currency = party_account_currency or company_currency
				sq.conversion_rate = exchange_rate
				sq.insert()
				sq.submit()
				frappe.db.commit()

	# make purchase orders
	if random.random() < 0.5:
		from erpnext.stock.doctype.material_request.material_request import make_purchase_order
		report = "Requested Items To Be Ordered"
		for row in query_report.run(report)["result"][:how_many("Purchase Order")]:
			if row[0] != "'Total'":
				po = frappe.get_doc(make_purchase_order(row[0]))
				po.supplier = supplier
				po.currency = party_account_currency or company_currency
				po.conversion_rate = exchange_rate
				po.transaction_date = frappe.flags.current_date
				po.insert()
				po.submit()
				frappe.db.commit()

	if random.random() < 0.2:
		make_subcontract()