fix: upgrade process to version-14 when currency opportunity wass not set

This commit is contained in:
Florian HENRY 2022-08-25 20:45:35 +02:00
parent 902797d0f0
commit 9d02fbadb4

View File

@ -4,6 +4,8 @@ from frappe.utils import flt
import erpnext import erpnext
from erpnext.setup.utils import get_exchange_rate from erpnext.setup.utils import get_exchange_rate
import click
def execute(): def execute():
frappe.reload_doctype("Opportunity") frappe.reload_doctype("Opportunity")
@ -16,6 +18,19 @@ def execute():
for opportunity in opportunities: for opportunity in opportunities:
company_currency = erpnext.get_company_currency(opportunity.company) company_currency = erpnext.get_company_currency(opportunity.company)
if opportunity.currency is None or opportunity.currency == '':
opportunity.currency = company_currency
frappe.db.set_value(
"Opportunity",
opportunity.name,
{"currency": opportunity.currency},
update_modified=False,
)
click.secho(
f" Opportunity `{opportunity.name}` has no currency set. We for it to company currency : `{opportunity.currency}`\"\n",
fg="yellow",
)
# base total and total will be 0 only since item table did not have amount field earlier # base total and total will be 0 only since item table did not have amount field earlier
if opportunity.currency != company_currency: if opportunity.currency != company_currency:
conversion_rate = get_exchange_rate(opportunity.currency, company_currency) conversion_rate = get_exchange_rate(opportunity.currency, company_currency)
@ -24,6 +39,10 @@ def execute():
conversion_rate = 1 conversion_rate = 1
base_opportunity_amount = flt(opportunity.opportunity_amount) base_opportunity_amount = flt(opportunity.opportunity_amount)
if conversion_rate is None:
print(opportunity.name,conversion_rate,opportunity.currency)
frappe.db.set_value( frappe.db.set_value(
"Opportunity", "Opportunity",
opportunity.name, opportunity.name,