Skip to Content
Menu
This question has been flagged
2 Replies
1351 Views

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
Discard
Author

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

Author

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

Best Answer

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
Discard
Author Best Answer

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
Discard
Related Posts Replies Views Activity
0
Apr 25
269
1
Aug 24
1038
0
May 22
1543
0
May 21
1162
2
Jul 16
4519