Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
751 Vizualizări

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!


Imagine profil
Abandonează
Cel mai bun răspuns

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.


Imagine profil
Abandonează
Cel mai bun răspuns

what is karma

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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.

Imagine profil
Abandonează