Add patch for speed up invoice posting process

This commit is contained in:
Sergi Almacellas Abellana 2015-07-07 09:38:47 +02:00
parent 7948a60ced
commit cb06607a3e
2 changed files with 74 additions and 0 deletions

73
invoice_speedup.diff Normal file
View File

@ -0,0 +1,73 @@
diff -r 60fd69f732c6 trytond/trytond/modules/account_invoice/invoice.py
--- a/trytond/trytond/modules/account_invoice/invoice.py Mon Mar 02 12:40:52 2015 +0100
+++ b/trytond/trytond/modules/account_invoice/invoice.py Tue Jul 07 09:25:19 2015 +0200
@@ -995,7 +995,6 @@
accounting_date = self.accounting_date or self.invoice_date
period_id = Period.find(self.company.id, date=accounting_date)
-
move, = Move.create([{
'journal': self.journal.id,
'period': period_id,
@@ -1003,9 +1002,8 @@
'origin': str(self),
'lines': [('create', move_lines)],
}])
- self.write([self], {
- 'move': move.id,
- })
+ self.move = move
+
return move
def set_number(self):
@@ -1037,11 +1035,12 @@
with Transaction().set_context(
date=self.invoice_date or Date.today()):
number = Sequence.get_id(sequence.id)
+ self.number = number
vals = {'number': number}
if (not self.invoice_date
and self.type in ('out_invoice', 'out_credit_note')):
vals['invoice_date'] = Transaction().context['date']
- self.write([self], vals)
+ self.invoice_date = Transaction().context['date']
@classmethod
def check_modify(cls, invoices):
@@ -1364,10 +1363,14 @@
@ModelView.button
@Workflow.transition('validated')
def validate_invoice(cls, invoices):
+ to_write = []
for invoice in invoices:
if invoice.type in ('in_invoice', 'in_credit_note'):
invoice.set_number()
invoice.create_move()
+ to_write.extend(([invoice], invoice._save_values))
+ if to_write:
+ cls.write(*to_write)
@classmethod
@ModelView.button
@@ -1375,14 +1378,17 @@
def post(cls, invoices):
Move = Pool().get('account.move')
- moves = []
+ to_write = []
for invoice in invoices:
invoice.set_number()
- moves.append(invoice.create_move())
+ invoice.create_move()
+ to_write.extend(([invoice], invoice._save_values))
+ if to_write:
+ cls.write(*to_write)
cls.write([i for i in invoices if i.state != 'posted'], {
'state': 'posted',
})
- Move.post([m for m in moves if m.state != 'posted'])
+ Move.post([i.move for i in invoices if i.move.state != 'posted'])
for invoice in invoices:
if invoice.type in ('out_invoice', 'out_credit_note'):
invoice.print_invoice()

1
series
View File

@ -56,3 +56,4 @@ issue13181002_1.diff
issue13211002_190001.diff
issue17281002_20001.diff
issue20301003_1.diff
invoice_speedup.diff