[MIG] account_payment_partner: Migration to 13.0

This commit is contained in:
Raf Ven
2019-12-19 11:28:06 +01:00
committed by Thomas Binsfeld
parent 31817a7d88
commit 26de286d5c
14 changed files with 345 additions and 341 deletions

View File

@@ -14,13 +14,13 @@ Account Payment Partner
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github .. |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_payment_partner :target: https://github.com/OCA/bank-payment/tree/13.0/account_payment_partner
:alt: OCA/bank-payment :alt: OCA/bank-payment
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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_payment_partner :target: https://translation.odoo-community.org/projects/bank-payment-13-0/bank-payment-13-0-account_payment_partner
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |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 :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@@ -84,7 +84,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-payment/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-payment/issues>`_.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_partner%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_partner%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@@ -128,6 +128,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/bank-payment <https://github.com/OCA/bank-payment/tree/12.0/account_payment_partner>`_ project on GitHub. This module is part of the `OCA/bank-payment <https://github.com/OCA/bank-payment/tree/13.0/account_payment_partner>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -5,7 +5,7 @@
{ {
"name": "Account Payment Partner", "name": "Account Payment Partner",
"version": "12.0.1.0.0", "version": "13.0.1.0.0",
"category": "Banking addons", "category": "Banking addons",
"license": "AGPL-3", "license": "AGPL-3",
"summary": "Adds payment mode on partners and invoices", "summary": "Adds payment mode on partners and invoices",
@@ -14,7 +14,7 @@
"depends": ["account_payment_mode"], "depends": ["account_payment_mode"],
"data": [ "data": [
"views/res_partner_view.xml", "views/res_partner_view.xml",
"views/account_invoice_view.xml", "views/account_move_view.xml",
"views/account_move_line.xml", "views/account_move_line.xml",
"views/account_payment_mode.xml", "views/account_payment_mode.xml",
"views/report_invoice.xml", "views/report_invoice.xml",

View File

@@ -1,4 +1,4 @@
from . import res_partner from . import res_partner
from . import account_invoice from . import account_move
from . import account_move_line from . import account_move_line
from . import account_payment_mode from . import account_payment_mode

View File

@@ -1,154 +0,0 @@
# Copyright 2014-16 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# Copyright 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class AccountInvoice(models.Model):
_inherit = "account.invoice"
payment_mode_id = fields.Many2one(
comodel_name="account.payment.mode",
string="Payment Mode",
ondelete="restrict",
readonly=True,
states={"draft": [("readonly", False)]},
)
bank_account_required = fields.Boolean(
related="payment_mode_id.payment_method_id.bank_account_required", readonly=True
)
partner_bank_id = fields.Many2one(ondelete="restrict")
@api.onchange("partner_id", "company_id")
def _onchange_partner_id(self):
res = super(AccountInvoice, self)._onchange_partner_id()
if self.partner_id:
if self.type == "in_invoice":
pay_mode = self.with_context(
force_company=self.company_id.id
).partner_id.supplier_payment_mode_id
self.payment_mode_id = pay_mode
if (
pay_mode
and pay_mode.payment_type == "outbound"
and pay_mode.payment_method_id.bank_account_required
and self.commercial_partner_id.bank_ids
):
self.partner_bank_id = self.commercial_partner_id.bank_ids.filtered(
lambda b: b.company_id == self.company_id or not b.company_id
)[:1]
else:
self.partner_bank_id = False
elif self.type == "out_invoice":
# No bank account assignation is done here as this is only
# needed for printing purposes and it can conflict with
# SEPA direct debit payments. Current report prints it.
self.payment_mode_id = self.with_context(
force_company=self.company_id.id
).partner_id.customer_payment_mode_id
else:
self.payment_mode_id = False
if self.type == "in_invoice":
self.partner_bank_id = False
return res
@api.onchange("payment_mode_id")
def _onchange_payment_mode_id(self):
pay_mode = self.payment_mode_id
if (
pay_mode
and pay_mode.payment_type == "outbound"
and not pay_mode.payment_method_id.bank_account_required
):
self.partner_bank_id = False
elif not self.payment_mode_id:
self.partner_bank_id = False
@api.model
def create(self, vals):
"""Fill the payment_mode_id from the partner if none is provided on
creation, using same method as upstream."""
onchanges = {"_onchange_partner_id": ["payment_mode_id"]}
for onchange_method, changed_fields in onchanges.items():
if any(f not in vals for f in changed_fields):
invoice = self.new(vals)
getattr(invoice, onchange_method)()
for field in changed_fields:
if field not in vals and invoice[field]:
vals[field] = invoice._fields[field].convert_to_write(
invoice[field], invoice
)
return super(AccountInvoice, self).create(vals)
@api.model
def line_get_convert(self, line, part):
"""Copy payment mode 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"])
res["payment_mode_id"] = invoice.payment_mode_id.id or False
return res
# I think copying payment mode from invoice to refund by default
# is a good idea because the most common way of "paying" a refund is to
# deduct it on the payment of the next invoice (and OCA/bank-payment
# allows to have negative payment lines since March 2016)
@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,
)
vals["payment_mode_id"] = invoice.payment_mode_id.id
if invoice.type == "in_invoice":
vals["partner_bank_id"] = invoice.partner_bank_id.id
return vals
@api.constrains("company_id", "payment_mode_id")
def _check_payment_mode_company_constrains(self):
for rec in self.sudo():
if rec.payment_mode_id and rec.company_id != rec.payment_mode_id.company_id:
raise ValidationError(
_(
"The company of the invoice %s does not match "
"with that of the payment mode"
)
% rec.name
)
@api.constrains("partner_id", "partner_bank_id")
def validate_partner_bank_id(self):
"""Inhibit the validation of the bank account by default, as core
rules are not the expected one for the bank-payment suite.
"""
if self.env.context.get("use_old_partner_bank_id_check"):
super().validate_partner_bank_id()
def partner_banks_to_show(self):
self.ensure_one()
if self.partner_bank_id:
return self.partner_bank_id
if self.payment_mode_id.show_bank_account_from_journal:
if self.payment_mode_id.bank_account_link == "fixed":
return self.payment_mode_id.fixed_journal_id.bank_account_id
else:
return self.payment_mode_id.variable_journal_ids.mapped(
"bank_account_id"
)
if (
self.payment_mode_id.payment_method_id.code == "sepa_direct_debit"
): # pragma: no cover
return (
self.mandate_id.partner_bank_id
or self.partner_id.valid_mandate_id.partner_bank_id
)
# Return this as empty recordset
return self.partner_bank_id

View File

@@ -0,0 +1,136 @@
# Copyright 2014-16 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
# Copyright 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class AccountMove(models.Model):
_inherit = "account.move"
payment_mode_filter_type_domain = fields.Char(
compute="_compute_payment_mode_filter_type_domain"
)
partner_bank_filter_type_domain = fields.Many2one(
comodel_name="res.partner", compute="_compute_partner_bank_filter_type_domain"
)
payment_mode_id = fields.Many2one(
comodel_name="account.payment.mode",
compute="_compute_payment_mode",
store=True,
ondelete="restrict",
states={"draft": [("readonly", False)]},
)
bank_account_required = fields.Boolean(
related="payment_mode_id.payment_method_id.bank_account_required", readonly=True
)
invoice_partner_bank_id = fields.Many2one(
compute="_compute_invoice_partner_bank",
store=True,
ondelete="restrict",
states={"draft": [("readonly", False)]},
)
@api.depends("type")
def _compute_payment_mode_filter_type_domain(self):
for move in self:
if move.type in ("out_invoice", "in_refund"):
move.payment_mode_filter_type_domain = "inbound"
elif move.type in ("in_invoice", "out_refund"):
move.payment_mode_filter_type_domain = "outbound"
else:
move.payment_mode_filter_type_domain = False
@api.depends("partner_id", "type")
def _compute_partner_bank_filter_type_domain(self):
for move in self:
if move.type in ("out_invoice", "in_refund"):
move.partner_bank_filter_type_domain = move.bank_partner_id
elif move.type in ("in_invoice", "out_refund"):
move.partner_bank_filter_type_domain = move.commercial_partner_id
else:
move.partner_bank_filter_type_domain = False
@api.depends("partner_id", "company_id")
def _compute_payment_mode(self):
for move in self:
if move.partner_id:
if move.type == "in_invoice":
move.payment_mode_id = move.with_context(
force_company=move.company_id.id
).partner_id.supplier_payment_mode_id
elif move.type == "out_invoice":
move.payment_mode_id = move.with_context(
force_company=move.company_id.id
).partner_id.customer_payment_mode_id
else:
move.payment_mode_id = False
@api.depends("partner_id", "payment_mode_id")
def _compute_invoice_partner_bank(self):
for move in self:
# No bank account assignation is done for out_invoice as this is only
# needed for printing purposes and it can conflict with
# SEPA direct debit payments. Current report prints it.
def get_bank_id():
return move.commercial_partner_id.bank_ids.filtered(
lambda b: b.company_id == move.company_id or not b.company_id
)[:1]
bank_id = False
if move.partner_id:
pay_mode = move.payment_mode_id
if move.type == "in_invoice":
if (
pay_mode
and pay_mode.payment_type == "outbound"
and pay_mode.payment_method_id.bank_account_required
and move.commercial_partner_id.bank_ids
):
bank_id = get_bank_id()
move.invoice_partner_bank_id = bank_id
# I think copying payment mode from invoice to refund by default
# is a good idea because the most common way of "paying" a refund is to
# deduct it on the payment of the next invoice (and OCA/bank-payment
# allows to have negative payment lines since March 2016)
def _reverse_move_vals(self, default_values, cancel=True):
move_vals = super()._reverse_move_vals(default_values, cancel=cancel)
move_vals["payment_mode_id"] = self.payment_mode_id.id
if self.type == "in_invoice":
move_vals["invoice_partner_bank_id"] = self.invoice_partner_bank_id.id
return move_vals
@api.constrains("company_id", "payment_mode_id")
def _check_payment_mode_company_constrains(self):
for rec in self.sudo():
if rec.payment_mode_id and rec.company_id != rec.payment_mode_id.company_id:
raise ValidationError(
_(
"The company of the invoice %s does not match "
"with that of the payment mode"
)
% rec.name
)
def partner_banks_to_show(self):
self.ensure_one()
if self.invoice_partner_bank_id:
return self.invoice_partner_bank_id
if self.payment_mode_id.show_bank_account_from_journal:
if self.payment_mode_id.bank_account_link == "fixed":
return self.payment_mode_id.fixed_journal_id.bank_account_id
else:
return self.payment_mode_id.variable_journal_ids.mapped(
"bank_account_id"
)
if (
self.payment_mode_id.payment_method_id.code == "sepa_direct_debit"
): # pragma: no cover
return (
self.mandate_id.partner_bank_id
or self.partner_id.valid_mandate_id.partner_bank_id
)
# Return this as empty recordset
return self.invoice_partner_bank_id

View File

@@ -1,16 +1,27 @@
# Copyright 2016 Akretion (http://www.akretion.com/) # Copyright 2016 Akretion (http://www.akretion.com/)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models from odoo import api, fields, models
class AccountMoveLine(models.Model): class AccountMoveLine(models.Model):
_inherit = "account.move.line" _inherit = "account.move.line"
payment_mode_id = fields.Many2one( payment_mode_id = fields.Many2one(
"account.payment.mode", comodel_name="account.payment.mode",
string="Payment Mode", compute="_compute_payment_mode",
domain="[('company_id', '=', company_id)]", store=True,
ondelete="restrict", ondelete="restrict",
index=True, index=True,
) )
@api.depends("move_id.payment_mode_id")
def _compute_payment_mode(self):
for line in self:
if line.move_id.is_invoice() and line.account_internal_type in (
"receivable",
"payable",
):
line.payment_mode_id = line.move_id.payment_mode_id
else:
line.payment_mode_id = False

View File

@@ -29,7 +29,7 @@ class AccountPaymentMode(models.Model):
def account_invoice_company_constrains(self): def account_invoice_company_constrains(self):
for mode in self: for mode in self:
if ( if (
self.env["account.invoice"] self.env["account.move"]
.sudo() .sudo()
.search( .search(
[ [
@@ -42,7 +42,7 @@ class AccountPaymentMode(models.Model):
raise ValidationError( raise ValidationError(
_( _(
"You cannot change the Company. There exists " "You cannot change the Company. There exists "
"at least one Invoice with this Payment Mode, " "at least one Journal Entry with this Payment Mode, "
"already assigned to another Company." "already assigned to another Company."
) )
) )

View File

@@ -8,17 +8,14 @@ from odoo import api, fields, models
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = "res.partner" _inherit = "res.partner"
# v8 fields : same without the _id suffix
supplier_payment_mode_id = fields.Many2one( supplier_payment_mode_id = fields.Many2one(
"account.payment.mode", "account.payment.mode",
string="Supplier Payment Mode",
company_dependent=True, company_dependent=True,
domain="[('payment_type', '=', 'outbound')]", domain="[('payment_type', '=', 'outbound')]",
help="Select the default payment mode for this supplier.", help="Select the default payment mode for this supplier.",
) )
customer_payment_mode_id = fields.Many2one( customer_payment_mode_id = fields.Many2one(
"account.payment.mode", "account.payment.mode",
string="Customer Payment Mode",
company_dependent=True, company_dependent=True,
domain="[('payment_type', '=', 'inbound')]", domain="[('payment_type', '=', 'inbound')]",
help="Select the default payment mode for this customer.", help="Select the default payment mode for this customer.",
@@ -26,6 +23,6 @@ class ResPartner(models.Model):
@api.model @api.model
def _commercial_fields(self): def _commercial_fields(self):
res = super(ResPartner, self)._commercial_fields() res = super()._commercial_fields()
res += ["supplier_payment_mode_id", "customer_payment_mode_id"] res += ["supplier_payment_mode_id", "customer_payment_mode_id"]
return res return res

View File

@@ -1 +0,0 @@
There is nothing to configure.

View File

@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<title>Account Payment Partner</title> <title>Account Payment Partner</title>
<style type="text/css"> <style type="text/css">
@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/bank-payment/tree/12.0/account_payment_partner"><img alt="OCA/bank-payment" src="https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/bank-payment-12-0/bank-payment-12-0-account_payment_partner"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/173/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/bank-payment/tree/13.0/account_payment_partner"><img alt="OCA/bank-payment" src="https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/bank-payment-13-0/bank-payment-13-0-account_payment_partner"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/173/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module adds severals fields:</p> <p>This module adds severals fields:</p>
<ul class="simple"> <ul class="simple">
<li>the <em>Supplier Payment Mode</em> and <em>Customer Payment Mode</em> on Partners,</li> <li>the <em>Supplier Payment Mode</em> and <em>Customer Payment Mode</em> on Partners,</li>
@@ -429,7 +429,7 @@ are displayed.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-payment/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-payment/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_partner%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/bank-payment/issues/new?body=module:%20account_payment_partner%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@@ -469,7 +469,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-payment/tree/12.0/account_payment_partner">OCA/bank-payment</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-payment/tree/13.0/account_payment_partner">OCA/bank-payment</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@@ -9,9 +9,10 @@ from odoo.tests import common
class TestAccountPaymentPartner(common.SavepointCase): class TestAccountPaymentPartner(common.SavepointCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestAccountPaymentPartner, cls).setUpClass() super().setUpClass()
cls.res_users_model = cls.env["res.users"] cls.res_users_model = cls.env["res.users"]
cls.move_model = cls.env["account.move"]
cls.journal_model = cls.env["account.journal"] cls.journal_model = cls.env["account.journal"]
cls.payment_mode_model = cls.env["account.payment.mode"] cls.payment_mode_model = cls.env["account.payment.mode"]
cls.partner_bank_model = cls.env["res.partner.bank"] cls.partner_bank_model = cls.env["res.partner.bank"]
@@ -46,6 +47,15 @@ class TestAccountPaymentPartner(common.SavepointCase):
} }
) )
cls.journal_purchase = cls.env["account.journal"].create(
{
"name": "Test Purchases Journal",
"code": "tPUR",
"type": "purchase",
"company_id": cls.company.id,
}
)
cls.journal_c1 = cls.journal_model.create( cls.journal_c1 = cls.journal_model.create(
{ {
"name": "J1", "name": "J1",
@@ -167,7 +177,7 @@ class TestAccountPaymentPartner(common.SavepointCase):
"bank_account_id": cls.journal_bank.id, "bank_account_id": cls.journal_bank.id,
} }
) )
cls.supplier_invoice = cls.env["account.invoice"].create( cls.supplier_invoice = cls.move_model.create(
{ {
"partner_id": cls.supplier.id, "partner_id": cls.supplier.id,
"type": "in_invoice", "type": "in_invoice",
@@ -176,28 +186,28 @@ class TestAccountPaymentPartner(common.SavepointCase):
) )
def _create_invoice(self): def _create_invoice(self):
invoice = self.move_model.create(
invoice = self.env["account.invoice"].create(
{ {
"partner_id": self.supplier.id, "partner_id": self.supplier.id,
"journal_id": self.journal_sale.id, "journal_id": self.journal_purchase.id,
"account_id": self.invoice_account.id,
"type": "in_invoice", "type": "in_invoice",
"company_id": self.company.id, "company_id": self.company.id,
"payment_mode_id": self.env.ref( "payment_mode_id": self.env.ref(
"account_payment_mode.payment_mode_outbound_ct1" "account_payment_mode.payment_mode_outbound_ct1"
).id, ).id,
} "invoice_line_ids": [
) (
0,
self.env["account.invoice.line"].create( None,
{ {
"product_id": self.env.ref("product.product_product_4").id, "product_id": self.env.ref("product.product_product_4").id,
"quantity": 1.0, "quantity": 1.0,
"price_unit": 100.0, "price_unit": 100.0,
"invoice_id": invoice.id, "name": "product that cost 100",
"name": "product that cost 100", "account_id": self.invoice_line_account.id,
"account_id": self.invoice_line_account.id, },
)
],
} }
) )
return invoice return invoice
@@ -229,73 +239,61 @@ class TestAccountPaymentPartner(common.SavepointCase):
def test_out_invoice_onchange(self): def test_out_invoice_onchange(self):
# Test the onchange methods in invoice # Test the onchange methods in invoice
invoice = self.env["account.invoice"].new( invoice = self.move_model.new(
{ {
"partner_id": self.customer.id, "partner_id": self.customer.id,
"type": "out_invoice", "type": "out_invoice",
"company_id": self.company.id, "company_id": self.company.id,
} }
) )
invoice._onchange_partner_id()
self.assertEquals(invoice.payment_mode_id, self.customer_payment_mode) self.assertEquals(invoice.payment_mode_id, self.customer_payment_mode)
invoice.company_id = self.company_2 invoice.company_id = self.company_2
invoice._onchange_partner_id()
self.assertEquals(invoice.payment_mode_id, self.payment_mode_model) self.assertEquals(invoice.payment_mode_id, self.payment_mode_model)
invoice.payment_mode_id = False invoice.payment_mode_id = False
invoice._onchange_payment_mode_id() self.assertFalse(invoice.invoice_partner_bank_id)
self.assertFalse(invoice.partner_bank_id)
def test_in_invoice_onchange(self): def test_in_invoice_onchange(self):
# Test the onchange methods in invoice # Test the onchange methods in invoice
self.manual_out.bank_account_required = True self.manual_out.bank_account_required = True
invoice = self.env["account.invoice"].new( invoice = self.move_model.new(
{ {
"partner_id": self.supplier.id, "partner_id": self.supplier.id,
"type": "in_invoice", "type": "in_invoice",
"company_id": self.company.id, "company_id": self.company.id,
} }
) )
invoice._onchange_partner_id()
self.assertEquals(invoice.payment_mode_id, self.supplier_payment_mode) self.assertEquals(invoice.payment_mode_id, self.supplier_payment_mode)
self.assertEquals(invoice.partner_bank_id, self.supplier_bank) self.assertEquals(invoice.invoice_partner_bank_id, self.supplier_bank)
invoice.company_id = self.company_2 invoice.company_id = self.company_2
invoice._onchange_partner_id()
self.assertEquals(invoice.payment_mode_id, self.supplier_payment_mode_c2) self.assertEquals(invoice.payment_mode_id, self.supplier_payment_mode_c2)
self.assertEquals(invoice.partner_bank_id, self.supplier_bank_2) self.assertEquals(invoice.invoice_partner_bank_id, self.supplier_bank_2)
invoice.payment_mode_id = self.supplier_payment_mode invoice.payment_mode_id = self.supplier_payment_mode
invoice._onchange_payment_mode_id() self.assertTrue(invoice.invoice_partner_bank_id)
self.assertTrue(invoice.partner_bank_id)
self.manual_out.bank_account_required = False self.manual_out.bank_account_required = False
invoice.payment_mode_id = self.supplier_payment_mode_c2 invoice.payment_mode_id = self.supplier_payment_mode_c2
invoice._onchange_payment_mode_id() self.assertFalse(invoice.invoice_partner_bank_id)
self.assertFalse(invoice.partner_bank_id)
invoice.partner_id = False invoice.partner_id = False
invoice._onchange_partner_id()
self.assertEquals(invoice.payment_mode_id, self.payment_mode_model) self.assertEquals(invoice.payment_mode_id, self.payment_mode_model)
self.assertEquals(invoice.partner_bank_id, self.partner_bank_model) self.assertEquals(invoice.invoice_partner_bank_id, self.partner_bank_model)
def test_invoice_create(self): def test_invoice_create(self):
invoice = self._create_invoice() invoice = self._create_invoice()
invoice.action_invoice_open() invoice.action_post()
aml = invoice.move_id.line_ids.filtered( aml = invoice.line_ids.filtered(
lambda l: l.account_id.user_type_id == self.acct_type_payable lambda l: l.account_id.user_type_id == self.acct_type_payable
) )
self.assertEquals(invoice.payment_mode_id, aml[0].payment_mode_id) self.assertEquals(invoice.payment_mode_id, aml[0].payment_mode_id)
def test_invoice_constrains(self): def test_invoice_constrains(self):
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
self.env["account.invoice"].create( self.move_model.create(
{ {
"partner_id": self.supplier.id, "partner_id": self.supplier.id,
"type": "in_invoice", "type": "in_invoice",
@@ -305,7 +303,7 @@ class TestAccountPaymentPartner(common.SavepointCase):
) )
def test_payment_mode_constrains_01(self): def test_payment_mode_constrains_01(self):
self.env["account.invoice"].create( self.move_model.create(
{ {
"partner_id": self.supplier.id, "partner_id": self.supplier.id,
"type": "in_invoice", "type": "in_invoice",
@@ -316,14 +314,14 @@ class TestAccountPaymentPartner(common.SavepointCase):
self.supplier_payment_mode.company_id = self.company_2 self.supplier_payment_mode.company_id = self.company_2
def test_payment_mode_constrains_02(self): def test_payment_mode_constrains_02(self):
self.env["account.move"].create( self.move_model.create(
{ {
"date": fields.Date.today(), "date": fields.Date.today(),
"journal_id": self.journal_sale.id, "journal_id": self.journal_sale.id,
"name": "/", "name": "/",
"ref": "reference", "ref": "reference",
"state": "draft", "state": "draft",
"line_ids": [ "invoice_line_ids": [
( (
0, 0,
0, 0,
@@ -354,28 +352,28 @@ class TestAccountPaymentPartner(common.SavepointCase):
def test_invoice_refund(self): def test_invoice_refund(self):
invoice = self._create_invoice() invoice = self._create_invoice()
invoice.partner_bank_id = False invoice.invoice_partner_bank_id = False
invoice.action_invoice_open() invoice.action_post()
# Lets create a refund invoice for invoice_1. # Lets create a refund invoice for invoice_1.
# I refund the invoice Using Refund Button. # I refund the invoice Using Refund Button.
context = { refund_invoice_wizard = (
"active_model": "account.invoice", self.env["account.move.reversal"]
"active_ids": [invoice.id], .with_context(
"active_id": invoice.id, {
} "active_ids": [invoice.id],
account_invoice_refund = ( "active_id": invoice.id,
self.env["account.invoice.refund"] "active_model": "account.move",
.with_context(context) }
.create(dict(description="Refund for Invoice", filter_refund="refund")) )
.create({"refund_method": "refund", "reason": "reason test create"})
)
refund_invoice = self.move_model.browse(
refund_invoice_wizard.reverse_moves()["res_id"]
) )
# I clicked on refund button.
account_invoice_refund.with_context(context).invoice_refund()
invoice_refund = invoice.refund_invoice_ids[0]
self.assertEquals(invoice_refund.payment_mode_id, invoice.payment_mode_id) self.assertEquals(refund_invoice.payment_mode_id, invoice.payment_mode_id)
self.assertEquals( self.assertEquals(
invoice_refund.partner_bank_id, refund_invoice.invoice_partner_bank_id, invoice.invoice_partner_bank_id
self.env.ref("account_payment_mode.main_company_iban"),
) )
def test_partner(self): def test_partner(self):
@@ -385,49 +383,94 @@ class TestAccountPaymentPartner(common.SavepointCase):
) )
def test_partner_onchange(self): def test_partner_onchange(self):
customer_invoice = self.env["account.invoice"].create( customer_invoice = self.move_model.create(
{"partner_id": self.customer.id, "type": "out_invoice"} {"partner_id": self.customer.id, "type": "out_invoice"}
) )
customer_invoice._onchange_partner_id()
self.assertEqual(customer_invoice.payment_mode_id, self.customer_payment_mode) self.assertEqual(customer_invoice.payment_mode_id, self.customer_payment_mode)
self.supplier_invoice._onchange_partner_id() self.assertEqual(
self.assertEqual(self.supplier_invoice.partner_bank_id, self.supplier_bank) self.supplier_invoice.invoice_partner_bank_id, self.supplier_bank
)
vals = {"partner_id": False, "type": "out_invoice"} vals = {"partner_id": False, "type": "out_invoice"}
invoice = self.env["account.invoice"].new(vals) invoice = self.move_model.new(vals)
invoice._onchange_partner_id()
self.assertFalse(invoice.payment_mode_id) self.assertFalse(invoice.payment_mode_id)
vals = {"partner_id": False, "type": "in_invoice"} vals = {"partner_id": False, "type": "in_invoice"}
invoice = self.env["account.invoice"].new(vals) invoice = self.move_model.new(vals)
invoice._onchange_partner_id() self.assertFalse(invoice.invoice_partner_bank_id)
self.assertFalse(invoice.partner_bank_id)
def test_onchange_payment_mode_id(self): def test_onchange_payment_mode_id(self):
mode = self.supplier_payment_mode mode = self.supplier_payment_mode
mode.payment_method_id.bank_account_required = True mode.payment_method_id.bank_account_required = True
self.supplier_invoice.partner_bank_id = self.supplier_bank.id self.supplier_invoice.invoice_partner_bank_id = self.supplier_bank.id
self.supplier_invoice.payment_mode_id = mode.id self.supplier_invoice.payment_mode_id = mode.id
self.supplier_invoice._onchange_payment_mode_id() self.assertEqual(
self.assertEqual(self.supplier_invoice.partner_bank_id, self.supplier_bank) self.supplier_invoice.invoice_partner_bank_id, self.supplier_bank
)
mode.payment_method_id.bank_account_required = False mode.payment_method_id.bank_account_required = False
self.supplier_invoice._onchange_payment_mode_id() self.assertEqual(
self.assertFalse(self.supplier_invoice.partner_bank_id) self.supplier_invoice.invoice_partner_bank_id, self.supplier_bank
)
self.supplier_invoice.payment_mode_id = False self.supplier_invoice.payment_mode_id = False
self.supplier_invoice._onchange_payment_mode_id() self.assertFalse(self.supplier_invoice.invoice_partner_bank_id)
self.assertFalse(self.supplier_invoice.partner_bank_id)
def test_print_report(self): def test_print_report(self):
self.supplier_invoice.partner_bank_id = self.supplier_bank.id self.supplier_invoice.invoice_partner_bank_id = self.supplier_bank.id
report = self.env.ref("account.account_invoices") report = self.env.ref("account.account_invoices")
res = str(report.render_qweb_html(self.supplier_invoice.ids)[0]) res = str(report.render_qweb_html(self.supplier_invoice.ids)[0])
self.assertIn(self.supplier_bank.acc_number, res) self.assertIn(self.supplier_bank.acc_number, res)
payment_mode = self.supplier_payment_mode payment_mode = self.supplier_payment_mode
payment_mode.show_bank_account_from_journal = True payment_mode.show_bank_account_from_journal = True
self.supplier_invoice.payment_mode_id = payment_mode.id self.supplier_invoice.payment_mode_id = payment_mode.id
self.supplier_invoice.partner_bank_id = False self.supplier_invoice.invoice_partner_bank_id = False
res = str(report.render_qweb_html(self.supplier_invoice.ids)[0]) res = str(report.render_qweb_html(self.supplier_invoice.ids)[0])
self.assertIn(self.journal_c1.bank_acc_number, res) self.assertIn(self.journal_c1.bank_acc_number, res)
payment_mode.bank_account_link = "variable" payment_mode.bank_account_link = "variable"
payment_mode.variable_journal_ids = [(6, 0, self.journal.ids)] payment_mode.variable_journal_ids = [(6, 0, self.journal.ids)]
res = str(report.render_qweb_html(self.supplier_invoice.ids)[0]) res = str(report.render_qweb_html(self.supplier_invoice.ids)[0])
self.assertIn(self.journal_bank.acc_number, res) self.assertIn(self.journal_bank.acc_number, res)
def test_filter_type_domain(self):
in_invoice = self.move_model.create(
{
"partner_id": self.supplier.id,
"type": "in_invoice",
"journal_id": self.journal_c1.id,
}
)
self.assertEqual(in_invoice.payment_mode_filter_type_domain, "outbound")
self.assertEqual(
in_invoice.partner_bank_filter_type_domain, in_invoice.commercial_partner_id
)
out_refund = self.move_model.create(
{
"partner_id": self.customer.id,
"type": "out_refund",
"journal_id": self.journal_c2.id,
}
)
self.assertEqual(out_refund.payment_mode_filter_type_domain, "outbound")
self.assertEqual(
out_refund.partner_bank_filter_type_domain, out_refund.commercial_partner_id
)
in_refund = self.move_model.create(
{
"partner_id": self.supplier.id,
"type": "in_refund",
"journal_id": self.journal_c1.id,
}
)
self.assertEqual(in_refund.payment_mode_filter_type_domain, "inbound")
self.assertEqual(
in_refund.partner_bank_filter_type_domain, in_refund.bank_partner_id
)
out_invoice = self.move_model.create(
{
"partner_id": self.customer.id,
"type": "out_invoice",
"journal_id": self.journal_c2.id,
}
)
self.assertEqual(out_invoice.payment_mode_filter_type_domain, "inbound")
self.assertEqual(
out_invoice.partner_bank_filter_type_domain, out_invoice.bank_partner_id
)

View File

@@ -1,85 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-16 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_account_invoice_filter" model="ir.ui.view">
<field name="name">account_payment_partner.account_invoice_search</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.view_account_invoice_filter"/>
<field name="arch" type="xml">
<filter name="status" position="after">
<filter string="Payment Mode" name="payment_mode_groupby"
context="{'group_by': 'payment_mode_id'}"/>
</filter>
</field>
</record>
<record id="invoice_form" model="ir.ui.view">
<field name="name">account_payment_partner.invoice_form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form" />
<field name="arch" type="xml">
<field name="payment_term_id" position="after">
<field name="payment_mode_id"
domain="[('payment_type', '=', 'inbound'), ('company_id', '=', company_id)]"
widget="selection"/>
<field name="commercial_partner_id" invisible="1"/>
</field>
<field name="partner_bank_id" position="attributes">
<attribute name="invisible">0</attribute>
</field>
</field>
</record>
<record id="invoice_supplier_form" model="ir.ui.view">
<field name="name">account_payment_partner.invoice_supplier_form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form" />
<field name="arch" type="xml">
<field name="payment_term_id" position="after">
<field name="payment_mode_id"
domain="[('payment_type', '=', 'outbound'), ('company_id', '=', company_id)]"
widget="selection"/>
<field name="commercial_partner_id" invisible="1"/>
<field name="bank_account_required" invisible="1"/>
</field>
<field name="partner_bank_id" position="attributes">
<attribute name="domain">[('partner_id', '=', commercial_partner_id),
'|',('company_id', '=', company_id),('company_id', '=', False)]</attribute>
<attribute name="invisible">0</attribute>
<attribute name="attrs">{'invisible': [('bank_account_required', '=', False)], 'required': [('bank_account_required', '=', True)]}</attribute>
<attribute name="context">{'default_partner_id':commercial_partner_id}</attribute>
</field>
</field>
</record>
<record id="invoice_tree" model="ir.ui.view">
<field name="name">account_payment_partner.customer_invoice_tree</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_tree"/>
<field name="arch" type="xml">
<field name="residual_signed" position="after">
<field name="payment_mode_id"/>
</field>
</field>
</record>
<record id="invoice_supplier_tree" model="ir.ui.view">
<field name="name">account_payment_partner.supplier_invoice_tree</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_tree"/>
<field name="arch" type="xml">
<field name="residual_signed" position="after">
<field name="payment_mode_id"/>
</field>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-16 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_account_invoice_filter" model="ir.ui.view">
<field name="name">account_payment_partner.account_invoice_search</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_account_invoice_filter"/>
<field name="arch" type="xml">
<filter name="status" position="after">
<filter string="Payment Mode" name="payment_mode_groupby"
context="{'group_by': 'payment_mode_id'}"/>
</filter>
</field>
</record>
<record id="view_move_form" model="ir.ui.view">
<field name="name">account_payment_partner.view_move_form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//div[field[@name='invoice_payment_term_id']]" position="after">
<field name="payment_mode_id"
domain="[('payment_type', '=', payment_mode_filter_type_domain), ('company_id', '=', company_id)]"
widget="selection"
invisible="context.get('default_type') not in ('out_invoice','out_refund','in_invoice','in_refund')"/>
<field name="commercial_partner_id" invisible="1"/>
<field name="bank_account_required" invisible="1"/>
<field name="payment_mode_filter_type_domain" invisible="1"/>
<field name="partner_bank_filter_type_domain" invisible="1"/>
</xpath>
<field name="invoice_partner_bank_id" position="attributes">
<attribute name="domain">[('partner_id', '=', partner_bank_filter_type_domain),
'|',('company_id', '=', company_id),('company_id', '=', False)]</attribute>
<attribute name="attrs">{'required': [('bank_account_required', '=', True)]}</attribute>
<attribute name="context">{'default_partner_id':commercial_partner_id}</attribute>
</field>
</field>
</record>
<record id="view_invoice_tree" model="ir.ui.view">
<field name="name">account_payment_partner.view_invoice_tree</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_invoice_tree"/>
<field name="arch" type="xml">
<field name="amount_residual_signed" position="after">
<field name="payment_mode_id"/>
</field>
</field>
</record>
</odoo>

View File

@@ -2,7 +2,7 @@
<odoo> <odoo>
<template id="report_invoice_payment_mode" inherit_id="account.report_invoice_document"> <template id="report_invoice_payment_mode" inherit_id="account.report_invoice_document">
<xpath expr="//p[@t-if='o.payment_term_id']" position="after"> <xpath expr="//p[@t-if='o.invoice_payment_term_id']" position="after">
<p t-if="o.payment_mode_id.note"> <p t-if="o.payment_mode_id.note">
<strong>Payment Mode:</strong> <strong>Payment Mode:</strong>
<span t-field="o.payment_mode_id.note" /> <span t-field="o.payment_mode_id.note" />