Se añade la inserción de las formas de pago a la nueva base de datos
This commit is contained in:
parent
0b5fac15af
commit
b25df0ce9b
@ -167,14 +167,19 @@ def insertar_datos(conn_mysql, filas, conn_factuges, config):
|
||||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 1, 'es', 'EUR', 'active', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) "
|
||||
)
|
||||
|
||||
insert_payment_methods_query = (
|
||||
"INSERT INTO payment_methods (id, description, factuges_id, created_at, updated_at ) "
|
||||
"VALUES (%s, %s, %s, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) "
|
||||
)
|
||||
|
||||
insert_customer_invoices_query = (
|
||||
"INSERT INTO customer_invoices (id, company_id, status, series, invoice_number, invoice_date, operation_date, "
|
||||
"subtotal_amount_value, discount_amount_value, discount_percentage_value, taxable_amount_value, taxes_amount_value, total_amount_value, "
|
||||
# "payment_method_id, payment_method_description, "
|
||||
"customer_id, customer_tin, customer_name, customer_street, customer_city, customer_province, customer_postal_code, customer_country, "
|
||||
"payment_method_id, payment_method_description, "
|
||||
"subtotal_amount_scale, discount_amount_scale, discount_percentage_scale, taxable_amount_scale, taxes_amount_scale, total_amount_scale, "
|
||||
"language_code, currency_code, created_at, updated_at) "
|
||||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 2, 2, 2, 2, 2, 2, 'es', 'EUR', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
|
||||
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 2, 2, 2, 2, 2, 2, 'es', 'EUR', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)"
|
||||
)
|
||||
|
||||
insert_customer_invoices_taxes_query = (
|
||||
@ -204,6 +209,12 @@ def insertar_datos(conn_mysql, filas, conn_factuges, config):
|
||||
"WHERE customers.factuges_id = %s"
|
||||
)
|
||||
|
||||
select_payment_method_query = (
|
||||
"SELECT payment_methods.id "
|
||||
"FROM payment_methods "
|
||||
"WHERE payment_methods.factuges_id = %s"
|
||||
)
|
||||
|
||||
cursorMySQL = None
|
||||
cursor_FactuGES = None
|
||||
factuges_id_anterior = None
|
||||
@ -245,7 +256,9 @@ def insertar_datos(conn_mysql, filas, conn_factuges, config):
|
||||
(factura_detalle['IMPORTE_IVA'] or 0) + (factura_detalle['IMPORTE_RE'] or 0))*100
|
||||
|
||||
total_amount_value = (factura_detalle['IMPORTE_TOTAL'] or 0)*100
|
||||
payment_method_id = str(factura_detalle['ID_FORMA_PAGO'])
|
||||
|
||||
payment_method_id = str(uuid4())
|
||||
factuges_payment_method_id = str(factura_detalle['ID_FORMA_PAGO'])
|
||||
payment_method_description = str(factura_detalle['DES_FORMA_PAGO'])
|
||||
|
||||
customer_id = str(uuid4())
|
||||
@ -271,9 +284,11 @@ def insertar_datos(conn_mysql, filas, conn_factuges, config):
|
||||
factura_detalle['CANTIDAD'] or 0)*100
|
||||
item_unit_amount_value = None if factura_detalle['IMPORTE_UNIDAD'] is None else (
|
||||
factura_detalle['IMPORTE_UNIDAD'] or 0)*10000
|
||||
item_discount_percentage_value = (
|
||||
factura_detalle['DESCUENTO'] or 0)*100
|
||||
Descuento = factura_detalle['DESCUENTO']
|
||||
item_discount_percentage_value = None if Descuento is None else None if Descuento == 0 else (
|
||||
factura_detalle['DESCUENTO'])*100
|
||||
item_discount_amount = None
|
||||
# Se calcula en el objeto de negocio de nuevo, comprobar si coincide
|
||||
# item_discount_amount = (
|
||||
# (factura_detalle['IMPORTE_UNIDAD'] or 0)*((factura_detalle['DESCUENTO'] or 0)/100))*100
|
||||
item_total_amount = None if factura_detalle['IMPORTE_TOTAL_DET'] is None else (
|
||||
@ -284,8 +299,8 @@ def insertar_datos(conn_mysql, filas, conn_factuges, config):
|
||||
# xxxxxxx = str(factura_detalle['ID_FORMA_PAGO']) según este id se debe de guardar en la factura los vencimiento asociados a la forma de pago
|
||||
# xxxxxxx = str(factura_detalle['OBSERVACIONES'])
|
||||
|
||||
# Comprobamos si existe el cliente del primer item de la factura
|
||||
if factuges_id_anterior is None or factuges_id_anterior != factuges_id:
|
||||
# Comprobamos si existe el cliente del primer item de la factura
|
||||
cursorMySQL.execute(select_customer_query,
|
||||
(factuges_customer_id, ))
|
||||
row = cursorMySQL.fetchone()
|
||||
@ -304,6 +319,24 @@ def insertar_datos(conn_mysql, filas, conn_factuges, config):
|
||||
f"Updating customer {factuges_customer_id} {customer_id}")
|
||||
# cursorMySQL.execute(update_customer_query, .....)
|
||||
|
||||
# Comprobamos si existe la forma de pago del primer item de la factura
|
||||
cursorMySQL.execute(select_payment_method_query,
|
||||
(factuges_payment_method_id, ))
|
||||
row = cursorMySQL.fetchone()
|
||||
is_new = (row is None) or (row[0] is None)
|
||||
|
||||
if is_new:
|
||||
logging.info(
|
||||
f"Inserting cuspayment method {factuges_payment_method_id} {payment_method_id} {payment_method_description}")
|
||||
cursorMySQL.execute(insert_payment_methods_query, (
|
||||
payment_method_id, payment_method_description, factuges_payment_method_id))
|
||||
else:
|
||||
# Si ya exite ponemos el id del customer correspondiente
|
||||
payment_method_id = str(row[0])
|
||||
logging.info(
|
||||
f"Updating customer {factuges_payment_method_id} {payment_method_id}")
|
||||
# cursorMySQL.execute(update_customer_query, .....)
|
||||
|
||||
# Insertamos cabecera de la factura
|
||||
# Generar un ID único para la tabla customer_invoices
|
||||
id_customer_invoice = str(uuid4())
|
||||
@ -311,8 +344,8 @@ def insertar_datos(conn_mysql, filas, conn_factuges, config):
|
||||
f"Inserting customer_invoice {id_customer_invoice} {invoice_number} {invoice_date}")
|
||||
cursorMySQL.execute(insert_customer_invoices_query, (id_customer_invoice, cte_company_id, invoice_status, invoice_series, invoice_number, invoice_date, operation_date,
|
||||
subtotal_amount_value, discount_amount_value, discount_percentage_value, taxable_amount_value, tax_amount_value, total_amount_value,
|
||||
# payment_method_id, payment_method_description,
|
||||
customer_id, customer_tin, customer_name, customer_street, customer_city, customer_province, customer_postal_code, customer_country))
|
||||
customer_id, customer_tin, customer_name, customer_street, customer_city, customer_province, customer_postal_code, customer_country,
|
||||
payment_method_id, payment_method_description))
|
||||
|
||||
# Insertamos el IVA y RE si viene
|
||||
if (factura_detalle['IVA'] > 0):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user