콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
1246 화면

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
1048
1
6월 25
894
1
6월 25
941
2
6월 25
1640
1
5월 25
1686