検証に続いて、def clean メソッドでいくつかの簡単な計算を試みています (基本的には、取得した英国の製品価格のユーロ換算をその場で吐き出します)。TypeError が発生し続けます。
完全なエラーの読み取り:
{'product': , 'invoice': , 'order_discount': Decimal("0.00"), 'order_price': {...}, 'order_adjust': None, 'order_value': None, 'DELETE': を変換できませんFalse、'id': 92、'quantity': 8} から 10 進数
したがって、djangoはcleaned_dataフォーム全体をDecimalメソッドに渡していると思います。どこが間違っているのかわからない-私が取り組んでいるコードは次のとおりです。
def clean_order_price(self):
cleaned_data = self.cleaned_data
data = self.data
order_price = cleaned_data.get("order_price")
if not order_price:
try:
existing_price = ProductCostPrice.objects.get(supplier=data['supplier'], product_id=cleaned_data['product'], is_latest=True)
except ProductCostPrice.DoesNotExist:
existing_price = None
if not existing_price:
raise forms.ValidationError('No match found, please enter new price')
else:
if data['invoice_type'] == 1:
return existing_price.cost_price_gross
elif data['invoice_type'] == 2:
exchange = EuroExchangeRate.objects.latest('exchange_date')
calc = exchange.exchange_rate * float(existing_price.cost_price_gross)
calc = Decimal(str(calc))
return calc
return cleaned_data
請求書がタイプ 2 (ユーロ請求書) の場合、システムは最新の為替レートを取得し、それを一致する英国ポンド価格に適用して、ユーロの結果を取得する必要があります。
def clean メソッド内で 10 進変換を実行することは問題になるはずですか?
ありがとう