这次开发的模块是订餐的类型设计,比如大荤 小荤 蔬菜 米饭 等基本数据。
1.设计model类,很简单就一个字段:
class MyLunchProductionCategory(osv.Model): _name = "mylunch.production.category" _description = "MyLunch Production Category" _columns = { 'name': fields.char('Category', required=True) }
2.设计菜单,菜单放在配置菜单下面,在mylunch_view.xml中增加如下代码
<menuitem name="MyLunch Production Category" parent="menu_lunch_config" id="menu_mylunch_production_category" action="action_mylunch_production_categories">
3.设计action动作,以便关联tree 和 form视图
<record model="ir.actions.act_window" id="action_mylunch_production_categories"> <field name="name">MyLunch Production Categories</field> <field name="res_model">mylunch.production.category</field> <field name="view_mode">tree,form</field> <field name="help" type="html"> <p class="oe_view_nocontent_create"> Click to create a mylunch category. </p> <p> Here you can find every mylunch categories for products. </p> </field> </record>
这里的字段help,主要目的是在tree列表没有数据的时候显示的内容
4.设计form视图, tree视图不设计,使用默认的样板
<record model="ir.ui.view" id="mylunch_production_category_form_view"> <field name="name">MyLunch Production Form View</field> <field name="model">mylunch.production.category</field> <field name="arch" type="xml"> <form string="Production Category Form"> <sheet> <group> <field name="name" string="Production Category:"></field> </group> </sheet> </form> </field> </record>
5.给类添加权限,在ir.model.access.csv中添加如下代码
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink mylunch_product_category_manager,"MyLunch Product category user",model_mylunch_production_category,group_my_lunch_manager,1,1,1,1 mylunch_product_category_user,"MyLunch Product category user",model_mylunch_production_category,group_my_lunch_user,1,0,0,0
模块升级运行之后的效果图: