Skip to content

Commit

Permalink
[REM] *: discard old implementation of onchange
Browse files Browse the repository at this point in the history
Part-of: odoo#133049
  • Loading branch information
rco-odoo committed Aug 31, 2023
1 parent 2dff833 commit 109935d
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 1,514 deletions.
18 changes: 0 additions & 18 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -2519,24 +2519,6 @@ def _compute_display_name(self):
for move in self:
move.display_name = move._get_move_display_name(show_ref=True)

def onchange(self, values, field_name, field_onchange):
if field_name in ('line_ids', 'invoice_line_ids'):
# Since only one field can be changed at the same time (the record is saved when changing tabs)
# we can avoid building the snapshots for the other field
to_del = 'invoice_line_ids' if field_name == 'line_ids' else 'line_ids'
for key in list(field_onchange):
if key == to_del or key.startswith(f"{to_del}."):
del field_onchange[key]
# test_01_account_tour
# File "/data/build/odoo/addons/account/models/account_move.py", line 2127, in onchange
# del values[to_del]
# KeyError: 'line_ids'
values.pop(to_del, None)
if field_name and not isinstance(field_name, list):
field_name = [field_name]
with self.env.protecting([self._fields[fname] for fname in field_name or []], self):
return super().onchange(values, field_name, field_onchange)

def onchange2(self, values, field_names, fields_spec):
# Since only one field can be changed at the same time (the record is
# saved when changing tabs) we can avoid building the snapshots for the
Expand Down
8 changes: 3 additions & 5 deletions addons/base_automation/tests/test_automation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import TransactionCase
from odoo.exceptions import UserError

import odoo.tests


@odoo.tests.tagged('post_install', '-at_install')
class TestAutomation(TransactionCase):

Expand Down Expand Up @@ -32,7 +32,6 @@ def test_01_on_create(self):
bilbo.name = "Bilbo"
self.assertFalse(bilbo.active)


