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

Hi, guys, I'm trying to inherit ir.attachment which is model1 and want to get field in another model which is model2, since many2one could reach the model2, however, it could not get the field in it.[expense_new_id.state   returns false]

Below is my code, hope somebody could help:

class ExpenseNewAttachment(models.Model):
_name = 'expense_new.attachment'
_inherit = 'ir.attachment'

expense_new_id = fields.Many2one('expense_new.expense_new', ondelete='cascade', string='attachment')
state = fields.Char(compute='_compute_state', store=True)

@api.one
@api.depends('expense_new_id.state')
def _compute_state(self):
for attachment in self:
if attachment.expense_new_id.state == "draft":
attachment.state = "draft"
elif attachment.expense_new_id.state == "submitted":
attachment.state = "submitted"
elif attachment.expense_new_id.state == "approved":
attachment.state = "approved"
elif attachment.expense_new_id.state == "posted":
attachment.state = "posted"
else:
print(attachment.expense_new_id.state)
attachment.state = "refused"
expense_attachment = fields.One2many('expense_new.attachment', inverse_name='expense_new_id')
Avatar
Discard
Best Answer

@api.depends('expense_new_id')

try it bro



Avatar
Discard