[MIG] account_banking_mandate: Migration to 13.0

This commit is contained in:
Marçal Isern
2020-03-27 06:55:19 +01:00
committed by Reyes4711
parent a90b928c26
commit 85ff85619d
16 changed files with 80 additions and 132 deletions

View File

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

View File

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

View File

@@ -1,7 +1,4 @@
# Copyright 2014 Compassion CH - Cyril Sester <csester@compassion.ch>
# Copyright 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
# Copyright 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2017 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2020 Marçal Isern <marsal.isern@qubiq.es>
# 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")

View File

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

View File

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

View File

@@ -2,7 +2,7 @@
# Copyright 2017 Carlos Dauden <carlos.dauden@tecnativa.com>
# 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)