Skip to content
Permalink
Browse files

[IMP] api: remove deprecated decorators

  • Loading branch information
rco-odoo committed Apr 10, 2019
1 parent fa50376 commit c552fb7a618afe2feea2e0358ead9eb6ebff0c94
Showing with 7 additions and 424 deletions.
  1. +0 −1 addons/account/models/account_analytic_line.py
  2. +0 −1 addons/account/models/account_move.py
  3. +0 −1 addons/account/report/account_invoice_report.py
  4. +0 −1 addons/base_automation/models/base_automation.py
  5. +0 −2 addons/base_gengo/wizard/base_gengo_translations.py
  6. +0 −2 addons/crm/models/crm_lead.py
  7. +0 −1 addons/crm/report/crm_activity_report.py
  8. +0 −1 addons/crm_iap_lead_website/models/crm_reveal_view.py
  9. +0 −1 addons/hr/models/hr_employee_public.py
  10. +0 −1 addons/hr_holidays/models/hr_leave.py
  11. +0 −1 addons/hr_timesheet_attendance/report/hr_timesheet_attendance_report.py
  12. +0 −1 addons/im_livechat/report/im_livechat_report_channel.py
  13. +0 −1 addons/im_livechat/report/im_livechat_report_operator.py
  14. +0 −1 addons/l10n_in/report/account_invoice_report.py
  15. +0 −1 addons/l10n_in/report/account_payment_report.py
  16. +0 −1 addons/l10n_in/report/exempted_gst_report.py
  17. +0 −1 addons/l10n_in/report/hsn_gst_report.py
  18. +0 −1 addons/mail/models/mail_alias.py
  19. +0 −1 addons/mail/models/mail_channel.py
  20. +0 −1 addons/mail/models/mail_message.py
  21. +0 −1 addons/mail/models/mail_notification.py
  22. +0 −3 addons/mail/wizard/mail_compose_message.py
  23. +0 −1 addons/mass_mailing/models/mass_mailing_report.py
  24. +0 −1 addons/membership/report/report_membership.py
  25. +0 −1 addons/point_of_sale/report/pos_order_report.py
  26. +0 −1 addons/purchase/report/purchase_bill.py
  27. +0 −1 addons/purchase/report/purchase_report.py
  28. +0 −1 addons/sale/report/report_all_channels_sales.py
  29. +0 −1 addons/sale/report/sale_report.py
  30. +0 −1 addons/stock/models/stock_move.py
  31. +0 −1 addons/stock/report/report_stock_forecast.py
  32. +0 −1 addons/website/models/res_users.py
  33. +0 −1 addons/website_crm_partner_assign/report/crm_partner_report.py
  34. +0 −1 addons/website_event_questions/report/report_event_registrations_questions.py
  35. +0 −1 addons/website_form/models/models.py
  36. +0 −1 addons/website_slides/models/slide_channel.py
  37. +0 −39 doc/reference/orm.rst
  38. +0 −5 odoo/addons/base/models/decimal_precision.py
  39. +0 −1 odoo/addons/base/models/ir_actions.py
  40. +0 −1 odoo/addons/base/models/ir_actions_report.py
  41. +0 −1 odoo/addons/base/models/ir_attachment.py
  42. +0 −1 odoo/addons/base/models/ir_config_parameter.py
  43. +0 −1 odoo/addons/base/models/ir_filters.py
  44. +0 −1 odoo/addons/base/models/ir_logging.py
  45. +2 −3 odoo/addons/base/models/ir_model.py
  46. +0 −2 odoo/addons/base/models/ir_translation.py
  47. +0 −2 odoo/addons/base/models/ir_ui_view.py
  48. +0 −1 odoo/addons/base/models/res_company.py
  49. +1 −1 odoo/addons/base/models/res_config.py
  50. +0 −1 odoo/addons/base/models/res_lang.py
  51. +0 −1 odoo/addons/base/models/res_partner.py
  52. +0 −1 odoo/addons/test_performance/models/models.py
  53. +3 −309 odoo/api.py
  54. +1 −13 odoo/models.py
