Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
1713 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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!

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 25
802
1
thg 8 24
1753
0
thg 5 22
2051
0
thg 5 21
1523
2
thg 7 16
4989