From 2269fc7709481c564208f18b3d201ef356194b62 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Tue, 20 Jan 2026 20:59:36 +0100 Subject: [PATCH] 20.01.26 --- modules/purchase_trade/weight_report.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/purchase_trade/weight_report.py b/modules/purchase_trade/weight_report.py index 68b6faa..697688a 100644 --- a/modules/purchase_trade/weight_report.py +++ b/modules/purchase_trade/weight_report.py @@ -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] \ No newline at end of file