Files
odoo_source/addons/account_debit_note/models/account_move.py
T
Josse Colpaert 47eff65afd [ADD] account_debit_note: Debit Note functionality
You might think that if the debit note is like the inverse
of a credit note, that it is just a regular invoice.

Well, it is, except that we had several localizations
adding a link with the original invoice for the debit note.
This way, we can share that many2one and add a wizard that is
similar as the one for the credit once and for all.

In order to keep things simple, we always create a
draft debit note.  The only option we give, is to copy
the original invoice lines or not.

You can also create a debit note from a credit note,
in which case the type needs to change, but we don't
copy the lines in that case (for now).

opw-2181586

closes odoo/odoo#45542

X-original-commit: f1af011d0966fa6e436168879b7f18fabb955934
Signed-off-by: Josse Colpaert <jco@openerp.com>
2020-02-17 16:33:22 +00:00

31 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, api, _
class AccountMove(models.Model):
_inherit = "account.move"
debit_origin_id = fields.Many2one('account.move', 'Original Invoice Debited', readonly=True, copy=False)
debit_note_ids = fields.One2many('account.move', 'debit_origin_id', 'Debit Notes',
help="The debit notes created for this invoice")
debit_note_count = fields.Integer('Number of Debit Notes', compute='_compute_debit_count')
@api.depends('debit_note_ids')
def _compute_debit_count(self):
debit_data = self.env['account.move'].read_group([('debit_origin_id', 'in', self.ids)],
['debit_origin_id'], ['debit_origin_id'])
data_map = {datum['debit_origin_id'][0]: datum['debit_origin_id_count'] for datum in debit_data}
for inv in self:
inv.debit_note_count = data_map.get(inv.id, 0.0)
def action_view_debit_notes(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': _('Debit Notes'),
'res_model': 'account.move',
'view_mode': 'tree,form',
'domain': [('debit_origin_id', '=', self.id)],
}