summaryrefslogtreecommitdiff
path: root/addons/account/models/account_move.py
diff options
context:
space:
mode:
authorwan <wan@odoo.com>2021-04-02 10:33:24 +0000
committerwan <wan@odoo.com>2021-04-12 18:19:00 +0000
commitfcaa54939e9a4f0dd5e47cd0ccffe7aa24bd451c (patch)
tree04953cd19b1bcb09648fc88624c3da7e403fc706 /addons/account/models/account_move.py
parent14abcfa92cd37db82338f9a933221142026a78bd (diff)
[FIX] account: never set default for invoice_date
For customer invoices: * do not set default date because if you prepare an invoice (and it gets a default date), then validate it the next day, the date will be wrong * set the date when posting if it wasn't set, because why not? For vendor bills: * do not set default date because you rarely encode a bill at the bill date. Forcing the user to enter it reduces risks of user error (duplicated vendor bill) * do not set it when posting, same reason. opw-2492862 Related #68368 Closes #68367 closes odoo/odoo#68689 Related: odoo/enterprise#17502 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Diffstat (limited to 'addons/account/models/account_move.py')
-rw-r--r--addons/account/models/account_move.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index f44cfcc7140..a6a9c7d4358 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -104,8 +104,10 @@ class AccountMove(models.Model):
return journal
+ # TODO remove in master
@api.model
def _get_default_invoice_date(self):
+ warnings.warn("Method '_get_default_invoice_date()' is deprecated and has been removed.", DeprecationWarning)
return fields.Date.context_today(self) if self._context.get('default_move_type', 'entry') in self.get_purchase_types(include_receipts=True) else False
@api.model
@@ -264,8 +266,7 @@ class AccountMove(models.Model):
string='Salesperson',
default=lambda self: self.env.user)
invoice_date = fields.Date(string='Invoice/Bill Date', readonly=True, index=True, copy=False,
- states={'draft': [('readonly', False)]},
- default=_get_default_invoice_date)
+ states={'draft': [('readonly', False)]})
invoice_date_due = fields.Date(string='Due Date', readonly=True, index=True, copy=False,
states={'draft': [('readonly', False)]})
invoice_origin = fields.Char(string='Origin', readonly=True, tracking=True,
@@ -1652,7 +1653,11 @@ class AccountMove(models.Model):
duplicated_moves = self.browse([r[0] for r in self._cr.fetchall()])
if duplicated_moves:
raise ValidationError(_('Duplicated vendor reference detected. You probably encoded twice the same vendor bill/credit note:\n%s') % "\n".join(
- duplicated_moves.mapped(lambda m: "%(partner)s - %(ref)s - %(date)s" % {'ref': m.ref, 'partner': m.partner_id.display_name, 'date': format_date(self.env, m.date)})
+ duplicated_moves.mapped(lambda m: "%(partner)s - %(ref)s - %(date)s" % {
+ 'ref': m.ref,
+ 'partner': m.partner_id.display_name,
+ 'date': format_date(self.env, m.invoice_date),
+ })
))
def _check_balanced(self):
@@ -2449,9 +2454,12 @@ class AccountMove(models.Model):
# lines are recomputed accordingly.
# /!\ 'check_move_validity' must be there since the dynamic lines will be recomputed outside the 'onchange'
# environment.
- if not move.invoice_date and move.is_invoice(include_receipts=True):
- move.invoice_date = fields.Date.context_today(self)
- move.with_context(check_move_validity=False)._onchange_invoice_date()
+ if not move.invoice_date:
+ if move.is_sale_document(include_receipts=True):
+ move.invoice_date = fields.Date.context_today(self)
+ move.with_context(check_move_validity=False)._onchange_invoice_date()
+ elif move.is_purchase_document(include_receipts=True):
+ raise UserError(_("The Bill/Refund date is required to validate this document."))
# When the accounting date is prior to the tax lock date, move it automatically to the next available date.
# /!\ 'check_move_validity' must be there since the dynamic lines will be recomputed outside the 'onchange'