diff --git a/account_banking_mandate/migrations/14.0.1.0.0/post-migrate.py b/account_banking_mandate/migrations/14.0.1.0.0/post-migrate.py new file mode 100644 index 000000000000..4f48dec45316 --- /dev/null +++ b/account_banking_mandate/migrations/14.0.1.0.0/post-migrate.py @@ -0,0 +1,30 @@ +# Copyright 2020 Opener B.V. - Stefan Rijnhart +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import logging + +from odoo.tools.sql import column_exists + + +def migrate(cr, version): + logger = logging.getLogger( + "odoo.addons.account_banking_mandate.migrations.14.0.1.0.0" + ) + if not column_exists(cr, "account_move_line", "mandate_id"): + logger.warning( + "Column account_move_line.mandate_id not found when " + "populating account_move.mandate_id" + ) + return + logger.info( + "Populating account_move.mandate_id from obsolete " + "account_move_line.mandate_id" + ) + cr.execute( + """ + UPDATE account_move am + SET mandate_id = aml.mandate_id + FROM account_move_line aml + WHERE aml.mandate_id IS NOT NULL + AND am.mandate_id IS NULL + """ + ) diff --git a/account_banking_mandate/models/account_move.py b/account_banking_mandate/models/account_move.py index ba58ef9a8e1c..8af23c7722e0 100644 --- a/account_banking_mandate/models/account_move.py +++ b/account_banking_mandate/models/account_move.py @@ -20,11 +20,6 @@ class AccountMove(models.Model): related="payment_mode_id.payment_method_id.mandate_required", readonly=True ) - def _post(self, soft=True): - for record in self: - record.line_ids.write({"mandate_id": record.mandate_id}) - return super()._post(soft=soft) - @api.model def create(self, vals): """Fill the mandate_id from the partner if none is provided on diff --git a/account_banking_mandate/models/account_move_line.py b/account_banking_mandate/models/account_move_line.py index 9b8e77a91611..93911ebd9b5d 100644 --- a/account_banking_mandate/models/account_move_line.py +++ b/account_banking_mandate/models/account_move_line.py @@ -3,24 +3,17 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import fields, models +from odoo import models class AccountMoveLine(models.Model): _inherit = "account.move.line" - mandate_id = fields.Many2one( - "account.banking.mandate", - string="Direct Debit Mandate", - ondelete="restrict", - check_company=True, - ) - def _prepare_payment_line_vals(self, payment_order): vals = super()._prepare_payment_line_vals(payment_order) if payment_order.payment_type != "inbound": return vals - mandate = self.mandate_id + mandate = self.move_id.mandate_id if not mandate and vals.get("mandate_id", False): mandate = mandate.browse(vals["mandate_id"]) partner_bank_id = vals.get("partner_bank_id", False) diff --git a/account_banking_mandate/views/account_move_line.xml b/account_banking_mandate/views/account_move_line.xml deleted file mode 100644 index 838827a067b7..000000000000 --- a/account_banking_mandate/views/account_move_line.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - account_banking_mandate.move_line_form - account.move.line - - - - - - - -