[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.
This commit is contained in:
Laurent Smet
2019-09-26 10:02:08 +00:00
parent 7de871cc38
commit 93fb9721fe
2 changed files with 8 additions and 3 deletions
+7 -2
View File
@@ -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()
@@ -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'