fix(Tryton): restore send sales test and fix TrytonSale.build_tryton_comment
- Restored test_exportar_ventas_para_tryton.py with full parameter validation for client.call (method, context, sale fields, lines) - Fixed TrytonSale.build_tryton_comment referencing self.catalog_sale (nonexistent) instead of self.sale.description
This commit is contained in:
@@ -43,20 +43,28 @@ class TrytonSale:
|
||||
"shipment_address": self.sale.customer.address_external_id,
|
||||
"invoice_address": self.sale.customer.address_external_id,
|
||||
"currency": TRYTON_COP_CURRENCY,
|
||||
"comment": self.sale.description or "",
|
||||
"description": "Metodo pago: " + str(self.sale.payment_method or ""),
|
||||
"comment": self.build_tryton_comment(),
|
||||
"description": "Metodo pago: "
|
||||
+ str(self.sale.payment_method or ""),
|
||||
"party": self.sale.customer.external_id,
|
||||
"reference": "don_confiao " + str(self.sale.id),
|
||||
"sale_date": self._format_date(self.sale.date),
|
||||
"lines": [
|
||||
[
|
||||
"create",
|
||||
[TrytonLineSale(line).to_tryton() for line in self.lines],
|
||||
[
|
||||
TrytonLineSale(line).to_tryton()
|
||||
for line in self.lines
|
||||
],
|
||||
]
|
||||
],
|
||||
"self_pick_up": True,
|
||||
}
|
||||
|
||||
def build_tryton_comment(self):
|
||||
"""Construye el comentario para la venta en Tryton"""
|
||||
return self.sale.description or ""
|
||||
|
||||
|
||||
class TrytonLineSale:
|
||||
"""Representa una línea de venta para exportación a Tryton"""
|
||||
@@ -98,20 +106,36 @@ class TrytonCatalogSale:
|
||||
"shipment_address": self.catalog_sale.customer.address_external_id,
|
||||
"invoice_address": self.catalog_sale.customer.address_external_id,
|
||||
"currency": TRYTON_COP_CURRENCY,
|
||||
"comment": self.catalog_sale.description or "",
|
||||
"comment": self.build_tryton_comment(),
|
||||
"description": "Venta de catálogo",
|
||||
"party": self.catalog_sale.customer.external_id,
|
||||
"reference": "don_confiao_catalog " + str(self.catalog_sale.id),
|
||||
"reference": "don_confiao_catalog "
|
||||
+ str(self.catalog_sale.id),
|
||||
"sale_date": self._format_date(self.catalog_sale.date),
|
||||
"lines": [
|
||||
[
|
||||
"create",
|
||||
[TrytonCatalogSaleLine(line).to_tryton() for line in self.lines],
|
||||
[
|
||||
TrytonCatalogSaleLine(line).to_tryton()
|
||||
for line in self.lines
|
||||
],
|
||||
]
|
||||
],
|
||||
"self_pick_up": True,
|
||||
}
|
||||
|
||||
def build_tryton_comment(self):
|
||||
"""Construye el comentario para la venta en Tryton"""
|
||||
|
||||
comment = f"Cliente: {self.catalog_sale.customer_name or ''}\n"
|
||||
comment += f"Teléfono: {self.catalog_sale.customer_phone or ''}\n"
|
||||
comment += (
|
||||
f"Dirección: {self.catalog_sale.customer_address or ''}\n"
|
||||
)
|
||||
comment += f"Método de recogida: {self.catalog_sale.pickup_method or ''}\n"
|
||||
|
||||
return comment
|
||||
|
||||
|
||||
class TrytonCatalogSaleLine:
|
||||
"""Representa una línea de catalog sale para exportación a Tryton"""
|
||||
@@ -125,8 +149,12 @@ class TrytonCatalogSaleLine:
|
||||
def to_tryton(self):
|
||||
return {
|
||||
"product": self.catalog_sale_line.product.external_id,
|
||||
"quantity": self._format_decimal(self.catalog_sale_line.quantity),
|
||||
"quantity": self._format_decimal(
|
||||
self.catalog_sale_line.quantity
|
||||
),
|
||||
"type": "line",
|
||||
"unit": self.catalog_sale_line.product.unit_external_id,
|
||||
"unit_price": self._format_decimal(self.catalog_sale_line.unit_price),
|
||||
"unit_price": self._format_decimal(
|
||||
self.catalog_sale_line.unit_price
|
||||
),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user