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

Hello all,

I have a query which needs a solution.

I have defined two float fields and assigned widget='float_time' as in xml. I need to subtract these two fields and need to get value in float.

For example:

start_time = 14:30 and end_time = 15:00

Now if i deduct i get value as 0.50 mins, But its wrong right?. So i need to value as 0.30 mins. How to achieve this?


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

Anyone knows please reply?

Please add your code as well

ผู้เขียน

class LostTimeDetails(models.Model):

_name = 'lost.time.details'

_description = "Lost Time Details"

odometer_id = fields.Many2one('production.odometer', 'Production Odometer')

lost_time = fields.Char('Lost Time Activity')

start_time = fields.Float('Start Time')

end_time = fields.Float('End Time')

<field name="lost_time_ids" nolabel="1" attrs="{'readonly': [('state', '=', 'confirm')]}">

<tree editable="bottom">

<field name="lost_time"/>

<field name="start_time" widget="float_time"/>

<field name="end_time" widget="float_time"/>

</tree>

</field>

function for subtracting float_time fields:

@api.multi

def calc_button(self):

lost_time = 0.0

for line in self.lost_time_ids:

lost_time += line.end_time - line.start_time

line.lost_time = str(lost_time)

return

คำตอบที่ดีที่สุด

Hi,

You can try this code,

difference_time = self.end_time - self.start_time
duration = '{0:02.0f}:{1:02.0f}'.format(*divmod(difference_time * 60, 60))

In the duration variable you will get it correctly.

Thanks

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

Thanks It worked.

Related Posts ตอบกลับ มุมมอง กิจกรรม
5
ต.ค. 24
12582
3
ต.ค. 24
34215
1
เม.ย. 20
16000
Datetime change Format issue in odoo10?? แก้ไขแล้ว
1
ก.ย. 19
13173
2
ก.ค. 19
3804