fix(#10): Corregir generación de código de barras en etiquetas

- Agregar método _ensure_barcode() para generar códigos faltantes
- Llamar _ensure_barcode() antes de imprimir etiquetas
- Usar name del lote como fallback si no hay barcode
- Manejar casos donde el campo barcode está vacío

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Luis Ernesto Portillo Zaldivar 2025-07-15 20:51:26 -06:00
parent 4b27b34189
commit 2c76b97402
3 changed files with 19 additions and 2 deletions

View File

@ -301,6 +301,9 @@ class SaleOrder(models.Model):
if not self.generated_sample_ids:
raise UserError(_('No hay muestras generadas para esta orden. Por favor, confirme la orden primero.'))
# Asegurar que todas las muestras tengan código de barras
self.generated_sample_ids._ensure_barcode()
# Obtener el reporte
report = self.env.ref('lims_management.action_report_sample_label')

View File

@ -229,3 +229,10 @@ class StockLot(models.Model):
even_sum = sum([sum(divmod(2 * d, 10)) for d in digits[-2::-2]])
total = odd_sum + even_sum
return (10 - (total % 10)) % 10
def _ensure_barcode(self):
"""Ensure all lab samples have a barcode"""
for record in self:
if record.is_lab_sample and not record.barcode:
record.barcode = record._generate_unique_barcode()
return True

View File

@ -58,8 +58,15 @@
<!-- Código de barras -->
<div style="text-align: center; margin-top: 3mm;">
<img t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s&amp;humanreadable=%s' % ('Code128', o.barcode, 250, 60, 1)"
style="width: 250px; height: 60px;"/>
<t t-if="o.barcode">
<img t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s&amp;humanreadable=%s' % ('Code128', o.barcode, 250, 60, 1)"
style="width: 250px; height: 60px;"/>
</t>
<t t-else="">
<!-- Si no hay barcode, usar el name del lote -->
<img t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s&amp;humanreadable=%s' % ('Code128', o.name, 250, 60, 1)"
style="width: 250px; height: 60px;"/>
</t>
</div>
<!-- Análisis a realizar (si caben) -->