def cfdis_usd(move_type=move_type_arg, excel_file=excel_file_arg, sheet_name=sheet_name_arg, serie_doc=serie_doc_arg): #out_refund customer_refunds.xlsx FEBRERO NCSAQ- try: dt = pd.read_excel(excel_file, sheet_name) xmlfile = '' directorio = "cfdis/QUINVALUSD/" for exl_row in dt.iterrows(): payment_reference = exl_row[1]['edi_document'] xmlfile = "{}{}.xml".format(directorio, payment_reference) if not Path(xmlfile).is_file(): print("Factura {} con Archivo XML: {}, NO ENCONTRADO".format(payment_reference, xmlfile)) continue domain = [[['name', '=', payment_reference], ['move_type', '=', move_type]]] invoices = models.execute_kw(db, uid, password, 'account.move', 'search_read', domain, {'fields': ['id', 'name', 'partner_id', 'l10n_mx_edi_usage', 'attachment_ids', 'edi_document_ids', 'currency_id', 'company_id', 'payment_reference', 'state', 'ref']}) fnstocall = ['action_post', 'action_process_edi_web_services'] if not invoices: print("Factura {} , no encontrada en Odoo".format(exl_row[1]['edi_document'])) continue for inv in invoices: #elimino cualquier attachment print("Procesando Factura {}".format(inv['payment_reference']), end=', ') for att in inv['edi_document_ids']: models.execute_kw(db, uid, password, 'account.edi.document', 'unlink', [att]) if inv['state'] == 'posted': try: models.execute_kw(db, uid, password, 'account.move', 'button_draft', [[int(inv['id'])]]) except Exception as err: pass try: readxml(inv, xmlfile) except Exception as err: pass for i in range(0, 2): try: models.execute_kw(db, uid, password, 'account.move', fnstocall[i], [[int(inv['id'])]]) except Exception as err: pass try: readxml(inv, xmlfile, inv['attachment_ids'][0]) except Exception as err: pass print("UUID y XML agregados") except Exception as err: print(repr(err)) return
def dopandas(): try: dt = pd.read_excel('customer_invoices.xlsx', 'DOLARES') xmlfile = '' for exl_row in dt.iterrows(): xmlfile = "cfdis/" + exl_row[1]['Nombre XML'] + ".xml" if not Path(xmlfile).is_file(): print("Factura {} con Archivo XML: {}, NO ENCONTRADO".format(exl_row[1]['edi_document'], xmlfile)) continue domain = [[['payment_reference', '=', exl_row[1]['edi_document']], ['move_type', '=', 'out_invoice']]] invoices = models.execute_kw(db, uid, password, 'account.move', 'search_read', domain, {'fields': ['id', 'name', 'partner_id', 'l10n_mx_edi_usage', 'attachment_ids', 'edi_document_ids', 'payment_reference', 'state']}) fnstocall = ['action_post', 'action_process_edi_web_services'] if not invoices: print("Factura {} , no encontrada en Odoo".format(exl_row[1]['edi_document'])) continue for inv in invoices: #elimino cualquier attachment print("Procesando Factura {}".format(inv['payment_reference']), end=', ') if inv['state'] != 'draft': print("YA PROCESADA") continue for att in inv['edi_document_ids']: models.execute_kw(db, uid, password, 'ir.attachment', 'unlink', [att]) for att in inv['attachment_ids']: models.execute_kw(db, uid, password, 'ir.attachment', 'unlink', [att]) #valido que tenga error el timbrado y confirmo la factura y genero con el error del CFDI #if inv['l10n_mx_edi_usage']: # models.execute_kw(db, uid, password, 'account.move', 'write', # [[inv['id']], {'l10n_mx_edi_usage': False}]) for i in range(0, 2): try: models.execute_kw(db, uid, password, 'account.move', fnstocall[i], [[int(inv['id'])]]) except Exception as err: pass savecfdi(inv['id'], xmlfile) print("UUID y XML agregados") except Exception as err: print(repr(err)) return
def cfdis_update(move_type=move_type_arg, excel_file=excel_file_arg, sheet_name=sheet_name_arg, serie_doc=serie_doc_arg): #out_refund customer_refunds.xlsx FEBRERO NCSAQ- try: dt = pd.read_excel(excel_file, sheet_name) xmlfile = '' directorio = "/Users/turbo/Downloads/" for exl_row in dt.iterrows(): payment_reference = int(exl_row[1]['edi_document']) xmlfile = "{}{}.xml".format(directorio, exl_row[1]['Nombre XML']) if not Path(xmlfile).is_file(): print("Factura {} con Archivo XML: {}, NO ENCONTRADO".format(payment_reference, xmlfile)) continue domain = [[['id', '=', payment_reference]]] invoices = models.execute_kw(db, uid, password, 'account.move', 'search_read', domain, {'fields': ['id', 'name', 'partner_id', 'l10n_mx_edi_usage', 'attachment_ids', 'edi_document_ids', 'currency_id', 'company_id', 'payment_reference', 'state', 'ref']}) if not invoices: print("Factura {} , no encontrada en Odoo".format(exl_row[1]['edi_document'])) continue for inv in invoices: #elimino cualquier attachment print("Procesando Factura {}".format(inv['payment_reference']), end=', ') try: updatecfdi(inv['attachment_ids'][0], inv['edi_document_ids'][0], xmlfile) #models.execute_kw(db, uid, password, 'account.move', 'action_process_edi_web_services', [[int(inv['id'])]]) except Exception as err: pass print("UUID y XML agregados") except Exception as err: print(repr(err)) return
def docfdis(move_type=move_type_arg, excel_file=excel_file_arg, sheet_name=sheet_name_arg): try: dt = pd.read_excel(excel_file, sheet_name) xmlfile = '' directorio = "cfdis/" for exl_row in dt.iterrows(): xmlfile = directorio + exl_row[1]['edi_document'] payment_reference = exl_row[1]['payment_reference'] if not Path(xmlfile).is_file(): print("Factura {} con Archivo XML: {}, NO ENCONTRADO".format( payment_reference, xmlfile)) continue domain = [[['payment_reference', '=', str(payment_reference)], ['move_type', '=', move_type]]] invoices = models.execute_kw( db, uid, password, 'account.move', 'search_read', domain, { 'fields': [ 'id', 'name', 'partner_id', 'l10n_mx_edi_usage', 'invoice_date', 'invoice_date_due', 'currency_id' 'attachment_ids', 'edi_document_ids', 'payment_reference', 'state', 'ref' ] }) fnstocall = ['action_post', 'action_process_edi_web_services'] if not invoices: print("Factura {} , no encontrada en Odoo".format( exl_row[1]['payment_reference'])) continue for inv in invoices: #elimino cualquier attachment print("Procesando Factura {}".format(inv['payment_reference']), end=', ') if inv['state'] != 'draft': print("YA PROCESADA") continue for att in inv['edi_document_ids']: models.execute_kw(db, uid, password, 'account.edi.document', 'unlink', [att]) for att in inv['attachment_ids']: models.execute_kw(db, uid, password, 'ir.attachment', 'unlink', [att]) #guardo la fechas de factura, porque al confirmar se alteran invoice_date = inv['invoice_date'] invoice_date_due = inv['invoice_date_due'] #valido que tenga error el timbrado y confirmo la factura y genero con el error del CFDI dicttoupdate = {} if inv['l10n_mx_edi_usage']: dicttoupdate = {'l10n_mx_edi_usage': False} if dicttoupdate: models.execute_kw(db, uid, password, 'account.move', 'write', [[inv['id']], dicttoupdate]) for i in range(0, 2): try: models.execute_kw(db, uid, password, 'account.move', fnstocall[i], [[int(inv['id'])]]) except Exception as err: pass savecfdi(inv['id'], xmlfile, invoice_date, invoice_date_due) print("UUID y XML agregados") except Exception as err: print(repr(err)) return
def docfdisprod(move_type=move_type_arg, excel_file=excel_file_arg, sheet_name=sheet_name_arg, serie_doc=serie_doc_arg): #out_invoice ventas_marzo.xlsx Sheet1 SAQFC- try: directorio = "cfdis/MARZO 21" dt = pd.read_excel(excel_file, sheet_name) xmlfile = '' xmlfiles = os.listdir(directorio) for exl_row in dt.iterrows(): folio_excel = str(int(exl_row[1]['Factura'])) if not folio_excel: print("El Pedido {} no tiene factura asignada".format(exl_row[1]['Referencia del pedido'])) continue xmlfile = "2021-03 F-{}".format(folio_excel) r = re.compile(xmlfile) lstxml = list(filter(r.match, xmlfiles)) if not lstxml: print("Factura {} sin Archivo XML, NO ENCONTRADO".format(xmlfile)) continue xmlfile = "{}/{}".format(directorio, lstxml[0]) sfolio = get_folio_from_cfdi(xmlfile) if sfolio != str(folio_excel): print("La factura {} en la orden de Compra {} " "no coincide con la del XML {}".format(folio_excel, exl_row[1]['Referencia del pedido'], sfolio)) else: print("Compra {}, con Factura {} OK".format(exl_row[1]['Referencia del pedido'], sfolio), end=", ") domain = [[['id', '=', exl_row[1]['ID']]]] so = models.execute_kw(db, uid, password, 'sale.order', 'search_read', domain, {'fields': ['id', 'name', 'partner_id', 'payment_term_id', 'currency_id', 'date_order', 'invoice_ids']})[0] # if so['currency_id'][1] != 'MXN': # print("es en moneda extranjera") # continue sale_date = so['date_order'] partner_id = so['partner_id'][0] if not so['invoice_ids']: print( "NO tiene factura generada") continue invoice_id = so['invoice_ids'][0] so_payment_id = 1 if so['payment_term_id']: so_payment_id = so['payment_term_id'][0] domain = [[['id', '=', partner_id]]] partner = models.execute_kw(db, uid, password, 'res.partner', 'search_read', domain, {'fields': ['property_payment_term_id', 'property_account_receivable_id']}) partner_payment_id = partner[0]['property_payment_term_id'][0] partner_account_id = partner[0]['property_account_receivable_id'][0] payment_reference = "{}{}".format(serie_doc, exl_row[1]['Factura']) dicttoupdate = {'payment_reference': payment_reference} term_lines = False if so_payment_id != partner_payment_id: domain = [[['id', '=', partner_payment_id]]] dicttoupdate.update({'invoice_payment_term_id': partner_payment_id}) else: domain = [[['id', '=', so_payment_id]]] payment_term = models.execute_kw(db, uid, password, 'account.payment.term', 'search_read', domain, {'fields': ['id', 'line_ids']}) term_lines = payment_term[0]['line_ids'] domain = domain = [[['id', '=', invoice_id]]] invoices = models.execute_kw(db, uid, password, 'account.move', 'search_read', domain, {'fields': ['id', 'name', 'partner_id', 'l10n_mx_edi_usage', 'attachment_ids', 'edi_document_ids', 'payment_reference', 'state', 'ref']}) fnstocall = ['action_post', 'action_process_edi_web_services'] if not invoices: print("Factura {} , no encontrada en Odoo".format(exl_row[1]['Factura'])) continue for inv in invoices: #elimino cualquier attachment if inv['state'] != 'draft': print("YA PROCESADA") continue for att in inv['edi_document_ids']: models.execute_kw(db, uid, password, 'account.edi.document', 'unlink', [att]) for att in inv['attachment_ids']: models.execute_kw(db, uid, password, 'ir.attachment', 'unlink', [att]) #valido que tenga error el timbrado y confirmo la factura y genero con el error del CFDI #dicttoupdate.update({'l10n_mx_edi_usage': False}) originalcfdiuuid = False if move_type == 'out_refund': originalcfdiuuid = getoriginalcfdiuuid(inv['ref']) dicttoupdate.update({'l10n_mx_edi_origin': originalcfdiuuid}) models.execute_kw(db, uid, password, 'account.move', 'write', [[inv['id']], dicttoupdate]) date_due = False for i in range(0, 2): try: models.execute_kw(db, uid, password, 'account.move', fnstocall[i], [[int(inv['id'])]]) date_due = update_movelines(inv['id'], term_lines, partner_account_id, sale_date, payment_reference) except Exception as err: pass savecfdi(inv['id'], xmlfile, serie_doc, sale_date, date_due) print("UUID y XML agregados") except Exception as err: print(repr(err)) return
def docfdis(move_type=move_type_arg, excel_file=excel_file_arg, sheet_name=sheet_name_arg, serie_doc=serie_doc_arg): #out_refund customer_refunds.xlsx FEBRERO NCSAQ- try: dt = pd.read_excel(excel_file, sheet_name) xmlfile = '' directorio = "cfdis/" for exl_row in dt.iterrows(): xmlfile = directorio + exl_row[1]['Nombre XML'] + ".xml" payment_reference = exl_row[1]['edi_document'] if not Path(xmlfile).is_file(): print("Factura {} con Archivo XML: {}, NO ENCONTRADO".format(payment_reference, xmlfile)) continue domain = [[['payment_reference', '=', str(payment_reference)], ['move_type', '=', move_type]]] invoices = models.execute_kw(db, uid, password, 'account.move', 'search_read', domain, {'fields': ['id', 'name', 'partner_id', 'l10n_mx_edi_usage', 'attachment_ids', 'edi_document_ids', 'payment_reference', 'state', 'ref']}) fnstocall = ['action_post', 'action_process_edi_web_services'] if not invoices: print("NC {} , no encontrada en Odoo".format(exl_row[1]['edi_document'])) continue for inv in invoices: #elimino cualquier attachment print("Procesando NC {}".format(inv['payment_reference']), end=', ') if inv['state'] != 'draft': print("YA PROCESADA") continue for att in inv['edi_document_ids']: models.execute_kw(db, uid, password, 'account.edi.document', 'unlink', [att]) for att in inv['attachment_ids']: models.execute_kw(db, uid, password, 'ir.attachment', 'unlink', [att]) #valido que tenga error el timbrado y confirmo la factura y genero con el error del CFDI #dicttoupdate = {'l10n_mx_edi_usage': False} dicttoupdate = {} originalcfdiuuid = False #if move_type == 'out_refund': # originalcfdiuuid = getoriginalcfdiuuid(inv['ref']) # dicttoupdate.update({'l10n_mx_edi_origin': originalcfdiuuid}) if originalcfdiuuid: models.execute_kw(db, uid, password, 'account.move', 'write', [[inv['id']], dicttoupdate]) for i in range(0, 2): try: models.execute_kw(db, uid, password, 'account.move', fnstocall[i], [[int(inv['id'])]]) except Exception as err: pass savecfdi(inv['id'], xmlfile, serie_doc, '2021-03-16', '2021-06-14') print("UUID y XML agregados") except Exception as err: print(repr(err)) return