@@ -17,7 +17,6 @@ class AccountAnalyticLine(models.Model):
code = fields.Char(size=8)
ref = fields.Char(string='Ref.')

@api.v8
@api.onchange('product_id', 'product_uom_id', 'unit_amount', 'currency_id')
def on_change_unit_amount(self):
if not self.product_id:
@@ -2779,7 +2779,6 @@ def _update_check(self):
# LOW-LEVEL METHODS
# -------------------------------------------------------------------------

@api.model_cr
def init(self):
""" change index on partner_id to a multi-column index on (partner_id, ref), the new index will behave in the
same way when we search on partner_id, with the addition of being optimal when having a query that will
@@ -164,7 +164,6 @@ def _group_by(self):
COALESCE(partner.country_id, commercial_partner.country_id)
'''

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute('''
@@ -231,7 +231,6 @@ def differ(name):
)
return any(differ(field.name) for field in self.trigger_field_ids)

@api.model_cr
def _register_hook(self):
""" Patch models that should trigger action rules based on creation,
modification, deletion of records and form onchanges.
@@ -45,13 +45,11 @@ def default_get(self, fields):
sync_limit = fields.Integer("No. of terms to sync", default=20)
authorized_credentials = fields.Boolean('The private and public keys are valid')

@api.model_cr
def init(self):
icp = self.env['ir.config_parameter'].sudo()
if not icp.get_param(self.GENGO_KEY):
icp.set_param(self.GENGO_KEY, str(uuid.uuid4()))

@api.model_cr
def get_gengo_key(self):
icp = self.env['ir.config_parameter'].sudo()
return icp.get_param(self.GENGO_KEY, default="Undefined")
@@ -57,7 +57,6 @@ class Lead(models.Model):
'utm.mixin', 'format.address.mixin', 'phone.validation.mixin']
_primary_email = 'email_from'

@api.model_cr_context
def _auto_init(self):
res = super(Lead, self)._auto_init()
tools.create_index(self._cr, 'crm_lead_create_date_team_id_idx',
@@ -146,7 +145,6 @@ def _default_stage_id(self):
('check_probability', 'check(probability >= 0 and probability <= 100)', 'The probability of closing the deal should be between 0% and 100%!')
]

@api.model_cr_context
def _auto_init(self):
res = super(Lead, self)._auto_init()
tools.create_index(self._cr, 'crm_lead_user_id_team_id_type_index',
@@ -75,7 +75,6 @@ def _where(self):
m.model = 'crm.lead' AND (m.mail_activity_type_id IS NOT NULL OR m.subtype_id = %s)
""" % (disccusion_subtype.id,)

@api.model_cr
def init(self):
tools.drop_view_if_exists(self._cr, self._table)
self._cr.execute("""
@@ -17,7 +17,6 @@ class CRMRevealView(models.Model):
reveal_state = fields.Selection([('to_process', 'To Process'), ('not_found', 'Not Found')], default='to_process', string="State", index=True)
create_date = fields.Datetime(index=True)

@api.model_cr
def init(self):
self._cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('crm_reveal_view_ip_rule_id',))
if not self._cr.fetchone():
@@ -49,7 +49,6 @@ def _compute_image(self):
def _get_fields(self):
return ','.join('emp.%s' % name for name, field in self._fields.items() if field.store and field.type not in ['many2many', 'one2many'])

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute("""CREATE or REPLACE VIEW %s as (
@@ -252,7 +252,6 @@ def _default_get_request_parameters(self, values):
('duration_check', "CHECK ( number_of_days >= 0 )", "If you want to change the number of days you should use the 'period' mode"),
]

@api.model_cr_context
def _auto_init(self):
res = super(HolidaysRequest, self)._auto_init()
tools.create_index(self._cr, 'hr_leave_date_to_date_from_index',
@@ -15,7 +15,6 @@ class TimesheetAttendance(models.Model):
total_attendance = fields.Float()
total_difference = fields.Float()

@api.model_cr
def init(self):
self._cr.execute("""CREATE OR REPLACE VIEW %s AS (
SELECT
@@ -38,7 +38,6 @@ class ImLivechatReportChannel(models.Model):
is_unrated = fields.Integer('Session not rated', readonly=True)
partner_id = fields.Many2one('res.partner', 'Operator', readonly=True)

@api.model_cr
def init(self):
# Note : start_date_hour must be remove when the read_group will allow grouping on the hour of a datetime. Don't forget to change the view !
tools.drop_view_if_exists(self.env.cr, 'im_livechat_report_channel')
@@ -20,7 +20,6 @@ class ImLivechatReportOperator(models.Model):
time_to_answer = fields.Float('Time to answer', digits=(16, 2), readonly=True, group_operator="avg", help="Average time to give the first answer to the visitor")
duration = fields.Float('Average duration', digits=(16, 2), readonly=True, group_operator="avg", help="Duration of the conversation (in seconds)")

@api.model_cr
def init(self):
# Note : start_date_hour must be remove when the read_group will allow grouping on the hour of a datetime. Don't forget to change the view !
tools.drop_view_if_exists(self.env.cr, 'im_livechat_report_operator')
@@ -302,7 +302,6 @@ def _group_by(self):
"""
return group_by_str

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute("""CREATE or REPLACE VIEW %s AS (
@@ -101,7 +101,6 @@ def _where(self):
AND tax.tax_group_id in (SELECT res_id FROM ir_model_data WHERE module='l10n_in' AND name in ('igst_group','gst_group'))
AND ac.internal_type IN ('receivable', 'payable') AND am.state = 'posted'"""

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute("""CREATE or REPLACE VIEW %s AS (
@@ -89,7 +89,6 @@ def _from(self):
"""
return from_str

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self._cr.execute("""CREATE OR REPLACE VIEW %s AS (%s %s)""" % (
@@ -98,7 +98,6 @@ def _from(self):
"""
return from_str

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute("""CREATE OR REPLACE VIEW %s AS (%s %s)""" % (
@@ -220,7 +220,6 @@ def unlink(self):
aliases.unlink()
return res

@api.model_cr_context
def _init_column(self, name):
""" Create aliases for existing rows. """
super(AliasMixin, self)._init_column(name)
@@ -410,7 +410,6 @@ def _alias_check_contact(self, message, message_dict, alias):
return True
return super(Channel, self)._alias_check_contact(message, message_dict, alias)

@api.model_cr
def init(self):
self._cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('mail_channel_partner_seen_message_id_idx',))
if not self._cr.fetchone():
@@ -585,7 +585,6 @@ def _notify_failure_update(self):
# mail_message internals
#------------------------------------------------------

@api.model_cr
def init(self):
self._cr.execute("""SELECT indexname FROM pg_indexes WHERE indexname = 'mail_message_model_res_id_idx'""")
if not self._cr.fetchone():
@@ -37,7 +37,6 @@ class Notification(models.Model):
], string='Failure type')
failure_reason = fields.Text('Failure reason', copy=False)

@api.model_cr
def init(self):
self._cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('mail_notification_res_partner_id_is_read_email_status_mail_message_id',))
if not self._cr.fetchone():
@@ -430,9 +430,6 @@ def onchange_template_id(self, template_id, composition_mode, model, res_id):
values['body'] = values.pop('body_html')

# This onchange should return command instead of ids for x2many field.
# ORM handle the assignation of command list on new onchange (api.v8),
# this force the complete replacement of x2many field with
# command and is compatible with onchange api.v7
values = self._convert_to_write(values)

return {'value': values}
@@ -22,7 +22,6 @@ class MassMailingReport(models.Model):
string='Status', readonly=True)
email_from = fields.Char('From', readonly=True)

@api.model_cr
def init(self):
"""Mass Mail Statistical Report: based on mail.mail.statistics that models the various
statistics collected for each mailing, and mail.mass_mailing model that models the
@@ -37,7 +37,6 @@ class ReportMembership(models.Model):
company_id = fields.Many2one('res.company', string='Company', readonly=True)
quantity = fields.Integer(readonly=True)

@api.model_cr
def init(self):
'''Create the view'''
tools.drop_view_if_exists(self._cr, self._table)
@@ -94,7 +94,6 @@ def _having(self):
SUM(l.qty * u.factor) != 0
"""

@api.model_cr
def init(self):
tools.drop_view_if_exists(self._cr, self._table)
self._cr.execute("""
@@ -20,7 +20,6 @@ class PurchaseBillUnion(models.Model):
vendor_bill_id = fields.Many2one('account.move', string='Vendor Bill', readonly=True)
purchase_order_id = fields.Many2one('purchase.order', string='Purchase Order', readonly=True)

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, 'purchase_bill_union')
self.env.cr.execute("""
@@ -50,7 +50,6 @@ class PurchaseReport(models.Model):
qty_billed = fields.Float('Qty Billed', readonly=True)
qty_to_be_billed = fields.Float('Qty to be Billed', readonly=True)

@api.model_cr
def init(self):
# self._table = sale_report
tools.drop_view_if_exists(self.env.cr, self._table)
@@ -82,7 +82,6 @@ def get_main_request(self):
AS foo""" % (self._table, self._from())
return request

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute(self.get_main_request())
@@ -144,7 +144,6 @@ def _query(self, with_clause='', fields={}, groupby='', from_clause=''):

return '%s (SELECT %s FROM %s WHERE l.product_id IS NOT NULL GROUP BY %s)' % (with_, select_, from_, groupby_)

@api.model_cr
def init(self):
# self._table = sale_report
tools.drop_view_if_exists(self.env.cr, self._table)
@@ -354,7 +354,6 @@ def _check_uom(self):
user_warning += _('\n\nBlocking: %s') % ' ,'.join(moves_error.mapped('name'))
raise UserError(user_warning)

@api.model_cr
def init(self):
self._cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('stock_move_product_location_index',))
if not self._cr.fetchone():
@@ -17,7 +17,6 @@ class ReportStockForecat(models.Model):
picking_id = fields.Many2one('stock.picking', string='Picking', readonly=True)
reference = fields.Char('Reference')

@api.model_cr
def init(self):
tools.drop_view_if_exists(self._cr, 'report_stock_forecast')
query = """
@@ -47,7 +47,6 @@ def _get_signup_invitation_scope(self):
current_website = self.env['website'].get_current_website()
return current_website.auth_signup_uninvited or super(ResUsers, self)._get_signup_invitation_scope()

@api.model_cr_context
def _auto_init(self):
result = super(ResUsers, self)._auto_init()
# Use unique index to implement unique constraint per website, even if website_id is null
@@ -30,7 +30,6 @@ class CrmPartnerReportAssign(models.Model):
'grade_id', 'parent_id', 'team_id', 'user_id'],
}

