- Odoo 11 Development Essentials(Third Edition)
- Daniel Reis
- 210字
- 2021-08-27 19:32:45
Extending Python methods
Python methods can also be extended for additional business logic. This is done by borrowing the mechanism Python already provides for inherited objects to extend their parent class behavior: super().
As an example, we will have the TodoTask class extend the ORM write() method to add some logic to it: when writing on a non-active record, it will automatically reactivate it.
Add this additional method in the models/todo_task_model.py file:
@api.multi def write(self, values): if 'active' not in values: values['active'] = True super().write(values)
The write() method expects an additional parameter, with a dictionary of values to write on the record. Unless a value is being explicitly set on the active field, we set it to True in case we are writing on an inactive record. We then use super() to call the parent write() method using the modified values.
super(TodoTask, self).write(values). This syntax also works with Python 3, so it should be preferred if keeping Python 2 compatibility is important.
We will have a chance to have a closer look at the ORM methods in Chapter 6, The ORM - Handling Application Data.
- 從原始數據到分析報告:Excel數據透視表高效達人養成記
- 五筆打字精品教程
- Excel 2010辦公應用實戰從入門到精通(超值版)
- Excel職場辦公:表格范例大全
- Adobe Premiere Pro 2020基礎培訓教材
- Excel公式與函數從入門到精通
- Oracle CX Cloud Suite
- Excel高效辦公:公司表格設計(修訂版)
- PPT制作應用大全2019
- Excel/PPT 2016辦公專家從入門到精通
- Excel 2013實戰應用超級手冊
- AutoCAD2015中文版從入門到精通
- Word/Excel/PPT 2016辦公應用從入門到精通
- 人事管理政務網上公開的發展與對策
- 圖表之美:打造優秀的Excel圖表