Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
1753 Visualizzazioni

I'm looking for help in adding custom fields in my custom addon.

My code (mass_mail.py):

from odoo import models, fields, api
from odoo.exceptions import UserError
import time

class MailingMailing(models.Model):
_inherit = "mailing.mailing"
max_emails_per_iteration = fields.Integer(string="Max Emails per Iteration", default=10)
time_interval_between_iterations = fields.Integer(string="Time Interval (seconds)", default=60)

def send_mail(self):
# Split the recipients into smaller groups based on max_emails_per_iteration
recipient_domain = self.mailing_domain
mailing_model_id = self.mailing_model_id

# Fetch the recipients based on the domain
recipients = self.env[self.env["ir.model"].browse(mailing_model_id).model].search([
("id", "in", self.env[self.env["ir.model"].browse(mailing_model_id).model].search([]).filtered_domain(recipient_domain).ids)
])

for i in range(0, len(recipients), self.max_emails_per_iteration):
email_batch = recipients[i:i + self.max_emails_per_iteration]
self.write({
"mailing_domain": [
("id", "in", email_batch.ids),
("model_id", "=", mailing_model_id),
]
})
super(MailingMailing, self).send_mail()
time.sleep(self.time_interval_between_iterations)

# Restore the original domain
self.write({"mailing_domain": [("id", "in", self.env[self.env["ir.model"].browse(mailing_model_id).model].search([]).filtered_domain(recipient_domain).ids)]})


Odoo is not adding new fields. When trying to add those fields in inherited view, it throws me an error:

odoo.exceptions.ValidationError: Error while validating view near:

                    
Field "max_emails_per_iteration" does not exist in model "mailing.mailing"


I have tried to install the addon without inherited view definition, it installs but there are no custom fields in mailing.mailing model added.

System id Odoo 15 Community.

Any help appreciated.

Avatar
Abbandona
Autore

Hi Savya,

thank you for your answer. My Odoo instance is running in docker (with docker-compose.yml). I have tried already to restart container, restart database, update and restart server and rebuild container (docker-compose down / up -d).

Still have the same error. What can be wrong? 

I have updated the answer, please check

Autore

I am trying (maybe not understand docker perfectly):

docker run -v odoo-project_odoo-db-data,odoo-project_odoo-web-data odoo:15.0 odoo -u all -d DATABASENAME

error: Database connection failure: could not translate host name "db" to address: Name or service not known

Tried with real database name instead, the same error. Should I build new container alongside existing one to do this? Beacause this command builds new container in the docker.. 

Risposta migliore

Hi,

Try to upgrade the module upon restarting the server. In your run configuration add 

-u custom_module

eg:

-c your_odoo.conf -u custom_module

restart and check if the field is added.

for docker setup, try 

docker run -v [your volumes] odoo:version odoo -u all -d DATABASENAME

-u all #updates all

-u module_name #update specific module


Thanks

Avatar
Abbandona
Autore Risposta migliore

Thank you, problem solved. Cannot mark your answer as Best one due to insufficient karma, but it was right one.

One more mistake I have made was an empty _ _ i n i t . p y _ _ file in the root of the addon. It should contain one line:

from . import models


Sorry for the confusion.

Best regards!

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
lug 25
807
1
ago 24
1792
0
mag 22
2074
0
mag 21
1526
2
lug 16
5002