diff --git a/account_banking_mandate/README.rst b/account_banking_mandate/README.rst index 70d8d56a7..bdfeec88f 100644 --- a/account_banking_mandate/README.rst +++ b/account_banking_mandate/README.rst @@ -14,13 +14,13 @@ Account Banking Mandate :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github - :target: https://github.com/OCA/bank-payment/tree/12.0/account_banking_mandate + :target: https://github.com/OCA/bank-payment/tree/13.0/account_banking_mandate :alt: OCA/bank-payment .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/bank-payment-12-0/bank-payment-12-0-account_banking_mandate + :target: https://translation.odoo-community.org/projects/bank-payment-13-0/bank-payment-13-0-account_banking_mandate :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/173/12.0 + :target: https://runbot.odoo-community.org/runbot/173/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -58,7 +58,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -82,6 +82,7 @@ Contributors * Sergio Teruel * Cédric Pigeon * Carlos Dauden +* Marçal Isern Maintainers ~~~~~~~~~~~ @@ -96,6 +97,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/bank-payment `_ project on GitHub. +This module is part of the `OCA/bank-payment `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_banking_mandate/__manifest__.py b/account_banking_mandate/__manifest__.py index a92f895c2..04ae0acdc 100644 --- a/account_banking_mandate/__manifest__.py +++ b/account_banking_mandate/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Account Banking Mandate", "summary": "Banking mandates", - "version": "12.0.2.0.0", + "version": "13.0.1.0.0", "license": "AGPL-3", "author": "Compassion CH, " "Tecnativa, " @@ -19,7 +19,7 @@ "data": [ "views/account_banking_mandate_view.xml", "views/account_payment_method.xml", - "views/account_invoice_view.xml", + "views/account_move_view.xml", "views/account_payment_line.xml", "views/res_partner_bank_view.xml", "views/res_partner.xml", diff --git a/account_banking_mandate/migrations/12.0.2.0.0/post-migration.py b/account_banking_mandate/migrations/12.0.2.0.0/post-migration.py deleted file mode 100644 index 0c30b3400..000000000 --- a/account_banking_mandate/migrations/12.0.2.0.0/post-migration.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2019 Tecnativa - Pedro M. Baeza -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html - -from openupgradelib import openupgrade, openupgrade_90 - - -@openupgrade.migrate(use_env=True) -def migrate(env, version): - column = openupgrade.get_legacy_name("scan") - if openupgrade.column_exists(env.cr, "account_banking_mandate", column): - openupgrade_90.convert_binary_field_to_attachment( - env, {"account.banking.mandate": [("scan", None)]}, - ) diff --git a/account_banking_mandate/migrations/12.0.2.0.0/pre-migration.py b/account_banking_mandate/migrations/12.0.2.0.0/pre-migration.py deleted file mode 100644 index 7b3e2f3be..000000000 --- a/account_banking_mandate/migrations/12.0.2.0.0/pre-migration.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2019 Tecnativa - Pedro M. Baeza -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openupgradelib import openupgrade - -column_renames = { - "account_banking_mandate": [("scan", None)], -} - - -@openupgrade.migrate() -def migrate(env, version): - if openupgrade.column_exists(env.cr, "account_banking_mandate", "scan"): - openupgrade.rename_columns(env.cr, column_renames) diff --git a/account_banking_mandate/models/__init__.py b/account_banking_mandate/models/__init__.py index f614e3fd0..096b524b8 100644 --- a/account_banking_mandate/models/__init__.py +++ b/account_banking_mandate/models/__init__.py @@ -1,6 +1,6 @@ from . import account_banking_mandate from . import account_payment_method -from . import account_invoice +from . import account_move from . import res_partner_bank from . import res_partner from . import account_payment_line diff --git a/account_banking_mandate/models/account_banking_mandate.py b/account_banking_mandate/models/account_banking_mandate.py index 0046da86e..0dcab8b1a 100644 --- a/account_banking_mandate/models/account_banking_mandate.py +++ b/account_banking_mandate/models/account_banking_mandate.py @@ -56,17 +56,15 @@ class AccountBankingMandate(models.Model): comodel_name="res.company", string="Company", required=True, - default=lambda self: self.env["res.company"]._company_default_get( - "account.banking.mandate" - ), + default=lambda self: self.env.company, ) unique_mandate_reference = fields.Char( - string="Unique Mandate Reference", track_visibility="onchange", copy=False, + string="Unique Mandate Reference", track_visibility="onchange", copy=False ) signature_date = fields.Date( string="Date of Signature of the Mandate", track_visibility="onchange" ) - scan = fields.Binary(string="Scan of the Mandate", attachment=True,) + scan = fields.Binary(string="Scan of the Mandate") last_debit_date = fields.Date(string="Date of the Last Debit", readonly=True) state = fields.Selection( [ @@ -86,7 +84,7 @@ class AccountBankingMandate(models.Model): inverse_name="mandate_id", string="Related Payment Lines", ) - payment_line_ids_count = fields.Integer(compute="_compute_payment_line_ids_count",) + payment_line_ids_count = fields.Integer(compute="_compute_payment_line_ids_count") _sql_constraints = [ ( @@ -106,13 +104,12 @@ class AccountBankingMandate(models.Model): result.append((mandate.id, name)) return result - @api.multi @api.depends("payment_line_ids") def _compute_payment_line_ids_count(self): payment_line_model = self.env["account.payment.line"] domain = [("mandate_id", "in", self.ids)] res = payment_line_model.read_group( - domain=domain, fields=["mandate_id"], groupby=["mandate_id"], + domain=domain, fields=["mandate_id"], groupby=["mandate_id"] ) payment_line_dict = {} for dic in res: @@ -122,7 +119,6 @@ class AccountBankingMandate(models.Model): for rec in self: rec.payment_line_ids_count = payment_line_dict.get(rec.id, 0) - @api.multi def show_payment_lines(self): self.ensure_one() return { @@ -133,7 +129,6 @@ class AccountBankingMandate(models.Model): "domain": [("mandate_id", "=", self.id)], } - @api.multi @api.constrains("signature_date", "last_debit_date") def _check_dates(self): for mandate in self: @@ -194,7 +189,7 @@ class AccountBankingMandate(models.Model): ) if ( - self.env["account.invoice"] + self.env["account.move"] .sudo() .search( [ @@ -253,7 +248,6 @@ class AccountBankingMandate(models.Model): % (mandate.display_name,) ) - @api.multi @api.constrains("state", "partner_bank_id", "signature_date") def _check_valid_state(self): for mandate in self: @@ -284,13 +278,11 @@ class AccountBankingMandate(models.Model): ) return super(AccountBankingMandate, self).create(vals) - @api.multi @api.onchange("partner_bank_id") def mandate_partner_bank_change(self): for mandate in self: mandate.partner_id = mandate.partner_bank_id.partner_id - @api.multi def validate(self): for mandate in self: if mandate.state != "draft": @@ -298,7 +290,6 @@ class AccountBankingMandate(models.Model): self.write({"state": "valid"}) return True - @api.multi def cancel(self): for mandate in self: if mandate.state not in ("draft", "valid"): @@ -306,7 +297,6 @@ class AccountBankingMandate(models.Model): self.write({"state": "cancel"}) return True - @api.multi def back2draft(self): """Allows to set the mandate back to the draft state. This is for mandates cancelled by mistake. diff --git a/account_banking_mandate/models/account_invoice.py b/account_banking_mandate/models/account_move.py similarity index 56% rename from account_banking_mandate/models/account_invoice.py rename to account_banking_mandate/models/account_move.py index d0fa015cc..06f29dfa7 100644 --- a/account_banking_mandate/models/account_invoice.py +++ b/account_banking_mandate/models/account_move.py @@ -1,7 +1,4 @@ -# Copyright 2014 Compassion CH - Cyril Sester -# Copyright 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza -# Copyright 2016 Akretion (Alexis de Lattre ) -# Copyright 2017 Carlos Dauden +# Copyright 2020 Marçal Isern # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). @@ -9,8 +6,8 @@ from odoo import _, api, fields, models from odoo.exceptions import ValidationError -class AccountInvoice(models.Model): - _inherit = "account.invoice" +class AccountMove(models.Model): + _inherit = "account.move" mandate_id = fields.Many2one( "account.banking.mandate", @@ -23,15 +20,9 @@ class AccountInvoice(models.Model): related="payment_mode_id.payment_method_id.mandate_required", readonly=True ) - @api.model - def line_get_convert(self, line, part): - """Copy mandate from invoice to account move line""" - res = super(AccountInvoice, self).line_get_convert(line, part) - if line.get("type") == "dest" and line.get("invoice_id"): - invoice = self.browse(line["invoice_id"]) - if invoice.type in ("out_invoice", "out_refund"): - res["mandate_id"] = invoice.mandate_id.id or False - return res + def post(self): + self.line_ids.mandate_id = self.mandate_id + super(AccountMove, self).post() @api.model def create(self, vals): @@ -48,28 +39,9 @@ class AccountInvoice(models.Model): for field in changed_fields: if field not in vals and invoice[field]: vals[field] = invoice._fields[field].convert_to_write( - invoice[field], invoice, + invoice[field], invoice ) - return super(AccountInvoice, self).create(vals) - - # If a customer pays via direct debit, it's refunds should - # be deducted form the next debit by default. The module - # account_payment_partner copies payment_mode_id from invoice - # to refund, and we also need to copy mandate from invoice to refund - @api.model - def _prepare_refund( - self, invoice, date_invoice=None, date=None, description=None, journal_id=None - ): - vals = super(AccountInvoice, self)._prepare_refund( - invoice, - date_invoice=date_invoice, - date=date, - description=description, - journal_id=journal_id, - ) - if invoice.type == "out_invoice": - vals["mandate_id"] = invoice.mandate_id.id - return vals + return super(AccountMove, self).create(vals) def set_mandate(self): if self.payment_mode_id.payment_method_id.mandate_required: @@ -80,13 +52,12 @@ class AccountInvoice(models.Model): @api.onchange("partner_id", "company_id") def _onchange_partner_id(self): """Select by default the first valid mandate of the partner""" - res = super(AccountInvoice, self)._onchange_partner_id() + res = super(AccountMove, self)._onchange_partner_id() self.set_mandate() return res @api.onchange("payment_mode_id") def _onchange_payment_mode_id(self): - super(AccountInvoice, self)._onchange_payment_mode_id() self.set_mandate() @api.constrains("mandate_id", "company_id") diff --git a/account_banking_mandate/models/account_move_line.py b/account_banking_mandate/models/account_move_line.py index ec923ba2d..ba5cd6165 100644 --- a/account_banking_mandate/models/account_move_line.py +++ b/account_banking_mandate/models/account_move_line.py @@ -14,7 +14,6 @@ class AccountMoveLine(models.Model): "account.banking.mandate", string="Direct Debit Mandate", ondelete="restrict" ) - @api.multi def _prepare_payment_line_vals(self, payment_order): vals = super(AccountMoveLine, self)._prepare_payment_line_vals(payment_order) if payment_order.payment_type != "inbound": @@ -38,7 +37,6 @@ class AccountMoveLine(models.Model): ) return vals - @api.multi @api.constrains("mandate_id", "company_id") def _check_company_constrains(self): for ml in self: diff --git a/account_banking_mandate/models/account_payment_line.py b/account_banking_mandate/models/account_payment_line.py index 286c5e1f4..cf515c728 100644 --- a/account_banking_mandate/models/account_payment_line.py +++ b/account_banking_mandate/models/account_payment_line.py @@ -19,7 +19,6 @@ class AccountPaymentLine(models.Model): related="order_id.payment_method_id.mandate_required", readonly=True ) - @api.multi @api.constrains("mandate_id", "partner_bank_id") def _check_mandate_bank_link(self): for pline in self: @@ -42,7 +41,6 @@ class AccountPaymentLine(models.Model): ) ) - @api.multi @api.constrains("mandate_id", "company_id") def _check_company_constrains(self): for pline in self: @@ -58,7 +56,6 @@ class AccountPaymentLine(models.Model): % (pline.name, pline.mandate_id.display_name) ) - @api.multi def draft2open_payment_line_check(self): res = super(AccountPaymentLine, self).draft2open_payment_line_check() if self.mandate_required and not self.mandate_id: diff --git a/account_banking_mandate/models/res_partner.py b/account_banking_mandate/models/res_partner.py index 1413d8e0e..2dde0ca9b 100644 --- a/account_banking_mandate/models/res_partner.py +++ b/account_banking_mandate/models/res_partner.py @@ -2,7 +2,7 @@ # Copyright 2017 Carlos Dauden # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, models +from odoo import fields, models class ResPartner(models.Model): @@ -17,7 +17,6 @@ class ResPartner(models.Model): string="First Valid Mandate", ) - @api.multi def _compute_mandate_count(self): mandate_data = self.env["account.banking.mandate"].read_group( [("partner_id", "in", self.ids)], ["partner_id"], ["partner_id"] @@ -29,7 +28,6 @@ class ResPartner(models.Model): for partner in self: partner.mandate_count = mapped_data.get(partner.id, 0) - @api.multi def _compute_valid_mandate_id(self): # Dict for reducing the duplicated searches on parent/child partners company_id = self.env.context.get("force_company", False) diff --git a/account_banking_mandate/readme/CONTRIBUTORS.rst b/account_banking_mandate/readme/CONTRIBUTORS.rst index deee727a0..c175ca726 100644 --- a/account_banking_mandate/readme/CONTRIBUTORS.rst +++ b/account_banking_mandate/readme/CONTRIBUTORS.rst @@ -5,3 +5,4 @@ * Sergio Teruel * Cédric Pigeon * Carlos Dauden +* Marçal Isern diff --git a/account_banking_mandate/static/description/index.html b/account_banking_mandate/static/description/index.html index adb00d369..e33a96d22 100644 --- a/account_banking_mandate/static/description/index.html +++ b/account_banking_mandate/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runbot

