This is the documentation for older versions of Odoo (formerly OpenERP).

See the new Odoo user documentation.

See the new Odoo technical documentation.

截图:*

OpenERP 物件可以从 PostgreSQL 的窗体创建产生。方式如下:

  1. 宣告你的栏位 _columns 定义。所有字段必须有 readonly=True. 的旗标。

  2. 对 OpenERP 物件指定参数 _auto=False ,所以不会自动产生对应到 _columns 定义的资料表。

  3. 增加一个方法 init(self, cr) 用来创建一个符合 _columns 栏位定义的 PostgreSQL 窗体 .

范例 report_crm_case_user 这个物件是依照以下模式创建的

class report_crm_case_user(osv.osv):
   _name = "report.crm.case.user"
   _description = "Cases by user and section"
   _auto = False
    _columns = {
   'name': fields.date('Month', readonly=True),
   'user_id':fields.many2one('res.users', 'User', readonly=True, relate=True),
   'section_id':fields.many2one('crm.case.section', 'Section', readonly=True, relate=True),
   'amount_revenue': fields.float('Est.Revenue', readonly=True),
      'amount_costs': fields.float('Est.Cost', readonly=True),
   'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
   'nbr': fields.integer('# of Cases', readonly=True),
      'probability': fields.float('Avg. Probability', readonly=True),
   'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
   'delay_close': fields.integer('Delay to close', readonly=True),
   }
    _order = 'name desc, user_id, section_id'

   def init(self, cr):
   cr.execute("""
        create or replace view report_crm_case_user as (
            select
                min(c.id) as id,
                substring(c.create_date for 7)||'-01' as name,
                c.state,
                c.user_id,
                c.section_id,
                count(*) as nbr,
                sum(planned_revenue) as amount_revenue,
                sum(planned_cost) as amount_costs,
                sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
                avg(probability)::decimal(16,2) as probability,
                to_char(avg(date_closed-c.create_date), 'DD"d" `HH24:MI:SS') as delay_close
            from
                crm_case c
            group by substring(c.create_date for 7), c.state, c.user_id, c.section_id
   )""")
   report_crm_case_user()