mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[IMP] account_payment_partner: black, isort
This commit is contained in:
@@ -4,23 +4,21 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
'name': 'Account Payment Partner',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Banking addons',
|
||||
'license': 'AGPL-3',
|
||||
'summary': 'Adds payment mode on partners and invoices',
|
||||
'author': "Akretion, "
|
||||
"Tecnativa, "
|
||||
"Odoo Community Association (OCA)",
|
||||
'website': 'https://github.com/OCA/bank-payment',
|
||||
'depends': ['account_payment_mode'],
|
||||
'data': [
|
||||
'views/res_partner_view.xml',
|
||||
'views/account_invoice_view.xml',
|
||||
'views/account_move_line.xml',
|
||||
'views/account_payment_mode.xml',
|
||||
'views/report_invoice.xml',
|
||||
"name": "Account Payment Partner",
|
||||
"version": "12.0.1.0.0",
|
||||
"category": "Banking addons",
|
||||
"license": "AGPL-3",
|
||||
"summary": "Adds payment mode on partners and invoices",
|
||||
"author": "Akretion, " "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/bank-payment",
|
||||
"depends": ["account_payment_mode"],
|
||||
"data": [
|
||||
"views/res_partner_view.xml",
|
||||
"views/account_invoice_view.xml",
|
||||
"views/account_move_line.xml",
|
||||
"views/account_payment_mode.xml",
|
||||
"views/report_invoice.xml",
|
||||
],
|
||||
'demo': ['demo/partner_demo.xml'],
|
||||
'installable': True,
|
||||
"demo": ["demo/partner_demo.xml"],
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
from . import res_partner
|
||||
from . import account_invoice
|
||||
from . import account_move_line
|
||||
|
||||
@@ -2,64 +2,66 @@
|
||||
# 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 import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = 'account.invoice'
|
||||
_inherit = "account.invoice"
|
||||
|
||||
payment_mode_id = fields.Many2one(
|
||||
comodel_name='account.payment.mode', string="Payment Mode",
|
||||
ondelete='restrict',
|
||||
readonly=True, states={'draft': [('readonly', False)]})
|
||||
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')
|
||||
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')
|
||||
@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':
|
||||
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
|
||||
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]
|
||||
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':
|
||||
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,
|
||||
force_company=self.company_id.id
|
||||
).partner_id.customer_payment_mode_id
|
||||
else:
|
||||
self.payment_mode_id = False
|
||||
if self.type == 'in_invoice':
|
||||
if self.type == "in_invoice":
|
||||
self.partner_bank_id = False
|
||||
return res
|
||||
|
||||
@api.onchange('payment_mode_id')
|
||||
@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
|
||||
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:
|
||||
@@ -69,9 +71,7 @@ class AccountInvoice(models.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'],
|
||||
}
|
||||
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)
|
||||
@@ -79,7 +79,7 @@ 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)
|
||||
|
||||
@@ -87,9 +87,9 @@ class AccountInvoice(models.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
|
||||
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
|
||||
@@ -98,31 +98,38 @@ class AccountInvoice(models.Model):
|
||||
# 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):
|
||||
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
|
||||
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')
|
||||
@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):
|
||||
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)
|
||||
_(
|
||||
"The company of the invoice %s does not match "
|
||||
"with that of the payment mode"
|
||||
)
|
||||
% rec.name
|
||||
)
|
||||
|
||||
@api.constrains('partner_id', 'partner_bank_id')
|
||||
@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'):
|
||||
if self.env.context.get("use_old_partner_bank_id_check"):
|
||||
super().validate_partner_bank_id()
|
||||
|
||||
def partner_banks_to_show(self):
|
||||
@@ -130,14 +137,18 @@ class AccountInvoice(models.Model):
|
||||
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':
|
||||
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)
|
||||
"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
|
||||
|
||||
@@ -5,12 +5,12 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
_inherit = "account.move.line"
|
||||
|
||||
payment_mode_id = fields.Many2one(
|
||||
'account.payment.mode',
|
||||
string='Payment Mode',
|
||||
"account.payment.mode",
|
||||
string="Payment Mode",
|
||||
domain="[('company_id', '=', company_id)]",
|
||||
ondelete='restrict',
|
||||
ondelete="restrict",
|
||||
index=True,
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Copyright 2018 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
@@ -11,39 +11,60 @@ class AccountPaymentMode(models.Model):
|
||||
|
||||
show_bank_account = fields.Selection(
|
||||
selection=[
|
||||
('full', 'Full'),
|
||||
('first', 'First n chars'),
|
||||
('last', 'Last n chars'),
|
||||
('no', 'No'),
|
||||
("full", "Full"),
|
||||
("first", "First n chars"),
|
||||
("last", "Last n chars"),
|
||||
("no", "No"),
|
||||
],
|
||||
string='Show bank account',
|
||||
default='full',
|
||||
help="Show in invoices partial or full bank account number")
|
||||
show_bank_account_from_journal = fields.Boolean(
|
||||
string='Bank account from journals'
|
||||
string="Show bank account",
|
||||
default="full",
|
||||
help="Show in invoices partial or full bank account number",
|
||||
)
|
||||
show_bank_account_from_journal = fields.Boolean(string="Bank account from journals")
|
||||
show_bank_account_chars = fields.Integer(
|
||||
string="# of digits for customer bank account",
|
||||
string="# of digits for customer bank account"
|
||||
)
|
||||
|
||||
@api.constrains('company_id')
|
||||
@api.constrains("company_id")
|
||||
def account_invoice_company_constrains(self):
|
||||
for mode in self:
|
||||
if self.env['account.invoice'].sudo().search(
|
||||
[('payment_mode_id', '=', mode.id),
|
||||
('company_id', '!=', mode.company_id.id)], limit=1):
|
||||
raise ValidationError(_(
|
||||
"You cannot change the Company. There exists "
|
||||
"at least one Invoice with this Payment Mode, "
|
||||
"already assigned to another Company."))
|
||||
if (
|
||||
self.env["account.invoice"]
|
||||
.sudo()
|
||||
.search(
|
||||
[
|
||||
("payment_mode_id", "=", mode.id),
|
||||
("company_id", "!=", mode.company_id.id),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"You cannot change the Company. There exists "
|
||||
"at least one Invoice with this Payment Mode, "
|
||||
"already assigned to another Company."
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains('company_id')
|
||||
@api.constrains("company_id")
|
||||
def account_move_line_company_constrains(self):
|
||||
for mode in self:
|
||||
if self.env['account.move.line'].sudo().search(
|
||||
[('payment_mode_id', '=', mode.id),
|
||||
('company_id', '!=', mode.company_id.id)], limit=1):
|
||||
raise ValidationError(_(
|
||||
"You cannot change the Company. There exists "
|
||||
"at least one Journal Item with this Payment Mode, "
|
||||
"already assigned to another Company."))
|
||||
if (
|
||||
self.env["account.move.line"]
|
||||
.sudo()
|
||||
.search(
|
||||
[
|
||||
("payment_mode_id", "=", mode.id),
|
||||
("company_id", "!=", mode.company_id.id),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"You cannot change the Company. There exists "
|
||||
"at least one Journal Item with this Payment Mode, "
|
||||
"already assigned to another Company."
|
||||
)
|
||||
)
|
||||
|
||||
@@ -6,22 +6,26 @@ from odoo import api, fields, models
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
_inherit = "res.partner"
|
||||
|
||||
# v8 fields : same without the _id suffix
|
||||
supplier_payment_mode_id = fields.Many2one(
|
||||
'account.payment.mode', string='Supplier Payment Mode',
|
||||
"account.payment.mode",
|
||||
string="Supplier Payment Mode",
|
||||
company_dependent=True,
|
||||
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(
|
||||
'account.payment.mode', string='Customer Payment Mode',
|
||||
"account.payment.mode",
|
||||
string="Customer Payment Mode",
|
||||
company_dependent=True,
|
||||
domain="[('payment_type', '=', 'inbound')]",
|
||||
help="Select the default payment mode for this customer.")
|
||||
help="Select the default payment mode for this customer.",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _commercial_fields(self):
|
||||
res = super(ResPartner, self)._commercial_fields()
|
||||
res += ['supplier_payment_mode_id', 'customer_payment_mode_id']
|
||||
res += ["supplier_payment_mode_id", "customer_payment_mode_id"]
|
||||
return res
|
||||
|
||||
@@ -1 +1 @@
|
||||
There is nothing to configure.
|
||||
There is nothing to configure.
|
||||
|
||||
@@ -1,193 +1,241 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import fields, _
|
||||
from odoo.tests import common
|
||||
from odoo import _, fields
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestAccountPaymentPartner(common.SavepointCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAccountPaymentPartner, cls).setUpClass()
|
||||
|
||||
cls.res_users_model = cls.env['res.users']
|
||||
cls.journal_model = cls.env['account.journal']
|
||||
cls.payment_mode_model = cls.env['account.payment.mode']
|
||||
cls.partner_bank_model = cls.env['res.partner.bank']
|
||||
cls.res_users_model = cls.env["res.users"]
|
||||
cls.journal_model = cls.env["account.journal"]
|
||||
cls.payment_mode_model = cls.env["account.payment.mode"]
|
||||
cls.partner_bank_model = cls.env["res.partner.bank"]
|
||||
|
||||
# Refs
|
||||
cls.company = cls.env.ref('base.main_company')
|
||||
cls.acct_type_payable = cls.env.ref(
|
||||
'account.data_account_type_payable')
|
||||
cls.acct_type_expenses = cls.env.ref(
|
||||
'account.data_account_type_expenses')
|
||||
cls.company = cls.env.ref("base.main_company")
|
||||
cls.acct_type_payable = cls.env.ref("account.data_account_type_payable")
|
||||
cls.acct_type_expenses = cls.env.ref("account.data_account_type_expenses")
|
||||
|
||||
cls.company_2 = cls.env['res.company'].create(
|
||||
{'name': 'Company 2'},
|
||||
)
|
||||
charts = cls.env['account.chart.template'].search([])
|
||||
cls.company_2 = cls.env["res.company"].create({"name": "Company 2"})
|
||||
charts = cls.env["account.chart.template"].search([])
|
||||
if charts:
|
||||
cls.chart = charts[0]
|
||||
else:
|
||||
raise ValidationError(
|
||||
_("No Chart of Account Template has been defined !"))
|
||||
raise ValidationError(_("No Chart of Account Template has been defined !"))
|
||||
old_company = cls.env.user.company_id
|
||||
cls.env.user.company_id = cls.company_2.id
|
||||
cls.chart.try_loading_for_current_company()
|
||||
cls.env.user.company_id = old_company.id
|
||||
|
||||
# refs
|
||||
cls.manual_out = cls.env.ref(
|
||||
'account.account_payment_method_manual_out')
|
||||
cls.manual_out = cls.env.ref("account.account_payment_method_manual_out")
|
||||
cls.manual_out.bank_account_required = True
|
||||
cls.manual_in = cls.env.ref(
|
||||
'account.account_payment_method_manual_in')
|
||||
cls.manual_in = cls.env.ref("account.account_payment_method_manual_in")
|
||||
|
||||
cls.journal_sale = cls.env['account.journal'].create({
|
||||
'name': 'Test Sales Journal',
|
||||
'code': 'tSAL',
|
||||
'type': 'sale',
|
||||
'company_id': cls.company.id,
|
||||
})
|
||||
cls.journal_sale = cls.env["account.journal"].create(
|
||||
{
|
||||
"name": "Test Sales Journal",
|
||||
"code": "tSAL",
|
||||
"type": "sale",
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
|
||||
cls.journal_c1 = cls.journal_model.create({
|
||||
'name': 'J1',
|
||||
'code': 'J1',
|
||||
'type': 'bank',
|
||||
'company_id': cls.company.id,
|
||||
'bank_acc_number': '123456',
|
||||
})
|
||||
cls.journal_c1 = cls.journal_model.create(
|
||||
{
|
||||
"name": "J1",
|
||||
"code": "J1",
|
||||
"type": "bank",
|
||||
"company_id": cls.company.id,
|
||||
"bank_acc_number": "123456",
|
||||
}
|
||||
)
|
||||
|
||||
cls.journal_c2 = cls.journal_model.create({
|
||||
'name': 'J2',
|
||||
'code': 'J2',
|
||||
'type': 'bank',
|
||||
'company_id': cls.company_2.id,
|
||||
'bank_acc_number': '552344',
|
||||
})
|
||||
cls.journal_c2 = cls.journal_model.create(
|
||||
{
|
||||
"name": "J2",
|
||||
"code": "J2",
|
||||
"type": "bank",
|
||||
"company_id": cls.company_2.id,
|
||||
"bank_acc_number": "552344",
|
||||
}
|
||||
)
|
||||
|
||||
cls.supplier_payment_mode = cls.payment_mode_model.create({
|
||||
'name': 'Suppliers Bank 1',
|
||||
'bank_account_link': 'variable',
|
||||
'payment_method_id': cls.manual_out.id,
|
||||
'show_bank_account_from_journal': True,
|
||||
'company_id': cls.company.id,
|
||||
'fixed_journal_id': cls.journal_c1.id,
|
||||
'variable_journal_ids': [(6, 0, [cls.journal_c1.id])]
|
||||
})
|
||||
cls.supplier_payment_mode = cls.payment_mode_model.create(
|
||||
{
|
||||
"name": "Suppliers Bank 1",
|
||||
"bank_account_link": "variable",
|
||||
"payment_method_id": cls.manual_out.id,
|
||||
"show_bank_account_from_journal": True,
|
||||
"company_id": cls.company.id,
|
||||
"fixed_journal_id": cls.journal_c1.id,
|
||||
"variable_journal_ids": [(6, 0, [cls.journal_c1.id])],
|
||||
}
|
||||
)
|
||||
|
||||
cls.supplier_payment_mode_c2 = cls.payment_mode_model.create({
|
||||
'name': 'Suppliers Bank 2',
|
||||
'bank_account_link': 'variable',
|
||||
'payment_method_id': cls.manual_out.id,
|
||||
'company_id': cls.company_2.id,
|
||||
'fixed_journal_id': cls.journal_c2.id,
|
||||
'variable_journal_ids': [(6, 0, [cls.journal_c2.id])]
|
||||
})
|
||||
cls.supplier_payment_mode_c2 = cls.payment_mode_model.create(
|
||||
{
|
||||
"name": "Suppliers Bank 2",
|
||||
"bank_account_link": "variable",
|
||||
"payment_method_id": cls.manual_out.id,
|
||||
"company_id": cls.company_2.id,
|
||||
"fixed_journal_id": cls.journal_c2.id,
|
||||
"variable_journal_ids": [(6, 0, [cls.journal_c2.id])],
|
||||
}
|
||||
)
|
||||
|
||||
cls.customer_payment_mode = cls.payment_mode_model.create({
|
||||
'name': 'Customers to Bank 1',
|
||||
'bank_account_link': 'fixed',
|
||||
'payment_method_id': cls.manual_in.id,
|
||||
'company_id': cls.company.id,
|
||||
'fixed_journal_id': cls.journal_c1.id,
|
||||
'variable_journal_ids': [(6, 0, [cls.journal_c1.id])]
|
||||
})
|
||||
cls.customer_payment_mode = cls.payment_mode_model.create(
|
||||
{
|
||||
"name": "Customers to Bank 1",
|
||||
"bank_account_link": "fixed",
|
||||
"payment_method_id": cls.manual_in.id,
|
||||
"company_id": cls.company.id,
|
||||
"fixed_journal_id": cls.journal_c1.id,
|
||||
"variable_journal_ids": [(6, 0, [cls.journal_c1.id])],
|
||||
}
|
||||
)
|
||||
|
||||
cls.customer = cls.env['res.partner'].with_context(
|
||||
force_company=cls.company.id).create({
|
||||
'name': 'Test customer',
|
||||
'customer_payment_mode_id': cls.customer_payment_mode,
|
||||
})
|
||||
cls.customer = (
|
||||
cls.env["res.partner"]
|
||||
.with_context(force_company=cls.company.id)
|
||||
.create(
|
||||
{
|
||||
"name": "Test customer",
|
||||
"customer_payment_mode_id": cls.customer_payment_mode,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
cls.supplier = cls.env['res.partner'].with_context(
|
||||
force_company=cls.company.id).create({
|
||||
'name': 'Test supplier',
|
||||
'supplier_payment_mode_id': cls.supplier_payment_mode,
|
||||
})
|
||||
cls.supplier_bank = cls.env['res.partner.bank'].create({
|
||||
'acc_number': '5345345',
|
||||
'partner_id': cls.supplier.id,
|
||||
'company_id': cls.company.id,
|
||||
})
|
||||
cls.supplier_bank_2 = cls.env['res.partner.bank'].create({
|
||||
'acc_number': '3452342',
|
||||
'partner_id': cls.supplier.id,
|
||||
'company_id': cls.company_2.id,
|
||||
})
|
||||
cls.supplier = (
|
||||
cls.env["res.partner"]
|
||||
.with_context(force_company=cls.company.id)
|
||||
.create(
|
||||
{
|
||||
"name": "Test supplier",
|
||||
"supplier_payment_mode_id": cls.supplier_payment_mode,
|
||||
}
|
||||
)
|
||||
)
|
||||
cls.supplier_bank = cls.env["res.partner.bank"].create(
|
||||
{
|
||||
"acc_number": "5345345",
|
||||
"partner_id": cls.supplier.id,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.supplier_bank_2 = cls.env["res.partner.bank"].create(
|
||||
{
|
||||
"acc_number": "3452342",
|
||||
"partner_id": cls.supplier.id,
|
||||
"company_id": cls.company_2.id,
|
||||
}
|
||||
)
|
||||
cls.supplier.with_context(
|
||||
force_company=cls.company_2.id).supplier_payment_mode_id = \
|
||||
cls.supplier_payment_mode_c2
|
||||
force_company=cls.company_2.id
|
||||
).supplier_payment_mode_id = cls.supplier_payment_mode_c2
|
||||
|
||||
cls.invoice_account = cls.env['account.account'].search(
|
||||
[('user_type_id', '=', cls.acct_type_payable.id),
|
||||
('company_id', '=', cls.company.id)],
|
||||
limit=1)
|
||||
cls.invoice_line_account = cls.env['account.account'].search(
|
||||
[('user_type_id', '=', cls.acct_type_expenses.id),
|
||||
('company_id', '=', cls.company.id)],
|
||||
limit=1)
|
||||
cls.journal_bank = cls.env['res.partner.bank'].create({
|
||||
'acc_number': 'GB95LOYD87430237296288',
|
||||
'partner_id': cls.env.user.company_id.id,
|
||||
})
|
||||
cls.journal = cls.env['account.journal'].create({
|
||||
'name': 'BANK TEST',
|
||||
'code': 'TEST',
|
||||
'type': 'bank',
|
||||
'bank_account_id': cls.journal_bank.id,
|
||||
})
|
||||
cls.supplier_invoice = cls.env['account.invoice'].create({
|
||||
'partner_id': cls.supplier.id,
|
||||
'type': 'in_invoice',
|
||||
'journal_id': cls.journal_c1.id,
|
||||
})
|
||||
cls.invoice_account = cls.env["account.account"].search(
|
||||
[
|
||||
("user_type_id", "=", cls.acct_type_payable.id),
|
||||
("company_id", "=", cls.company.id),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
cls.invoice_line_account = cls.env["account.account"].search(
|
||||
[
|
||||
("user_type_id", "=", cls.acct_type_expenses.id),
|
||||
("company_id", "=", cls.company.id),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
cls.journal_bank = cls.env["res.partner.bank"].create(
|
||||
{
|
||||
"acc_number": "GB95LOYD87430237296288",
|
||||
"partner_id": cls.env.user.company_id.id,
|
||||
}
|
||||
)
|
||||
cls.journal = cls.env["account.journal"].create(
|
||||
{
|
||||
"name": "BANK TEST",
|
||||
"code": "TEST",
|
||||
"type": "bank",
|
||||
"bank_account_id": cls.journal_bank.id,
|
||||
}
|
||||
)
|
||||
cls.supplier_invoice = cls.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": cls.supplier.id,
|
||||
"type": "in_invoice",
|
||||
"journal_id": cls.journal_c1.id,
|
||||
}
|
||||
)
|
||||
|
||||
def _create_invoice(self):
|
||||
|
||||
invoice = self.env['account.invoice'].create({
|
||||
'partner_id': self.supplier.id,
|
||||
'journal_id': self.journal_sale.id,
|
||||
'account_id': self.invoice_account.id,
|
||||
'type': 'in_invoice',
|
||||
'company_id': self.company.id,
|
||||
'payment_mode_id': self.env.ref(
|
||||
'account_payment_mode.payment_mode_outbound_ct1').id
|
||||
})
|
||||
invoice = self.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": self.supplier.id,
|
||||
"journal_id": self.journal_sale.id,
|
||||
"account_id": self.invoice_account.id,
|
||||
"type": "in_invoice",
|
||||
"company_id": self.company.id,
|
||||
"payment_mode_id": self.env.ref(
|
||||
"account_payment_mode.payment_mode_outbound_ct1"
|
||||
).id,
|
||||
}
|
||||
)
|
||||
|
||||
self.env['account.invoice.line'].create({
|
||||
'product_id': self.env.ref('product.product_product_4').id,
|
||||
'quantity': 1.0,
|
||||
'price_unit': 100.0,
|
||||
'invoice_id': invoice.id,
|
||||
'name': 'product that cost 100',
|
||||
'account_id': self.invoice_line_account.id,
|
||||
})
|
||||
self.env["account.invoice.line"].create(
|
||||
{
|
||||
"product_id": self.env.ref("product.product_product_4").id,
|
||||
"quantity": 1.0,
|
||||
"price_unit": 100.0,
|
||||
"invoice_id": invoice.id,
|
||||
"name": "product that cost 100",
|
||||
"account_id": self.invoice_line_account.id,
|
||||
}
|
||||
)
|
||||
return invoice
|
||||
|
||||
def test_create_partner(self):
|
||||
customer = self.env['res.partner'].with_context(
|
||||
force_company=self.company.id).create({
|
||||
'name': 'Test customer',
|
||||
'customer_payment_mode_id': self.customer_payment_mode,
|
||||
})
|
||||
customer = (
|
||||
self.env["res.partner"]
|
||||
.with_context(force_company=self.company.id)
|
||||
.create(
|
||||
{
|
||||
"name": "Test customer",
|
||||
"customer_payment_mode_id": self.customer_payment_mode,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
self.assertEquals(customer.with_context(
|
||||
force_company=self.company.id).customer_payment_mode_id,
|
||||
self.customer_payment_mode)
|
||||
self.assertEquals(customer.with_context(
|
||||
force_company=self.company_2.id).customer_payment_mode_id,
|
||||
self.payment_mode_model)
|
||||
self.assertEquals(
|
||||
customer.with_context(
|
||||
force_company=self.company.id
|
||||
).customer_payment_mode_id,
|
||||
self.customer_payment_mode,
|
||||
)
|
||||
self.assertEquals(
|
||||
customer.with_context(
|
||||
force_company=self.company_2.id
|
||||
).customer_payment_mode_id,
|
||||
self.payment_mode_model,
|
||||
)
|
||||
|
||||
def test_out_invoice_onchange(self):
|
||||
# Test the onchange methods in invoice
|
||||
invoice = self.env['account.invoice'].new({
|
||||
'partner_id': self.customer.id,
|
||||
'type': 'out_invoice',
|
||||
'company_id': self.company.id,
|
||||
})
|
||||
invoice = self.env["account.invoice"].new(
|
||||
{
|
||||
"partner_id": self.customer.id,
|
||||
"type": "out_invoice",
|
||||
"company_id": self.company.id,
|
||||
}
|
||||
)
|
||||
|
||||
invoice._onchange_partner_id()
|
||||
|
||||
@@ -204,11 +252,13 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
def test_in_invoice_onchange(self):
|
||||
# Test the onchange methods in invoice
|
||||
self.manual_out.bank_account_required = True
|
||||
invoice = self.env['account.invoice'].new({
|
||||
'partner_id': self.supplier.id,
|
||||
'type': 'in_invoice',
|
||||
'company_id': self.company.id,
|
||||
})
|
||||
invoice = self.env["account.invoice"].new(
|
||||
{
|
||||
"partner_id": self.supplier.id,
|
||||
"type": "in_invoice",
|
||||
"company_id": self.company.id,
|
||||
}
|
||||
)
|
||||
|
||||
invoice._onchange_partner_id()
|
||||
|
||||
@@ -217,8 +267,7 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
|
||||
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)
|
||||
|
||||
invoice.payment_mode_id = self.supplier_payment_mode
|
||||
@@ -233,57 +282,73 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
|
||||
invoice.partner_id = False
|
||||
invoice._onchange_partner_id()
|
||||
self.assertEquals(invoice.payment_mode_id,
|
||||
self.payment_mode_model)
|
||||
self.assertEquals(invoice.partner_bank_id,
|
||||
self.partner_bank_model)
|
||||
self.assertEquals(invoice.payment_mode_id, self.payment_mode_model)
|
||||
self.assertEquals(invoice.partner_bank_id, self.partner_bank_model)
|
||||
|
||||
def test_invoice_create(self):
|
||||
invoice = self._create_invoice()
|
||||
invoice.action_invoice_open()
|
||||
aml = invoice.move_id.line_ids.filtered(
|
||||
lambda l: l.account_id.user_type_id == self.acct_type_payable)
|
||||
self.assertEquals(invoice.payment_mode_id,
|
||||
aml[0].payment_mode_id)
|
||||
lambda l: l.account_id.user_type_id == self.acct_type_payable
|
||||
)
|
||||
self.assertEquals(invoice.payment_mode_id, aml[0].payment_mode_id)
|
||||
|
||||
def test_invoice_constrains(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env['account.invoice'].create({
|
||||
'partner_id': self.supplier.id,
|
||||
'type': 'in_invoice',
|
||||
'company_id': self.company.id,
|
||||
'payment_mode_id': self.supplier_payment_mode_c2.id
|
||||
})
|
||||
self.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": self.supplier.id,
|
||||
"type": "in_invoice",
|
||||
"company_id": self.company.id,
|
||||
"payment_mode_id": self.supplier_payment_mode_c2.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_payment_mode_constrains_01(self):
|
||||
self.env['account.invoice'].create({
|
||||
'partner_id': self.supplier.id,
|
||||
'type': 'in_invoice',
|
||||
'company_id': self.company.id,
|
||||
})
|
||||
self.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": self.supplier.id,
|
||||
"type": "in_invoice",
|
||||
"company_id": self.company.id,
|
||||
}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.supplier_payment_mode.company_id = self.company_2
|
||||
|
||||
def test_payment_mode_constrains_02(self):
|
||||
self.env['account.move'].create({
|
||||
'date': fields.Date.today(),
|
||||
'journal_id': self.journal_sale.id,
|
||||
'name': '/',
|
||||
'ref': 'reference',
|
||||
'state': 'draft',
|
||||
'line_ids': [(0, 0, {
|
||||
'account_id': self.invoice_account.id,
|
||||
'credit': 1000,
|
||||
'debit': 0,
|
||||
'name': 'Test',
|
||||
'ref': 'reference',
|
||||
}), (0, 0, {
|
||||
'account_id': self.invoice_line_account.id,
|
||||
'credit': 0,
|
||||
'debit': 1000,
|
||||
'name': 'Test',
|
||||
'ref': 'reference',
|
||||
})]})
|
||||
self.env["account.move"].create(
|
||||
{
|
||||
"date": fields.Date.today(),
|
||||
"journal_id": self.journal_sale.id,
|
||||
"name": "/",
|
||||
"ref": "reference",
|
||||
"state": "draft",
|
||||
"line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"account_id": self.invoice_account.id,
|
||||
"credit": 1000,
|
||||
"debit": 0,
|
||||
"name": "Test",
|
||||
"ref": "reference",
|
||||
},
|
||||
),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"account_id": self.invoice_line_account.id,
|
||||
"credit": 0,
|
||||
"debit": 1000,
|
||||
"name": "Test",
|
||||
"ref": "reference",
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.supplier_payment_mode.company_id = self.company_2
|
||||
|
||||
@@ -293,50 +358,47 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
invoice.action_invoice_open()
|
||||
# Lets create a refund invoice for invoice_1.
|
||||
# I refund the invoice Using Refund Button.
|
||||
context = {"active_model": 'account.invoice',
|
||||
"active_ids": [invoice.id], "active_id": invoice.id}
|
||||
account_invoice_refund = self.env[
|
||||
'account.invoice.refund'].with_context(context).create(dict(
|
||||
description='Refund for Invoice',
|
||||
filter_refund='refund',
|
||||
))
|
||||
context = {
|
||||
"active_model": "account.invoice",
|
||||
"active_ids": [invoice.id],
|
||||
"active_id": invoice.id,
|
||||
}
|
||||
account_invoice_refund = (
|
||||
self.env["account.invoice.refund"]
|
||||
.with_context(context)
|
||||
.create(dict(description="Refund for Invoice", filter_refund="refund"))
|
||||
)
|
||||
# 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(invoice_refund.partner_bank_id,
|
||||
self.env.ref(
|
||||
'account_payment_mode.main_company_iban'))
|
||||
self.assertEquals(invoice_refund.payment_mode_id, invoice.payment_mode_id)
|
||||
self.assertEquals(
|
||||
invoice_refund.partner_bank_id,
|
||||
self.env.ref("account_payment_mode.main_company_iban"),
|
||||
)
|
||||
|
||||
def test_partner(self):
|
||||
self.customer.write({
|
||||
'customer_payment_mode_id': self.customer_payment_mode.id
|
||||
})
|
||||
self.customer.write({"customer_payment_mode_id": self.customer_payment_mode.id})
|
||||
self.assertEqual(
|
||||
self.customer.customer_payment_mode_id,
|
||||
self.customer_payment_mode
|
||||
self.customer.customer_payment_mode_id, self.customer_payment_mode
|
||||
)
|
||||
|
||||
def test_partner_onchange(self):
|
||||
customer_invoice = self.env['account.invoice'].create({
|
||||
'partner_id': self.customer.id,
|
||||
'type': 'out_invoice',
|
||||
})
|
||||
customer_invoice = self.env["account.invoice"].create(
|
||||
{"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.supplier_invoice.partner_bank_id,
|
||||
self.supplier_bank)
|
||||
vals = {'partner_id': False, 'type': 'out_invoice'}
|
||||
invoice = self.env['account.invoice'].new(vals)
|
||||
self.assertEqual(self.supplier_invoice.partner_bank_id, self.supplier_bank)
|
||||
vals = {"partner_id": False, "type": "out_invoice"}
|
||||
invoice = self.env["account.invoice"].new(vals)
|
||||
invoice._onchange_partner_id()
|
||||
self.assertFalse(invoice.payment_mode_id)
|
||||
vals = {'partner_id': False, 'type': 'in_invoice'}
|
||||
invoice = self.env['account.invoice'].new(vals)
|
||||
vals = {"partner_id": False, "type": "in_invoice"}
|
||||
invoice = self.env["account.invoice"].new(vals)
|
||||
invoice._onchange_partner_id()
|
||||
self.assertFalse(invoice.partner_bank_id)
|
||||
|
||||
@@ -346,8 +408,7 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
self.supplier_invoice.partner_bank_id = self.supplier_bank.id
|
||||
self.supplier_invoice.payment_mode_id = mode.id
|
||||
self.supplier_invoice._onchange_payment_mode_id()
|
||||
self.assertEqual(self.supplier_invoice.partner_bank_id,
|
||||
self.supplier_bank)
|
||||
self.assertEqual(self.supplier_invoice.partner_bank_id, self.supplier_bank)
|
||||
mode.payment_method_id.bank_account_required = False
|
||||
self.supplier_invoice._onchange_payment_mode_id()
|
||||
self.assertFalse(self.supplier_invoice.partner_bank_id)
|
||||
@@ -357,7 +418,7 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
|
||||
def test_print_report(self):
|
||||
self.supplier_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])
|
||||
self.assertIn(self.supplier_bank.acc_number, res)
|
||||
payment_mode = self.supplier_payment_mode
|
||||
@@ -366,7 +427,7 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
self.supplier_invoice.partner_bank_id = False
|
||||
res = str(report.render_qweb_html(self.supplier_invoice.ids)[0])
|
||||
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)]
|
||||
res = str(report.render_qweb_html(self.supplier_invoice.ids)[0])
|
||||
self.assertIn(self.journal_bank.acc_number, res)
|
||||
|
||||
Reference in New Issue
Block a user