This question has been flagged
3 Replies
10147 Views

In which case we use the attribute _auto = False in our classes ?
It seems that its use has changed in v7.

Avatar
Discard

I would say that in 99.99% of the cases you won't need it.

Best Answer

Hello,

_auto is a Predefined field that determines whether a corresponding PostgreSQL table must be generated automatically from the object. Setting _auto to False can be useful in case of OpenERP objects generated from PostgreSQL views. See the “Document” for more details.

Thanks,

Serpent Consulting Services.

Avatar
Discard
Best Answer

Please check Object Attributes

Avatar
Discard
Best Answer

The parameter _auto=False to the OpenERP object is used, so no table corresponding to the _columns dictionary is created automatically. For getting values add a method init(self, cr) that creates a PostgreSQL View matching the fields declared in _columns. And also all fields in the _columns dictionary must have a flag readonly=True.

For example:

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()

You can find the applications of _auto=False in the Sales Analysis report in Reporting tab of OpenERP and the code in report folder in sales module.

Avatar
Discard