diff --git a/account_banking_mandate/models/__init__.py b/account_banking_mandate/models/__init__.py index 4ffd1831d..145c8921a 100644 --- a/account_banking_mandate/models/__init__.py +++ b/account_banking_mandate/models/__init__.py @@ -2,7 +2,6 @@ from . import account_banking_mandate from . import account_payment_method -from . import account_payment_order from . import account_invoice from . import res_partner_bank from . import res_partner diff --git a/account_banking_mandate/models/account_invoice.py b/account_banking_mandate/models/account_invoice.py index 46d884493..140a78229 100644 --- a/account_banking_mandate/models/account_invoice.py +++ b/account_banking_mandate/models/account_invoice.py @@ -50,9 +50,9 @@ class AccountInvoice(models.Model): super(AccountInvoice, self)._onchange_partner_id() if ( self.type == 'out_invoice' and - self.partner_id.customer_payment_mode_id.\ + self.partner_id.customer_payment_mode_id. payment_type == 'inbound' and - self.partner_id.customer_payment_mode_id.payment_method_id.\ + self.partner_id.customer_payment_mode_id.payment_method_id. mandate_required and self.commercial_partner_id): mandates = self.env['account.banking.mandate'].search([ diff --git a/account_banking_mandate/models/account_payment_line.py b/account_banking_mandate/models/account_payment_line.py index bb0a2cb43..4650b2f98 100644 --- a/account_banking_mandate/models/account_payment_line.py +++ b/account_banking_mandate/models/account_payment_line.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api, _ -from openerp.exceptions import ValidationError +from openerp.exceptions import ValidationError, UserError class AccountPaymentLine(models.Model): @@ -14,6 +14,8 @@ class AccountPaymentLine(models.Model): mandate_id = fields.Many2one( comodel_name='account.banking.mandate', string='Direct Debit Mandate', domain=[('state', '=', 'valid')]) + mandate_required = fields.Boolean( + related='order_id.payment_method_id.mandate_required', readonly=True) @api.multi @api.constrains('mandate_id', 'partner_bank_id') @@ -31,7 +33,10 @@ class AccountPaymentLine(models.Model): pline.mandate_id.unique_mandate_reference, pline.mandate_id.partner_bank_id.acc_number)) -# @api.multi -# def check_payment_line(self): -# TODO : i would like to block here is mandate is missing... -# but how do you know it's required ? => create option on payment order ? + @api.multi + def draft2open_payment_line_check(self): + res = super(AccountPaymentLine, self).draft2open_payment_line_check() + if self.mandate_required and not self.mandate_id: + raise UserError(_( + 'Missing Mandate on payment line %s') % self.name) + return res diff --git a/account_banking_mandate/models/account_payment_order.py b/account_banking_mandate/models/account_payment_order.py deleted file mode 100644 index 1d6ef8e7d..000000000 --- a/account_banking_mandate/models/account_payment_order.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Akretion (Alexis de Lattre - alexis.delattre@akretion.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openerp import models, api, _ -from openerp.exceptions import UserError - - -class AccountPaymentOrder(models.Model): - _inherit = 'account.payment.order' - - @api.multi - def draft2open(self): - for order in self: - if order.payment_mode_id.payment_method_id.mandate_required: - for line in order.payment_line_ids: - if not line.mandate_id: - raise UserError(_( - "Missing mandate in payment line %s") % line.name) - return super(AccountPaymentOrder, self).draft2open() diff --git a/account_banking_mandate/views/account_payment_line.xml b/account_banking_mandate/views/account_payment_line.xml index 48e6a753f..55f1c0297 100644 --- a/account_banking_mandate/views/account_payment_line.xml +++ b/account_banking_mandate/views/account_payment_line.xml @@ -1,10 +1,9 @@ - + @@ -13,9 +12,10 @@ + @@ -34,4 +34,4 @@ - + diff --git a/account_banking_mandate/views/account_payment_method.xml b/account_banking_mandate/views/account_payment_method.xml index c6067e150..66744a970 100644 --- a/account_banking_mandate/views/account_payment_method.xml +++ b/account_banking_mandate/views/account_payment_method.xml @@ -6,9 +6,9 @@ account_banking_mandate.account.payment.method.form account.payment.method - + - + 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 f183ee6b9..85c94c724 100644 --- a/account_banking_sepa_credit_transfer/models/account_payment_order.py +++ b/account_banking_sepa_credit_transfer/models/account_payment_order.py @@ -15,12 +15,10 @@ class AccountPaymentOrder(models.Model): def generate_payment_file(self): """Creates the SEPA Credit Transfer file. That's the important code!""" self.ensure_one() - if ( - self.payment_mode_id.payment_method_id.code != - 'sepa_credit_transfer'): + if self.payment_method_id.code != 'sepa_credit_transfer': return super(AccountPaymentOrder, self).generate_payment_file() - pain_flavor = self.payment_mode_id.payment_method_id.pain_version + pain_flavor = self.payment_method_id.pain_version if not pain_flavor: pain_flavor = 'pain.001.001.03' # We use pain_flavor.startswith('pain.001.001.xx') @@ -60,12 +58,11 @@ class AccountPaymentOrder(models.Model): else: raise UserError( _("PAIN version '%s' is not supported.") % pain_flavor) - pay_method = self.payment_mode_id.payment_method_id - xsd_file = pay_method.get_xsd_file_path() + xsd_file = self.payment_method_id.get_xsd_file_path() gen_args = { 'bic_xml_tag': bic_xml_tag, 'name_maxsize': name_maxsize, - 'convert_to_ascii': pay_method.convert_to_ascii, + 'convert_to_ascii': self.payment_method_id.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 ff1d28d66..67a3339f6 100644 --- a/account_banking_sepa_direct_debit/data/account_payment_method.xml +++ b/account_banking_sepa_direct_debit/data/account_payment_method.xml @@ -7,6 +7,7 @@ SEPA Direct Debit for customers sepa_direct_debit inbound + pain.008.001.02 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 38e6daa22..16bd8557b 100644 --- a/account_banking_sepa_direct_debit/models/account_payment_order.py +++ b/account_banking_sepa_direct_debit/models/account_payment_order.py @@ -36,10 +36,10 @@ class AccountPaymentOrder(models.Model): """Creates the SEPA Direct Debit file. That's the important code !""" self.ensure_one() if ( - self.payment_mode_id.payment_method_id.code != + self.payment_method_id.code != 'sepa_direct_debit'): return super(AccountPaymentOrder, self).generate_payment_file() - pain_flavor = self.payment_mode_id.payment_method_id.pain_version + pain_flavor = self.payment_method_id.pain_version # We use pain_flavor.startswith('pain.008.001.xx') # to support country-specific extensions such as # pain.008.001.02.ch.01 (cf l10n_ch_sepa) diff --git a/account_payment_mode/models/account_payment_method.py b/account_payment_mode/models/account_payment_method.py index 5387f3843..748027a4d 100644 --- a/account_payment_mode/models/account_payment_method.py +++ b/account_payment_mode/models/account_payment_method.py @@ -15,7 +15,10 @@ class AccountPaymentMethod(models.Model): "this payment method. Therefore, if you change it, " "the generation of the payment file may fail.") active = fields.Boolean(string='Active', default=True) - # In the pain_base module, we will add a default_pain_version + bank_account_required = fields.Boolean( + string='Bank Account Required', + help="Activate this option if this payment method requires you to " + "know the bank account number of your customer or supplier.") display_name = fields.Char( compute='compute_display_name', store=True, string='Display Name') diff --git a/account_payment_mode/views/account_payment_method.xml b/account_payment_mode/views/account_payment_method.xml index f912e45e9..f467f01f6 100644 --- a/account_payment_mode/views/account_payment_method.xml +++ b/account_payment_mode/views/account_payment_method.xml @@ -1,5 +1,5 @@ - + + @@ -59,4 +60,4 @@ here. I hate the objects that don't have a view... --> sequence="30" /> - + diff --git a/account_payment_order/models/account_payment_line.py b/account_payment_order/models/account_payment_line.py index 2ac4fbfac..5df4c2644 100644 --- a/account_payment_order/models/account_payment_line.py +++ b/account_payment_order/models/account_payment_line.py @@ -20,6 +20,9 @@ class AccountPaymentLine(models.Model): related='order_id.company_currency_id', store=True, readonly=True) payment_type = fields.Selection( related='order_id.payment_type', store=True, readonly=True) + bank_account_required = fields.Boolean( + related='order_id.payment_method_id.bank_account_required', + readonly=True) state = fields.Selection( related='order_id.state', string='State', readonly=True, store=True) @@ -127,9 +130,8 @@ class AccountPaymentLine(models.Model): return res @api.multi - def check_payment_line(self): - for line in self: - if not line.partner_bank_id: - raise UserError(_( - 'Missing Partner Bank Account on payment line %s') - % line.name) + def draft2open_payment_line_check(self): + self.ensure_one() + if self.bank_account_required and not self.partner_bank_id: + raise UserError(_( + 'Missing Partner Bank Account on payment line %s') % self.name) diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index b3ce326d4..e1e0163a2 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -25,6 +25,9 @@ class AccountPaymentOrder(models.Model): ('inbound', 'Inbound'), ('outbound', 'Outbound'), ], string='Payment Type', readonly=True, required=True) + payment_method_id = fields.Many2one( + 'account.payment.method', related='payment_mode_id.payment_method_id', + readonly=True, store=True) company_id = fields.Many2one( related='payment_mode_id.company_id', store=True, readonly=True) company_currency_id = fields.Many2one( @@ -210,7 +213,7 @@ class AccountPaymentOrder(models.Model): # Create the bank payment lines from the payment lines group_paylines = {} # key = hashcode for payline in order.payment_line_ids: - payline.check_payment_line() + payline.draft2open_payment_line_check() # Compute requested payment date if order.date_prefered == 'due': requested_date = payline.ml_maturity_date or today diff --git a/account_payment_order/views/account_payment_line.xml b/account_payment_order/views/account_payment_line.xml index 152c119d4..c1155ac03 100644 --- a/account_payment_order/views/account_payment_line.xml +++ b/account_payment_order/views/account_payment_line.xml @@ -18,7 +18,10 @@ - + + diff --git a/account_payment_partner/__openerp__.py b/account_payment_partner/__openerp__.py index 844f5a553..8c1068021 100644 --- a/account_payment_partner/__openerp__.py +++ b/account_payment_partner/__openerp__.py @@ -16,7 +16,6 @@ 'depends': ['account_payment_mode'], 'data': [ 'views/res_partner_view.xml', - 'views/account_payment_method.xml', 'views/account_invoice_view.xml', 'views/account_move_line.xml', 'views/report_invoice.xml', diff --git a/account_payment_partner/models/__init__.py b/account_payment_partner/models/__init__.py index caea9e62c..152bb919c 100644 --- a/account_payment_partner/models/__init__.py +++ b/account_payment_partner/models/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- from . import res_partner -from . import account_payment_method from . import account_invoice from . import account_move_line diff --git a/account_payment_partner/models/account_invoice.py b/account_payment_partner/models/account_invoice.py index ac7d6827e..14ac17a77 100644 --- a/account_payment_partner/models/account_invoice.py +++ b/account_payment_partner/models/account_invoice.py @@ -29,7 +29,8 @@ class AccountInvoice(models.Model): 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] + 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 @@ -46,13 +47,11 @@ class AccountInvoice(models.Model): 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): + not self.payment_mode_id.payment_method_id. + bank_account_required): self.partner_bank_id = False - print "false" elif not self.payment_mode_id: self.partner_bank_id = False - print "false" @api.model def line_get_convert(self, line, part): diff --git a/account_payment_partner/models/account_payment_method.py b/account_payment_partner/models/account_payment_method.py deleted file mode 100644 index 97289f14f..000000000 --- a/account_payment_partner/models/account_payment_method.py +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2016 Akretion (Alexis de Lattre ) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openerp import models, fields - - -class AccountPaymentMethod(models.Model): - _inherit = "account.payment.method" - - bank_account_required = fields.Boolean( - string='Bank Account Required', - help="Activate this option if this payment method requires to " - "set the bank account of your supplier on the vendor bills.") diff --git a/account_payment_partner/views/account_payment_method.xml b/account_payment_partner/views/account_payment_method.xml deleted file mode 100644 index 4f2448ffa..000000000 --- a/account_payment_partner/views/account_payment_method.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - account_payment_partner.account.payment.method.form - account.payment.method - - - - - - - - - - -