@api.model_cr
def init(self):
"""
CRM Lead Report
@@ -14,7 +14,6 @@ class ReportEventRegistrationQuestions(models.Model):
answer_id = fields.Many2one(comodel_name='event.answer', string='Answer')
event_id = fields.Many2one(comodel_name='event.event', string='Event')

@api.model_cr
def init(self):
""" Event Question main report """
tools.drop_view_if_exists(self._cr, 'event_question_report')
@@ -79,7 +79,6 @@ class website_form_model_fields(models.Model):
_description = 'Fields'
_inherit = 'ir.model.fields'

@api.model_cr
def init(self):
# set all existing unset website_form_blacklisted fields to ``true``
# (so that we can use it as a whitelist rather than a blacklist)
@@ -294,7 +294,6 @@ def _compute_action_rights(self):
# ORM Overrides
# ---------------------------------------------------------

@api.model_cr_context
def _init_column(self, column_name):
""" Initialize the value of the given column for existing rows.
Overridden here because we need to generate different access tokens
@@ -1205,20 +1205,6 @@ Porting from the old API to the new API
:attr:`~odoo.models.Model.write_date` fields: they are now created as
regular "legitimate" fields, and can be read and written like any other
field out-of-the-box
* when straight conversion is impossible (semantics can not be bridged) or the
"old API" version is not desirable and could be improved for the new API, it
is possible to use completely different "old API" and "new API"
implementations for the same method name using :func:`~odoo.api.v7` and
:func:`~odoo.api.v8`. The method should first be defined using the
old-API style and decorated with :func:`~odoo.api.v7`, it should then be
re-defined using the exact same name but the new-API style and decorated
with :func:`~odoo.api.v8`. Calls from an old-API context will be
dispatched to the first implementation and calls from a new-API context will
be dispatched to the second implementation. One implementation can call (and
frequently does) call the other by switching context.

