[FIX] *: remove buggy calls to with_context
When .with_context() is called with a dictionary as 1st positional argument, it will replace context (and not modify the referenced keys) It may create bugs when losing the content of the context (e.g. remove partner's language) This is a partial merge of #36164 without the inventory part as discussed. closes odoo/odoo#36729 X-forward: 4717ccfa Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
committed by
Martin Trigaux
parent
e7697ea472
commit
5dad570423
@@ -279,13 +279,13 @@ class AccountAccount(models.Model):
|
||||
if opening_move_line:
|
||||
if amount:
|
||||
# modify the line
|
||||
setattr(opening_move_line.with_context({'check_move_validity': False}), field, amount)
|
||||
opening_move_line.with_context(check_move_validity=False)[field] = amount
|
||||
elif counter_part_map[field]:
|
||||
# delete the line (no need to keep a line with value = 0)
|
||||
opening_move_line.with_context({'check_move_validity': False}).unlink()
|
||||
opening_move_line.with_context(check_move_validity=False).unlink()
|
||||
elif amount:
|
||||
# create a new line, as none existed before
|
||||
self.env['account.move.line'].with_context({'check_move_validity': False}).create({
|
||||
self.env['account.move.line'].with_context(check_move_validity=False).create({
|
||||
'name': _('Opening balance'),
|
||||
field: amount,
|
||||
'move_id': opening_move.id,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<odoo>
|
||||
<template id="report_payment_receipt_document">
|
||||
<t t-call="web.external_layout">
|
||||
<t t-set="o" t-value="o.with_context({'lang': lang})"/>
|
||||
<t t-set="o" t-value="o.with_context(lang=lang)"/>
|
||||
<div class="page">
|
||||
<h3><strong>Payment Receipt: <span t-field="o.name"/></strong></h3>
|
||||
<div class="row mt64">
|
||||
|
||||
@@ -561,7 +561,7 @@ class EventRegistration(models.Model):
|
||||
elif event_date.month == (today + relativedelta(months=+1)).month:
|
||||
return _('next month')
|
||||
else:
|
||||
return _('on ') + format_tz(self.with_context({'use_babel': True}).env, self.event_begin_date, tz=self.event_id.date_tz or 'UTC')
|
||||
return _('on ') + format_tz(self.with_context(use_babel=True).env, self.event_begin_date, tz=self.event_id.date_tz or 'UTC')
|
||||
|
||||
@api.multi
|
||||
def summary(self):
|
||||
|
||||
@@ -96,7 +96,7 @@ class EventTicket(models.Model):
|
||||
def _compute_is_expired(self):
|
||||
for record in self:
|
||||
if record.deadline:
|
||||
current_date = fields.Date.context_today(record.with_context({'tz': record.event_id.date_tz}))
|
||||
current_date = fields.Date.context_today(record.with_context(tz=record.event_id.date_tz))
|
||||
record.is_expired = record.deadline < current_date
|
||||
else:
|
||||
record.is_expired = False
|
||||
|
||||
@@ -249,7 +249,7 @@ class AliasMixin(models.AbstractModel):
|
||||
for record in child_model.search([('alias_id', '=', False)]):
|
||||
# create the alias, and link it to the current record
|
||||
alias = alias_model.create(record.get_alias_values())
|
||||
record.with_context({'mail_notrack': True}).alias_id = alias
|
||||
record.with_context(mail_notrack=True).alias_id = alias
|
||||
_logger.info('Mail alias created for %s %s (id %s)',
|
||||
record._name, record.display_name, record.id)
|
||||
|
||||
|
||||
@@ -949,7 +949,7 @@ class Message(models.Model):
|
||||
def create(self, values):
|
||||
# coming from mail.js that does not have pid in its values
|
||||
if self.env.context.get('default_starred'):
|
||||
self = self.with_context({'default_starred_partner_ids': [(4, self.env.user.partner_id.id)]})
|
||||
self = self.with_context(default_starred_partner_ids=[(4, self.env.user.partner_id.id)])
|
||||
|
||||
if 'email_from' not in values: # needed to compute reply_to
|
||||
values['email_from'] = self._get_default_from()
|
||||
|
||||
@@ -30,7 +30,7 @@ class MailBot(models.AbstractModel):
|
||||
if answer:
|
||||
message_type = values.get('message_type', 'comment')
|
||||
subtype_id = values.get('subtype_id', self.env['ir.model.data'].xmlid_to_res_id('mail.mt_comment'))
|
||||
record.with_context({"mail_create_nosubscribe": True}).sudo().message_post(body=answer, author_id=odoobot_id, message_type=message_type, subtype_id=subtype_id)
|
||||
record.with_context(mail_create_nosubscribe=True).sudo().message_post(body=answer, author_id=odoobot_id, message_type=message_type, subtype_id=subtype_id)
|
||||
|
||||
def _get_answer(self, record, body, values, command=False):
|
||||
# onboarding
|
||||
|
||||
@@ -16,7 +16,7 @@ class Channel(models.Model):
|
||||
if self.env.user.odoobot_state == 'not_initialized':
|
||||
partner = self.env.user.partner_id
|
||||
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("base.partner_root")
|
||||
channel = self.with_context({"mail_create_nosubscribe": True}).create({
|
||||
channel = self.with_context(mail_create_nosubscribe=True).create({
|
||||
'channel_partner_ids': [(4, partner.id), (4, odoobot_id)],
|
||||
'public': 'private',
|
||||
'channel_type': 'chat',
|
||||
|
||||
@@ -475,7 +475,7 @@ class SaleOrder(models.Model):
|
||||
self.filtered(lambda s: s.state == 'draft').write({'state': 'sent'})
|
||||
|
||||
return self.env.ref('sale.action_report_saleorder')\
|
||||
.with_context({'discard_logo_check': True}).report_action(self)
|
||||
.with_context(discard_logo_check=True).report_action(self)
|
||||
|
||||
@api.multi
|
||||
def action_view_invoice(self):
|
||||
|
||||
@@ -38,7 +38,7 @@ class GoogleMap(http.Controller):
|
||||
"counter": len(partners),
|
||||
"partners": []
|
||||
}
|
||||
for partner in partners.with_context({'show_address': True}):
|
||||
for partner in partners.with_context(show_address=True):
|
||||
# TODO in master, do not use `escape` but `t-esc` in the qweb template.
|
||||
partner_data["partners"].append({
|
||||
'id': partner.id,
|
||||
|
||||
@@ -153,7 +153,7 @@ For example, let's look at the Sale Order report from the Sale module::
|
||||
<!-- Translatable template -->
|
||||
<template id="report_saleorder_document">
|
||||
<!-- Re-browse of the record with the partner lang -->
|
||||
<t t-set="doc" t-value="doc.with_context({'lang':doc.partner_id.lang})" />
|
||||
<t t-set="doc" t-value="doc.with_context(lang=doc.partner_id.lang)" />
|
||||
<t t-call="web.external_layout">
|
||||
<div class="page">
|
||||
<div class="oe_structure"/>
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestIrSequenceDateRangeStandard(SingleTransactionCase):
|
||||
year = date.today().year - 1
|
||||
january = lambda d: date(year, 1, d)
|
||||
|
||||
seq16 = self.env['ir.sequence'].with_context({'ir_sequence_date': january(16)})
|
||||
seq16 = self.env['ir.sequence'].with_context(ir_sequence_date=january(16))
|
||||
n = seq16.next_by_code('test_sequence_date_range')
|
||||
self.assertEqual(n, '1')
|
||||
n = seq16.next_by_code('test_sequence_date_range')
|
||||
|
||||
Reference in New Issue
Block a user