Skip to Content
Menu
This question has been flagged
1 Reply
2229 Views

Hey guys,


I'm creating a tracking form view that should populate a model that I'm inheriting through a One2many field. The data is being created through this function:

class Groups(models.Model):
_inherit = 'res.groups'
group_log_ids = fields.One2many(string="Changes", comodel_name="res.groups.logger", inverse_name="group_id")
def create_record(self):
         self.env['res.groups.logger'].create({
'user_id' : self .env.user.id,
'date_of_creation' : datetime.today (),
'user_changed' : user.name,
'group_name' : self .name,
'log _changes' : "Removed" ,
})

Here's my res.group.logger file that will be displayed in my xml file

.class LogGroups (models.Model):

 _name = 'res.groups.logger'
_description = "Groups logger"
user_id = fields.Many2one ( string = "User" , comodel_name = "res.users" ) date_of_creation = fields.Datetime ( "Date Created" ) user_changed = fields. Char ( string = "Changed User" ) group_name = fields.Char ( string = "Group Name" ) log_changes = fields.Char ( string = "Action" )





Here's how it's called in my xml file.< page name = "tracking" string = "Tracking" groups = "base.group_no_one" >
    < Group > 
< field name = "group_log_ids" nolabel = "1" readonly = "1" >
< tree >
< field name = "user_id" />
< field name = "date_of_creation" />
< field name = "user_changed" / >
< field name = "group_name" />
< field name = "log_changes" />
</ tree >
</ field >
</ group>
</ page >

Is there any reason why the data isn't being populated in the view form when self.env.create is called?

I get this error in my log 2021-05-14 17:44:32,043 29484 ERROR testing1 odoo.sql_db: bad query: UPDATE "res_users" SET "im_status_stored"='online',"write_uid"=1,"write_date"=(now() at time zone 'UTC') WHERE id IN (2)


Please help

Avatar
Discard
Best Answer

Hi,

You can try using the following code:



class Groups(models.Model):
_inherit = 'res.groups'

group_log_ids = fields.One2many("res.groups.logger","group_id", string="Changes") # that "group_id" must be a many2one field in "res.groups.logger" model, and Many2one must link to 'res.groups'

def create_record(self):
self.env['res.groups.logger'].create({
'user_id': self.env.user.id,
'date_of_creation': datetime.today(),
'user_changed': self.env.user.name,
'group_name': self.name,
'log _changes': "Removed",
})

class LogGroups (models.Model):
_name = 'res.groups.logger'
_description = "Groups logger"

user_id = fields.Many2one(string = "User", comodel_name="res.users")
date_of_creation = fields.Datetime("Date Created")
user_changed = fields.Char(string="Changed User")
group_name = fields.Char(string = "Group Name")
log_changes = fields.Char( string = "Action")


You can also contact my team at support@rolustech.com for further assistance. Rolustech is an Odoo partner experienced in providing customization, integration, and support services to Odoo users across the globe. 

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 24
91
0
Sep 23
450
1
Jun 22
1119
2
Oct 19
6598
0
Feb 18
2683