.. danger:: using these decorators makes methods extremely difficult to
override and harder to understand and document
* uses of :attr:`~odoo.models.Model._columns` or
:attr:`~odoo.models.Model._all_columns` should be replaced by
:attr:`~odoo.models.Model._fields`, which provides access to instances of
@@ -1277,28 +1263,3 @@ decorating the old-style method:
* disabling it entirely, by decorating a method with
:func:`~odoo.api.noguess` there will be no bridging and methods will be
called the exact same way from the new and old API styles
* defining the bridge explicitly, this is mostly for methods which are matched
incorrectly (because parameters are named in unexpected ways):

:func:`~odoo.api.cr`
will automatically prepend the current cursor to explicitly provided
parameters, positionally
:func:`~odoo.api.cr_uid`
will automatically prepend the current cursor and user's id to explictly
provided parameters
:func:`~odoo.api.cr_uid_ids`
will automatically prepend the current cursor, user's id and recordset's
ids to explicitly provided parameters
:func:`~odoo.api.cr_uid_id`
will loop over the current recordset and call the method once for each
record, prepending the current cursor, user's id and record's id to
explicitly provided parameters.

.. danger:: the result of this wrapper is *always a list* when calling
from a new-API context

All of these methods have a ``_context``-suffixed version
(e.g. :func:`~odoo.api.cr_uid_context`) which also passes the current
context *by keyword*.
* dual implementations using :func:`~odoo.api.v7` and
:func:`~odoo.api.v8` will be ignored as they provide their own "bridging"
@@ -32,11 +32,6 @@ def precision_get(self, application):
res = self.env.cr.fetchone()
return res[0] if res else 2

@api.model_cr
def clear_cache(self):
""" Deprecated, use `clear_caches` instead. """
self.clear_caches()

@api.model_create_multi
def create(self, vals_list):
res = super(DecimalPrecision, self).create(vals_list)
@@ -283,7 +283,6 @@ class IrActionsActWindowView(models.Model):
act_window_id = fields.Many2one('ir.actions.act_window', string='Action', ondelete='cascade')
multi = fields.Boolean(string='On Multiple Doc.', help="If set to true, the action will not be displayed on the right toolbar of a form view.")

@api.model_cr_context
def _auto_init(self):
res = super(IrActionsActWindowView, self)._auto_init()
tools.create_unique_index(self._cr, 'act_window_view_unique_mode_per_action',
@@ -765,7 +765,6 @@ def render(self, res_ids, data=None):
return None
return render_func(res_ids, data=data)

@api.noguess
def report_action(self, docids, data=None, config=True):
"""Return an action of type ir.actions.report.
@@ -300,7 +300,6 @@ def get_serving_groups(self):
mimetype = fields.Char('Mime Type', readonly=True)
index_content = fields.Text('Indexed Content', readonly=True, prefetch=False)

@api.model_cr_context
def _auto_init(self):
res = super(IrAttachment, self)._auto_init()
tools.create_index(self._cr, 'ir_attachment_res_idx',
@@ -39,7 +39,6 @@ class IrConfigParameter(models.Model):
('key_uniq', 'unique (key)', 'Key must be unique.')
]

@api.model_cr
@mute_logger('odoo.addons.base.models.ir_config_parameter')
def init(self, force=False):
"""

0 comments on commit c552fb7

Please sign in to comment.
You can’t perform that action at this time.