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

Hi,

I would like to display some fields base on value of Boolean field. 

In this case, I want to show 'vat_invoice_no' field on Sale.Order

Here is my source code:

class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.depends('picking_ids')
def _compute_delivery_done(self):
for order in self:
if order.picking_ids:
for picking in order.picking_ids:
if picking.state != 'done':
return False
return True

vat_invoice_no = fields.Char('VAT Invoice No.')
delivery_done = fields.Boolean('Delivery Completed', compute=_compute_delivery_done)
<xpath expr='//field[@name="partner_id"]' position="after">
<field name="delivery_done" invisible="1"/>
<field name="vat_invoice_no" attrs="{'invisible':[('delivery_done','=',False)]}"/>
</xpath>

It showed nothing even when 'delivery_done' = True.

I checked on HTML render view then have these below:

[div class="o_field_boolean o_field_widget custom-control custom-checkbox o_invisible_modifier o_readonly_modifier" name="delivery_done"]
      [input type="checkbox" id="checkbox-68" class="custom-control-input" disabled=""]
      [label for="o_field_input_69" class="custom-control-label"]​[/label]
[/div]

อวตาร
ละทิ้ง
ผู้เขียน

I am so sorry! This is my fault!

Here is the correct code:

@api.depends('picking_ids')

def _compute_delivery_done(self):

done = True

for order in self:

if order.picking_ids:

for picking in order.picking_ids:

if picking.state != 'done':

done = False

self.delivery_done = done

done should be calculated and set per order -> order.delivery_done = done

ผู้เขียน คำตอบที่ดีที่สุด

Here is the correct code:

@api.depends('picking_ids')
def _compute_delivery_done(self):
done = True
for order in self:
if order.picking_ids:
for picking in order.picking_ids:
if picking.state != 'done':
done = False
self.delivery_done = done



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ย. 23
12765
2
มิ.ย. 20
9016
0
มิ.ย. 19
7365
0
ก.พ. 17
2936
0
มี.ค. 15
3022