{"id":13,"date":"2023-07-27T11:40:00","date_gmt":"2023-07-27T11:40:00","guid":{"rendered":""},"modified":"2024-01-28T09:05:18","modified_gmt":"2024-01-28T09:05:18","slug":"method-and-decorator-in-odoo","status":"publish","type":"post","link":"https:\/\/pythonpower.in\/index.php\/2023\/07\/27\/method-and-decorator-in-odoo\/","title":{"rendered":"Method and decorator In Odoo"},"content":{"rendered":"<\/p>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/pythonpower.in\/wp-content\/uploads\/2023\/07\/Expert-20In-20Odoo-2016-20-20Hindi-20-1-.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" data-original-height=\"720\" data-original-width=\"1280\" height=\"360\" src=\"http:\/\/pythonpower.in\/wp-content\/uploads\/2023\/07\/Expert-20In-20Odoo-2016-20-20Hindi-20-1--300x169.png\" width=\"640\" \/><\/a><\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<h1 dir=\"auto\" style=\"background-color: white; border-bottom: 1px solid var(--borderColor-muted, var(--color-border-muted)); box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-weight: var(--base-text-weight-semibold, 600); line-height: 1.25; margin-bottom: 16px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; margin: 0px 0px 16px; padding-bottom: 0.3em;\" tabindex=\"-1\">Method and decorator<\/h1>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">New decorators are just mapper around the new API. The decorator are mandatory as webclient and HTTP controller are not compliant with new API.<\/span><\/p>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><code style=\"background-color: var(--bgColor-neutral-muted, var(--color-neutral-muted)); border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; margin: 0px; padding: 0.2em 0.4em; white-space-collapse: break-spaces;\"><span style=\"font-size: large;\">api<\/span><\/code><span style=\"font-size: medium;\">&nbsp;namespace decorators will detect signature using variable name and decide to match old signature or not.<\/span><\/p>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">Recognized variable names are:<\/span><\/p>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><code style=\"background-color: var(--bgColor-neutral-muted, var(--color-neutral-muted)); border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; margin: 0px; padding: 0.2em 0.4em; white-space-collapse: break-spaces;\"><span style=\"font-size: large;\">cr, cursor, uid, user, user_id, id, ids, context<\/span><\/code><\/p>\n<p><span style=\"font-size: large;\"><a name=\"user-content-api-returns\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;;\"><\/a><span face=\"-apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;\" style=\"background-color: white; color: #0e1116;\"><\/span><\/span><\/p>\n<h2 dir=\"auto\" style=\"background-color: white; border-bottom: 1px solid var(--borderColor-muted, var(--color-border-muted)); box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-weight: var(--base-text-weight-semibold, 600); line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;\" tabindex=\"-1\"><a aria-hidden=\"true\" href=\"https:\/\/github.com\/nbessi\/odoo_new_api_guideline\/blob\/master\/source\/decorator.rst#apireturns\" style=\"background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewbox=\"0 0 16 16\" width=\"16\"><\/svg><span style=\"font-size: large;\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/span><\/a>@api.returns<\/h2>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">This decorator guaranties unity of returned value. It will return a RecordSet of specified model based on original returned value:<\/span><\/p>\n<pre style=\"border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; line-height: 1.45; margin-bottom: 16px; margin-top: 0px; overflow-wrap: normal; overflow: auto; padding: 16px;\"><span style=\"font-size: medium;\"><span style=\"color: white;\">@api.returns('res.partner')\ndef afun(self):\n    ...\n    return x  # a RecordSet<\/span><span style=\"color: #0e1116;\">\n<\/span><\/span><\/pre>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">And if an old API function calls a new API function it will automatically convert it into a list of ids<\/span><\/p>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">All decorators inherits from this decorator to upgrade or downgrade the returned value.<\/span><\/p>\n<p><span style=\"font-size: medium;\"><a name=\"user-content-api-one\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;;\"><\/a><span face=\"-apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;\" style=\"background-color: white; color: #0e1116;\"><\/span><\/span><\/p>\n<h2 dir=\"auto\" style=\"background-color: white; border-bottom: 1px solid var(--borderColor-muted, var(--color-border-muted)); box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-weight: var(--base-text-weight-semibold, 600); line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;\" tabindex=\"-1\"><a aria-hidden=\"true\" href=\"https:\/\/github.com\/nbessi\/odoo_new_api_guideline\/blob\/master\/source\/decorator.rst#apione\" style=\"background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewbox=\"0 0 16 16\" width=\"16\"><\/svg><span style=\"font-size: medium;\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/span><\/a>@api.one<\/h2>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: 16px;\">T<\/span><span style=\"font-size: medium;\">his decorator loops automatically on Records of RecordSet for you. Self is redefined as current record:<\/span><\/p>\n<pre style=\"border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; line-height: 1.45; margin-bottom: 16px; margin-top: 0px; overflow-wrap: normal; overflow: auto; padding: 16px;\"><span style=\"font-size: medium;\"><span style=\"color: white;\">@api.one\ndef afun(self):\n    self.name = 'toto'<\/span><span style=\"color: #0e1116;\">\n<\/span><\/span><\/pre>\n<div dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;;\">\n<p dir=\"auto\" style=\"box-sizing: border-box; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">Note<\/span><\/p>\n<p dir=\"auto\" style=\"box-sizing: border-box; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">Caution: the returned value is put in a list. This is not always supported by the web client, e.g. on button action methods. In that case, you should use&nbsp;<code style=\"background-color: var(--bgColor-neutral-muted, var(--color-neutral-muted)); border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; margin: 0px; padding: 0.2em 0.4em; white-space-collapse: break-spaces;\">@api.multi<\/code>&nbsp;to decorate your method, and probably call self.ensure_one() in the method definition.<\/span><\/p>\n<\/div>\n<p><span style=\"font-size: medium;\"><a name=\"user-content-api-multi\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;;\"><\/a><span face=\"-apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;\" style=\"background-color: white; color: #0e1116;\"><\/span><\/span><\/p>\n<h2 dir=\"auto\" style=\"background-color: white; border-bottom: 1px solid var(--borderColor-muted, var(--color-border-muted)); box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-weight: var(--base-text-weight-semibold, 600); line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;\" tabindex=\"-1\"><a aria-hidden=\"true\" href=\"https:\/\/github.com\/nbessi\/odoo_new_api_guideline\/blob\/master\/source\/decorator.rst#apimulti\" style=\"background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewbox=\"0 0 16 16\" width=\"16\"><\/svg><span style=\"font-size: medium;\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/span><\/a>@api.multi<\/h2>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">Self will be the current RecordSet without iteration. It is the default behavior:<\/span><\/p>\n<pre style=\"border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; line-height: 1.45; margin-bottom: 16px; margin-top: 0px; overflow-wrap: normal; overflow: auto; padding: 16px;\"><span style=\"color: white; font-size: medium;\">@api.multi\ndef afun(self):\n    len(self)<\/span><span style=\"color: #0e1116; font-size: 13.6px;\">\n<\/span><\/pre>\n<p><a name=\"user-content-api-model\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px;\"><\/a><span face=\"-apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;\" style=\"background-color: white; color: #0e1116; font-size: 16px;\"><\/span><\/p>\n<h2 dir=\"auto\" style=\"background-color: white; border-bottom: 1px solid var(--borderColor-muted, var(--color-border-muted)); box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-weight: var(--base-text-weight-semibold, 600); line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;\" tabindex=\"-1\"><a aria-hidden=\"true\" href=\"https:\/\/github.com\/nbessi\/odoo_new_api_guideline\/blob\/master\/source\/decorator.rst#apimodel\" style=\"background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewbox=\"0 0 16 16\" width=\"16\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a>@api.model<\/h2>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">This decorator will convert old API calls to decorated function to new API signature. It allows to be polite when migrating code.<\/span><\/p>\n<pre style=\"border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; line-height: 1.45; margin-bottom: 16px; margin-top: 0px; overflow-wrap: normal; overflow: auto; padding: 16px;\"><span style=\"color: white; font-size: medium;\">@api.model\ndef afun(self):\n    pass<\/span><span style=\"color: #0e1116; font-size: 13.6px;\">\n<\/span><\/pre>\n<p><a name=\"user-content-api-constrains\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px;\"><\/a><span face=\"-apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;\" style=\"background-color: white; color: #0e1116; font-size: 16px;\"><\/span><\/p>\n<h2 dir=\"auto\" style=\"background-color: white; border-bottom: 1px solid var(--borderColor-muted, var(--color-border-muted)); box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-weight: var(--base-text-weight-semibold, 600); line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;\" tabindex=\"-1\"><a aria-hidden=\"true\" href=\"https:\/\/github.com\/nbessi\/odoo_new_api_guideline\/blob\/master\/source\/decorator.rst#apiconstrains\" style=\"background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewbox=\"0 0 16 16\" width=\"16\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a>@api.constrains<\/h2>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">This decorator will ensure that decorated function will be called on create, write, unlink operation. If a constraint is met the function should raise a openerp.exceptions.Warning with appropriate messag<\/span><span style=\"font-size: 16px;\">e.<\/span><\/p>\n<p><a name=\"user-content-api-depends\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px;\"><\/a><span face=\"-apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;\" style=\"background-color: white; color: #0e1116; font-size: 16px;\"><\/span><\/p>\n<h2 dir=\"auto\" style=\"background-color: white; border-bottom: 1px solid var(--borderColor-muted, var(--color-border-muted)); box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-weight: var(--base-text-weight-semibold, 600); line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;\" tabindex=\"-1\"><a aria-hidden=\"true\" href=\"https:\/\/github.com\/nbessi\/odoo_new_api_guideline\/blob\/master\/source\/decorator.rst#apidepends\" style=\"background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewbox=\"0 0 16 16\" width=\"16\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a>@api.depends<\/h2>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">This decorator will trigger the call to the decorated function if any of the fields specified in the decorator is altered by ORM or changed in the form:<\/span><\/p>\n<pre style=\"border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; line-height: 1.45; margin-bottom: 16px; margin-top: 0px; overflow-wrap: normal; overflow: auto; padding: 16px;\"><span style=\"font-size: medium;\"><span style=\"color: white;\">@api.depends('name', 'an_other_field')\ndef afun(self):\n    pass<\/span><span style=\"color: #0e1116;\">\n<\/span><\/span><\/pre>\n<div dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;;\">\n<p dir=\"auto\" style=\"box-sizing: border-box; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">Note<\/span><\/p>\n<p dir=\"auto\" style=\"box-sizing: border-box; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">when you redefine depends you have to redefine all @api.depends, so it loses some of his interest.<\/span><\/p>\n<\/div>\n<p><a name=\"user-content-view-management\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px;\"><\/a><span face=\"-apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;\" style=\"background-color: white; color: #0e1116; font-size: 16px;\"><\/span><\/p>\n<h3 dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 1.25em; font-weight: var(--base-text-weight-semibold, 600); line-height: 1.25; margin-bottom: 16px; margin-top: 24px;\" tabindex=\"-1\"><a aria-hidden=\"true\" href=\"https:\/\/github.com\/nbessi\/odoo_new_api_guideline\/blob\/master\/source\/decorator.rst#view-management\" style=\"background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewbox=\"0 0 16 16\" width=\"16\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a>View management<\/h3>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">One of the great improvement of the new API is that the depends are automatically inserted into the form for you in a simple way. You do not have to worry about modifying views anymore.<\/span><\/p>\n<p><a name=\"user-content-id1\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px;\"><\/a><span face=\"-apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;\" style=\"background-color: white; color: #0e1116; font-size: 16px;\"><\/span><\/p>\n<h2 dir=\"auto\" style=\"background-color: white; border-bottom: 1px solid var(--borderColor-muted, var(--color-border-muted)); box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-weight: var(--base-text-weight-semibold, 600); line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em;\" tabindex=\"-1\"><a aria-hidden=\"true\" href=\"https:\/\/github.com\/nbessi\/odoo_new_api_guideline\/blob\/master\/source\/decorator.rst#apionchange\" style=\"background-color: transparent; box-sizing: border-box; float: left; line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewbox=\"0 0 16 16\" width=\"16\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a>@api.onchange<\/h2>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">This decorator will trigger the call to the decorated function if any of the fields specified in the decorator is changed in the form:<\/span><\/p>\n<pre style=\"border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; line-height: 1.45; margin-bottom: 16px; margin-top: 0px; overflow-wrap: normal; overflow: auto; padding: 16px;\"><span style=\"color: white; font-size: medium;\">@api.onchange('fieldx')\ndef do_stuff(self):\n   if self.fieldx == x:\n      self.fieldy = 'toto'\n<\/span><\/pre>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">In previous sample self corresponds to the record currently edited on the form. When in on_change context all work is done in the cache. So you can alter RecordSet inside your function without being worried about altering database. That&#8217;s the main difference with&nbsp;<code style=\"background-color: var(--bgColor-neutral-muted, var(--color-neutral-muted)); border-radius: 6px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; margin: 0px; padding: 0.2em 0.4em; white-space-collapse: break-spaces;\">@api.depends<\/code><\/span><\/p>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">At function return, differences between the cache and the RecordSet will be returned to the form.<\/span><\/p>\n<p><span style=\"font-size: medium;\"><a name=\"user-content-id2\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;;\"><\/a><span face=\"-apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;\" style=\"background-color: white; color: #0e1116;\"><\/span><\/span><\/p>\n<h3 dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; line-height: 1.25; margin-bottom: 16px; margin-top: 24px;\" tabindex=\"-1\"><a aria-hidden=\"true\" href=\"https:\/\/github.com\/nbessi\/odoo_new_api_guideline\/blob\/master\/source\/decorator.rst#view-management-1\" style=\"background-color: transparent; box-sizing: border-box; float: left; font-size: 1.25em; font-weight: var(--base-text-weight-semibold, 600); line-height: 1; margin-left: -20px; padding-right: 4px; text-decoration-line: none;\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewbox=\"0 0 16 16\" width=\"16\"><\/svg><span style=\"font-size: large;\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/span><\/a><span style=\"font-size: large;\">View management<\/span><\/h3>\n<p dir=\"auto\" style=\"background-color: white; box-sizing: border-box; color: #0e1116; font-family: -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; margin-bottom: 16px; margin-top: 0px;\"><span style=\"font-size: medium;\">One of the great improvement of the new API is that the onchange are automatically inserted into the form for you in a simple way. You do not have to worry about modifying views anymore<\/span><\/p>\n<\/div>\n<div style=\"clear: both; text-align: center;\"><span style=\"font-size: medium;\"><br \/><\/span><\/div>\n<div style=\"clear: both; text-align: center;\"><span style=\"font-size: medium;\"><br \/><\/span><\/div>\n<div style=\"clear: both; text-align: center;\"><span style=\"font-size: medium;\"><br \/><\/span><\/div>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Method and decorator New decorators are just mapper around the new API. The decorator&hellip;<\/p>\n","protected":false},"author":2,"featured_media":70,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_joinchat":[]},"categories":[5],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/posts\/13"}],"collection":[{"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":1,"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":71,"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/posts\/13\/revisions\/71"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/media\/70"}],"wp:attachment":[{"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonpower.in\/index.php\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}