Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
6469 มุมมอง

What is wrong with the following code? I set default value preset_quantity as 1.0, but in the view it appears 0.0 instead. 

I'm using Odoo 10

python code

class stock_picking_barcode(models.Model): 
 _name = 'stock.picking'
 _inherit = ['stock.picking', 'barcodes.barcode_events_mixin']

 preset_quantity = fields.Float(store=False,
     default=1.0,
     help="The quantity will be applied to the pending product.")

 def on_barcode_scanned(self, barcode):
...

xml

<record model="ir.ui.view" id="view_picking_barcode_form">
     <field name="name">stock.picking.barcode.form</field>
     <field name="model">stock.picking</field>
     <field name="inherit_id" ref="stock.view_picking_form"/>
     <field name="arch" type="xml">
         <notebook position="before">
         <group attrs="{'invisible': [('state', 'not in', ('assigned'))]}" class="oe_edit_only">
             <field name="_barcode_scanned" widget="barcode_handler"/>
             <field name="preset_quantity" readonly="1"/>
         </group>
         </notebook>
    </field>
</record>

 

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

I just found the cause myself. In the initial state, the default value is correct but the field is hidden as stated in "attrs =". When state is change to "assigned", the value is somehow cleanup, so that it seems the default value won't work.

Use "compute" instead of default to solve this 

preset_quantity = fields.Float(store=False, compute="_get_preset_quantity")
  @api.one
@api.depends('state')
def _get_preset_quantity(self):
  if self.state == 'assigned':
    self.preset_quantity = 1.0

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 19
6554
4
ส.ค. 17
7506
1
ธ.ค. 16
10635
odoo9: why default value does not work แก้ไขแล้ว
7
ก.ค. 16
6180
0
ก.พ. 23
3111