diff --git a/account_payment_sale/README.rst b/account_payment_sale/README.rst index 456a589ee..95fdacb80 100644 --- a/account_payment_sale/README.rst +++ b/account_payment_sale/README.rst @@ -4,10 +4,8 @@ Account Payment Sale ==================== -This module should be used when the invoice is based on the sale order. - This modules adds one field on sale orders: *Payment Mode*. -This field is copied from partner to sale order and then from sale order to +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 @@ -19,7 +17,8 @@ Installation ============ This module depends on : -* purchase + +* sale * account_payment_partner This module is part of the OCA/bank-payment suite. @@ -35,25 +34,19 @@ 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 could be change in a draft sale order or draft invoice. -When you create an direct debit order, only invoices related to chosen payment mode are displayed. -Invoices without any payment mode are displayed to. - -For further information, please visit: - - * https://www.odoo.com/forum/help-1 Known issues / Roadmap ====================== * No known issues. - + 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 -`here `_. +`here `_. Credits ======= diff --git a/account_payment_sale/__init__.py b/account_payment_sale/__init__.py index 11323c6e9..35e7c9600 100644 --- a/account_payment_sale/__init__.py +++ b/account_payment_sale/__init__.py @@ -1,23 +1,4 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Account Payment Sale module for OpenERP -# Copyright (C) 2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- from . import models +from . import wizard diff --git a/account_payment_sale/__openerp__.py b/account_payment_sale/__openerp__.py index 7ca0364c2..09a9f10d9 100644 --- a/account_payment_sale/__openerp__.py +++ b/account_payment_sale/__openerp__.py @@ -1,28 +1,11 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Account Payment Sale module for OpenERP -# Copyright (C) 2014 Akretion (http://www.akretion.com). -# @author Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2016 Akretion (http://www.akretion.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# @author Alexis de Lattre { 'name': 'Account Payment Sale', - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'category': 'Banking addons', 'license': 'AGPL-3', 'summary': "Adds payment mode on sale orders", @@ -38,6 +21,6 @@ 'data': [ 'views/sale_order_view.xml', ], - 'installable': False, + 'installable': True, 'auto_install': True, } diff --git a/account_payment_sale/models/sale_order.py b/account_payment_sale/models/sale_order.py index d8ed2722f..244165703 100644 --- a/account_payment_sale/models/sale_order.py +++ b/account_payment_sale/models/sale_order.py @@ -1,24 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Account Payment Sale module for OpenERP -# Copyright (C) 2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import models, fields, api @@ -27,24 +9,25 @@ class SaleOrder(models.Model): _inherit = "sale.order" payment_mode_id = fields.Many2one( - 'payment.mode', string='Payment Mode', - domain="[('sale_ok', '=', True)]") + 'account.payment.mode', string='Payment Mode', + domain=[('payment_type', '=', 'inbound')]) - @api.multi - def onchange_partner_id(self, partner_id): - res = super(SaleOrder, self).onchange_partner_id(partner_id) - if partner_id: - partner = self.env['res.partner'].browse(partner_id) - res['value']['payment_mode_id'] = partner.customer_payment_mode.id + @api.onchange('partner_id') + def onchange_partner_id(self): + res = super(SaleOrder, self).onchange_partner_id() + if self.partner_id: + self.payment_mode_id = self.partner_id.customer_payment_mode.id else: - res['value']['payment_mode_id'] = False + self.payment_mode_id = False return res - @api.model - def _prepare_invoice(self, order, lines): + @api.multi + def _prepare_invoice(self): """Copy bank partner from sale order to invoice""" - vals = super(SaleOrder, self)._prepare_invoice(order, lines) - if order.payment_mode_id: - vals['payment_mode_id'] = order.payment_mode_id.id - vals['partner_bank_id'] = order.payment_mode_id.bank_id.id + vals = super(SaleOrder, self)._prepare_invoice() + 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'] =\ + self.payment_mode_id.fixed_journal_id.bank_account_id.id return vals diff --git a/account_payment_sale/views/sale_order_view.xml b/account_payment_sale/views/sale_order_view.xml index c5f5c65d8..c002971d1 100644 --- a/account_payment_sale/views/sale_order_view.xml +++ b/account_payment_sale/views/sale_order_view.xml @@ -1,7 +1,7 @@ @@ -14,9 +14,9 @@ sale.order - + diff --git a/account_payment_sale/wizard/__init__.py b/account_payment_sale/wizard/__init__.py new file mode 100644 index 000000000..1eb17ffa1 --- /dev/null +++ b/account_payment_sale/wizard/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import sale_make_invoice_advance diff --git a/account_payment_sale/wizard/sale_make_invoice_advance.py b/account_payment_sale/wizard/sale_make_invoice_advance.py new file mode 100644 index 000000000..a962e49c5 --- /dev/null +++ b/account_payment_sale/wizard/sale_make_invoice_advance.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, api + + +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(SaleAdvancePaymentInv, self)._create_invoice( + order, so_line, amount) + vals = {} + if order.payment_mode_id: + vals['payment_mode_id'] = order.payment_mode_id.id + if order.payment_mode_id.bank_account_link == 'fixed': + vals['partner_bank_id'] =\ + order.payment_mode_id.fixed_journal_id.bank_account_id.id + if vals: + inv.write(vals) + return inv