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

I have a class:

class ReceiptNotes(models.Model):
_inherit = 'stock.picking'

is_finalized_receipt = fields.Boolean(string='Received')
finalized_receipt_date = fields.Datetime(string='Received Timestamp', readonly=True)

my view goes (sorry had to remove the because it wouldn't display)

xpath expr="//field[@name='backorder_id']" position="after"

field name="is_finalized_receipt" invisible="picking_type_code != 'incoming'"

field name="finalized_receipt_date" invisible="picking_type_code != 'incoming'"

   I want to be able to change the value of finalized_receipt_date when the checkbox for is_finalized_receipt is checked and back to null if it is unchecked. how do i do this? do i need to bind an onchange function (how?) or will computing for the value of finalized_receipt_date is fine when form is saved?


       

           

               

               

               

           

       

   





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

Hello Kim,

I hope you are doing well.

-To achieve this functionality of updating the finalized_receipt_date field based on the value of the is_finalized_receipt checkbox, you can use an onchange method. 

Here's an example implementation in a Python file where you defined your fields:

@api.on change('is_finalized_receipt')

    def _onchange_is_finalized_receipt(self):

        if self.is_finalized_receipt:

            # Set the current date and time when the checkbox is checked

            self.finalized_receipt_date = fields.DateTime.now()

        else:

            # Set the field to null when the checkbox is unchecked

            self.finalized_receipt_date = False


- You need to change the xml file code and add force_save="1" to save the field value forcefully in the database when the form is saved.

Hope this information helps you.

อวตาร
ละทิ้ง

Here is the xml file code,

<field name="finalized_receipt_date" invisible="picking_type_code != 'incoming'" force_save="1"/>

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

def onchange_is_finalized_receipt(self):
timezone_variable = gettz(self.env.user.tz)
if self.is_finalized_receipt is True:
self.finalized_receipt_date = datetime.datetime.now().astimezone(timezone_variable).strftime("%m/%d/%Y, %H:%M:%S")
else:
self.finalized_receipt_date = '00/00/00 00:00:00'


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ส.ค. 25
1046
1
มิ.ย. 25
891
1
มิ.ย. 25
940
Inventory app undone status แก้ไขแล้ว
2
มิ.ย. 25
1639
1
พ.ค. 25
1685