Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
1238 Widoki

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?


       

           

               

               

               

           

       

   





Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć

Here is the xml file code,

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

Autor Najlepsza odpowiedź
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'


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sie 25
1047
1
cze 25
892
1
cze 25
941
2
cze 25
1639
1
maj 25
1685