Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
761 Lượt xem

Hey,


I'm trying to have the following code working in my python module on Odoo17:

```python

class ftp_client(models.Model):

  host = fields.Char()

  def connect(self):

    _logger.info(f"Connecting to host: {self.host}")


class ResConfigSettings(models.TransientModel):

  _inherit = 'res.config.settings'

  ftp_client = fields.Many2one('ftp_client')

  

  def some_action(self):

    self.ftp_client.connect()

```


When I trigger "some_action" from a Scheduled Actions, I don't have any values in ftp_client.host: I get the following log: "Connecting to host: False"


Thanks for you help!


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

In your code, when calling self.ftp_client.connect() in the some_action method, the issue is that the host attribute is not accessed correctly. You need to use self.ftp_client.host instead of just host.

Make sure you have the correct import statements (from odoo import models, fields, api) at the beginning of your module. Additionally, ensure that your ftp_client records have the host field set before calling the some_action method.

With these corrections, when you trigger the some_action method, it should log the correct host value instead of False.


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

what is karma

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thanks a lot for your answer.


The missing self was an issue when simplifing my code, it was correct in my tests.

I have all correct import, and the record is correctly set in the ftp_client record I'm trying to access: the connection is working correctly when called from the record and not from the ResConfigSettings class.

Ảnh đại diện
Huỷ bỏ