diff --git a/addons/account/account.py b/addons/account/account.py
index 67abf8b4520..7878ba68e66 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -629,8 +629,8 @@ class account_journal(osv.osv):
'currency': fields.many2one('res.currency', 'Currency', help='The currency used to enter statement'),
'entry_posted': fields.boolean('Skip \'Draft\' State for Created Entries', help='Check this box if you don\'t want new account moves to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation.'),
'company_id': fields.many2one('res.company', 'Company', required=True, select=1, help="Company related to this journal"),
-# 'invoice_sequence_id': fields.many2one('ir.sequence', 'Invoice Sequence', \
-# help="The sequence used for invoice numbers in this journal."),
+ 'invoice_sequence_id': fields.many2one('ir.sequence', 'Invoice Sequence', \
+ help="The sequence used for invoice numbers in this journal."),
'allow_date':fields.boolean('Check Date not in the Period', help= 'If set to True then do not accept the entry if the entry date is not into the period dates'),
}
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index aaa880929b1..f8c38ccbf92 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -388,14 +388,15 @@
+
+
+
+
+
-
-
-
-
diff --git a/addons/account/invoice.py b/addons/account/invoice.py
index b15c8667972..1816f4c31bf 100644
--- a/addons/account/invoice.py
+++ b/addons/account/invoice.py
@@ -231,8 +231,8 @@ class account_invoice(osv.osv):
('in_refund','Supplier Refund'),
],'Type', readonly=True, select=True, change_default=True),
- 'number': fields.related('move_id','name', type='char', readonly=True, size=64, relation='account.move', store=True, string='Number'),
- #'number': fields.char('Invoice Number', size=32, readonly=True, help="Unique number of the invoice, computed automatically when the invoice is created."),
+# 'number': fields.related('move_id','name', type='char', readonly=True, size=64, relation='account.move', store=True, string='Number'),
+ 'number': fields.char('Invoice Number', size=32, readonly=True, help="Unique number of the invoice, computed automatically when the invoice is created."),
'reference': fields.char('Invoice Reference', size=64, help="The partner reference of this invoice."),
'reference_type': fields.selection(_get_reference_type, 'Reference Type',
required=True, readonly=True, states={'draft':[('readonly',False)]}),
@@ -769,7 +769,7 @@ class account_invoice(osv.osv):
cur_obj = self.pool.get('res.currency')
context = {}
for inv in self.browse(cr, uid, ids):
- if not inv.journal_id.sequence_id:
+ if not inv.journal_id.invoice_sequence_id:
raise osv.except_osv(_('Error !'), _('Please define sequence on invoice journal'))
if not inv.invoice_line:
raise osv.except_osv(_('No Invoice Lines !'), _('Please create some invoice lines.'))
@@ -927,35 +927,45 @@ class account_invoice(osv.osv):
}
def action_number(self, cr, uid, ids, *args):
- #TODO: not correct fix but required a frech values before reading it.
- self.write(cr, uid, ids, {})
+# #TODO: not correct fix but required a frech values before reading it.
+# self.write(cr, uid, ids, {})
+#
+ cr.execute('SELECT id, type, number, move_id, reference ' \
+ 'FROM account_invoice ' \
+ 'WHERE id IN ('+','.join(map(str,ids))+')')
+ obj_inv = self.browse(cr, uid, ids)[0]
- for obj_inv in self.browse(cr, uid, ids):
- id = obj_inv.id
- invtype = obj_inv.type
- number = obj_inv.number
- move_id = obj_inv.move_id and obj_inv.move_id.id or False
- reference = obj_inv.reference or ''
-
- if invtype in ('in_invoice', 'in_refund'):
- ref = reference
- else:
- ref = self._convert_ref(cr, uid, number)
-
- cr.execute('UPDATE account_move SET ref=%s ' \
- 'WHERE id=%s AND (ref is null OR ref = \'\')',
- (ref, move_id))
- cr.execute('UPDATE account_move_line SET ref=%s ' \
- 'WHERE move_id=%s AND (ref is null OR ref = \'\')',
- (ref, move_id))
- cr.execute('UPDATE account_analytic_line SET ref=%s ' \
- 'FROM account_move_line ' \
- 'WHERE account_move_line.move_id = %s ' \
- 'AND account_analytic_line.move_id = account_move_line.id',
+ for (id, invtype, number, move_id, reference) in cr.fetchall():
+ if not number:
+ if obj_inv.journal_id.invoice_sequence_id:
+ sid = obj_inv.journal_id.invoice_sequence_id.id
+ number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id', {'fiscalyear_id': obj_inv.period_id.fiscalyear_id.id})
+ else:
+ number = self.pool.get('ir.sequence').get(cr, uid, 'account.invoice.' + invtype)
+
+ if invtype in ('in_invoice', 'in_refund'):
+ ref = reference
+ else:
+ ref = self._convert_ref(cr, uid, number)
+
+ cr.execute('UPDATE account_invoice SET number=%s ' \
+ 'WHERE id=%s', (number, id))
+ cr.execute('UPDATE account_move SET ref=%s ' \
+ 'WHERE id=%s AND (ref is null OR ref = \'\')',
(ref, move_id))
+ cr.execute('UPDATE account_move_line SET ref=%s ' \
+ 'WHERE move_id=%s AND (ref is null OR ref = \'\')',
+ (ref, move_id))
+ cr.execute('UPDATE account_analytic_line SET ref=%s ' \
+ 'FROM account_move_line ' \
+ 'WHERE account_move_line.move_id = %s ' \
+ 'AND account_analytic_line.move_id = account_move_line.id',
+ (ref, move_id))
+
for inv_id, name in self.name_get(cr, uid, [id]):
message = _('Invoice ') + " '" + name + "' "+ _("is validated.")
self.log(cr, uid, inv_id, message)
+
return True
def action_cancel(self, cr, uid, ids, *args):