From 93fb9721fec5e45996098d2d03e3899d22a096b8 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Mon, 23 Sep 2019 13:09:11 +0000 Subject: [PATCH] [IMP] account: Set today as default bill date Suppose the following workflow: - Creates a new vendor bill. - Set an accounting date but no bill date. - Post the vendor bill => accounting date / bill date are set at today. This behavior is due to the fact the user didn't set a bill date. This commit aims to set a default bill date to encourage the user to edit it instead of letting it empty. --- addons/account/models/account_move.py | 9 +++++++-- addons/account/tests/test_account_move_in_invoice.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 90b3f7a70b9..afc1d49b6c2 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -70,6 +70,10 @@ class AccountMove(models.Model): raise UserError(error_msg) return journal + @api.model + def _get_default_invoice_date(self): + return fields.Date.today() if self._context.get('default_type', 'entry') in ('in_invoice', 'in_refund', 'in_receipt') else False + @api.model def _get_default_currency(self): ''' Get the default currency from either the journal, either the default journal's company. ''' @@ -185,7 +189,8 @@ class AccountMove(models.Model): string='Payment', store=True, readonly=True, copy=False, tracking=True, compute='_compute_amount') invoice_date = fields.Date(string='Invoice/Bill Date', readonly=True, index=True, copy=False, - states={'draft': [('readonly', False)]}) + states={'draft': [('readonly', False)]}, + default=_get_default_invoice_date) invoice_date_due = fields.Date(string='Due Date', readonly=True, index=True, copy=False, states={'draft': [('readonly', False)]}) invoice_payment_ref = fields.Char(string='Payment Reference', index=True, copy=False, @@ -263,7 +268,7 @@ class AccountMove(models.Model): @api.onchange('invoice_date') def _onchange_invoice_date(self): if self.invoice_date: - if not self.invoice_date_due and not self.invoice_payment_term_id: + if not self.invoice_payment_term_id: self.invoice_date_due = self.invoice_date self.date = self.invoice_date self._onchange_currency() diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index c1be996ed55..f773577d010 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -1172,7 +1172,7 @@ class TestAccountMoveInInvoiceOnchanges(InvoiceTestCommon): def test_in_invoice_duplicate_supplier_reference(self): ''' Ensure two vendor bills can't share the same vendor reference. ''' self.invoice.ref = 'a supplier reference' - invoice2 = self.invoice.copy() + invoice2 = self.invoice.copy(default={'invoice_date': self.invoice.invoice_date}) with self.assertRaises(ValidationError): invoice2.ref = 'a supplier reference'