[MIG] account_move_reconcile_forbid_cancel: Migration to 15.0

TT40142
pull/568/head
Víctor Martínez 2022-11-22 17:06:26 +01:00 committed by Alejandro Ji Cheung
parent 6101ff7edc
commit ea579679a4
5 changed files with 55 additions and 85 deletions

View File

@ -14,13 +14,13 @@ Account Move Reconcile Forbid Cancel
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github
:target: https://github.com/OCA/account-reconcile/tree/13.0/account_move_reconcile_forbid_cancel
:target: https://github.com/OCA/account-reconcile/tree/15.0/account_move_reconcile_forbid_cancel
:alt: OCA/account-reconcile
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-reconcile-13-0/account-reconcile-13-0-account_move_reconcile_forbid_cancel
:target: https://translation.odoo-community.org/projects/account-reconcile-15-0/account-reconcile-15-0-account_move_reconcile_forbid_cancel
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/98/13.0
:target: https://runbot.odoo-community.org/runbot/98/15.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@ -50,7 +50,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-reconcile/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_move_reconcile_forbid_cancel%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_move_reconcile_forbid_cancel%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
@ -83,6 +83,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/13.0/account_move_reconcile_forbid_cancel>`_ project on GitHub.
This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/15.0/account_move_reconcile_forbid_cancel>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -3,7 +3,7 @@
{
"name": "Account Move Reconcile Forbid Cancel",
"version": "13.0.1.0.2",
"version": "15.0.1.0.0",
"category": "Finance",
"website": "https://github.com/OCA/account-reconcile",
"author": "Tecnativa, Odoo Community Association (OCA)",

View File

@ -23,7 +23,7 @@ class AccountMove(models.Model):
raise ValidationError(
_("You cannot reset to draft reconciled entries.")
)
super().button_draft()
return super().button_draft()
def button_cancel(self):
if not self.env.context.get("skip_reconcile_forbid_cancel") and (
@ -33,4 +33,4 @@ class AccountMove(models.Model):
rec_pay_lines = self._get_receivable_payable_lines()
if rec_pay_lines.matched_debit_ids or rec_pay_lines.matched_credit_ids:
raise ValidationError(_("You cannot cancel reconciled entries."))
super().button_cancel()
return super().button_cancel()

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Account Move Reconcile Forbid Cancel</title>
<style type="text/css">
@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/13.0/account_move_reconcile_forbid_cancel"><img alt="OCA/account-reconcile" src="https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-reconcile-13-0/account-reconcile-13-0-account_move_reconcile_forbid_cancel"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/98/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/15.0/account_move_reconcile_forbid_cancel"><img alt="OCA/account-reconcile" src="https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-reconcile-15-0/account-reconcile-15-0-account_move_reconcile_forbid_cancel"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/98/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module restricts to cancel or reset to draft any invoice/journal entry that
has been reconciled (aka paid).</p>
<p><strong>Table of contents</strong></p>
@ -399,7 +399,7 @@ it has already an associated payment.</li>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-reconcile/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_move_reconcile_forbid_cancel%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_move_reconcile_forbid_cancel%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@ -427,7 +427,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/13.0/account_move_reconcile_forbid_cancel">OCA/account-reconcile</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/15.0/account_move_reconcile_forbid_cancel">OCA/account-reconcile</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

View File

@ -1,56 +1,23 @@
# Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo.exceptions import ValidationError
from odoo.tests.common import Form, SavepointCase
from odoo.tests.common import Form, TransactionCase
class TestAccountMoveReconcileForbidCancel(SavepointCase):
class TestAccountMoveReconcileForbidCancel(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
purchase_journal = cls.env["account.journal"].create(
{"name": "Purchase journal", "code": "PJ", "type": "purchase"}
)
sale_journal = cls.env["account.journal"].create(
{"name": "Sale journal", "code": "SJ", "type": "sale"}
)
cls.env["account.journal"].create(
{"name": "Bank Journal", "code": "BANK", "type": "bank"}
)
receivable_account_type = cls.env["account.account.type"].create(
{
"name": "Receivable account type",
"type": "receivable",
"internal_group": "asset",
}
)
payable_account_type = cls.env["account.account.type"].create(
{
"name": "Payable account type",
"type": "payable",
"internal_group": "liability",
}
)
income_account_type = cls.env["account.account.type"].create(
{
"name": "Income account type",
"type": "other",
"internal_group": "income",
}
)
expense_account_type = cls.env["account.account.type"].create(
{
"name": "Expense account type",
"type": "other",
"internal_group": "expense",
}
)
receivable_account = cls.env["account.account"].create(
{
"name": "Receivable Account",
"code": "REC",
"user_type_id": receivable_account_type.id,
"user_type_id": cls.env.ref("account.data_account_type_receivable").id,
"reconcile": True,
}
)
@ -58,7 +25,7 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase):
{
"name": "Payable Account",
"code": "PAY",
"user_type_id": payable_account_type.id,
"user_type_id": cls.env.ref("account.data_account_type_payable").id,
"reconcile": True,
}
)
@ -66,7 +33,9 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase):
{
"name": "Income Account",
"code": "INC",
"user_type_id": income_account_type.id,
"user_type_id": cls.env.ref(
"account.data_account_type_other_income"
).id,
"reconcile": False,
}
)
@ -74,18 +43,18 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase):
{
"name": "Expense Account",
"code": "EXP",
"user_type_id": expense_account_type.id,
"user_type_id": cls.env.ref("account.data_account_type_expenses").id,
"reconcile": False,
}
)
partner = cls.env["res.partner"].create(
cls.partner = cls.env["res.partner"].create(
{
"name": "Partner test",
"property_account_receivable_id": receivable_account.id,
"property_account_payable_id": payable_account.id,
}
)
product = cls.env["product.product"].create(
cls.product = cls.env["product.product"].create(
{
"name": "Product Test",
"property_account_income_id": income_account.id,
@ -93,45 +62,34 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase):
}
)
# Create a purchase invoice
move_form = Form(
cls.env["account.move"].with_context(default_type="in_invoice")
)
move_form.journal_id = purchase_journal
move_form.partner_id = partner
with move_form.invoice_line_ids.new() as line_form:
line_form.product_id = product
line_form.price_unit = 100.0
cls.purchase_invoice = move_form.save()
cls.purchase_invoice = cls._create_invoice(cls, "in_invoice")
cls.purchase_invoice.action_post()
# Create payment from invoice
payment_register_form = Form(
cls.env["account.payment"].with_context(
active_model="account.move",
active_ids=cls.purchase_invoice.ids,
)
)
payment = payment_register_form.save()
payment.post()
cls._create_payment_from_invoice(cls, cls.purchase_invoice)
# Create a sale invoice
move_form = Form(
cls.env["account.move"].with_context(default_type="out_invoice")
)
move_form.journal_id = sale_journal
move_form.partner_id = partner
with move_form.invoice_line_ids.new() as line_form:
line_form.product_id = product
line_form.price_unit = 100.0
cls.sale_invoice = move_form.save()
cls.sale_invoice = cls._create_invoice(cls, "out_invoice")
cls.sale_invoice.action_post()
# Create payment from invoice
cls._create_payment_from_invoice(cls, cls.sale_invoice)
def _create_invoice(self, move_type):
move_form = Form(
self.env["account.move"].with_context(default_move_type=move_type)
)
move_form.invoice_date = fields.Date.today()
move_form.partner_id = self.partner
with move_form.invoice_line_ids.new() as line_form:
line_form.product_id = self.product
line_form.price_unit = 100.0
return move_form.save()
def _create_payment_from_invoice(self, invoice):
res = invoice.action_register_payment()
payment_register_form = Form(
cls.env["account.payment"].with_context(
active_model="account.move",
active_ids=cls.sale_invoice.ids,
)
self.env[res["res_model"]].with_context(**res["context"])
)
payment = payment_register_form.save()
payment.post()
payment.action_create_payments()
def test_reset_invoice_to_draft(self):
with self.assertRaises(ValidationError):
@ -152,3 +110,15 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase):
self.sale_invoice.with_context(
test_reconcile_forbid_cancel=True
).button_cancel()
def test_extra_invoice_process_to_draft(self):
invoice = self._create_invoice("out_invoice")
invoice.action_post()
invoice.button_draft()
self.assertEqual(invoice.state, "draft")
def test_extra_invoice_process_cancel(self):
invoice = self._create_invoice("out_invoice")
invoice.action_post()
invoice.button_cancel()
self.assertEqual(invoice.state, "cancel")