تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
13503 أدوات العرض

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



الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
سبتمبر 23
12393
2
يونيو 20
8686
0
يونيو 19
6940
0
فبراير 17
2767
0
مارس 15
2838