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

Here is my code


@api.model_create_multi

    def create(self, vals_list):

        # context: no_log, because subtype already handle this

        maintenance_requests = super().create(vals_list)

        for request in maintenance_requests:

            if request.owner_user_id or request.user_id:

                request._add_followers()

            if request.equipment_id and not request.maintenance_team_id:

                request.maintenance_team_id = request.equipment_id.maintenance_team_id

            if request.close_date and not request.stage_id.done:

                request.close_date = False

            if not request.close_date and request.stage_id.done:

                request.close_date = fields.Date.today()


The bold one is the part that i'd like to change to datetime now.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด


 HI  Ricky\\ Raymond


After seeing your code we understood that , you want to add current datetime into field.

So here how it is you can do this ,

  • Firstly import datetime into your py file like this 


   Below code represent exact time


   from datetime import datetime

   request.close_date = fields.Datetime.now()


                   2nd way 


   from datetime import datetime

   request.close_date = fields.Datetime.today()


  I hope this is helpful to you.


  Thanks & Regards,

   Email: odoo@devintellecs.com

   Skype: devintelle

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Please try with below code.
 request.close_date =fields.datetime.now()
Instead of today() use now()

Hope it helps

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

Still not working. The time always " 07:00:00"

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi Ricky,

You can set datetime now value using datetime.datetime.now() into that data.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
มิ.ย. 25
1010
4
พ.ค. 25
2688
2
พ.ค. 25
6119
1
มี.ค. 25
1802
4
มี.ค. 25
4678