import xhiveframework


def execute():
	xhiveframework.reload_doctype("Pricing Rule")

	currency = xhiveframework.db.get_default("currency")
	for doc in xhiveframework.get_all("Pricing Rule", fields=["company", "name"]):
		if doc.company:
			currency = xhiveframework.get_cached_value("Company", doc.company, "default_currency")

		xhiveframework.db.sql(
			"""update `tabPricing Rule` set currency = %s where name = %s""", (currency, doc.name)
		)
