diff --git a/account_payment_partner/README.rst b/account_payment_partner/README.rst index 2837e36a1..704ca358a 100644 --- a/account_payment_partner/README.rst +++ b/account_payment_partner/README.rst @@ -1,6 +1,7 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg :alt: License: AGPL-3 +======================= Account Payment Partner ======================= @@ -17,7 +18,8 @@ Installation ============ This module depends on : -* account_banking_payment_export + +* account_payment_mode This module is part of the OCA/bank-payment suite. @@ -34,22 +36,22 @@ This payment mode is automatically associated to the invoice related to the part When you create an payment 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 +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/173/9.0 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 `_. +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. Credits ======= @@ -58,7 +60,7 @@ Contributors ------------ * Pedro M. Baeza -* Alexis de Lattre +* Alexis de Lattre * Raphaël Valyi * Stefan Rijnhart (Therp) * Alexandre Fayolle diff --git a/account_payment_partner/__init__.py b/account_payment_partner/__init__.py index 794e1a243..3845dd2da 100644 --- a/account_payment_partner/__init__.py +++ b/account_payment_partner/__init__.py @@ -3,4 +3,3 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models -from . import wizard diff --git a/account_payment_partner/__openerp__.py b/account_payment_partner/__openerp__.py index 0460a7c26..8c1068021 100644 --- a/account_payment_partner/__openerp__.py +++ b/account_payment_partner/__openerp__.py @@ -5,7 +5,7 @@ { 'name': 'Account Payment Partner', - 'version': '8.0.0.2.0', + 'version': '9.0.1.0.0', 'category': 'Banking addons', 'license': 'AGPL-3', 'summary': 'Adds payment mode on partners and invoices', @@ -13,14 +13,12 @@ "Serv. Tecnol. Avanzados - Pedro M. Baeza, " "Odoo Community Association (OCA)", 'website': 'https://github.com/OCA/bank-payment', - 'depends': ['account_banking_payment_export'], + 'depends': ['account_payment_mode'], 'data': [ 'views/res_partner_view.xml', 'views/account_invoice_view.xml', + 'views/account_move_line.xml', 'views/report_invoice.xml', - 'views/payment_mode.xml', - 'security/ir.model.access.csv', - 'wizard/payment_order_create_view.xml', ], 'demo': ['demo/partner_demo.xml'], 'installable': True, diff --git a/account_payment_partner/demo/partner_demo.xml b/account_payment_partner/demo/partner_demo.xml index 776058d44..20545d978 100644 --- a/account_payment_partner/demo/partner_demo.xml +++ b/account_payment_partner/demo/partner_demo.xml @@ -3,49 +3,23 @@ - - - supplier_payment_mode_12 + + Default Supplier Payment Mode + search="[('model','=','res.partner'),('name','=','supplier_payment_mode_id')]"/> + eval="'account.payment.mode,'+str(ref('account_payment_mode.payment_mode_outbound_ct1'))"/> - - - customer_payment_mode_12 + + Default Customer Payment Mode + search="[('model','=','res.partner'),('name','=','customer_payment_mode_id')]"/> + eval="'account.payment.mode,'+str(ref('account_payment_mode.payment_mode_inbound_ct1'))"/> - - - - customer_payment_mode_2 - - - - - - - - - supplier_payment_mode_1 - - - - - - - diff --git a/account_payment_partner/models/__init__.py b/account_payment_partner/models/__init__.py index be3f531bb..152bb919c 100644 --- a/account_payment_partner/models/__init__.py +++ b/account_payment_partner/models/__init__.py @@ -2,4 +2,4 @@ from . import res_partner from . import account_invoice -from . import payment_mode +from . import account_move_line diff --git a/account_payment_partner/models/account_invoice.py b/account_payment_partner/models/account_invoice.py index 4c5b971c6..14ac17a77 100644 --- a/account_payment_partner/models/account_invoice.py +++ b/account_payment_partner/models/account_invoice.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2014 Akretion - Alexis de Lattre +# © 2014-2016 Akretion - Alexis de Lattre # © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -10,27 +10,70 @@ class AccountInvoice(models.Model): _inherit = 'account.invoice' payment_mode_id = fields.Many2one( - comodel_name='payment.mode', string="Payment Mode", - domain="[('type', '=', type)]") + 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) - @api.multi - def onchange_partner_id( - self, type, partner_id, date_invoice=False, - payment_term=False, partner_bank_id=False, company_id=False): - res = super(AccountInvoice, self).onchange_partner_id( - type, partner_id, date_invoice=date_invoice, - payment_term=payment_term, partner_bank_id=partner_bank_id, - company_id=company_id) - if partner_id: - partner = self.env['res.partner'].browse(partner_id) - if type == 'in_invoice': - res['value']['payment_mode_id'] = \ - partner.supplier_payment_mode.id - elif type == 'out_invoice': - res['value'].update({ - 'payment_mode_id': partner.customer_payment_mode.id, - 'partner_bank_id': partner.customer_payment_mode.bank_id.id - }) + @api.onchange('partner_id', 'company_id') + def _onchange_partner_id(self): + super(AccountInvoice, self)._onchange_partner_id() + if self.partner_id: + if self.type == 'in_invoice': + pay_mode = self.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): + self.partner_bank_id =\ + self.commercial_partner_id.bank_ids[0] + elif self.type == 'out_invoice': + pay_mode = self.partner_id.customer_payment_mode_id + self.payment_mode_id = pay_mode + if pay_mode and pay_mode.bank_account_link == 'fixed': + self.partner_bank_id = pay_mode.fixed_journal_id.\ + bank_account_id else: - res['value']['payment_mode_id'] = False + self.payment_mode_id = False + if self.type == 'in_invoice': + self.partner_bank_id = False + + @api.onchange('payment_mode_id') + def payment_mode_id_change(self): + if ( + self.payment_mode_id and + self.payment_mode_id.payment_type == 'outbound' and + not self.payment_mode_id.payment_method_id. + bank_account_required): + self.partner_bank_id = False + elif not self.payment_mode_id: + self.partner_bank_id = False + + @api.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 return res + + # I think copying payment mode from invoice to refund by default + # is a good idea because the most common way of "paying" a refund is to + # deduct it on the payment of the next invoice (and OCA/bank-payment + # 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): + 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 + return vals diff --git a/account_payment_partner/models/account_move_line.py b/account_payment_partner/models/account_move_line.py new file mode 100644 index 000000000..080e73369 --- /dev/null +++ b/account_payment_partner/models/account_move_line.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (http://www.akretion.com/) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields + + +class AccountMoveLine(models.Model): + _inherit = 'account.move.line' + + payment_mode_id = fields.Many2one( + 'account.payment.mode', string='Payment Mode', ondelete='restrict') diff --git a/account_payment_partner/models/payment_mode.py b/account_payment_partner/models/payment_mode.py deleted file mode 100644 index 6d2fa946b..000000000 --- a/account_payment_partner/models/payment_mode.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2014 Akretion - Alexis de Lattre -# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openerp import models, fields - - -class PaymentMode(models.Model): - _inherit = "payment.mode" - - default_payment_mode = fields.Selection([ - ('same', 'Same'), - ('same_or_null', 'Same or empty'), - ('any', 'Any'), - ], string='Payment Mode on Invoice', default='same') diff --git a/account_payment_partner/models/res_partner.py b/account_payment_partner/models/res_partner.py index 7b6c850aa..b7a35e93c 100644 --- a/account_payment_partner/models/res_partner.py +++ b/account_payment_partner/models/res_partner.py @@ -9,17 +9,20 @@ from openerp import models, fields, api class ResPartner(models.Model): _inherit = 'res.partner' - supplier_payment_mode = fields.Many2one( - 'payment.mode', string='Supplier Payment Mode', company_dependent=True, - domain="[('purchase_ok', '=', True)]", + # v8 fields : same without the _id suffix + supplier_payment_mode_id = fields.Many2one( + 'account.payment.mode', string='Supplier Payment Mode', + company_dependent=True, + domain=[('payment_type', '=', 'outbound')], help="Select the default payment mode for this supplier.") - customer_payment_mode = fields.Many2one( - 'payment.mode', string='Customer Payment Mode', company_dependent=True, - domain="[('sale_ok', '=', True)]", + customer_payment_mode_id = fields.Many2one( + 'account.payment.mode', string='Customer Payment Mode', + company_dependent=True, + domain=[('payment_type', '=', 'inbound')], 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', 'customer_payment_mode'] + res += ['supplier_payment_mode_id', 'customer_payment_mode_id'] return res diff --git a/account_payment_partner/security/ir.model.access.csv b/account_payment_partner/security/ir.model.access.csv deleted file mode 100644 index ac6d96dfd..000000000 --- a/account_payment_partner/security/ir.model.access.csv +++ /dev/null @@ -1,3 +0,0 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_payment_mode_read,Read access on payment.mode to Employees,account_payment.model_payment_mode,base.group_user,1,0,0,0 -access_payment_mode_type_read,Read access on payment.mode.type to Employees,account_banking_payment_export.model_payment_mode_type,base.group_user,1,0,0,0 diff --git a/account_payment_partner/views/account_invoice_view.xml b/account_payment_partner/views/account_invoice_view.xml index 895e03bf5..0e59c514d 100644 --- a/account_payment_partner/views/account_invoice_view.xml +++ b/account_payment_partner/views/account_invoice_view.xml @@ -1,21 +1,20 @@ - - + - - account_payment_partner.invoice_filter + + account_payment_partner.account_invoice_search account.invoice - - + + @@ -28,8 +27,12 @@ + + + + 0 @@ -40,14 +43,43 @@ account.invoice - + + + + + + [('partner_id', '=', commercial_partner_id)] + 0 + {'invisible': [('bank_account_required', '=', False)], 'required': [('bank_account_required', '=', True)]} + + + + + + account_payment_partner.customer_invoice_tree + account.invoice + + + + + + + + + + account_payment_partner.supplier_invoice_tree + account.invoice + + + + - + diff --git a/account_payment_partner/views/account_move_line.xml b/account_payment_partner/views/account_move_line.xml new file mode 100644 index 000000000..b0d0ca102 --- /dev/null +++ b/account_payment_partner/views/account_move_line.xml @@ -0,0 +1,28 @@ + + + + + + + + + + account_payment_partner.move_line_form + account.move.line + + + + + + + + + + + + + diff --git a/account_payment_partner/views/payment_mode.xml b/account_payment_partner/views/payment_mode.xml deleted file mode 100644 index 120ca6970..000000000 --- a/account_payment_partner/views/payment_mode.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - account_payment_partner.payment.mode.form - payment.mode - - - - - - - - - - - diff --git a/account_payment_partner/views/report_invoice.xml b/account_payment_partner/views/report_invoice.xml index 356ec1d4d..9368238f1 100644 --- a/account_payment_partner/views/report_invoice.xml +++ b/account_payment_partner/views/report_invoice.xml @@ -2,7 +2,7 @@