20.01.26
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pool import Pool
|
||||
from decimal import Decimal
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
from datetime import datetime as dt
|
||||
|
||||
class WeightReport(ModelSQL, ModelView):
|
||||
@@ -169,12 +169,21 @@ class WeightReport(ModelSQL, ModelView):
|
||||
|
||||
# 6. Weights Information
|
||||
weights_data = json_data.get('weights', {})
|
||||
report['gross_landed_kg'] = Decimal(weights_data.get('gross_landed_kg', 0) or 0)
|
||||
report['tare_kg'] = Decimal(weights_data.get('tare_kg', 0) or 0)
|
||||
report['net_landed_kg'] = Decimal(weights_data.get('net_landed_kg', 0) or 0)
|
||||
report['invoice_net_kg'] = Decimal(weights_data.get('invoice_net_kg', 0) or 0)
|
||||
report['gain_loss_kg'] = Decimal(weights_data.get('gain_loss_kg', 0) or 0)
|
||||
report['gain_loss_percent'] = Decimal(weights_data.get('gain_loss_percent', 0) or 0)
|
||||
|
||||
gross = Decimal(str(weights_data.get('gross_landed_kg', 0) or 0))
|
||||
tare = Decimal(str(weights_data.get('tare_kg', 0) or 0))
|
||||
net = Decimal(str(weights_data.get('net_landed_kg', 0) or 0))
|
||||
invoice = Decimal(str(weights_data.get('invoice_net_kg', 0) or 0))
|
||||
gain_loss = Decimal(str(weights_data.get('gain_loss_kg', 0) or 0))
|
||||
gain_loss_percent = Decimal(str(weights_data.get('gain_loss_percent', 0) or 0))
|
||||
|
||||
# Arrondir à 2 décimales
|
||||
report['gross_landed_kg'] = gross.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
report['tare_kg'] = tare.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
report['net_landed_kg'] = net.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
report['invoice_net_kg'] = invoice.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
report['gain_loss_kg'] = gain_loss.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
report['gain_loss_percent'] = gain_loss_percent.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
|
||||
# 7. Création du rapport
|
||||
return cls.create([report])[0]
|
||||
Reference in New Issue
Block a user