feature/correccion-enteros-csv

This commit is contained in:
2026-04-17 08:42:52 -06:00
parent eabc3e5b42
commit 82c319afea
3 changed files with 38 additions and 214 deletions

View File

@@ -86,6 +86,11 @@ class DownloadedPartsReportService:
return ''
return value.replace(',', ' ').replace('\r', ' ').replace('\n', ' ').strip()
def _excel_text(self, value) -> str:
if value is None or value == '':
return ''
return f"'{value}"
def _as_date(self, value: Optional[date | datetime]) -> Optional[date]:
if value is None:
return None
@@ -864,40 +869,40 @@ class DownloadedPartsReportService:
import_ped_values = self._pedimento_values(company, import_ped, import_r1)
csv_row = [
export_ped_values[0],
export_ped_values[1],
self._format_date(row.expo_payment_date, req.julian_date),
row.expo_clave or '',
self._format_date(row.discharge_date, req.julian_date),
row.expo_invoice_number or '',
self._format_date(row.expo_invoice_date, req.julian_date),
class_code,
description_value,
export_fraction,
self._excel_text(export_ped_values[0]),
self._excel_text(export_ped_values[1]),
self._excel_text(self._format_date(row.expo_payment_date, req.julian_date)),
self._excel_text(row.expo_clave or ''),
self._excel_text(self._format_date(row.discharge_date, req.julian_date)),
self._excel_text(row.expo_invoice_number or ''),
self._excel_text(self._format_date(row.expo_invoice_date, req.julian_date)),
self._excel_text(class_code),
self._excel_text(description_value),
self._excel_text(export_fraction),
self._decimal_str(quantity, 4),
row.unit_of_measure or '',
import_ped_values[0],
import_ped_values[1],
self._format_date(row.impo_payment_date, req.julian_date),
row.import_invoice_number or row.import_invoice_str or '',
self._format_date(row.impo_invoice_date, req.julian_date),
self._excel_text(row.unit_of_measure or ''),
self._excel_text(import_ped_values[0]),
self._excel_text(import_ped_values[1]),
self._excel_text(self._format_date(row.impo_payment_date, req.julian_date)),
self._excel_text(row.import_invoice_number or row.import_invoice_str or ''),
self._excel_text(self._format_date(row.impo_invoice_date, req.julian_date)),
self._decimal_str(weight_kgs, 4),
self._decimal_str(value_me),
self._decimal_str(value_mn),
self._decimal_str(selected_rate, 6) if selected_rate else '',
row.part_number_str or '',
part_description,
row.material_key or '',
class_fraction,
import_ped_18,
export_ped_18,
row.tariff_uom or '',
self._excel_text(row.part_number_str or ''),
self._excel_text(part_description),
self._excel_text(row.material_key or ''),
self._excel_text(class_fraction),
self._excel_text(import_ped_18),
self._excel_text(export_ped_18),
self._excel_text(row.tariff_uom or ''),
]
if req.include_american_fraction_and_country:
csv_row.extend([
row.american_fraction or '',
row.country_of_origin or '',
self._excel_text(row.american_fraction or ''),
self._excel_text(row.country_of_origin or ''),
])
writer.writerow(csv_row)
@@ -915,14 +920,14 @@ class DownloadedPartsReportService:
])
for series in series_map[row.export_line_id]:
writer.writerow([
series.row or '',
series.serial_numbers or '',
series.model or '',
series.sub_model or '',
row.part_number_str or '',
series.number_id or '',
row.export_brand or '',
row.export_model or '',
self._excel_text(series.row or ''),
self._excel_text(series.serial_numbers or ''),
self._excel_text(series.model or ''),
self._excel_text(series.sub_model or ''),
self._excel_text(row.part_number_str or ''),
self._excel_text(series.number_id or ''),
self._excel_text(row.export_brand or ''),
self._excel_text(row.export_model or ''),
])
flush_class_total()