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

hi all

i try to create 'mail.activity' from 'stock.scrap'

class InheritStockScrap(models.Model):
_inherit = 'stock.scrap'

def action_confirm_draft(self):
for rec in self:
rec.state = 'inventory_manager_approval'
group_xml_id = 'stock.group_stock_manager'
if group_xml_id:
users = self.env['res.users'].search([("groups_id", "=", self.env.ref(group_xml_id).id)])
note = 'Please Confirm Scrap Stock ..'
activity_type_id = self.env.ref('mail.mail_activity_data_todo').id
for rec in users:
self.env['mail.activity'].create({
'activity_type_id': activity_type_id,
'note': note,
'user_id': rec.id,
'res_id': self.id,
'res_model_id': self.env.ref('stock.model_stock_scrap').id,
'date_deadline': datetime.now().date(),
})

but faced this error .. any idea ?

ValueError: Invalid field stock.scrap.activity_ids in leaf ('activity_ids.user_id', '=', 2)
Avatar
Discard

This link might help as well as it is with an existing model.

http://www.odooninja.com/add-chatter-existing-model/

Best Answer

Hello Omar,

I don't believe this code is creating your error. What the error code is saying is you are using a domain somewhere which is searching the model stock.scrap.activity_ids where activity_ids.user_id = 2.

The error is saying that this field doesn't exist, because it doesn't. I think you want to inherit the mail models and add the relevant to the code. See this post with the answer:

https://www.odoo.com/forum/help-1/i-created-a-new-module-in-crm-how-can-i-add-the-schedule-activity-button-to-the-chatter-box-130557

I hope this helps,

thanks,

Avatar
Discard
Author

i added

class InheritStockScrap(models.Model):

_name = 'stock.scrap'

_inherit = ['stock.scrap','mail.thread', 'mail.activity.mixin']

then

added xml code (same as in link)

and it works fine now

thanks

Happy to help, all the best.

Related Posts Replies Views Activity
1
May 24
1433
1
Apr 24
23271
1
Nov 22
1405
2
Jul 22
1805
2
Jul 22
1828