2019-02-06 12:14:42 +01:00
|
|
|
# Copyright 2016-2019 Onestein (<https://www.onestein.eu>)
|
2018-10-22 12:27:50 +02:00
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
|
|
|
|
|
|
class AccountInvoice(models.Model):
|
|
|
|
_inherit = 'account.invoice'
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def action_move_create(self):
|
|
|
|
"""Invoked when validating the invoices."""
|
|
|
|
res = super().action_move_create()
|
2019-06-04 13:38:00 +02:00
|
|
|
spreads = self.mapped('invoice_line_ids.spread_id')
|
|
|
|
spreads.compute_spread_board()
|
|
|
|
spreads.reconcile_spread_moves()
|
2018-10-22 12:27:50 +02:00
|
|
|
return res
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def invoice_line_move_line_get(self):
|
|
|
|
"""Copying expense/revenue account from spread to move lines."""
|
|
|
|
res = super().invoice_line_move_line_get()
|
|
|
|
for line in res:
|
|
|
|
invl_id = line.get('invl_id')
|
|
|
|
invl = self.env['account.invoice.line'].browse(invl_id)
|
|
|
|
if invl.spread_id:
|
|
|
|
if invl.invoice_id.type in ('out_invoice', 'in_refund'):
|
|
|
|
account = invl.spread_id.debit_account_id
|
|
|
|
else:
|
|
|
|
account = invl.spread_id.credit_account_id
|
|
|
|
line['account_id'] = account.id
|
|
|
|
return res
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def action_cancel(self):
|
|
|
|
"""Cancel the spread lines and their related moves when
|
|
|
|
the invoice is canceled."""
|
|
|
|
res = super().action_cancel()
|
2019-06-04 13:38:00 +02:00
|
|
|
spread_lines = self.mapped('invoice_line_ids.spread_id.line_ids')
|
|
|
|
moves = spread_lines.mapped('move_id')
|
|
|
|
moves.button_cancel()
|
|
|
|
moves.unlink()
|
|
|
|
spread_lines.unlink()
|
2018-10-22 12:27:50 +02:00
|
|
|
return res
|
2019-02-06 12:14:42 +01:00
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _refund_cleanup_lines(self, lines):
|
2019-06-04 13:38:00 +02:00
|
|
|
result = super()._refund_cleanup_lines(lines)
|
2019-02-06 12:14:42 +01:00
|
|
|
for i, line in enumerate(lines):
|
2019-06-04 13:38:00 +02:00
|
|
|
for name in line._fields.keys():
|
2019-02-06 12:14:42 +01:00
|
|
|
if name == 'spread_id':
|
|
|
|
result[i][2][name] = False
|
|
|
|
break
|
|
|
|
return result
|