How do I enter Invoice Numbers manually?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
By default the invoice number is generated. If you want to ad it manually, you have to create a new module, which extends account_invoice, and you override the methods create and/or save.
But it is dangerous to type the invoice numbers manually, because you can forget it, you can skip numbers or use numbers multiple times.
Depending on the reason you want to type the numbers manually, it can already be done, or changed easily. If you can tell us the reason(s), we might be able to help you with it.
Example script:
# -*- coding: UTF-8 -*-
import openerplib
import datetime
import psycopg2
h = "localhost"
db= 'database'
u = "admin"
p = 'password'
h_sql = h
db_sql = db
u_sql = "openerp"
p_sql = "openerp"
line = '-' *45 + '\n'
file_dbo_factuur = 'dbo_Factuur.csv'
file_dbo_factuurregel = 'dbo_Factuurregels.csv'
f_result = 'factuur_Result.txt'
f_error = 'factuur_Error.csv'
file_finance = 'factuur_finance.csv'
invoiceAdded = 0
invoiceRejected = 0
################################################################################
## VARIOUS ROUTINES
################################################################################
def printHeading():
f_res.write(line)
dateX = str(datetime.datetime.now())
f_res.write('-' * 10 + dateX+'\n')
def initConnection(h, db, u, p):
printHeading()
f_res.write('Connecting to %s \nuser: %s\ndatabase: %s\n' %(h, u, db))
return openerplib.get_connection(
hostname=h, database=db, login=u, password=p)
def addValsToDB(c, m, vals):
printHeading()
f_res.write('Adding data to %s\n' %(m))
print 'Adding data to', m
model = c.get_model(m)
result = []
i = 0
for v in vals:
result.append(model.create(v))
i += 1
x, y = divmod(i, 100)
if y == 0:
f_res.write('Added already %d records to %s\n' %(x*100, m))
f_res.write('Number of records added: %d\n' %(len(result)))
return result
def writeData(c, m, ids, vals):
printHeading()
f_res.write('Modifying data of model %s with id(s) = %s\n' %(m, ids))
print 'Modifying data of model', m, 'with id =', ids
model = c.get_model(m)
return model.write(ids, vals)
################################################################################
## SCRIPT SPECIFIC ROUTINE(S)
################################################################################
def addInvoice(c, factuur, lines):
global invoiceAdded
global invoiceRejected
#check invoice itself
factuur_split = factuur.split(';')
m = 'account.invoice'
vals = []
# do your checks
if sjoemel: #so old order
resOrder = order_obj.onchange_partner_id(0, partner)['value']
origin = 'Factuur %s, van order voor 2013' %(factuur_split[2])
currency = factuur_split[9]
if currency == '1': # Euro
pass
elif currency == '6': # USD
currency = '3'
elif currency == '7': # GBP
currency = '152'
fiscal = resOrder['fiscal_position']
reference = factuur_split[30]
user = 1 #fixed to admin
payment = resOrder['payment_term']
comment = factuur_split[13]
else: #order uit 2013
origin = order['name']
currency = order['currency_id'][0]
partner = order['partner_id'][0]
if order['fiscal_position'] == False:
fiscal = False
else:
fiscal = order['fiscal_position'][0]
reference = order['client_order_ref']
user = order['user_id'][0]
payment = order['payment_term'][0]
comment = order['note']
agent = klant_agent.get(partner, False)
agent_code = agent_id_code.get(agent, '')
klant = partner_obj.read(partner)
hb_inkoop_org = klant['hb_inkoop_org']
vals.append({
'origin': origin,
'date_due': factuur_split[30],
'check_total': 0.0,
'partner_bank_id': False,
'supplier_invoice_number': False,
'paypal_url': False,
'company_id': 1,
'currency_id': currency,
'partner_id': partner,
'fiscal_position': fiscal,
'user_id': user,
'reference': reference,
'message_is_follower': False,
'payment_term': payment,
'reference_type': 'none',
'journal_id': 11,
'account_id': 166,
'type': 'out_invoice',
'internal_number': 'Q:%s' %(factuur_split[2]),
'reconciled': False,
'move_name': '/',
'section_id': False,
'date_invoice': factuur_split[3],
'name': factuur_split[29], #?
'comment': comment,
'sent': False,
'agent_id': agent,
'agent_code': agent_code,
'message_unread': False,
})
invoiceID = addValsToDB(connection, m, vals)[0]
# add the various lines to the invoice.
vals = []
m = 'account.invoice.line'
invoice_line_tax_id = []
if fiscal == 1: #NL
invoice_line_tax_id = [2]
# elif fiscal == 2: # EU
elif fiscal == 3: # EU
invoice_line_tax_id = [15]
# elif fiscal == 3: # Non EU
elif fiscal == 4: # Non EU
invoice_line_tax_id = [12]
else:
invoice_line_tax_id = [2]
for line_split in resFactLines:
orderlineOld = line_split[13]
if orderlineOld:
orderlineID = old_orderline_obj.search([('orderline_id', '=', line_split[3])])
orderline = old_orderline_obj.read(orderlineID)[0]
product = prod_obj.read(int(orderline['product_id']))
else:
orderlineID = orderline_obj.search([('hb_id_q', '=', line_split[3])])
orderLine = orderline_obj.read(orderlineID)[0]
product = prod_obj.read(orderLine['product_id'][0])
priceArticle = float(line_split[6])
vals.append({
'origin': origin,
'uos_id': 1,
'asset_category_id': False,
'account_id': 458,
'name': product['name'],
'sequence': 5,
'invoice_id': invoiceID,
'price_unit': priceArticle,
'company_id': 1,
'invoice_line_tax_id': [[6, 0, invoice_line_tax_id]],
'discount': line_split[4],
'account_analytic_id': False,
'quantity': line_split[5],
'partner_id': partner,
'product_id': product['id'],
})
factuurLineIDs = addValsToDB(connection, m, vals)
# Validate invoice
context = {}
context['active_ids'] = [invoiceID]
x = factuur_confirm_obj.invoice_confirm([invoiceID], context)
#start of script
f_factuur = open(file_dbo_factuur, 'r')
f_fout = open(f_error, 'a')
f_res = open(f_result, 'a')
startTime = str(datetime.datetime.now())
print startTime
f_fout.write('error code;Omschrijving;factuur;factuurID;order;orderregel\n')
#finance
f_fin = open(file_finance, 'w+')
f_fin.write('Factuur Q;bedrag Q;Factuur openERP;bedrag openERP;verschil (Q - OpenERP)\n')
connection = initConnection(h, db, u, p)
f_res.write('Connecting with SQL:\nuser: %s\ndatabase: %s\n' %(u_sql, db_sql))
conn_string = "dbname='%s' user='%s' password='%s'" %(db_sql, u_sql, p_sql)
conn_sql = psycopg2.connect(conn_string)
cursor = conn_sql.cursor()
# search partners with agent
statement = "select partner_id, agent_id from res_partner_agent"
klant_agent = {}
cursor.execute(statement)
result = cursor.fetchall()
for r in result:
klant_agent[r[0]] = r[1]
statement = "select hb_id_q, id from res_partner"
partner_Q_id = {}
cursor.execute(statement)
result = cursor.fetchall()
for r in result:
partner_Q_id[r[0]] = r[1]
f_factuur = open(file_dbo_factuur_nw, 'r')
f_factuurline = open(file_dbo_factuurregel, 'r')
# get rid of the headings
header_f = f_factuur.readline()
header_l = f_factuurline.readline()
# get the first entry of the factuurline
line_factuur = f_factuurline.readline()
numberOfLines = 1 #because of line above
factuur_obj = connection.get_model('account.invoice')
factuurline_obj = connection.get_model('account.invoice.line')
order_obj = connection.get_model('sale.order')
orderline_obj = connection.get_model('sale.order.line')
prod_obj = connection.get_model('product.product')
old_order_obj = connection.get_model('hb.order')
old_orderline_obj = connection.get_model('hb.order.line')
partner_obj = connection.get_model('res.partner')
#nodig om facturen te bevestigen....
factuur_confirm_obj = connection.get_model('account.invoice.confirm')
partner_q_id = {}
statement = "select hb_id_q, id from res_partner where customer = True"
cursor.execute(statement)
result = cursor.fetchall()
for r in result:
partner_q_id[r[0]] = r[1]
partner_id_obj = {}
s = ''
numberOfRecords = 0
for factuur in f_factuur:
lines = []
numberOfRecords += 1
factuur_result = factuur.split(';')
if len(factuur_result) != lengte_f:
print 'Factuur niet goede lengte. %s' %(factuur)
continue
s = factuur
while s:
if line_factuur == '\n': # end of file
if len(lines) > 0:
result = addInvoice(connection, s, lines)
print 'Einde, wegens alleen \\n'
break
if line_factuur == '': # end of file?!
if len(lines) > 0:
result = addInvoice(connection, s, lines)
print 'Einde, wegens lege regel'
break
if line_factuur == '\r\n': # zou niet mogen!
print line_factuur
print line_result
line_result = line_factuur.replace('\n','').split(';')
if factuur_result[0] < line_result[2]: #order lines later than order
if len(lines) > 0:
result = addInvoice(connection, s, lines)
else:
f_fout.write('06;Factuur %s zonder regels\n' %(factuur_result[0]))
break
if factuur_result[0] == line_result[2]: # order line part of order
lines.append(line_factuur)
line_factuur = f_factuurline.readline()
numberOfLines += 1
s = ''
print line
print 'Records:', numberOfRecords
print 'Lines :', numberOfLines
print 'Invoices made in openERP:', invoiceAdded
print 'Invoices rejected by openERP:', invoiceRejected
print line
f_res.write(line+'\n')
f_res.write('Invoices read: %d\n' %(numberOfRecords))
f_res.write('Invoicelines read: %d\n' %(numberOfLines))
f_res.write('Invoices made in openERP: %d\n' %(invoiceAdded))
f_res.write('Invoices rejected by openERP: %d\n' %(invoiceRejected))
f_res.write(line+'\n')
eindTime = str(datetime.datetime.now())
f_fout.write(eindTime+'\n')
f_res.write(eindTime+'\n')
f_fin.write(eindTime+'\n')
f_fin.close()
f_fout.close()
f_res.close()
print eindTime
print 'einde'
print line
I want to enter the invoice numbers manually because I have to enter the invoices which I already created manually before I began to use OpenERP. So each invoice has its own sequences. After I complete all the previous invoice entries I will begin to use the invoice numbers generated by the software.
If needed, I can show a small script to do the import for you. Just let me know if you are interested. You want to place your own invoice number as account_invoice.internal_number. This field will be used to generate/display the invoice number
Yes I am interested.
i agree with patrick, importing the invoices is a much better idea than manually keying data.
Dear I'm facing the same problem and i want to import invoices with pregenerated numbers as beginign balances, (will that affect accounting side also or i have to make entry with total balance ?)
The first thing I tried with OpenERP was editing old invoices (and still don't know how to do it). It seems that I may not be the only one...
once an invoice is out of draft state, you cannot edit it. You need to either have your customer pay the invoice short and issue a credit memo to zero out the balance OR you need to issue a credit for the entire invoice and re-invoice at the correct amount. This is a basic principle of accounting that openERP must follow otherwise it would not be taken seriously as an accounting package.
By "old invoices" I doesn't mean "paid invoices". I mean "invoices which was edited out of OpenERP". Fact is that if we had already issued paper wrote invoices with manually-attributed reference numbers, it's not possible to create the same invoice in OpenERP with the same reference number, as it's automatically generated and not editable.
You can load them directly into the database using pgadmin or custom scripting to put the information into the database. But this method might lead to unforeseen issues.
Of course! We can do anything this way... But the purpose of a framework is not to make us choose between "not doing something" and "doing it the bad way". OpenERP is quite well designed. But it's very difficult to convince a customer when we are not even able to import it's own data for a demo.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
PrijaviRelated Posts | Odgovori | Prikazi | Aktivnost | |
---|---|---|---|---|
|
0
sep. 24
|
1203 | ||
|
2
mar. 24
|
2732 | ||
|
2
feb. 23
|
3361 | ||
Manually set invoice number
Solved
|
|
6
okt. 20
|
37144 | |
|
1
sep. 20
|
4095 |