Refactoring to post/write/do with multiple sales and omit cancel invocies in workflow to end
task-033187
This commit is contained in:
parent
4b1ece67c6
commit
a41d4ff251
60
sale.py
60
sale.py
@ -57,7 +57,11 @@ class Sale:
|
||||
def workflow_to_end(cls, sales):
|
||||
pool = Pool()
|
||||
Invoice = pool.get('account.invoice')
|
||||
StatementLine = pool.get('account.statement.line')
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
invoices = []
|
||||
to_post = set()
|
||||
for sale in sales:
|
||||
if sale.state == 'draft':
|
||||
cls.quote([sale])
|
||||
@ -73,27 +77,45 @@ class Sale:
|
||||
False)
|
||||
if sale.invoices and not grouping:
|
||||
for invoice in sale.invoices:
|
||||
if invoice.state == 'draft':
|
||||
if not getattr(invoice, 'invoice_date', False):
|
||||
invoice.invoice_date = Date.today()
|
||||
if not getattr(invoice, 'accounting_date', False):
|
||||
invoice.accounting_date = Date.today()
|
||||
invoice.description = sale.reference
|
||||
invoice.save()
|
||||
Invoice.post(sale.invoices)
|
||||
for payment in sale.payments:
|
||||
invoice = sale.invoices[0]
|
||||
payment.invoice = invoice.id
|
||||
# Because of account_invoice_party_without_vat module
|
||||
# could be installed, invoice party may be different of
|
||||
# payment party if payment party has not any vat
|
||||
# and both parties must be the same
|
||||
if payment.party != invoice.party:
|
||||
payment.party = invoice.party
|
||||
payment.save()
|
||||
if not invoice.state == 'draft':
|
||||
continue
|
||||
if not getattr(invoice, 'invoice_date', False):
|
||||
invoice.invoice_date = Date.today()
|
||||
if not getattr(invoice, 'accounting_date', False):
|
||||
invoice.accounting_date = Date.today()
|
||||
invoice.description = sale.reference
|
||||
invoices.extend(([invoice], invoice._save_values))
|
||||
to_post.add(invoice)
|
||||
|
||||
if to_post:
|
||||
Invoice.write(*invoices)
|
||||
Invoice.post(list(to_post))
|
||||
|
||||
to_write = []
|
||||
to_do = []
|
||||
for sale in sales:
|
||||
for payment in sale.payments:
|
||||
invoices = [invoice for invoice in sale.invoices
|
||||
if invoice and invoice.state == 'posted']
|
||||
if not invoices:
|
||||
continue
|
||||
payment.invoice = invoices[0]
|
||||
# Because of account_invoice_party_without_vat module
|
||||
# could be installed, invoice party may be different of
|
||||
# payment party if payment party has not any vat
|
||||
# and both parties must be the same
|
||||
if payment.party != invoice.party:
|
||||
payment.party = invoice.party
|
||||
to_write.extend(([payment], payment._save_values))
|
||||
|
||||
if sale.is_done():
|
||||
cls.do([sale])
|
||||
to_do.append(sale)
|
||||
|
||||
if to_write:
|
||||
StatementLine.write(*to_write)
|
||||
|
||||
if to_do:
|
||||
cls.do(to_do)
|
||||
|
||||
@classmethod
|
||||
def get_paid_amount(cls, sales, names):
|
||||
|
Loading…
Reference in New Issue
Block a user