コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
1239 ビュー

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'


アバター
破棄
関連投稿 返信 ビュー 活動
1
8月 25
1047
1
6月 25
892
1
6月 25
941
2
6月 25
1639
1
5月 25
1685