From 09516007add5e9b9b88c037569bc650b2aeb070f Mon Sep 17 00:00:00 2001 From: carlosgalvez-nan Date: Wed, 29 Jan 2020 11:21:20 +0100 Subject: [PATCH] Refactor of the workoflow_to_end method to allow to modify in another modules what happens to the invoices created. --- sale.py | 17 +++++++++++------ tests/scenario_sale_payment.rst | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sale.py b/sale.py index b199af7..c4caf9c 100644 --- a/sale.py +++ b/sale.py @@ -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) diff --git a/tests/scenario_sale_payment.rst b/tests/scenario_sale_payment.rst index cb14169..e9708ce 100644 --- a/tests/scenario_sale_payment.rst +++ b/tests/scenario_sale_payment.rst @@ -20,7 +20,7 @@ Imports:: Install sale:: - >>> config = activate_modules('sale_payment') + >>> config = activate_modules(['party', 'sale_payment']) Create company::