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.
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
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..