mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[MIG] account_payment_sale: Migration to 13.0
This commit is contained in:
@@ -14,13 +14,13 @@ Account Payment Sale
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |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_sale
|
||||
:target: https://github.com/OCA/bank-payment/tree/13.0/account_payment_sale
|
||||
:alt: OCA/bank-payment
|
||||
.. |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_sale
|
||||
:target: https://translation.odoo-community.org/projects/bank-payment-13-0/bank-payment-13-0-account_payment_sale
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/97/12.0
|
||||
:target: https://runbot.odoo-community.org/runbot/173/13.0
|
||||
:alt: Try me on Runbot
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
@@ -39,11 +39,6 @@ modules in the banking addons conflict with *account_payment_extension*.
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
There is nothing to configure.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
@@ -57,7 +52,7 @@ Bug Tracker
|
||||
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.
|
||||
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_sale%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_sale%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.
|
||||
|
||||
@@ -78,6 +73,7 @@ Contributors
|
||||
* Alexandre Fayolle
|
||||
* Danimar Ribeiro
|
||||
* Raphaël Valyi
|
||||
* Raf Ven <raf.ven@dynapps.be>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
@@ -92,6 +88,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
This module is part of the `OCA/bank-payment <https://github.com/OCA/bank-payment/tree/12.0/account_payment_sale>`_ project on GitHub.
|
||||
This module is part of the `OCA/bank-payment <https://github.com/OCA/bank-payment/tree/13.0/account_payment_sale>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
{
|
||||
"name": "Account Payment Sale",
|
||||
"version": "12.0.1.1.0",
|
||||
"version": "13.0.1.1.0",
|
||||
"category": "Banking addons",
|
||||
"license": "AGPL-3",
|
||||
"summary": "Adds payment mode on sale orders",
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
from . import account_move
|
||||
from . import sale_order
|
||||
|
||||
19
account_payment_sale/models/account_move.py
Normal file
19
account_payment_sale/models/account_move.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
@api.model
|
||||
def create(self, vals_list):
|
||||
if vals_list.get("payment_mode_id"):
|
||||
payment_mode = self.env["account.payment.mode"].browse(
|
||||
vals_list["payment_mode_id"]
|
||||
)
|
||||
if payment_mode.bank_account_link == "fixed":
|
||||
vals_list[
|
||||
"invoice_partner_bank_id"
|
||||
] = payment_mode.fixed_journal_id.bank_account_id.id
|
||||
return super().create(vals_list)
|
||||
@@ -8,59 +8,31 @@ class SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
payment_mode_id = fields.Many2one(
|
||||
"account.payment.mode",
|
||||
string="Payment Mode",
|
||||
comodel_name="account.payment.mode",
|
||||
compute="_compute_payment_mode",
|
||||
store=True,
|
||||
readonly=False,
|
||||
domain=[("payment_type", "=", "inbound")],
|
||||
)
|
||||
|
||||
@api.depends("partner_id")
|
||||
def _compute_payment_mode(self):
|
||||
for order in self:
|
||||
if order.partner_id:
|
||||
order.payment_mode_id = order.partner_id.customer_payment_mode_id
|
||||
else:
|
||||
order.payment_mode_id = False
|
||||
|
||||
def _get_payment_mode_vals(self, vals):
|
||||
if self.payment_mode_id:
|
||||
vals["payment_mode_id"] = self.payment_mode_id.id
|
||||
if self.payment_mode_id.bank_account_link == "fixed":
|
||||
vals[
|
||||
"partner_bank_id"
|
||||
"invoice_partner_bank_id"
|
||||
] = self.payment_mode_id.fixed_journal_id.bank_account_id.id
|
||||
return vals
|
||||
|
||||
@api.onchange("partner_id")
|
||||
def onchange_partner_id(self):
|
||||
res = super().onchange_partner_id()
|
||||
if self.partner_id:
|
||||
self.payment_mode_id = self.partner_id.customer_payment_mode_id
|
||||
else:
|
||||
self.payment_mode_id = False
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def _prepare_invoice(self):
|
||||
"""Copy bank partner from sale order to invoice"""
|
||||
vals = super()._prepare_invoice()
|
||||
return self._get_payment_mode_vals(vals)
|
||||
|
||||
def _finalize_invoices(self, invoices, references):
|
||||
"""
|
||||
Invoked after creating invoices at the end of action_invoice_create.
|
||||
|
||||
We must override this method since the onchange on partner is called by
|
||||
the base method and therefore will change the specific payment_mode set
|
||||
on the SO if one is defined on the partner..
|
||||
|
||||
:param invoices: {group_key: invoice}
|
||||
:param references: {invoice: order}
|
||||
"""
|
||||
payment_vals_by_invoice = {}
|
||||
for invoice in invoices.values():
|
||||
payment_vals_by_invoice[invoice] = {
|
||||
"payment_mode_id": invoice.payment_mode_id.id,
|
||||
"partner_bank_id": invoice.partner_bank_id.id,
|
||||
}
|
||||
res = super()._finalize_invoices(invoices, references)
|
||||
for invoice in invoices.values():
|
||||
payment_vals = payment_vals_by_invoice[invoice]
|
||||
if invoice.payment_mode_id.id == payment_vals["payment_mode_id"]:
|
||||
payment_vals.pop("payment_mode_id")
|
||||
if invoice.partner_bank_id.id == payment_vals["partner_bank_id"]:
|
||||
payment_vals.pop("partner_bank_id")
|
||||
if payment_vals:
|
||||
invoice.write(payment_vals)
|
||||
return res
|
||||
|
||||
6
account_payment_sale/readme/CONTRIBUTORS.rst
Normal file
6
account_payment_sale/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
* Pedro M. Baeza
|
||||
* Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
* Alexandre Fayolle
|
||||
* Danimar Ribeiro
|
||||
* Raphaël Valyi
|
||||
* Raf Ven <raf.ven@dynapps.be>
|
||||
8
account_payment_sale/readme/DESCRIPTION.rst
Normal file
8
account_payment_sale/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,8 @@
|
||||
This modules adds one field on sale orders: *Payment Mode*.
|
||||
This field is copied from customer to sale order and then from sale order to
|
||||
customer invoice.
|
||||
|
||||
This module is similar to the *sale_payment* module; the main difference is
|
||||
that it doesn't depend on the *account_payment_extension* module (it's not the
|
||||
only module to conflict with *account_payment_extension*; all the SEPA
|
||||
modules in the banking addons conflict with *account_payment_extension*.
|
||||
3
account_payment_sale/readme/USAGE.rst
Normal file
3
account_payment_sale/readme/USAGE.rst
Normal file
@@ -0,0 +1,3 @@
|
||||
You are able to add a payment mode directly on a partner.
|
||||
This payment mode is automatically associated to the sale order, then on related invoice.
|
||||
This default value can be changed in a draft sale order or draft invoice.
|
||||
@@ -367,7 +367,7 @@ ul.auto-toc {
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! 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_sale"><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_sale"><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/97/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_sale"><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_sale"><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 modules adds one field on sale orders: <em>Payment Mode</em>.
|
||||
This field is copied from customer to sale order and then from sale order to
|
||||
customer invoice.</p>
|
||||
@@ -378,62 +378,58 @@ modules in the banking addons conflict with <em>account_payment_extension</em>.<
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
|
||||
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
|
||||
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="configuration">
|
||||
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
|
||||
<p>There is nothing to configure.</p>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
|
||||
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
|
||||
<p>You are able to add a payment mode directly on a partner.
|
||||
This payment mode is automatically associated to the sale order, then on related invoice.
|
||||
This default value can be changed in a draft sale order or draft invoice.</p>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
|
||||
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
|
||||
<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.
|
||||
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_sale%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_sale%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>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
|
||||
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
|
||||
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Akretion</li>
|
||||
<li>Tecnativa</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
|
||||
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Pedro M. Baeza</li>
|
||||
<li>Alexis de Lattre <<a class="reference external" href="mailto:alexis.delattre@akretion.com">alexis.delattre@akretion.com</a>></li>
|
||||
<li>Alexandre Fayolle</li>
|
||||
<li>Danimar Ribeiro</li>
|
||||
<li>Raphaël Valyi</li>
|
||||
<li>Raf Ven <<a class="reference external" href="mailto:raf.ven@dynapps.be">raf.ven@dynapps.be</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
|
||||
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
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_sale">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_sale">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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,51 +1,45 @@
|
||||
# Copyright 2018 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests import Form
|
||||
|
||||
from .common import CommonTestCase
|
||||
|
||||
|
||||
class TestSaleOrder(CommonTestCase):
|
||||
def create_sale_order(self, payment_mode=None):
|
||||
so_lines = [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": p.name,
|
||||
"product_id": p.id,
|
||||
"product_uom_qty": 2,
|
||||
"product_uom": p.uom_id.id,
|
||||
"price_unit": p.list_price,
|
||||
},
|
||||
)
|
||||
for (_, p) in self.products.items()
|
||||
]
|
||||
so = self.env["sale.order"].create(
|
||||
{
|
||||
"partner_id": self.base_partner.id,
|
||||
"partner_invoice_id": self.base_partner.id,
|
||||
"partner_shipping_id": self.base_partner.id,
|
||||
"order_line": so_lines,
|
||||
"pricelist_id": self.env.ref("product.list0").id,
|
||||
}
|
||||
with Form(self.env["sale.order"]) as sale_form:
|
||||
sale_form.partner_id = self.base_partner
|
||||
sale_form.partner_invoice_id = self.base_partner
|
||||
sale_form.partner_shipping_id = self.base_partner
|
||||
sale_form.pricelist_id = self.env.ref("product.list0")
|
||||
for (_, p) in self.products.items():
|
||||
with sale_form.order_line.new() as order_line:
|
||||
order_line.product_id = p
|
||||
order_line.name = p.name
|
||||
order_line.product_uom_qty = 2
|
||||
order_line.product_uom = p.uom_id
|
||||
order_line.price_unit = p.list_price
|
||||
sale = sale_form.save()
|
||||
self.assertEqual(
|
||||
sale.payment_mode_id, self.base_partner.customer_payment_mode_id
|
||||
)
|
||||
self.assertFalse(so.payment_mode_id)
|
||||
so.onchange_partner_id()
|
||||
self.assertEqual(so.payment_mode_id, self.base_partner.customer_payment_mode_id)
|
||||
sale_form = Form(sale)
|
||||
|
||||
# force payment mode
|
||||
if payment_mode:
|
||||
so.payment_mode_id = payment_mode.id
|
||||
return so
|
||||
sale_form.payment_mode_id = payment_mode
|
||||
return sale_form.save()
|
||||
|
||||
def create_invoice_and_check(
|
||||
self, order, expected_payment_mode, expected_partner_bank
|
||||
):
|
||||
order.action_confirm()
|
||||
order.action_invoice_create()
|
||||
order._create_invoices()
|
||||
invoice = order.invoice_ids
|
||||
self.assertEqual(len(invoice), 1)
|
||||
self.assertEqual(invoice.payment_mode_id, expected_payment_mode)
|
||||
self.assertEqual(invoice.partner_bank_id, expected_partner_bank)
|
||||
self.assertEqual(invoice.invoice_partner_bank_id, expected_partner_bank)
|
||||
|
||||
def test_sale_to_invoice_payment_mode(self):
|
||||
"""
|
||||
@@ -93,7 +87,7 @@ class TestSaleOrder(CommonTestCase):
|
||||
payment = self.env["sale.advance.payment.inv"].create(
|
||||
{
|
||||
"advance_payment_method": "fixed",
|
||||
"amount": 5,
|
||||
"fixed_amount": 5,
|
||||
"product_id": self.env.ref("sale.advance_product_0").id,
|
||||
}
|
||||
)
|
||||
@@ -101,4 +95,4 @@ class TestSaleOrder(CommonTestCase):
|
||||
invoice = order.invoice_ids
|
||||
self.assertEqual(len(invoice), 1)
|
||||
self.assertEqual(invoice.payment_mode_id, self.payment_mode_2)
|
||||
self.assertEqual(invoice.partner_bank_id, self.bank)
|
||||
self.assertEqual(invoice.invoice_partner_bank_id, self.bank)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
# Copyright 2016 Akretion - Alexis de Lattre
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models
|
||||
from odoo import models
|
||||
|
||||
|
||||
class SaleAdvancePaymentInv(models.TransientModel):
|
||||
_inherit = "sale.advance.payment.inv"
|
||||
|
||||
@api.multi
|
||||
def _create_invoice(self, order, so_line, amount):
|
||||
"""Copy payment mode from sale order to invoice"""
|
||||
inv = super()._create_invoice(order, so_line, amount)
|
||||
|
||||
Reference in New Issue
Block a user