Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
1225 Prikazi

I created credit note and i need to show it in the invoice smart button of sale order and link it with sale order 

credit_note=self.env['account.move'].create({
'move_type': 'out_refund',
'invoice_origin'
: picking_id.name,
'invoice_user_id'
: current_user,
'narration'
: picking_id.name,
'partner_id'
: picking_id.partner_id.id,
'currency_id'
: picking_id.env.user.company_id.currency_id.id,
'ref'
: _('Reversal for: %s') % self.reason.name if self.reason else '',
'date'
: self.date or False,
'invoice_date'
: self.date or False,
'journal_id'
: self.journal_id and self.journal_id.id or False,
'invoice_line_ids'
: invoice_line_list,

})


Avatar
Opusti
Best Answer

Here's how you can achieve this:


Associate the Credit Note with the Sale Order:

After creating the credit note, you should associate it with the related sale order. You can do this by setting the invoice_ids field of the sale order to include the newly created credit note.

Assuming self refers to the sale order object, you can update the code as follows:


python


credit_note = self.env['account.move'].create({
    # ... (your credit note creation code)
})
# Associate the credit note with the sale order
self.write({'invoice_ids': [(4, credit_note.id)]})

Configure the Smart Button:


Then, in your smart button definition in the sale order form view, display the number of invoices (including credit notes) and link to the list of invoices:


Avatar
Opusti
Avtor

i linked it by :self.write({'invoice_ids': [(4, credit_note.id)]})
but it doesn't show

where do you want to show it? what a view?
Just doing that should add the counter of the invoices linked to the sales order. The button to see sales order invoices should also work normally