Skip to content

Commit

Permalink
[RFR] Simplify datamodel
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanRijnhart committed Jan 8, 2021
1 parent efdfef7 commit e242654
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
30 changes: 30 additions & 0 deletions account_banking_mandate/migrations/14.0.1.0.0/post-migrate.py
@@ -0,0 +1,30 @@
# Copyright 2020 Opener B.V. - Stefan Rijnhart <stefan@opener.amsterdam>
# 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
"""
)
5 changes: 0 additions & 5 deletions account_banking_mandate/models/account_move.py
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions account_banking_mandate/models/account_move_line.py
Expand Up @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions account_banking_mandate/views/account_move_line.xml

This file was deleted.

0 comments on commit e242654

Please sign in to comment.