Ta sẽ lập trình odoo theo mô hình MVC giống như các farmwork trong php:
- Model : xây dựng các phương thức xử lý đến database
- Views : Xử lý các views liên quan đến hiển thị người dùng
- Controller : Xử lý các thuật toán logic cho app
Các thành phần module của Odoo như sau :
- data : chứa xml data
- model : định nghĩa các model của module ví dụ như tạo bảng
- controllers : chứa các controllers
- static/ : gồm web assets, được tách thành css/, js/, img/, lib/, …
Ngoài ra còn có các thành phần sau (tùy chọn):
- wizard : xử lý các transient models ,kiểu như chuyển đổi giữa các views : ví dụ như nhập email sau đó đến nhập password thì trường nhập email sẽ được lưu trữ tạm thời ở đây
- report : chứa các thành phần báo cáo như excel hay pdf
- tests/ : Python/YML tests, tất nhiên là cho việc unit testing
Dưới đây là case cơ bản :
addons/<my_module_name>/ |-- __init__.py |-- __manifest__.py |-- controllers/ | |-- __init__.py | |-- <inherited_module_name>.py | `-- main.py |-- data/ | |-- <main_model>_data.xml | `-- <inherited_main_model>_demo.xml |-- models/ | |-- __init__.py | |-- <main_model>.py | `-- <inherited_main_model>.py |-- report/ | |-- __init__.py | |-- <main_stat_report_model>.py | |-- <main_stat_report_model>_views.xml | |-- <main_print_report>_reports.xml | `-- <main_print_report>_templates.xml |-- security/ | |-- ir.model.access.csv | `-- <main_model>_security.xml |-- static/ | |-- img/ | | |-- my_little_kitten.png | | `-- troll.jpg | |-- lib/ | | `-- external_lib/ | `-- src/ | |-- js/ | | `-- <my_module_name>.js | |-- css/ | | `-- <my_module_name>.css | |-- less/ | | `-- <my_module_name>.less | `-- xml/ | `-- <my_module_name>.xml |-- views/ | |-- <main_model>_templates.xml | |-- <main_model>_views.xml | |-- <inherited_main_model>_templates.xml | `-- <inherited_main_model>_views.xml `-- wizard/ |-- <main_transient_A>.py |-- <main_transient_A>_views.xml |-- <main_transient_B>.py `-- <main_transient_B>_views.xml Tài liệu tham khảo : https://dammecode.wordpress.com/2018/07/28/odoo/