Public bug reported:

Problem with default function in readonly fields in a form?

When i set the pos_display field in a form to readonly="True" and calculate a 
value with this function below, this field stays 0.
i miss order_id in context when save the form.

Please take a look at this example.

class sale_order_line(osv.osv):
    _inherit = "sale.order.line"
    _name = "sale.order.line"

    def _gen_next_pos_display(self, cr, uid, context={}):
        print "_gen_next_pos_display",context
        if 'order_id' in context:
            order_id = context['order_id']
            cr.execute("select max(pos_display) from sale_order_line where 
order_id=%s",(order_id,))
            res = cr.fetchall()
            if res[0][0] == None:
                return 1
            else:
                next_pos_display = res[0][0] + 1
                return next_pos_display
        return

    _columns = {
        'pos_display'   : fields.integer('Pos.'),
    }

    _defaults = {
        'pos_display'   : _gen_next_pos_display,
    }

sale_order_line()


when add new order-line
_gen_next_pos_display {'order_id': 18, 'lang': u'de_DE', 'tz': False}

When save or reload the form i miss "order_id" in context. This is my main 
problem.
_gen_next_pos_display {'lang': u'de_DE', 'order_id': 18, 'tz': False}
_gen_next_pos_display {'lang': u'de_DE', 'search_default_user_id': 1, 
'no_store_function': True, 'tz': False,
                       '__last_update': {}, 'active_model': 'ir.ui.menu', 
'active_ids': [309], 'active_id': 309}

With " <field name="pos_display" string="Pos." readonly="False" 
attrs="{'invisible':[('layout_type','!=','article')]}"/>
it works fine.


snippet from sale_layout:

                <record model="ir.ui.view" id="view_order_form_inherit_1">
                        <field 
name="name">rockel.sale.order.form.inherit_1</field>
                        <field name="model">sale.order</field>
                        <field name="inherit_id" ref="sale.view_order_form"/>
                        <field name="priority">30</field>
                        <field name="type">form</field>
                        <field name="arch" type="xml">
                                <xpath 
expr="/form/notebook/page/field[@name='order_line']" position="replace">
                                <field name="order_line" invisible="True"/>
                                <field name="abstract_line_ids"
                                                colspan="4" 
                                                nolabel="1"
                                                widget="one2many_list"
=============>                                  default_get="{'order_id': 
active_id or False}"
                                                
on_change="on_change_order_line(abstract_line_ids,name)">
                                <form string="Sale Order Lines">
                                     <notebook>
                                        <page string="Order Line">
============>                                   <field name="pos_display" 
string="Pos." readonly="True" 
attrs="{'invisible':[('layout_type','!=','article')]}"/>
                                                <field name="sequence" 
string="Seq."/>
                                                <field name="layout_type"
                                                  
on_change="onchange_sale_order_line_view(layout_type)" 
                                                  colspan="1"/>

** Affects: openobject-client
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to OpenERP Project Group.
https://bugs.launchpad.net/bugs/900230

Title:
  Problem with readonly fields?

Status in OpenERP GTK Client:
  New

Bug description:
  Problem with default function in readonly fields in a form?

  When i set the pos_display field in a form to readonly="True" and calculate a 
value with this function below, this field stays 0.
  i miss order_id in context when save the form.

  Please take a look at this example.

  class sale_order_line(osv.osv):
      _inherit = "sale.order.line"
      _name = "sale.order.line"

      def _gen_next_pos_display(self, cr, uid, context={}):
          print "_gen_next_pos_display",context
          if 'order_id' in context:
              order_id = context['order_id']
              cr.execute("select max(pos_display) from sale_order_line where 
order_id=%s",(order_id,))
              res = cr.fetchall()
              if res[0][0] == None:
                  return 1
              else:
                  next_pos_display = res[0][0] + 1
                  return next_pos_display
          return

      _columns = {
          'pos_display'   : fields.integer('Pos.'),
      }

      _defaults = {
          'pos_display'   : _gen_next_pos_display,
      }

  sale_order_line()

  
  when add new order-line
  _gen_next_pos_display {'order_id': 18, 'lang': u'de_DE', 'tz': False}

  When save or reload the form i miss "order_id" in context. This is my main 
problem.
  _gen_next_pos_display {'lang': u'de_DE', 'order_id': 18, 'tz': False}
  _gen_next_pos_display {'lang': u'de_DE', 'search_default_user_id': 1, 
'no_store_function': True, 'tz': False,
                       '__last_update': {}, 'active_model': 'ir.ui.menu', 
'active_ids': [309], 'active_id': 309}

  With " <field name="pos_display" string="Pos." readonly="False" 
attrs="{'invisible':[('layout_type','!=','article')]}"/>
  it works fine.


  snippet from sale_layout:

                <record model="ir.ui.view" id="view_order_form_inherit_1">
                        <field 
name="name">rockel.sale.order.form.inherit_1</field>
                        <field name="model">sale.order</field>
                        <field name="inherit_id" ref="sale.view_order_form"/>
                          <field name="priority">30</field>
                        <field name="type">form</field>
                        <field name="arch" type="xml">
                                <xpath 
expr="/form/notebook/page/field[@name='order_line']" position="replace">
                                <field name="order_line" invisible="True"/>
                                <field name="abstract_line_ids"
                                                colspan="4" 
                                                nolabel="1"
                                                widget="one2many_list"
  =============>                                        
default_get="{'order_id': active_id or False}"
                                                
on_change="on_change_order_line(abstract_line_ids,name)">
                                <form string="Sale Order Lines">
                                     <notebook>
                                        <page string="Order Line">
  ============>                                   <field name="pos_display" 
string="Pos." readonly="True" 
attrs="{'invisible':[('layout_type','!=','article')]}"/>
                                                <field name="sequence" 
string="Seq."/>
                                                <field name="layout_type"
                                                  
on_change="onchange_sale_order_line_view(layout_type)" 
                                                  colspan="1"/>

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-client/+bug/900230/+subscriptions

_______________________________________________
Mailing list: https://launchpad.net/~c2c-oerpscenario
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~c2c-oerpscenario
More help   : https://help.launchpad.net/ListHelp

Reply via email to