Skip to Content
Menu
This question has been flagged
2 Replies
1227 Views

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?


       

           

               

               

               

           

       

   





Avatar
Discard
Best Answer

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.

Avatar
Discard

Here is the xml file code,

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

Author Best Answer
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'


Avatar
Discard
Related Posts Replies Views Activity
1
Aug 25
1045
1
Jun 25
890
1
Jun 25
916
2
Jun 25
1636
1
May 25
1683