Skip to Content
Menu
This question has been flagged
3 Replies
736 Views

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!


Avatar
Discard
Best Answer

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.


Avatar
Discard
Best Answer

what is karma

Avatar
Discard
Author Best Answer

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.

Avatar
Discard