diff --git a/account_payment_sale/README.rst b/account_payment_sale/README.rst index b06129e42..d4e1399d0 100644 --- a/account_payment_sale/README.rst +++ b/account_payment_sale/README.rst @@ -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 `_. 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 `_. +`feedback `_. 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 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 `_ project on GitHub. +This module is part of the `OCA/bank-payment `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_sale/__manifest__.py b/account_payment_sale/__manifest__.py index f1fce0f34..7966b4d6c 100644 --- a/account_payment_sale/__manifest__.py +++ b/account_payment_sale/__manifest__.py @@ -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", diff --git a/account_payment_sale/models/__init__.py b/account_payment_sale/models/__init__.py index 6aacb7531..df48fd830 100644 --- a/account_payment_sale/models/__init__.py +++ b/account_payment_sale/models/__init__.py @@ -1 +1,2 @@ +from . import account_move from . import sale_order diff --git a/account_payment_sale/models/account_move.py b/account_payment_sale/models/account_move.py new file mode 100644 index 000000000..f2bf20f88 --- /dev/null +++ b/account_payment_sale/models/account_move.py @@ -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) diff --git a/account_payment_sale/models/sale_order.py b/account_payment_sale/models/sale_order.py index 79de661bd..cea5f06f3 100644 --- a/account_payment_sale/models/sale_order.py +++ b/account_payment_sale/models/sale_order.py @@ -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 diff --git a/account_payment_sale/readme/CONTRIBUTORS.rst b/account_payment_sale/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..66e1e8090 --- /dev/null +++ b/account_payment_sale/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +* Pedro M. Baeza +* Alexis de Lattre +* Alexandre Fayolle +* Danimar Ribeiro +* Raphaël Valyi +* Raf Ven diff --git a/account_payment_sale/readme/DESCRIPTION.rst b/account_payment_sale/readme/DESCRIPTION.rst new file mode 100644 index 000000000..3f30200f3 --- /dev/null +++ b/account_payment_sale/readme/DESCRIPTION.rst @@ -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*. diff --git a/account_payment_sale/readme/USAGE.rst b/account_payment_sale/readme/USAGE.rst new file mode 100644 index 000000000..59244604c --- /dev/null +++ b/account_payment_sale/readme/USAGE.rst @@ -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. diff --git a/account_payment_sale/static/description/index.html b/account_payment_sale/static/description/index.html index db1b96213..e7e5a9709 100644 --- a/account_payment_sale/static/description/index.html +++ b/account_payment_sale/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runbot

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.

@@ -378,62 +378,58 @@ modules in the banking addons conflict with account_payment_extension.<

Table of contents

-
-

Configuration

-

There is nothing to configure.

-
-

Usage

+

Usage

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.

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub 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.

+feedback.

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Akretion
  • Tecnativa
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

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 project on GitHub.

+

This module is part of the OCA/bank-payment project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/account_payment_sale/tests/test_sale_order.py b/account_payment_sale/tests/test_sale_order.py index 6c351afb1..b6c60dbcb 100644 --- a/account_payment_sale/tests/test_sale_order.py +++ b/account_payment_sale/tests/test_sale_order.py @@ -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) diff --git a/account_payment_sale/wizard/sale_make_invoice_advance.py b/account_payment_sale/wizard/sale_make_invoice_advance.py index b452459a6..6aed7c2f9 100644 --- a/account_payment_sale/wizard/sale_make_invoice_advance.py +++ b/account_payment_sale/wizard/sale_make_invoice_advance.py @@ -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)