I have this model
class crm_claim(models.Model):
_inherit = 'crm.claim'
needs_credit_note = fields.Boolean(string="Needs Credit Note?")
partner_id = fields.Many2one('res.partner', string='Partner')
I need to create a function that, when needs_credit_note == True, creates a new record con account.invoice with the same partner_id, and when needs_credit_note == False, delete this record. This is what I did but is not working yet.
@api.depends("needs_credit_note")
def create(self, vals):
self.ensure_one()
if self.needs_credit_note:
self.env['account.invoice'].create({
'partner_id': self.partner_id.id,
})