summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwan <wan@odoo.com>2020-08-06 08:04:01 +0000
committerwan <wan@odoo.com>2020-08-06 10:07:28 +0000
commitb13f40c83e5e16a255dc3bdf5393a80a699d87fd (patch)
tree4824f3bd53328331fd4577c63f7ef4b31a7abd7d
parent09bfca4d0c9bdbdd4b93d8f982a9b7d06528fdf8 (diff)
[FIX] account: use context_today instead of today
The problem of using fields.Date.today() instead of fields.Date.context_today() arose with the recent changes in the account.move._post() method used in the POS tests, around 1 am. This commit changes all occurences of today to context_today. closes odoo/odoo#55511 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
-rw-r--r--addons/account/models/account_full_reconcile.py2
-rw-r--r--addons/account/models/account_journal_dashboard.py4
-rw-r--r--addons/account/models/account_move.py16
-rw-r--r--addons/account/models/account_partial_reconcile.py2
-rw-r--r--addons/account/models/account_payment_term.py4
-rw-r--r--addons/account/models/account_reconcile_model.py2
-rw-r--r--addons/account/models/company.py4
-rw-r--r--addons/account/tests/test_reconciliation.py2
-rw-r--r--addons/account/wizard/account_automatic_entry_wizard.py2
9 files changed, 19 insertions, 19 deletions
diff --git a/addons/account/models/account_full_reconcile.py b/addons/account/models/account_full_reconcile.py
index b8ef91ec1fa..f2ff0ea0895 100644
--- a/addons/account/models/account_full_reconcile.py
+++ b/addons/account/models/account_full_reconcile.py
@@ -27,7 +27,7 @@ class AccountFullReconcile(models.Model):
res = super().unlink()
# Reverse all exchange moves at once.
- today = fields.Date.today()
+ today = fields.Date.context_today(self)
default_values_list = [{
'date': today,
'ref': _('Reversal of: %s') % move.name,
diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py
index 55070e0a257..63a75bf323e 100644
--- a/addons/account/models/account_journal_dashboard.py
+++ b/addons/account/models/account_journal_dashboard.py
@@ -263,7 +263,7 @@ class account_journal(models.Model):
self.env.cr.execute(query, query_args)
query_results_drafts = self.env.cr.dictfetchall()
- today = fields.Date.today()
+ today = fields.Date.context_today(self)
query = '''
SELECT
(CASE WHEN move_type IN ('out_refund', 'in_refund') THEN -1 ELSE 1 END) * amount_residual AS amount_total,
@@ -373,7 +373,7 @@ class account_journal(models.Model):
cur = self.env['res.currency'].browse(result.get('currency'))
company = self.env['res.company'].browse(result.get('company_id')) or self.env.company
rslt_count += 1
- date = result.get('invoice_date') or fields.Date.today()
+ date = result.get('invoice_date') or fields.Date.context_today(self)
amount = result.get('amount_total', 0) or 0
if cur != target_currency:
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index fccccb49ae6..ec931923532 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -105,7 +105,7 @@ class AccountMove(models.Model):
@api.model
def _get_default_invoice_date(self):
- return fields.Date.today() if self._context.get('default_move_type', 'entry') in ('in_invoice', 'in_refund', 'in_receipt') else False
+ return fields.Date.context_today(self) if self._context.get('default_move_type', 'entry') in ('in_invoice', 'in_refund', 'in_receipt') else False
@api.model
def _get_default_currency(self):
@@ -1430,7 +1430,7 @@ class AccountMove(models.Model):
tax_key_add_base = tuple(move._get_tax_key_for_group_add_base(line))
if tax_key_add_base not in done_taxes:
if line.currency_id and line.company_currency_id and line.currency_id != line.company_currency_id:
- amount = line.company_currency_id._convert(line.tax_base_amount, line.currency_id, line.company_id, line.date or fields.Date.today())
+ amount = line.company_currency_id._convert(line.tax_base_amount, line.currency_id, line.company_id, line.date or fields.Date.context_today(self))
else:
amount = line.tax_base_amount
res[line.tax_line_id.tax_group_id]['base'] += amount
@@ -2309,7 +2309,7 @@ class AccountMove(models.Model):
:return Model<account.move>: the documents that have been posted
"""
if soft:
- future_moves = self.filtered(lambda move: move.date > fields.Date.today())
+ future_moves = self.filtered(lambda move: move.date > fields.Date.context_today(self))
future_moves.auto_post = True
for move in future_moves:
msg = _('This move will be posted at the accounting date: %(date)s', date=format_date(self.env, move.date))
@@ -2324,7 +2324,7 @@ class AccountMove(models.Model):
for move in to_post:
if not move.line_ids.filtered(lambda line: not line.display_type):
raise UserError(_('You need to add a line before posting.'))
- if move.auto_post and move.date > fields.Date.today():
+ if move.auto_post and move.date > fields.Date.context_today(self):
date_msg = move.date.strftime(get_lang(self.env).date_format)
raise UserError(_("This move is configured to be auto-posted on %s", date_msg))
@@ -2653,7 +2653,7 @@ class AccountMove(models.Model):
'''
records = self.search([
('state', '=', 'draft'),
- ('date', '<=', fields.Date.today()),
+ ('date', '<=', fields.Date.context_today(self)),
('auto_post', '=', True),
])
records._post()
@@ -3360,7 +3360,7 @@ class AccountMoveLine(models.Model):
company_currency = line.account_id.company_id.currency_id
balance = line.amount_currency
if line.currency_id and company_currency and line.currency_id != company_currency:
- balance = line.currency_id._convert(balance, company_currency, line.account_id.company_id, line.move_id.date or fields.Date.today())
+ balance = line.currency_id._convert(balance, company_currency, line.account_id.company_id, line.move_id.date or fields.Date.context_today(self))
line.debit = balance > 0 and balance or 0.0
line.credit = balance < 0 and -balance or 0.0
# -------------------------------------------------------------------------
@@ -4450,7 +4450,7 @@ class AccountMoveLine(models.Model):
total = 0
total_currency = 0
writeoff_lines = []
- date = fields.Date.today()
+ date = fields.Date.context_today(self)
for vals in lines:
# Check and complete vals
if 'account_id' not in vals or 'journal_id' not in vals:
@@ -4458,7 +4458,7 @@ class AccountMoveLine(models.Model):
if ('debit' in vals) ^ ('credit' in vals):
raise UserError(_("Either pass both debit and credit or none."))
if 'date' not in vals:
- vals['date'] = self._context.get('date_p') or fields.Date.today()
+ vals['date'] = self._context.get('date_p') or fields.Date.context_today(self)
vals['date'] = fields.Date.to_date(vals['date'])
if vals['date'] and vals['date'] < date:
date = vals['date']
diff --git a/addons/account/models/account_partial_reconcile.py b/addons/account/models/account_partial_reconcile.py
index ef9d8f4891e..a35f8bcc381 100644
--- a/addons/account/models/account_partial_reconcile.py
+++ b/addons/account/models/account_partial_reconcile.py
@@ -108,7 +108,7 @@ class AccountPartialReconcile(models.Model):
# Reverse all exchange moves at once.
moves_to_reverse = self.env['account.move'].search([('tax_cash_basis_rec_id', 'in', self.ids)])
- today = fields.Date.today()
+ today = fields.Date.context_today(self)
default_values_list = [{
'date': move.date if move.date > (move.company_id.period_lock_date or date.min) else today,
'ref': _('Reversal of: %s') % move.name,
diff --git a/addons/account/models/account_payment_term.py b/addons/account/models/account_payment_term.py
index c7d8dd8d734..018000aa469 100644
--- a/addons/account/models/account_payment_term.py
+++ b/addons/account/models/account_payment_term.py
@@ -33,7 +33,7 @@ class AccountPaymentTerm(models.Model):
def compute(self, value, date_ref=False, currency=None):
self.ensure_one()
- date_ref = date_ref or fields.Date.today()
+ date_ref = date_ref or fields.Date.context_today(self)
amount = value
sign = value < 0 and -1 or 1
result = []
@@ -63,7 +63,7 @@ class AccountPaymentTerm(models.Model):
amount = sum(amt for _, amt in result)
dist = currency.round(value - amount)
if dist:
- last_date = result and result[-1][0] or fields.Date.today()
+ last_date = result and result[-1][0] or fields.Date.context_today(self)
result.append((last_date, dist))
return result
diff --git a/addons/account/models/account_reconcile_model.py b/addons/account/models/account_reconcile_model.py
index 6f5de73d398..6f840f25eb4 100644
--- a/addons/account/models/account_reconcile_model.py
+++ b/addons/account/models/account_reconcile_model.py
@@ -627,7 +627,7 @@ class AccountReconcileModel(models.Model):
# If this reconciliation model defines a past_months_limit, we add a condition
# to the query to only search on move lines that are younger than this limit.
if self.past_months_limit:
- date_limit = fields.Date.today() - relativedelta(months=self.past_months_limit)
+ date_limit = fields.Date.context_today(self) - relativedelta(months=self.past_months_limit)
query += "AND aml.date >= %(aml_date_limit)s"
params['aml_date_limit'] = date_limit
diff --git a/addons/account/models/company.py b/addons/account/models/company.py
index 2f3f1e5864c..d71c0962875 100644
--- a/addons/account/models/company.py
+++ b/addons/account/models/company.py
@@ -82,7 +82,7 @@ class ResCompany(models.Model):
#Fields of the setup step for opening move
account_opening_move_id = fields.Many2one(string='Opening Journal Entry', comodel_name='account.move', help="The journal entry containing the initial balance of all this company's accounts.")
account_opening_journal_id = fields.Many2one(string='Opening Journal', comodel_name='account.journal', related='account_opening_move_id.journal_id', help="Journal where the opening entry of this company's accounting has been posted.", readonly=False)
- account_opening_date = fields.Date(string='Opening Entry', default=lambda self: fields.Date.today().replace(month=1, day=1), required=True, help="That is the date of the opening entry.")
+ account_opening_date = fields.Date(string='Opening Entry', default=lambda self: fields.Date.context_today(self).replace(month=1, day=1), required=True, help="That is the date of the opening entry.")
# Fields marking the completion of a setup step
account_setup_bank_data_state = fields.Selection(ONBOARDING_STEP_STATES, string="State of the onboarding bank data step", default='not_done')
@@ -501,7 +501,7 @@ class ResCompany(models.Model):
journals = self.env['account.journal'].search([('company_id', '=', self.id)])
results_by_journal = {
'results': [],
- 'printing_date': format_date(self.env, fields.Date.to_string(fields.Date.today()))
+ 'printing_date': format_date(self.env, fields.Date.to_string(fields.Date.context_today(self)))
}
for journal in journals:
diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py
index 6e2e49c6937..e8bbf84da9e 100644
--- a/addons/account/tests/test_reconciliation.py
+++ b/addons/account/tests/test_reconciliation.py
@@ -749,7 +749,7 @@ class TestReconciliationExec(TestAccountReconciliationCommon):
})
purchase_move.action_post()
- reverse_date = fields.Date.today() + timedelta(days=+7)
+ reverse_date = fields.Date.context_today(purchase_move) + timedelta(days=+7)
revertWidget = self.env['account.move.reversal'].create({
'move_ids': [(6, 0, [purchase_move.id])],
'date': reverse_date,
diff --git a/addons/account/wizard/account_automatic_entry_wizard.py b/addons/account/wizard/account_automatic_entry_wizard.py
index 920e209c5a5..2259dacb922 100644
--- a/addons/account/wizard/account_automatic_entry_wizard.py
+++ b/addons/account/wizard/account_automatic_entry_wizard.py
@@ -16,7 +16,7 @@ class AutomaticEntryWizard(models.TransientModel):
move_data = fields.Text(compute="_compute_move_data", help="JSON value of the moves to be created")
preview_move_data = fields.Text(compute="_compute_preview_move_data", help="JSON value of the data to be displayed in the previewer")
move_line_ids = fields.Many2many('account.move.line')
- date = fields.Date(required=True, default=fields.Date.today())
+ date = fields.Date(required=True, default=lambda self: fields.Date.context_today(self))
company_id = fields.Many2one('res.company', required=True, readonly=True)
company_currency_id = fields.Many2one('res.currency', related='company_id.currency_id')
percentage = fields.Float("Percentage", compute='_compute_percentage', readonly=False, store=True, help="Percentage of each line to execute the action on.")