[RFR] Simplify datamodel

This commit is contained in:
Stefan Rijnhart
2021-01-08 09:42:47 +01:00
parent bd2d666e59
commit 1fd22aaebe
4 changed files with 32 additions and 34 deletions

View File

@@ -0,0 +1,30 @@
# Copyright 2021 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
"""
)

View File

@@ -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

View File

@@ -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)

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
© 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_move_line_form" model="ir.ui.view">
<field name="name">account_banking_mandate.move_line_form</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account_payment_order.view_move_line_form" />
<field name="arch" type="xml">
<field name="partner_bank_id" position="after">
<field
name="mandate_id"
domain="[('partner_id', '=', partner_id), ('state', '=', 'valid')]"
/>
</field>
</field>
</record>
</odoo>