def test_02_on_create_restricted(self):
""" on_create action with low portal user """
action = self.env["base.automation"].create({
Expand Down Expand Up @@ -68,7 +67,6 @@ def test_02_on_create_restricted(self):
filters.name = "Where is Bilbo Baggins?"
self.assertFalse(filters.active)


def test_03_on_change_restricted(self):
""" on_create action with low portal user """
action = self.env["base.automation"].create({
Expand All @@ -86,5 +84,5 @@ def test_03_on_change_restricted(self):
self_portal = self.env["ir.filters"].with_user(self.env.ref("base.user_demo").id)

# simulate a onchange call on name
onchange = self_portal.onchange({}, [], {"name": "1", "active": ""})
self.assertEqual(onchange["value"]["active"], False)
result = self_portal.onchange2({}, [], {"name": {}, "active": {}})
self.assertEqual(result["value"]["active"], False)
5 changes: 0 additions & 5 deletions addons/hr_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,11 +1254,6 @@ def _read_format(self, fnames, load='_classic_read'):
self = self.with_context(show_payment_journal_id=True)
return super()._read_format(fnames, load)

def onchange(self, values, field_name, field_onchange):
# setting the context in the field on the view is not enough
self = self.with_context(show_payment_journal_id=True)
return super().onchange(values, field_name, field_onchange)

@api.model_create_multi
def create(self, vals_list):
context = clean_context(self.env.context)
Expand Down
6 changes: 3 additions & 3 deletions addons/hr_holidays/models/hr_leave.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,14 +840,14 @@ def _compute_display_name(self):
start=display_date,
)

def onchange(self, values, field_name, field_onchange):
def onchange2(self, values, field_names, fields_spec):
# Try to force the leave_type display_name when creating new records
# This is called right after pressing create and returns the display_name for
# most fields in the view.
if field_onchange.get('employee_id') and 'employee_id' not in self._context and values:
if values and 'employee_id' in fields_spec and 'employee_id' not in self._context:
employee_id = get_employee_from_context(values, self._context, self.env.user.employee_id.id)
self = self.with_context(employee_id=employee_id)
return super().onchange(values, field_name, field_onchange)
return super().onchange2(values, field_names, fields_spec)

def add_follower(self, employee_id):
employee = self.env['hr.employee'].browse(employee_id)
Expand Down
6 changes: 3 additions & 3 deletions addons/hr_holidays/models/hr_leave_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,14 @@ def _update_accrual(self):
# ORM Overrides methods
####################################################

def onchange(self, values, field_name, field_onchange):
def onchange2(self, values, field_names, fields_spec):
# Try to force the leave_type display_name when creating new records
# This is called right after pressing create and returns the display_name for
# most fields in the view.
if field_onchange.get('employee_id') and 'employee_id' not in self._context and values:
if values and 'employee_id' in fields_spec and 'employee_id' not in self._context:
employee_id = get_employee_from_context(values, self._context, self.env.user.employee_id.id)
self = self.with_context(employee_id=employee_id)
return super().onchange(values, field_name, field_onchange)
return super().onchange2(values, field_names, fields_spec)

@api.depends(
'holiday_type', 'mode_company_id', 'department_id',
Expand Down
12 changes: 0 additions & 12 deletions addons/purchase/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,6 @@ def _must_delete_date_planned(self, field_name):
# To be overridden
return field_name == 'order_line'

def onchange(self, values, field_name, field_onchange):
"""Override onchange to NOT to update all date_planned on PO lines when
date_planned on PO is updated by the change of date_planned on PO lines.
"""
result = super(PurchaseOrder, self).onchange(values, field_name, field_onchange)
if self._must_delete_date_planned(field_name) and 'value' in result:
already_exist = [ol[1] for ol in values.get('order_line', []) if ol[1]]
for line in result['value'].get('order_line', []):
if line[0] < 2 and 'date_planned' in line[2] and line[1] in already_exist:
del line[2]['date_planned']
return result

def _get_report_base_filename(self):
self.ensure_one()
return 'Purchase Order-%s' % (self.name)
Expand Down
11 changes: 0 additions & 11 deletions addons/stock_picking_batch/models/stock_picking_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,6 @@ def _unlink_if_not_done(self):
if any(batch.state == 'done' for batch in self):
raise UserError(_("You cannot delete Done batch transfers."))

def onchange(self, values, field_name, field_onchange):
"""Override onchange to NOT to update all scheduled_date on pickings when
scheduled_date on batch is updated by the change of scheduled_date on pickings.
"""
result = super().onchange(values, field_name, field_onchange)
if field_name == 'picking_ids' and 'value' in result:
for line in result['value'].get('picking_ids', []):
if line[0] < 2 and 'scheduled_date' in line[2]:
del line[2]['scheduled_date']
return result

# -------------------------------------------------------------------------
# Action methods
# -------------------------------------------------------------------------
Expand Down
26 changes: 0 additions & 26 deletions odoo/addons/base/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,32 +1737,6 @@ def _read_format(self, fnames, load='_classic_read'):
valid_fields = partition(is_reified_group, fnames)[1]
return super()._read_format(valid_fields, load)

def onchange(self, values, field_name, field_onchange):
# field_name can be either a string, a list or Falsy
if isinstance(field_name, list):
names = field_name
elif field_name:
names = [field_name]
else:
names = []

if any(is_reified_group(field) for field in names):
field_name = (
['groups_id']
+ [field for field in names if not is_reified_group(field)]
)
values.pop('groups_id', None)
values.update(self._remove_reified_groups(values))

field_onchange['groups_id'] = ''
result = super().onchange(values, field_name, field_onchange)
if not field_name: # merged default_get
self._add_reified_groups(
filter(is_reified_group, field_onchange),
result.setdefault('value', {})
)
return result

def onchange2(self, values, field_names, fields_spec):
reified_fnames = [fname for fname in fields_spec if is_reified_group(fname)]
if reified_fnames:
Expand Down
1 change: 0 additions & 1 deletion odoo/addons/test_new_api/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

from . import test_new_fields
from . import test_onchange
from . import test_onchange2
from . import test_attributes
from . import test_one2many
Expand Down
Loading

0 comments on commit 109935d

Please sign in to comment.