This module adds a generic model for banking mandates. These mandates can be specialized to fit any banking mandates (such as sepa or lsv).

A banking mandate is attached to a bank account and represents an @@ -404,7 +404,7 @@ account.

Bugs are tracked on GitHub 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.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -427,6 +427,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Sergio Teruel <sergio.teruel@tecnativa.com>
  • Cédric Pigeon <cedric.pigeon@acsone.eu>
  • Carlos Dauden <carlos.dauden@tecnativa.com>
  • +
  • Marçal Isern <marsal.isern@qubiq.es>
  • @@ -436,7 +437,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

    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/bank-payment project on GitHub.

    +

    This module is part of the OCA/bank-payment project on GitHub.

    You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

    diff --git a/account_banking_mandate/tests/test_invoice_mandate.py b/account_banking_mandate/tests/test_invoice_mandate.py index a3dfba874..21071463c 100644 --- a/account_banking_mandate/tests/test_invoice_mandate.py +++ b/account_banking_mandate/tests/test_invoice_mandate.py @@ -1,6 +1,7 @@ # Copyright 2017 Creu Blanca # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase @@ -11,16 +12,16 @@ class TestInvoiceMandate(TransactionCase): self.assertEqual(self.invoice.mandate_id, self.mandate) - self.invoice.action_invoice_open() + self.invoice.action_post() - payable_move_lines = self.invoice.move_id.line_ids.filtered( + payable_move_lines = self.invoice.line_ids.filtered( lambda s: s.account_id == self.invoice_account ) if payable_move_lines: self.assertEqual(payable_move_lines[0].mandate_id, self.mandate) self.env["account.invoice.payment.line.multi"].with_context( - active_model="account.invoice", active_ids=self.invoice.ids + active_model="account.move", active_ids=self.invoice.ids ).create({}).run() payment_order = self.env["account.payment.order"].search([]) @@ -54,9 +55,9 @@ class TestInvoiceMandate(TransactionCase): self.invoice._onchange_partner_id() self.assertEqual(self.invoice.mandate_id, self.mandate) - self.invoice.action_invoice_open() + self.invoice.action_post() - payable_move_lines = self.invoice.move_id.line_ids.filtered( + payable_move_lines = self.invoice.line_ids.filtered( lambda s: s.account_id == self.invoice_account ) if payable_move_lines: @@ -65,9 +66,22 @@ class TestInvoiceMandate(TransactionCase): def test_post_invoice_and_refund_02(self): self.invoice._onchange_partner_id() - self.invoice.action_invoice_open() + self.invoice.action_post() self.assertEqual(self.invoice.mandate_id, self.mandate) - self.invoice.refund() + move_reversal = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=self.invoice.ids) + .create( + { + "date": fields.Date.today(), + "reason": "no reason", + "refund_method": "refund", + } + ) + ) + reversal = move_reversal.reverse_moves() + ref = self.env["account.move"].browse(reversal["res_id"]) + self.assertEqual(self.invoice.mandate_id, ref.mandate_id) def test_onchange_partner(self): partner_2 = self._create_res_partner("Jane with ACME Bank") @@ -90,10 +104,9 @@ class TestInvoiceMandate(TransactionCase): ) mandate_2.validate() - invoice = self.env["account.invoice"].new( + invoice = self.env["account.move"].new( { "partner_id": self.partner.id, - "account_id": self.invoice_account.id, "type": "out_invoice", "company_id": self.company.id, } @@ -104,10 +117,9 @@ class TestInvoiceMandate(TransactionCase): self.assertEqual(invoice.mandate_id, mandate_2) def test_onchange_payment_mode(self): - invoice = self.env["account.invoice"].new( + invoice = self.env["account.move"].new( { "partner_id": self.partner.id, - "account_id": self.invoice_account.id, "type": "out_invoice", "company_id": self.company.id, } @@ -156,10 +168,9 @@ class TestInvoiceMandate(TransactionCase): ) mandate_2.validate() - invoice = self.env["account.invoice"].create( + invoice = self.env["account.move"].create( { "partner_id": self.partner.id, - "account_id": self.invoice_account.id, "type": "out_invoice", "company_id": self.company.id, } @@ -252,23 +263,29 @@ class TestInvoiceMandate(TransactionCase): .id ) - self.invoice = self.env["account.invoice"].create( + invoice_vals = [ + ( + 0, + 0, + { + "product_id": self.env.ref("product.product_product_4").id, + "quantity": 1.0, + "account_id": invoice_line_account, + "price_unit": 200.00, + }, + ) + ] + + self.invoice = self.env["account.move"].create( { "partner_id": self.partner.id, - "account_id": self.invoice_account.id, "type": "out_invoice", "company_id": self.company.id, + "journal_id": self.env["account.journal"] + .search([("type", "=", "sale")], limit=1) + .id, + "invoice_line_ids": invoice_vals, } ) - self.env["account.invoice.line"].create( - { - "product_id": self.env.ref("product.product_product_4").id, - "quantity": 1.0, - "price_unit": 100.0, - "invoice_id": self.invoice.id, - "name": "product that cost 100", - "account_id": invoice_line_account, - } - ) return res diff --git a/account_banking_mandate/views/account_banking_mandate_view.xml b/account_banking_mandate/views/account_banking_mandate_view.xml index ffcce21c0..4f96c6b49 100644 --- a/account_banking_mandate/views/account_banking_mandate_view.xml +++ b/account_banking_mandate/views/account_banking_mandate_view.xml @@ -105,7 +105,8 @@ diff --git a/account_banking_mandate/views/account_invoice_view.xml b/account_banking_mandate/views/account_move_view.xml similarity index 67% rename from account_banking_mandate/views/account_invoice_view.xml rename to account_banking_mandate/views/account_move_view.xml index c3e5b78e1..48fab3661 100644 --- a/account_banking_mandate/views/account_invoice_view.xml +++ b/account_banking_mandate/views/account_move_view.xml @@ -4,12 +4,12 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> - - add.mandate.on.customer.invoice.form - account.invoice - + + add.mandate.on.account.move.form + account.move + - + res.partner.bank - +