mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[MIG] account_payment_order: Migration to 16.0
This commit is contained in:
committed by
Pedro M. Baeza
parent
170117c1e9
commit
0c98de15fa
@@ -9,7 +9,7 @@
|
||||
|
||||
{
|
||||
"name": "Account Payment Order",
|
||||
"version": "15.0.1.1.2",
|
||||
"version": "16.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "ACSONE SA/NV, "
|
||||
"Therp BV, "
|
||||
@@ -19,7 +19,6 @@
|
||||
"website": "https://github.com/OCA/bank-payment",
|
||||
"development_status": "Mature",
|
||||
"category": "Banking addons",
|
||||
"external_dependencies": {"python": ["lxml"]},
|
||||
"depends": ["account_payment_partner", "base_iban"], # for manual_bank_tranfer
|
||||
"data": [
|
||||
"views/account_payment_method.xml",
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
# Copyright 2021 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
if not version:
|
||||
return
|
||||
|
||||
cr.execute("UPDATE account_payment_order SET state='uploaded' WHERE state='done'")
|
||||
@@ -61,7 +61,8 @@ class AccountMove(models.Model):
|
||||
lambda x: (
|
||||
not x.reconciled
|
||||
and x.payment_mode_id.payment_order_ok
|
||||
and x.account_id.internal_type in ("receivable", "payable")
|
||||
and x.account_id.account_type
|
||||
in ("asset_receivable", "liability_payable")
|
||||
and not any(
|
||||
p_state in ("draft", "open", "generated")
|
||||
for p_state in x.payment_line_ids.mapped("state")
|
||||
|
||||
@@ -32,7 +32,8 @@ class AccountMoveLine(models.Model):
|
||||
ml.move_id.move_type in ("in_invoice", "in_refund")
|
||||
and not ml.reconciled
|
||||
and ml.payment_mode_id.payment_order_ok
|
||||
and ml.account_id.internal_type in ("receivable", "payable")
|
||||
and ml.account_id.account_type
|
||||
in ("asset_receivable", "liability_payable")
|
||||
and not any(
|
||||
p_state in ("draft", "open", "generated")
|
||||
for p_state in ml.payment_line_ids.mapped("state")
|
||||
@@ -64,11 +65,13 @@ class AccountMoveLine(models.Model):
|
||||
)
|
||||
reference_moves |= self.move_id.reversal_move_id
|
||||
# Retrieve partial payments - e.g.: manual credit notes
|
||||
for (
|
||||
_,
|
||||
_,
|
||||
payment_move_line,
|
||||
) in self.move_id._get_reconciled_invoices_partials():
|
||||
(
|
||||
invoice_partials,
|
||||
exchange_diff_moves,
|
||||
) = self.move_id._get_reconciled_invoices_partials()
|
||||
for (_, _, payment_move_line,) in (
|
||||
invoice_partials + exchange_diff_moves
|
||||
):
|
||||
payment_move = payment_move_line.move_id
|
||||
if payment_move not in reference_moves and (
|
||||
payment_move.payment_reference or payment_move.ref
|
||||
|
||||
@@ -11,19 +11,20 @@ class AccountPayment(models.Model):
|
||||
payment_order_id = fields.Many2one(comodel_name="account.payment.order")
|
||||
payment_line_ids = fields.Many2many(comodel_name="account.payment.line")
|
||||
|
||||
def _get_default_journal(self):
|
||||
res = super()._get_default_journal()
|
||||
return res.filtered(lambda journal: not journal.inbound_payment_order_only)
|
||||
|
||||
@api.depends("payment_type", "journal_id")
|
||||
def _compute_payment_method_line_fields(self):
|
||||
res = super()._compute_payment_method_line_fields()
|
||||
for pay in self:
|
||||
pay.available_payment_method_line_ids = (
|
||||
pay.journal_id._get_available_payment_method_lines(
|
||||
pay.payment_type
|
||||
).filtered(lambda x: not x.payment_method_id.payment_order_only)
|
||||
)
|
||||
if pay.payment_order_id:
|
||||
pay.available_payment_method_line_ids = (
|
||||
pay.journal_id._get_available_payment_method_lines(pay.payment_type)
|
||||
)
|
||||
else:
|
||||
pay.available_payment_method_line_ids = (
|
||||
pay.journal_id._get_available_payment_method_lines(
|
||||
pay.payment_type
|
||||
).filtered(lambda x: not x.payment_method_id.payment_order_only)
|
||||
)
|
||||
to_exclude = pay._get_payment_method_codes_to_exclude()
|
||||
if to_exclude:
|
||||
pay.available_payment_method_line_ids = (
|
||||
@@ -31,17 +32,4 @@ class AccountPayment(models.Model):
|
||||
lambda x: x.code not in to_exclude
|
||||
)
|
||||
)
|
||||
if (
|
||||
pay.payment_method_line_id.id
|
||||
not in pay.available_payment_method_line_ids.ids
|
||||
):
|
||||
# In some cases, we could be linked to a payment method
|
||||
# line that has been unlinked from the journal.
|
||||
# In such cases, we want to show it on the payment.
|
||||
pay.hide_payment_method_line = False
|
||||
else:
|
||||
pay.hide_payment_method_line = (
|
||||
len(pay.available_payment_method_line_ids) == 1
|
||||
and pay.available_payment_method_line_ids.code == "manual"
|
||||
)
|
||||
return res
|
||||
|
||||
@@ -91,13 +91,15 @@ class AccountPaymentLine(models.Model):
|
||||
)
|
||||
]
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get("name", "New") == "New":
|
||||
vals["name"] = (
|
||||
self.env["ir.sequence"].next_by_code("account.payment.line") or "New"
|
||||
)
|
||||
return super(AccountPaymentLine, self).create(vals)
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
for vals in vals_list:
|
||||
if vals.get("name", "New") == "New":
|
||||
vals["name"] = (
|
||||
self.env["ir.sequence"].next_by_code("account.payment.line")
|
||||
or "New"
|
||||
)
|
||||
return super().create(vals_list)
|
||||
|
||||
@api.depends("amount_currency", "currency_id", "company_currency_id", "date")
|
||||
def _compute_amount_company_currency(self):
|
||||
|
||||
@@ -221,22 +221,24 @@ class AccountPaymentOrder(models.Model):
|
||||
for order in self:
|
||||
order.move_count = mapped_data.get(order.id, 0)
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get("name", "New") == "New":
|
||||
vals["name"] = (
|
||||
self.env["ir.sequence"].next_by_code("account.payment.order") or "New"
|
||||
)
|
||||
if vals.get("payment_mode_id"):
|
||||
payment_mode = self.env["account.payment.mode"].browse(
|
||||
vals["payment_mode_id"]
|
||||
)
|
||||
vals["payment_type"] = payment_mode.payment_type
|
||||
if payment_mode.bank_account_link == "fixed":
|
||||
vals["journal_id"] = payment_mode.fixed_journal_id.id
|
||||
if not vals.get("date_prefered") and payment_mode.default_date_prefered:
|
||||
vals["date_prefered"] = payment_mode.default_date_prefered
|
||||
return super(AccountPaymentOrder, self).create(vals)
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
for vals in vals_list:
|
||||
if vals.get("name", "New") == "New":
|
||||
vals["name"] = (
|
||||
self.env["ir.sequence"].next_by_code("account.payment.order")
|
||||
or "New"
|
||||
)
|
||||
if vals.get("payment_mode_id"):
|
||||
payment_mode = self.env["account.payment.mode"].browse(
|
||||
vals["payment_mode_id"]
|
||||
)
|
||||
vals["payment_type"] = payment_mode.payment_type
|
||||
if payment_mode.bank_account_link == "fixed":
|
||||
vals["journal_id"] = payment_mode.fixed_journal_id.id
|
||||
if not vals.get("date_prefered") and payment_mode.default_date_prefered:
|
||||
vals["date_prefered"] = payment_mode.default_date_prefered
|
||||
return super(AccountPaymentOrder, self).create(vals_list)
|
||||
|
||||
@api.onchange("payment_mode_id")
|
||||
def payment_mode_id_change(self):
|
||||
@@ -343,7 +345,7 @@ class AccountPaymentOrder(models.Model):
|
||||
"paylines": payline,
|
||||
"total": payline.amount_currency,
|
||||
}
|
||||
order.recompute()
|
||||
order.env.flush_all()
|
||||
# Create account payments
|
||||
payment_vals = []
|
||||
for paydict in list(group_paylines.values()):
|
||||
|
||||
@@ -12,27 +12,13 @@
|
||||
<div class="oe_structure" />
|
||||
<div class="row">
|
||||
<div class="col-4 offset-8">
|
||||
<span
|
||||
t-raw="'%s <br>' % doc.journal_id.bank_id.name if doc.journal_id.bank_id.name else ''"
|
||||
/>
|
||||
<span
|
||||
t-raw="'%s <br>' % doc.journal_id.bank_id.street if doc.journal_id.bank_id.street else ''"
|
||||
/>
|
||||
<span
|
||||
t-raw="'%s <br>' % doc.journal_id.bank_id.street2 if doc.journal_id.bank_id.street2 else ''"
|
||||
/>
|
||||
<span
|
||||
t-raw="'%s <br>' % doc.journal_id.bank_id.zip if doc.journal_id.bank_id.zip else ''"
|
||||
/>
|
||||
<span
|
||||
t-raw="'%s <br>' % doc.journal_id.bank_id.city if doc.journal_id.bank_id.city else ''"
|
||||
/>
|
||||
<span
|
||||
t-raw="'%s <br>' % doc.journal_id.bank_id.state.name if doc.journal_id.bank_id.state.name else ''"
|
||||
/>
|
||||
<span
|
||||
t-raw="'%s <br>' % doc.journal_id.bank_id.country.name if doc.journal_id.bank_id.country.name else ''"
|
||||
/>
|
||||
<div t-field="doc.journal_id.bank_id.name" />
|
||||
<div t-field="doc.journal_id.bank_id.street" />
|
||||
<div t-field="doc.journal_id.bank_id.treet2" />
|
||||
<div t-field="doc.journal_id.bank_id.zip" />
|
||||
<div t-field="doc.journal_id.bank_id.city" />
|
||||
<div t-field="doc.journal_id.bank_id.state.name" />
|
||||
<div t-field="doc.journal_id.bank_id.country.name" />
|
||||
</div>
|
||||
</div>
|
||||
<t t-if="doc.payment_type == 'inbound'">
|
||||
|
||||
@@ -105,9 +105,6 @@ class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
"company_id": self.company.id,
|
||||
}
|
||||
)
|
||||
# check journals
|
||||
journals = new_account_payment._get_default_journal()
|
||||
self.assertIn(self.bank_journal, journals)
|
||||
# check payment methods
|
||||
payment_methods = (
|
||||
new_account_payment.available_payment_method_line_ids.filtered(
|
||||
@@ -120,9 +117,6 @@ class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
self.assertIn(self.inbound_payment_method_02.id, payment_methods)
|
||||
# Set one payment method of the bank journal 'payment order only'
|
||||
self.inbound_payment_method_01.payment_order_only = True
|
||||
# check journals
|
||||
journals = new_account_payment._get_default_journal()
|
||||
self.assertIn(self.bank_journal, journals)
|
||||
# check payment methods
|
||||
new_account_payment2 = self.account_payment_model.with_context(
|
||||
default_company_id=self.company.id
|
||||
@@ -143,9 +137,6 @@ class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
for p in self.bank_journal.inbound_payment_method_line_ids.payment_method_id:
|
||||
p.payment_order_only = True
|
||||
self.assertTrue(self.bank_journal.inbound_payment_order_only)
|
||||
# check journals
|
||||
journals = new_account_payment._get_default_journal()
|
||||
self.assertNotIn(self.bank_journal, journals)
|
||||
# check payment methods
|
||||
new_account_payment3 = self.account_payment_model.with_context(
|
||||
default_company_id=self.company.id
|
||||
|
||||
@@ -28,7 +28,7 @@ class TestPaymentOrderOutboundBase(AccountTestInvoicingCommon):
|
||||
{
|
||||
"name": "Test account",
|
||||
"code": "TEST1",
|
||||
"user_type_id": cls.env.ref("account.data_account_type_expenses").id,
|
||||
"account_type": "expense",
|
||||
}
|
||||
)
|
||||
cls.mode = cls.env["account.payment.mode"].create(
|
||||
@@ -361,10 +361,10 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
|
||||
|
||||
# The user add the outstanding payment to the invoice
|
||||
invoice_line = self.invoice.line_ids.filtered(
|
||||
lambda line: line.account_internal_type == "payable"
|
||||
lambda line: line.account_type == "liability_payable"
|
||||
)
|
||||
refund_line = self.refund.line_ids.filtered(
|
||||
lambda line: line.account_internal_type == "payable"
|
||||
lambda line: line.account_type == "liability_payable"
|
||||
)
|
||||
(invoice_line | refund_line).reconcile()
|
||||
|
||||
@@ -399,7 +399,7 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase):
|
||||
self.refund.action_post()
|
||||
|
||||
(self.invoice.line_ids + self.refund.line_ids).filtered(
|
||||
lambda line: line.account_internal_type == "payable"
|
||||
lambda line: line.account_type == "liability_payable"
|
||||
).reconcile()
|
||||
|
||||
self.env["account.invoice.payment.line.multi"].with_context(
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<form string="Payment Lines">
|
||||
<group name="main" col="2">
|
||||
<group name="left">
|
||||
<field name="company_id" invisible="1" />
|
||||
<field
|
||||
name="order_id"
|
||||
invisible="not context.get('account_payment_line_main_view')"
|
||||
@@ -25,7 +26,7 @@
|
||||
<field
|
||||
name="partner_bank_id"
|
||||
context="{'default_partner_id': partner_id}"
|
||||
domain="[('partner_id', '=', partner_id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]"
|
||||
domain="[('partner_id', '=', partner_id)]"
|
||||
attrs="{'required': [('bank_account_required', '=', True)]}"
|
||||
/>
|
||||
<field name="bank_account_required" invisible="1" />
|
||||
|
||||
@@ -119,12 +119,20 @@ class AccountPaymentLineCreate(models.TransientModel):
|
||||
# will not be refunded with a payment.
|
||||
domain += [
|
||||
("credit", ">", 0),
|
||||
("account_id.internal_type", "in", ["payable", "receivable"]),
|
||||
(
|
||||
"account_id.account_type",
|
||||
"in",
|
||||
["liability_payable", "asset_receivable"],
|
||||
),
|
||||
]
|
||||
elif self.order_id.payment_type == "inbound":
|
||||
domain += [
|
||||
("debit", ">", 0),
|
||||
("account_id.internal_type", "in", ["receivable", "payable"]),
|
||||
(
|
||||
"account_id.account_type",
|
||||
"in",
|
||||
["asset_receivable", "liability_payable"],
|
||||
),
|
||||
]
|
||||
# Exclude lines that are already in a non-cancelled
|
||||
# and non-uploaded payment order; lines that are in a
|
||||
|
||||
1
setup/account_payment_order/odoo/addons/account_payment_order
Symbolic link
1
setup/account_payment_order/odoo/addons/account_payment_order
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../account_payment_order
|
||||
6
setup/account_payment_order/setup.py
Normal file
6
setup/account_payment_order/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user