目录
1.创建模块
- 在主目录下,新建custom的文件夹
- 进入到pycharm中的命令行,创建estate命令
python odoo-bin scaffold estate custom
创建好后,查看
添加到配置文件中
2.运行程序,安装上模块
3.创建模型类
- 在模块的models文件夹下,新建 estate_property.py
- 在estate_property.py中,写入模型类代码
from datetime import datetime from dateutil.relativedelta import relativedelta from odoo import models, fields, api class estate_property(models.Model): _name = 'estate.property' _description = '不动产模型类' name = fields.Char(required=True, string='名称') # 名称 description = fields.Text(string='描述') # 描述 postcode = fields.Char(string='邮政编码') # 邮政编码 @api.model def _get_time(self): return datetime.now() + relativedelta(months=3) # date_availability = fields.Date(string='可用日期', copy=False, default=datetime.now() + relativedelta(months=3)) # 可用日期 date_availability = fields.Date(string='可用日期', copy=False, default=_get_time) # 可用日期 expected_price = fields.Float(required=True, string='预期价格') # 预期价格 selling_price = fields.Float(string='售价', readonly=True, copy=False) # 售价 bedrooms = fields.Integer(string='卧室数量', default=2) # 卧室数量 living_area = fields.Integer(string='居住面积') # 居住面积 facades = fields.Integer(string='正面') # 正面(外墙) garage = fields.Boolean(string='车库') # 车库 garden = fields.Boolean(string='花园') # 花园 garden_area = fields.Integer(string='绿化面积') # 绿化面积 garden_orientation = fields.Selection( string='花园方向', selection=[('North', '北面'), ('South', '南面'), ('East', '东面'), ('West', '西面'), ] ) # 花园方向
- copy是在点击odoo动作下拉菜单时,该字段是否复制的属性
- 装饰器@api.model,是使用函数的方式,确定值
- Selection字段中,selection属性,是一个数据是一个元组,元组中第一个是在数据库中存储的值,元组中第二个是在应用中显示的值
- 重新运行odoo,到数据库中查看
4.配置角色安全权限文件
创建模块后,默认有开启就行
Developer — Odoo 15.0 文档https://www.odoo.com/documentation/15.0/zh_CN/developer.html
1.odoo13之跟着官网做项目/实例(创建模块、创建模型类、配置角色安全权限文件)
于 2022-03-19 21:35:56 首次发布