Update and improve invoice speedup patch
This commit is contained in:
parent
cbb46cdd5c
commit
508715c4e2
|
@ -1,6 +1,15 @@
|
|||
diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
||||
--- a/trytond/trytond/modules/account_invoice/invoice.py Tue Jul 07 16:46:50 2015 +0200
|
||||
+++ b/trytond/trytond/modules/account_invoice/invoice.py Tue Jul 07 17:12:14 2015 +0200
|
||||
@@ -852,7 +852,7 @@
|
||||
if line.type != 'line':
|
||||
continue
|
||||
with Transaction().set_context(**context):
|
||||
- tax_list = Tax.compute(Tax.browse(line.taxes),
|
||||
+ tax_list = Tax.compute(line.taxes,
|
||||
line.unit_price, line.quantity,
|
||||
date=self.accounting_date or self.invoice_date)
|
||||
for tax in tax_list:
|
||||
@@ -944,33 +944,35 @@
|
||||
'''
|
||||
Return move line
|
||||
|
@ -125,7 +134,16 @@ diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
|||
|
||||
@classmethod
|
||||
def check_modify(cls, invoices):
|
||||
@@ -1308,26 +1304,18 @@
|
||||
@@ -1109,7 +1105,7 @@
|
||||
all_invoices += invoices
|
||||
update_tax = [i for i in all_invoices if i.state == 'draft']
|
||||
super(Invoice, cls).write(*args)
|
||||
- if update_tax:
|
||||
+ if update_tax and not Transaction().context.get('skip_update_taxes'):
|
||||
cls.update_taxes(update_tax)
|
||||
|
||||
@classmethod
|
||||
@@ -1311,26 +1307,18 @@
|
||||
'''
|
||||
Return values to credit invoice.
|
||||
'''
|
||||
|
@ -160,7 +178,7 @@ diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
|||
|
||||
@classmethod
|
||||
def credit(cls, invoices, refund=False):
|
||||
@@ -1337,18 +1325,17 @@
|
||||
@@ -1340,18 +1328,17 @@
|
||||
'''
|
||||
MoveLine = Pool().get('account.move.line')
|
||||
|
||||
|
@ -185,7 +203,7 @@ diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
|||
return new_invoices
|
||||
|
||||
@classmethod
|
||||
@@ -1368,10 +1355,16 @@
|
||||
@@ -1371,10 +1358,16 @@
|
||||
@ModelView.button
|
||||
@Workflow.transition('validated')
|
||||
def validate_invoice(cls, invoices):
|
||||
|
@ -203,12 +221,12 @@ diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
|||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@@ -1379,14 +1372,18 @@
|
||||
@@ -1382,14 +1375,29 @@
|
||||
def post(cls, invoices):
|
||||
Move = Pool().get('account.move')
|
||||
|
||||
- moves = []
|
||||
+ to_write = []
|
||||
+ to_create = []
|
||||
for invoice in invoices:
|
||||
invoice.set_number()
|
||||
- moves.append(invoice.create_move())
|
||||
|
@ -218,17 +236,28 @@ diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
|||
- Move.post([m for m in moves if m.state != 'posted'])
|
||||
+ move = invoice.get_move()
|
||||
+ if move != invoice.move:
|
||||
+ invoice.move = move
|
||||
+ to_write.extend(([invoice], invoice._save_values))
|
||||
+
|
||||
+ to_create.append(move._save_values)
|
||||
+ invoices2move = {}
|
||||
+ if to_create:
|
||||
+ moves = Move.create(to_create)
|
||||
+ for move in moves:
|
||||
+ invoices2move[move.origin.id] = move.id
|
||||
+ to_write = []
|
||||
+ for invoice in invoices:
|
||||
+ values = invoice._save_values
|
||||
+ if invoice.id in invoices2move:
|
||||
+ values['move'] = invoices2move[invoice.id]
|
||||
+ if values:
|
||||
+ to_write.extend(([invoice], values))
|
||||
+ if to_write:
|
||||
+ cls.write(*to_write)
|
||||
+ with Transaction().set_context(skip_update_taxes=True):
|
||||
+ cls.write(*to_write)
|
||||
+ cls.write(invoices, {'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()
|
||||
@@ -1425,14 +1422,17 @@
|
||||
@@ -1428,14 +1436,17 @@
|
||||
|
||||
cancel_moves = []
|
||||
delete_moves = []
|
||||
|
@ -247,7 +276,17 @@ diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
|||
if delete_moves:
|
||||
Move.delete(delete_moves)
|
||||
if cancel_moves:
|
||||
@@ -2000,6 +2000,7 @@
|
||||
@@ -1754,8 +1765,7 @@
|
||||
context = self.invoice.get_tax_context()
|
||||
taxes_keys = []
|
||||
with Transaction().set_context(**context):
|
||||
- taxes = Tax.compute(Tax.browse(self.taxes),
|
||||
- self.unit_price, self.quantity)
|
||||
+ taxes = Tax.compute(self.taxes, self.unit_price, self.quantity)
|
||||
for tax in taxes:
|
||||
key, _ = Invoice._compute_tax(tax, self.invoice.type)
|
||||
taxes_keys.append(key)
|
||||
@@ -2003,14 +2013,14 @@
|
||||
pool = Pool()
|
||||
Tax = pool.get('account.tax')
|
||||
Currency = pool.get('currency.currency')
|
||||
|
@ -255,7 +294,16 @@ diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
|||
|
||||
context = self.invoice.get_tax_context()
|
||||
res = []
|
||||
@@ -2022,79 +2023,76 @@
|
||||
if self.type != 'line':
|
||||
return res
|
||||
with Transaction().set_context(**context):
|
||||
- taxes = Tax.compute(Tax.browse(self.taxes),
|
||||
- self.unit_price, self.quantity)
|
||||
+ taxes = Tax.compute(self.taxes, self.unit_price, self.quantity)
|
||||
for tax in taxes:
|
||||
if self.invoice.type in ('out_invoice', 'in_invoice'):
|
||||
base_code_id = (tax['tax'].invoice_base_code.id
|
||||
@@ -2025,79 +2035,76 @@
|
||||
date=self.invoice.currency_date):
|
||||
amount = Currency.compute(self.invoice.currency,
|
||||
amount, self.invoice.company.currency)
|
||||
|
@ -375,7 +423,7 @@ diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
|||
|
||||
|
||||
class InvoiceLineTax(ModelSQL):
|
||||
@@ -2290,67 +2288,67 @@
|
||||
@@ -2293,67 +2300,67 @@
|
||||
|
||||
def get_move_line(self):
|
||||
'''
|
||||
|
@ -484,7 +532,7 @@ diff -r 3681a54fda0a trytond/trytond/modules/account_invoice/invoice.py
|
|||
diff -r 0e69764f2826 trytond/trytond/modules/account_payment_type/invoice.py
|
||||
--- a/trytond/trytond/modules/account_payment_type/invoice.py Tue Jul 07 10:10:50 2015 +0200
|
||||
+++ b/trytond/trytond/modules/account_payment_type/invoice.py Tue Jul 07 17:06:02 2015 +0200
|
||||
@@ -51,7 +51,7 @@
|
||||
@@ -59,10 +59,10 @@
|
||||
return res
|
||||
|
||||
def _get_move_line(self, date, amount):
|
||||
|
@ -495,6 +543,9 @@ diff -r 0e69764f2826 trytond/trytond/modules/account_payment_type/invoice.py
|
|||
- return res
|
||||
+ line.payment_type = self.payment_type
|
||||
+ return line
|
||||
|
||||
@classmethod
|
||||
def compute_default_payment_type(cls, values):
|
||||
diff -r 6429c9c53cb8 trytond/trytond/modules/account_bank/account.py
|
||||
--- a/trytond/trytond/modules/account_bank/account.py Tue May 05 14:36:02 2015 +0200
|
||||
+++ b/trytond/trytond/modules/account_bank/account.py Tue Jul 07 15:36:26 2015 +0200
|
||||
|
|
Loading…
Reference in New Issue