Compare commits
3 Commits
a7868ba6c8
...
ef315b1479
| Author | SHA1 | Date | |
|---|---|---|---|
| ef315b1479 | |||
| 4b27315372 | |||
| a85a7afec4 |
@ -135,9 +135,9 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
Normaliza campos de detalle de factura desde el registro de origen `fd`.
|
Normaliza campos de detalle de factura desde el registro de origen `fd`.
|
||||||
Escalas:
|
Escalas:
|
||||||
- quantity_value: escala 2 (cents)
|
- quantity_value: escala 2 (cents)
|
||||||
- unit_value: escala 4 (cents4)
|
- unit_amount_value: escala 4 (cents4)
|
||||||
- discount_percentage_value: escala 2 (10 -> 1000)
|
- discount_percentage_value: escala 2 (10 -> 1000)
|
||||||
- total_value: escala 4 (cents4)
|
- total_amount_value: escala 4 (cents4)
|
||||||
- iva_amount: escala 2 (cents), calculado con redondeo a 2 decimales
|
- iva_amount: escala 2 (cents), calculado con redondeo a 2 decimales
|
||||||
-
|
-
|
||||||
"""
|
"""
|
||||||
@ -157,7 +157,7 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
# --- cantidad y precio unitario ---
|
# --- cantidad y precio unitario ---
|
||||||
quantity_value = None if cantidad is None else cents(
|
quantity_value = None if cantidad is None else cents(
|
||||||
cantidad) # escala 2
|
cantidad) # escala 2
|
||||||
unit_value = None if importe_unidad is None else cents4(
|
unit_amount_value = None if importe_unidad is None else cents4(
|
||||||
importe_unidad) # escala 4
|
importe_unidad) # escala 4
|
||||||
|
|
||||||
# --- descuento de linea % (escala 2) ---
|
# --- descuento de linea % (escala 2) ---
|
||||||
@ -182,16 +182,17 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
total_discount_amount_value = discount_amount_value + global_discount_amount_value
|
total_discount_amount_value = discount_amount_value + global_discount_amount_value
|
||||||
|
|
||||||
# --- total de línea (escala 4) ---
|
# --- total de línea (escala 4) ---
|
||||||
total_value = cents4(total_det)
|
total_amount_value = cents4(total_det)
|
||||||
|
|
||||||
if total_value > 0:
|
if total_amount_value > 0:
|
||||||
# DEBE SER LO MISMO LO CALCULADO QUE LO QUE NOS VIENE POR BD DE FACTUGES
|
# DEBE SER LO MISMO LO CALCULADO QUE LO QUE NOS VIENE POR BD DE FACTUGES
|
||||||
logger.info("total con dto linea calculado: %s - total que llega: %s", subtotal_amount_with_dto, total_value)
|
logger.info("total con dto linea calculado: %s - total que llega: %s",
|
||||||
|
subtotal_amount_with_dto, total_amount_value)
|
||||||
|
|
||||||
# la base imponible sobre la que calcular impuestos es el neto menos el dto de linea y dto global
|
# la base imponible sobre la que calcular impuestos es el neto menos el dto de linea y dto global
|
||||||
base = unscale_to_decimal(taxable_amount_value, 4)
|
base = unscale_to_decimal(taxable_amount_value, 4)
|
||||||
|
|
||||||
if total_value > 0:
|
if total_amount_value > 0:
|
||||||
logger.info("base imponible calculada: %s - subtotal: %s - descuentodto: %s - descuentoglobal: %s",
|
logger.info("base imponible calculada: %s - subtotal: %s - descuentodto: %s - descuentoglobal: %s",
|
||||||
base, subtotal_amount_value, discount_amount_value, global_discount_amount_value)
|
base, subtotal_amount_value, discount_amount_value, global_discount_amount_value)
|
||||||
|
|
||||||
@ -219,13 +220,13 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
|
|
||||||
taxes_amount_value = iva_amount_c4 + rec_amount_c4
|
taxes_amount_value = iva_amount_c4 + rec_amount_c4
|
||||||
|
|
||||||
total_value = taxable_amount_value + taxes_amount_value
|
total_amount_value = taxable_amount_value + taxes_amount_value
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'position': int(fd.get("POSICION") or 0),
|
'position': int(fd.get("POSICION") or 0),
|
||||||
'description': rtf_a_texto_plano(str(concepto_rtf or "")),
|
'description': rtf_a_texto_plano(str(concepto_rtf or "")),
|
||||||
'quantity_value': quantity_value,
|
'quantity_value': quantity_value,
|
||||||
'unit_value': unit_value,
|
'unit_amount_value': unit_amount_value,
|
||||||
'subtotal_amount_value': subtotal_amount_value,
|
'subtotal_amount_value': subtotal_amount_value,
|
||||||
'disc_pct': disc_pct,
|
'disc_pct': disc_pct,
|
||||||
'discount_percentage_value': discount_percentage_value,
|
'discount_percentage_value': discount_percentage_value,
|
||||||
@ -234,7 +235,7 @@ def normalize_details_invoice_fields(fd: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
'global_discount_amount_value': global_discount_amount_value,
|
'global_discount_amount_value': global_discount_amount_value,
|
||||||
'total_discount_amount_value': total_discount_amount_value,
|
'total_discount_amount_value': total_discount_amount_value,
|
||||||
'taxable_amount_value': taxable_amount_value,
|
'taxable_amount_value': taxable_amount_value,
|
||||||
'total_value': total_value,
|
'total_amount_value': total_amount_value,
|
||||||
'iva_code': iva_code,
|
'iva_code': iva_code,
|
||||||
'iva_percentage_value': iva_percentage_value,
|
'iva_percentage_value': iva_percentage_value,
|
||||||
'iva_amount_value': iva_amount_c4,
|
'iva_amount_value': iva_amount_c4,
|
||||||
|
|||||||
@ -376,7 +376,7 @@ def insert_item_and_taxes(cur, invoice_id: str, fields: Dict[str, Any]) -> None:
|
|||||||
fields.get("position"),
|
fields.get("position"),
|
||||||
fields.get("description"),
|
fields.get("description"),
|
||||||
fields.get("quantity_value"),
|
fields.get("quantity_value"),
|
||||||
fields.get("unit_value"),
|
fields.get("unit_amount_value"),
|
||||||
fields.get("subtotal_amount_value"),
|
fields.get("subtotal_amount_value"),
|
||||||
fields.get("discount_percentage_value"),
|
fields.get("discount_percentage_value"),
|
||||||
fields.get("discount_amount_value"),
|
fields.get("discount_amount_value"),
|
||||||
@ -384,7 +384,7 @@ def insert_item_and_taxes(cur, invoice_id: str, fields: Dict[str, Any]) -> None:
|
|||||||
fields.get("global_discount_amount_value"),
|
fields.get("global_discount_amount_value"),
|
||||||
fields.get("total_discount_amount_value"),
|
fields.get("total_discount_amount_value"),
|
||||||
fields.get("taxable_amount_value"),
|
fields.get("taxable_amount_value"),
|
||||||
fields.get("total_value"),
|
fields.get("total_amount_value"),
|
||||||
fields.get("iva_code"),
|
fields.get("iva_code"),
|
||||||
fields.get("iva_percentage_value"),
|
fields.get("iva_percentage_value"),
|
||||||
fields.get("iva_amount_value"),
|
fields.get("iva_amount_value"),
|
||||||
@ -396,8 +396,8 @@ def insert_item_and_taxes(cur, invoice_id: str, fields: Dict[str, Any]) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# logger.info("Inserting item tax %s code=%s base=%s tax=%s",
|
# logger.info("Inserting item tax %s code=%s base=%s tax=%s",
|
||||||
# item_id, fields.get('tax_code'), fields.get('total_value'), fields.get('tax_amount'))
|
# item_id, fields.get('tax_code'), fields.get('total_amount_value'), fields.get('tax_amount'))
|
||||||
# cur.execute(
|
# cur.execute(
|
||||||
# SQL.INSERT_INVOICE_ITEM_TAX, (str(uuid7()), item_id, fields.get('tax_code'),
|
# SQL.INSERT_INVOICE_ITEM_TAX, (str(uuid7()), item_id, fields.get('tax_code'),
|
||||||
# fields.get('total_value'), fields.get('tax_amount'))
|
# fields.get('total_amount_value'), fields.get('tax_amount'))
|
||||||
# )
|
# )
|
||||||
|
|||||||
@ -67,7 +67,7 @@ def calc_discount_cents4(subtotal_cents4: int, disc_pct: Optional[Decimal | floa
|
|||||||
pct = Decimal(str(disc_pct or 0))
|
pct = Decimal(str(disc_pct or 0))
|
||||||
# descuento = round(subtotal * pct / 100) en la MISMA escala (×10000)
|
# descuento = round(subtotal * pct / 100) en la MISMA escala (×10000)
|
||||||
disc = (Decimal(subtotal_cents4) * pct / Decimal(100)).to_integral_value(rounding=ROUND_HALF_UP)
|
disc = (Decimal(subtotal_cents4) * pct / Decimal(100)).to_integral_value(rounding=ROUND_HALF_UP)
|
||||||
return disc
|
return int(disc)
|
||||||
|
|
||||||
|
|
||||||
def apply_discount_cents4(subtotal_cents4: int, disc_pct: Optional[Decimal | float | int]) -> Tuple[int, int]:
|
def apply_discount_cents4(subtotal_cents4: int, disc_pct: Optional[Decimal | float | int]) -> Tuple[int, int]:
|
||||||
|
|||||||
@ -67,7 +67,7 @@ def insert_item_and_taxes(fields) -> Dict[str, Any]:
|
|||||||
"position": str(fields.get("position")),
|
"position": str(fields.get("position")),
|
||||||
"description": str(none_to_empty(fields.get("description"))),
|
"description": str(none_to_empty(fields.get("description"))),
|
||||||
"quantity_value": str(none_to_empty(fields.get("quantity_value"))),
|
"quantity_value": str(none_to_empty(fields.get("quantity_value"))),
|
||||||
"unit_value": str(none_to_empty(fields.get("unit_value"))),
|
"unit_amount_value": str(none_to_empty(fields.get("unit_amount_value"))),
|
||||||
"subtotal_amount_value": str(fields.get("subtotal_amount_value")),
|
"subtotal_amount_value": str(fields.get("subtotal_amount_value")),
|
||||||
"item_discount_percentage_value": str(none_to_empty(fields.get("item_discount_percentage_value"))),
|
"item_discount_percentage_value": str(none_to_empty(fields.get("item_discount_percentage_value"))),
|
||||||
"item_discount_amount_value": str(none_to_empty(fields.get("item_discount_amount_value"))),
|
"item_discount_amount_value": str(none_to_empty(fields.get("item_discount_amount_value"))),
|
||||||
@ -75,7 +75,7 @@ def insert_item_and_taxes(fields) -> Dict[str, Any]:
|
|||||||
"global_discount_amount_value": str(none_to_empty(fields.get("global_discount_amount_value"))),
|
"global_discount_amount_value": str(none_to_empty(fields.get("global_discount_amount_value"))),
|
||||||
"total_discount_amount_value": str(fields.get("total_discount_amount_value")),
|
"total_discount_amount_value": str(fields.get("total_discount_amount_value")),
|
||||||
"taxable_amount_value": str(fields.get("taxable_amount_value")),
|
"taxable_amount_value": str(fields.get("taxable_amount_value")),
|
||||||
"total_value": str(fields.get("total_value")),
|
"total_amount_value": str(fields.get("total_amount_value")),
|
||||||
"iva_code": str(fields.get("iva_code")),
|
"iva_code": str(fields.get("iva_code")),
|
||||||
"iva_percentage_value": str(str(fields.get("iva_percentage_value"))),
|
"iva_percentage_value": str(str(fields.get("iva_percentage_value"))),
|
||||||
"iva_amount_value": str(fields.get("iva_amount_value")),
|
"iva_amount_value": str(fields.get("iva_amount_value")),
|
||||||
@ -86,8 +86,8 @@ def insert_item_and_taxes(fields) -> Dict[str, Any]:
|
|||||||
}
|
}
|
||||||
|
|
||||||
# logger.info("Inserting item tax %s code=%s base=%s tax=%s",
|
# logger.info("Inserting item tax %s code=%s base=%s tax=%s",
|
||||||
# item_id, fields.get('tax_code'), fields.get('total_value'), fields.get('tax_amount'))
|
# item_id, fields.get('tax_code'), fields.get('total_amount_value'), fields.get('tax_amount'))
|
||||||
# cur.execute(
|
# cur.execute(
|
||||||
# SQL.INSERT_INVOICE_ITEM_TAX, (str(uuid7()), item_id, fields.get('tax_code'),
|
# SQL.INSERT_INVOICE_ITEM_TAX, (str(uuid7()), item_id, fields.get('tax_code'),
|
||||||
# fields.get('total_value'), fields.get('tax_amount'))
|
# fields.get('total_amount_value'), fields.get('tax_amount'))
|
||||||
# )
|
# )
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user