-
Notifications
You must be signed in to change notification settings - Fork 8
/
import_factura_linea.py
73 lines (59 loc) · 2.28 KB
/
import_factura_linea.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#-*- coding: utf-8 -*-
import ydbf
import sys
import erppeek
import csv
import datetime
import requests
import os.path
import vatnumber
SERVER_origen = 'http://localhost:8069'
DATABASE_origen = 'base_de_datos'
USERNAME = 'usuario'
PASSWORD = 'contraseña'
debug = True
# Conectar al ERP
origen = erppeek.Client(SERVER_origen, DATABASE_origen, USERNAME, PASSWORD)
VentasAccount = origen.model(name='account.account').browse([('code','=','700000')])[0]
iva21b = origen.model(name='account.tax').browse([('description','=','S_IVA21B')])[0]
def importar():
dbf = ydbf.open(os.path.join('dbfs', 'FacCliL.dbf'), encoding='latin-1')
for row in dbf:
product_obj = origen.model('product.product')
product_id = product_obj.browse([('default_code','=',row['CREF'].strip())])
if product_id:
product_id = product_id[0].id
else:
product_id = product_obj.browse([('default_code','=','Facturaplus')])
if not product_id:
product = {
'name': 'Producto',
'default_code': 'Facturaplus',
'type': 'product',
}
product_id = product_obj.create(product)
else:
product_id = product_id[0].id
# BÚSQUEDA DE CABECERAS DE FACTURAS
invoice_obj = origen.model('account.invoice')
invoice_id = invoice_obj.browse([('name','=',str(row['CSERIE']) + '0' + str(row['NNUMFAC']))])
if invoice_id:
invoice_id = invoice_id[0]
# CREACION DE LINEAS DE FACTURA
invoice_vals = {
'name': row['CDETALLE'].strip(),
'invoice_id': invoice_id.id,
'product_id': product_id,
'quantity': float(row['NCANENT']),
'discount': float(row['NDTO']),
'account_id': VentasAccount.id,
'invoice_line_tax_ids': [(4,iva21b.id)] if bool(float(row['NIVA'])) else False,
'price_unit':float(row['NPREUNIT']),
'price_subtotal':float(row['NTOTLINEA']),
'origin': str(row['NNUMFAC']),
'facturaplus': True,
}
invoice_line_obj = origen.model('account.invoice.line')
invoice_line_id = invoice_line_obj.create(invoice_vals)
invoice_id.compute_taxes()
importar()