From 4e6261a9b1b3b16608911aab2f8850bdda5b422e Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 10 May 2016 23:16:31 +0200 Subject: [PATCH] Move fields mandate_required and export_ascii from payment mode to payment method Display chatter on payment orders Several small usability improvements --- account_banking_mandate/__openerp__.py | 2 +- account_banking_mandate/models/__init__.py | 5 +---- account_banking_mandate/models/account_invoice.py | 2 +- ...t_payment_mode.py => account_payment_method.py} | 6 +++--- .../models/account_payment_order.py | 2 +- ...payment_mode.xml => account_payment_method.xml} | 12 ++++++------ account_banking_mandate_sale/models/sale_order.py | 4 +++- .../models/account_payment_method.py | 5 +++++ .../models/account_payment_mode.py | 5 ----- .../models/account_payment_order.py | 11 +++++++---- .../views/account_payment_method.xml | 2 ++ .../views/account_payment_mode.xml | 1 - .../data/account_payment_method.xml | 2 +- .../models/account_payment_order.py | 5 +++-- .../data/account_payment_method.xml | 3 ++- .../demo/sepa_direct_debit_demo.xml | 1 - .../models/account_banking_mandate.py | 14 ++++++++++++++ .../models/account_payment_order.py | 5 +++-- .../views/account_banking_mandate_view.xml | 6 +++--- .../models/account_payment_order.py | 12 ++++++++---- .../views/account_payment_order.xml | 6 +++++- 21 files changed, 69 insertions(+), 42 deletions(-) rename account_banking_mandate/models/{account_payment_mode.py => account_payment_method.py} (68%) rename account_banking_mandate/views/{account_payment_mode.xml => account_payment_method.xml} (52%) diff --git a/account_banking_mandate/__openerp__.py b/account_banking_mandate/__openerp__.py index a53d4e75b..01242f081 100644 --- a/account_banking_mandate/__openerp__.py +++ b/account_banking_mandate/__openerp__.py @@ -20,7 +20,7 @@ ], 'data': [ 'views/account_banking_mandate_view.xml', - 'views/account_payment_mode.xml', + 'views/account_payment_method.xml', 'views/account_invoice_view.xml', 'views/account_payment_line.xml', 'views/res_partner_bank_view.xml', diff --git a/account_banking_mandate/models/__init__.py b/account_banking_mandate/models/__init__.py index 50af22b59..acec851ac 100644 --- a/account_banking_mandate/models/__init__.py +++ b/account_banking_mandate/models/__init__.py @@ -1,10 +1,7 @@ # -*- coding: utf-8 -*- -# © 2014 Compassion CH - Cyril Sester -# © 2015 Akretion - Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import account_banking_mandate -from . import account_payment_mode +from . import account_payment_method from . import account_payment_order from . import account_invoice from . import res_partner_bank diff --git a/account_banking_mandate/models/account_invoice.py b/account_banking_mandate/models/account_invoice.py index 12afdc33e..23255c58e 100644 --- a/account_banking_mandate/models/account_invoice.py +++ b/account_banking_mandate/models/account_invoice.py @@ -47,7 +47,7 @@ class AccountInvoice(models.Model): if ( self.type in ('out_invoice', 'out_refund') and self.payment_mode_id.payment_type == 'inbound' and - self.payment_mode_id.mandate_required and + self.payment_mode_id.payment_method_id.mandate_required and self.partner_id): mandates = self.env['account.banking.mandate'].search([ ('state', '=', 'valid'), diff --git a/account_banking_mandate/models/account_payment_mode.py b/account_banking_mandate/models/account_payment_method.py similarity index 68% rename from account_banking_mandate/models/account_payment_mode.py rename to account_banking_mandate/models/account_payment_method.py index 6f46ab430..589506a9c 100644 --- a/account_banking_mandate/models/account_payment_mode.py +++ b/account_banking_mandate/models/account_payment_method.py @@ -5,10 +5,10 @@ from openerp import models, fields -class AccountPaymentMode(models.Model): - _inherit = "account.payment.mode" +class AccountPaymentMethod(models.Model): + _inherit = "account.payment.method" mandate_required = fields.Boolean( string='Mandate Required', - help="Activate this option is this payment mode requires your " + help="Activate this option is this payment method requires your " "customer to sign a direct debit mandate with your company.") diff --git a/account_banking_mandate/models/account_payment_order.py b/account_banking_mandate/models/account_payment_order.py index c9f762c95..1d6ef8e7d 100644 --- a/account_banking_mandate/models/account_payment_order.py +++ b/account_banking_mandate/models/account_payment_order.py @@ -12,7 +12,7 @@ class AccountPaymentOrder(models.Model): @api.multi def draft2open(self): for order in self: - if order.payment_mode_id.mandate_required: + if order.payment_mode_id.payment_method_id.mandate_required: for line in order.payment_line_ids: if not line.mandate_id: raise UserError(_( diff --git a/account_banking_mandate/views/account_payment_mode.xml b/account_banking_mandate/views/account_payment_method.xml similarity index 52% rename from account_banking_mandate/views/account_payment_mode.xml rename to account_banking_mandate/views/account_payment_method.xml index 488251185..2d4079533 100644 --- a/account_banking_mandate/views/account_payment_mode.xml +++ b/account_banking_mandate/views/account_payment_method.xml @@ -3,15 +3,15 @@ - - account_banking_mandate.account.payment.mode.form - account.payment.mode - + + account_banking_mandate.account.payment.method.form + account.payment.method + - + - + diff --git a/account_banking_mandate_sale/models/sale_order.py b/account_banking_mandate_sale/models/sale_order.py index beba347e8..5f4fc9cf9 100644 --- a/account_banking_mandate_sale/models/sale_order.py +++ b/account_banking_mandate_sale/models/sale_order.py @@ -28,7 +28,9 @@ class SaleOrder(models.Model): @api.onchange('payment_mode_id') def payment_mode_change(self): """Select by default the first valid mandate of the partner""" - if self.payment_mode_id.mandate_required and self.partner_id: + if ( + self.payment_mode_id.payment_method_id.mandate_required and + self.partner_id): mandates = self.env['account.banking.mandate'].search([ ('state', '=', 'valid'), ('partner_id', '=', self.commercial_partner_id.id), diff --git a/account_banking_pain_base/models/account_payment_method.py b/account_banking_pain_base/models/account_payment_method.py index 90b485fa0..2d517e3db 100644 --- a/account_banking_pain_base/models/account_payment_method.py +++ b/account_banking_pain_base/models/account_payment_method.py @@ -10,6 +10,11 @@ class AccountPaymentMethod(models.Model): _inherit = 'account.payment.method' pain_version = fields.Selection([], string='PAIN Version') + convert_to_ascii = fields.Boolean( + string='Convert to ASCII', default=True, + help="If active, Odoo will convert each accented caracter to " + "the corresponding unaccented caracter, so that only ASCII " + "caracters are used in the generated PAIN file.") @api.multi def get_xsd_file_path(self): diff --git a/account_banking_pain_base/models/account_payment_mode.py b/account_banking_pain_base/models/account_payment_mode.py index fd36ea3cd..e0e628a59 100644 --- a/account_banking_pain_base/models/account_payment_mode.py +++ b/account_banking_pain_base/models/account_payment_mode.py @@ -10,11 +10,6 @@ from openerp import models, fields class AccountPaymentMode(models.Model): _inherit = 'account.payment.mode' - convert_to_ascii = fields.Boolean( - string='Convert to ASCII', default=True, - help="If active, Odoo will convert each accented caracter to " - "the corresponding unaccented caracter, so that only ASCII " - "caracters are used in the generated PAIN file.") initiating_party_issuer = fields.Char( string='Initiating Party Issuer', size=35, help="This will be used as the 'Initiating Party Issuer' in the " diff --git a/account_banking_pain_base/models/account_payment_order.py b/account_banking_pain_base/models/account_payment_order.py index a7e7106b9..d4ea8e6e5 100644 --- a/account_banking_pain_base/models/account_payment_order.py +++ b/account_banking_pain_base/models/account_payment_order.py @@ -10,14 +10,15 @@ class AccountPaymentOrder(models.Model): _inherit = 'account.payment.order' sepa = fields.Boolean( - compute='compute_sepa', readonly=True, - string="SEPA Payment") + compute='compute_sepa', readonly=True, string="SEPA Payment") charge_bearer = fields.Selection([ ('SLEV', 'Following Service Level'), ('SHAR', 'Shared'), ('CRED', 'Borne by Creditor'), ('DEBT', 'Borne by Debtor')], string='Charge Bearer', - default='SLEV', + default='SLEV', readonly=True, + states={'draft': [('readonly', False)], 'open': [('readonly', False)]}, + track_visibility='onchange', help="Following service level : transaction charges are to be " "applied following the rules agreed in the service level " "and/or scheme (SEPA Core messages must use this). Shared : " @@ -28,7 +29,9 @@ class AccountPaymentOrder(models.Model): "by debtor : all transaction charges are to be borne by the " "debtor.") batch_booking = fields.Boolean( - string='Batch Booking', + string='Batch Booking', readonly=True, + states={'draft': [('readonly', False)], 'open': [('readonly', False)]}, + track_visibility='onchange', help="If true, the bank statement will display only one debit " "line for all the wire transfers of the SEPA XML file ; if " "false, the bank statement will display one debit line per wire " diff --git a/account_banking_pain_base/views/account_payment_method.xml b/account_banking_pain_base/views/account_payment_method.xml index 7a9e65982..8d223b2b0 100644 --- a/account_banking_pain_base/views/account_payment_method.xml +++ b/account_banking_pain_base/views/account_payment_method.xml @@ -10,6 +10,8 @@ + diff --git a/account_banking_pain_base/views/account_payment_mode.xml b/account_banking_pain_base/views/account_payment_mode.xml index d92a5e786..cc7346dd6 100644 --- a/account_banking_pain_base/views/account_payment_mode.xml +++ b/account_banking_pain_base/views/account_payment_mode.xml @@ -16,7 +16,6 @@ - diff --git a/account_banking_sepa_credit_transfer/data/account_payment_method.xml b/account_banking_sepa_credit_transfer/data/account_payment_method.xml index 36a8961c8..307ad7d46 100644 --- a/account_banking_sepa_credit_transfer/data/account_payment_method.xml +++ b/account_banking_sepa_credit_transfer/data/account_payment_method.xml @@ -1,6 +1,6 @@ - + diff --git a/account_banking_sepa_credit_transfer/models/account_payment_order.py b/account_banking_sepa_credit_transfer/models/account_payment_order.py index 57b7b0602..29c746b1c 100644 --- a/account_banking_sepa_credit_transfer/models/account_payment_order.py +++ b/account_banking_sepa_credit_transfer/models/account_payment_order.py @@ -57,11 +57,12 @@ class AccountPaymentOrder(models.Model): else: raise UserError( _("PAIN version '%s' is not supported.") % pain_flavor) - xsd_file = self.payment_mode_id.payment_method_id.get_xsd_file_path() + pay_method = self.payment_mode_id.payment_method_id + xsd_file = pay_method.get_xsd_file_path() gen_args = { 'bic_xml_tag': bic_xml_tag, 'name_maxsize': name_maxsize, - 'convert_to_ascii': self.payment_mode_id.convert_to_ascii, + 'convert_to_ascii': pay_method.convert_to_ascii, 'payment_method': 'TRF', 'file_prefix': 'sct_', 'pain_flavor': pain_flavor, diff --git a/account_banking_sepa_direct_debit/data/account_payment_method.xml b/account_banking_sepa_direct_debit/data/account_payment_method.xml index d2ef66bfd..ff1d28d66 100644 --- a/account_banking_sepa_direct_debit/data/account_payment_method.xml +++ b/account_banking_sepa_direct_debit/data/account_payment_method.xml @@ -1,12 +1,13 @@ - + SEPA Direct Debit for customers sepa_direct_debit inbound + pain.008.001.02 diff --git a/account_banking_sepa_direct_debit/demo/sepa_direct_debit_demo.xml b/account_banking_sepa_direct_debit/demo/sepa_direct_debit_demo.xml index 2eeca210b..a93f87b3f 100644 --- a/account_banking_sepa_direct_debit/demo/sepa_direct_debit_demo.xml +++ b/account_banking_sepa_direct_debit/demo/sepa_direct_debit_demo.xml @@ -9,7 +9,6 @@ variable - diff --git a/account_banking_sepa_direct_debit/models/account_banking_mandate.py b/account_banking_sepa_direct_debit/models/account_banking_mandate.py index 2c065b4ef..744903cb6 100644 --- a/account_banking_sepa_direct_debit/models/account_banking_mandate.py +++ b/account_banking_sepa_direct_debit/models/account_banking_mandate.py @@ -16,6 +16,7 @@ logger = logging.getLogger(__name__) class AccountBankingMandate(models.Model): """SEPA Direct Debit Mandate""" _inherit = 'account.banking.mandate' + _rec_name = 'display_name' format = fields.Selection( selection_add=[('sepa', 'Sepa Mandate')], default='sepa') @@ -35,6 +36,7 @@ class AccountBankingMandate(models.Model): ('B2B', 'Enterprise (B2B)')], string='Scheme', default="CORE", track_visibility='onchange') unique_mandate_reference = fields.Char(size=35) # cf ISO 20022 + display_name = fields.Char(compute='compute_display_name', store=True) @api.multi @api.constrains('type', 'recurrent_sequence_type') @@ -46,6 +48,18 @@ class AccountBankingMandate(models.Model): _("The recurrent mandate '%s' must have a sequence type.") % mandate.unique_mandate_reference) + @api.multi + @api.depends('unique_mandate_reference', 'recurrent_sequence_type') + def compute_display_name(self): + for mandate in self: + if mandate.format == 'sepa': + name = '%s (%s)' % ( + mandate.unique_mandate_reference, + mandate.recurrent_sequence_type) + else: + name = mandate.unique_mandate_reference + mandate.display_name = name + @api.multi @api.onchange('partner_bank_id') def mandate_partner_bank_change(self): diff --git a/account_banking_sepa_direct_debit/models/account_payment_order.py b/account_banking_sepa_direct_debit/models/account_payment_order.py index 047ab1f12..58aee5bf5 100644 --- a/account_banking_sepa_direct_debit/models/account_payment_order.py +++ b/account_banking_sepa_direct_debit/models/account_payment_order.py @@ -62,11 +62,12 @@ class AccountPaymentOrder(models.Model): "Payment Type Code supported for SEPA Direct Debit are " "'pain.008.001.02', 'pain.008.001.03' and " "'pain.008.001.04'.") % pain_flavor) - xsd_file = self.payment_mode_id.payment_method_id.get_xsd_file_path() + pay_method = self.payment_mode_id.payment_method_id + xsd_file = pay_method.get_xsd_file_path() gen_args = { 'bic_xml_tag': bic_xml_tag, 'name_maxsize': name_maxsize, - 'convert_to_ascii': self.payment_mode_id.convert_to_ascii, + 'convert_to_ascii': pay_method.convert_to_ascii, 'payment_method': 'DD', 'file_prefix': 'sdd_', 'pain_flavor': pain_flavor, diff --git a/account_banking_sepa_direct_debit/views/account_banking_mandate_view.xml b/account_banking_sepa_direct_debit/views/account_banking_mandate_view.xml index 7d8d73312..c27dcb175 100644 --- a/account_banking_sepa_direct_debit/views/account_banking_mandate_view.xml +++ b/account_banking_sepa_direct_debit/views/account_banking_mandate_view.xml @@ -17,13 +17,13 @@ + - @@ -34,8 +34,8 @@ - + diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index ed037cef9..9f36ae853 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -16,8 +16,7 @@ class AccountPaymentOrder(models.Model): _order = 'id desc' name = fields.Char( - string='Number', readonly=True, copy=False, - track_visibility='onchange') # v8 field : name + string='Number', readonly=True, copy=False) # v8 field : name payment_mode_id = fields.Many2one( 'account.payment.mode', 'Payment Method', required=True, ondelete='restrict', track_visibility='onchange', @@ -35,7 +34,8 @@ class AccountPaymentOrder(models.Model): related='payment_mode_id.bank_account_link', readonly=True) journal_id = fields.Many2one( 'account.journal', string='Bank Journal', ondelete='restrict', - readonly=True, states={'draft': [('readonly', False)]}) + readonly=True, states={'draft': [('readonly', False)]}, + track_visibility='onchange') allowed_journal_ids = fields.Many2many( 'account.journal', compute='_compute_allowed_journals', readonly=True, string='Selectable Bank Journals') @@ -200,7 +200,11 @@ class AccountPaymentOrder(models.Model): for order in self: if not order.journal_id: raise UserError(_( - 'Missing Bank Journal on payment order %s') % order.name) + 'Missing Bank Journal on payment order %s.') % order.name) + if not order.payment_line_ids: + raise UserError(_( + 'There are no transactions on payment order %s.') + % order.name) # Delete existing bank payment lines order.bank_line_ids.unlink() # Create the bank payment lines from the payment lines diff --git a/account_payment_order/views/account_payment_order.xml b/account_payment_order/views/account_payment_order.xml index f2818659b..8ac4691c5 100644 --- a/account_payment_order/views/account_payment_order.xml +++ b/account_payment_order/views/account_payment_order.xml @@ -46,7 +46,7 @@ + attrs="{'invisible': [('date_prefered', '!=', 'fixed')], 'required': [('date_prefered', '=', 'fixed')]}"/> @@ -66,6 +66,10 @@ +
+ + +