Refactor of the workoflow_to_end method to allow to modify in another modules what

happens to the invoices created.
This commit is contained in:
carlosgalvez-nan 2020-01-29 11:21:20 +01:00
parent 5174a64ad6
commit 09516007ad
2 changed files with 12 additions and 7 deletions

17
sale.py
View File

@ -48,12 +48,21 @@ class Sale(metaclass=PoolMeta):
user = User(Transaction().user)
return user.sale_device and user.sale_device.id or None
def set_values_to_invoice(self, invoice):
pool = Pool()
Date = pool.get('ir.date')
today = Date.today()
if not getattr(invoice, 'invoice_date', False):
invoice.invoice_date = today
if not getattr(invoice, 'accounting_date', False):
invoice.accounting_date = today
invoice.description = self.reference
@classmethod
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()
@ -76,11 +85,7 @@ class Sale(metaclass=PoolMeta):
for invoice in sale.invoices:
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
sale.set_values_to_invoice(invoice)
invoices.extend(([invoice], invoice._save_values))
to_post.add(invoice)

View File

@ -20,7 +20,7 @@ Imports::
Install sale::
>>> config = activate_modules('sale_payment')
>>> config = activate_modules(['party', 'sale_payment'])
Create company::