Files
tocmo0nlord adbe430761
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled
Initial commit: Odoo 18.0-20251222 extra-addons
2026-03-13 20:43:25 +00:00

35 lines
1.3 KiB
Python
Executable File

# Copyright 2016-2020 Onestein (<https://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class AccountMove(models.Model):
_inherit = "account.move"
def action_post(self):
"""Invoked when validating the invoices."""
self.mapped("invoice_line_ids").create_auto_spread()
res = super().action_post()
spreads = self.mapped("invoice_line_ids.spread_id")
spreads.compute_spread_board()
# On posting of spread moves. Find their related spreads to reconcile
move_spreads = self.env["account.spread"].search(
[("line_ids.move_id", "in", self.ids)]
)
spreads += move_spreads
spreads.reconcile_spread_moves()
return res
def button_cancel(self):
"""Cancel the spread lines and their related moves when
the invoice is canceled."""
spread_lines = self.mapped("invoice_line_ids.spread_id.line_ids")
moves = spread_lines.mapped("move_id")
moves.line_ids.remove_move_reconcile()
moves.filtered(lambda move: move.state == "posted").button_draft()
moves.with_context(force_delete=True).unlink()
spread_lines.unlink()
res = super().button_cancel()
return res