diff --git a/account_banking_pain_base/banking_export_pain.py b/account_banking_pain_base/banking_export_pain.py index 334c106c2..ffabe82dc 100644 --- a/account_banking_pain_base/banking_export_pain.py +++ b/account_banking_pain_base/banking_export_pain.py @@ -271,3 +271,20 @@ class banking_export_pain(orm.AbstractModel): convert_to_ascii=gen_args.get('convert_to_ascii'), context=context) return True + + def generate_creditor_scheme_identification( + self, cr, uid, parent_node, identification, identification_label, + eval_ctx, scheme_name_proprietary, gen_args, context=None): + csi_id = etree.SubElement( + parent_node, 'Id') + csi_privateid = csi_id = etree.SubElement(csi_id, 'PrvtId') + csi_other = etree.SubElement(csi_privateid, 'Othr') + csi_other_id = etree.SubElement(csi_other, 'Id') + csi_other_id.text = self._prepare_field( + cr, uid, identification_label, identification, eval_ctx, + convert_to_ascii=gen_args.get('convert_to_ascii'), context=context) + csi_scheme_name = etree.SubElement(csi_other, 'SchmeNm') + csi_scheme_name_proprietary = etree.SubElement( + csi_scheme_name, 'Prtry') + csi_scheme_name_proprietary.text = scheme_name_proprietary + return True diff --git a/account_banking_sepa_direct_debit/account_banking_sdd.py b/account_banking_sepa_direct_debit/account_banking_sdd.py index 7b2be778f..b54f3002c 100644 --- a/account_banking_sepa_direct_debit/account_banking_sdd.py +++ b/account_banking_sepa_direct_debit/account_banking_sdd.py @@ -148,6 +148,12 @@ class sdd_mandate(orm.Model): help="Only valid mandates can be used in a payment line. A cancelled mandate is a mandate that has been cancelled by the customer. A one-off mandate expires after its first use. A recurrent mandate expires after it's final use or if it hasn't been used for 36 months."), 'payment_line_ids': fields.one2many( 'payment.line', 'sdd_mandate_id', "Related Payment Lines"), + 'sepa_migrated': fields.boolean( + 'Migrated to SEPA', + help="If this field is not active, the mandate section of the direct debit file will contain the Original Mandate Identification and the Original Creditor Scheme Identification."), + 'original_mandate_identification': fields.char( + 'Original Mandate Identification', size=35, + help="When the field 'Migrated to SEPA' is not active, this field will be used as the Original Mandate Identification in the the Direct Debit file."), } _defaults = { @@ -157,6 +163,7 @@ class sdd_mandate(orm.Model): 'unique_mandate_reference': lambda self, cr, uid, ctx: self.pool['ir.sequence'].get(cr, uid, 'sdd.mandate.reference'), 'state': 'draft', + 'sepa_migrated': True, } _sql_constraints = [( diff --git a/account_banking_sepa_direct_debit/company.py b/account_banking_sepa_direct_debit/company.py index eb3730d57..ba4c7b7c8 100644 --- a/account_banking_sepa_direct_debit/company.py +++ b/account_banking_sepa_direct_debit/company.py @@ -32,6 +32,8 @@ class res_company(orm.Model): 'sepa_creditor_identifier': fields.char( 'SEPA Creditor Identifier', size=35, help="Enter the Creditor Identifier that has been attributed to your company to make SEPA Direct Debits. This identifier is composed of :\n- your country ISO code (2 letters)\n- a 2-digits checkum\n- a 3-letters business code\n- a country-specific identifier"), + 'original_creditor_identifier': fields.char( + 'Original Creditor Identifier', size=70), } def is_sepa_creditor_identifier_valid( diff --git a/account_banking_sepa_direct_debit/company_view.xml b/account_banking_sepa_direct_debit/company_view.xml index 7691844c1..4599454f5 100644 --- a/account_banking_sepa_direct_debit/company_view.xml +++ b/account_banking_sepa_direct_debit/company_view.xml @@ -14,6 +14,7 @@ + diff --git a/account_banking_sepa_direct_debit/sdd_mandate_view.xml b/account_banking_sepa_direct_debit/sdd_mandate_view.xml index ad11d8804..15ec3a675 100644 --- a/account_banking_sepa_direct_debit/sdd_mandate_view.xml +++ b/account_banking_sepa_direct_debit/sdd_mandate_view.xml @@ -35,6 +35,8 @@ + + diff --git a/account_banking_sepa_direct_debit/wizard/export_sdd.py b/account_banking_sepa_direct_debit/wizard/export_sdd.py index 59d031362..babec1260 100644 --- a/account_banking_sepa_direct_debit/wizard/export_sdd.py +++ b/account_banking_sepa_direct_debit/wizard/export_sdd.py @@ -302,20 +302,11 @@ class banking_export_sdd_wizard(orm.TransientModel): creditor_scheme_identification_2_27 = etree.SubElement( payment_info_2_0, 'CdtrSchmeId') - csi_id = etree.SubElement( - creditor_scheme_identification_2_27, 'Id') - csi_privateid = csi_id = etree.SubElement(csi_id, 'PrvtId') - csi_other = etree.SubElement(csi_privateid, 'Othr') - csi_other_id = etree.SubElement(csi_other, 'Id') - csi_other_id.text = self._prepare_field( - cr, uid, 'SEPA Creditor Identifier', + self.generate_creditor_scheme_identification( + cr, uid, creditor_scheme_identification_2_27, 'sepa_export.payment_order_ids[0].company_id.sepa_creditor_identifier', - {'sepa_export': sepa_export}, - convert_to_ascii=convert_to_ascii, context=context) - csi_scheme_name = etree.SubElement(csi_other, 'SchmeNm') - csi_scheme_name_proprietary = etree.SubElement( - csi_scheme_name, 'Prtry') - csi_scheme_name_proprietary.text = 'SEPA' + 'SEPA Creditor Identifier', {'sepa_export': sepa_export}, + 'SEPA', gen_args, context=context) transactions_count_2_4 = 0 amount_control_sum_2_5 = 0.0 @@ -359,16 +350,18 @@ class banking_export_sdd_wizard(orm.TransientModel): 'line.sdd_mandate_id.signature_date', {'line': line}, 10, convert_to_ascii=convert_to_ascii, context=context) - if (sequence_type == 'FRST' - and line.sdd_mandate_id.last_debit_date): + if sequence_type == 'FRST' and ( + line.sdd_mandate_id.last_debit_date or + not line.sdd_mandate_id.sepa_migrated): previous_bank = self._get_previous_bank( cr, uid, line, context=context) - if previous_bank: + if previous_bank or not line.sdd_mandate_id.sepa_migrated: amendment_indicator_2_50 = etree.SubElement( mandate_related_info_2_47, 'AmdmntInd') amendment_indicator_2_50.text = 'true' amendment_info_details_2_51 = etree.SubElement( mandate_related_info_2_47, 'AmdmntInfDtls') + if previous_bank: if previous_bank.bank.bic == line.bank_id.bank.bic: ori_debtor_account_2_57 = etree.SubElement( amendment_info_details_2_51, 'OrgnlDbtrAcct') @@ -403,6 +396,24 @@ class banking_export_sdd_wizard(orm.TransientModel): ori_debtor_agent_other, 'Id') ori_debtor_agent_other_id.text = 'SMNDA' # SMNDA = Same Mandate New Debtor Agent + elif not line.sdd_mandate_id.sepa_migrated: + ori_mandate_identification_2_52 = etree.SubElement( + amendment_info_details_2_51, 'OrgnlMndtId') + ori_mandate_identification_2_52.text = \ + self._prepare_field( + cr, uid, 'Original Mandate Identification', + 'line.sdd_mandate_id.original_mandate_identification', + {'line': line}, + convert_to_ascii=convert_to_ascii, + context=context) + ori_creditor_scheme_id_2_53 = etree.SubElement( + amendment_info_details_2_51, 'OrgnlCdtrSchmeId') + self.generate_creditor_scheme_identification( + cr, uid, ori_creditor_scheme_id_2_53, + 'sepa_export.payment_order_ids[0].company_id.original_creditor_identifier', + 'Original Creditor Identifier', + {'sepa_export': sepa_export}, + 'SEPA', gen_args, context=context) self.generate_party_block( cr, uid, dd_transaction_info_2_28, 'Dbtr', 'C', @@ -494,6 +505,8 @@ class banking_export_sdd_wizard(orm.TransientModel): self.pool['sdd.mandate'].write( cr, uid, to_expire_ids, {'state': 'expired'}, context=context) self.pool['sdd.mandate'].write( - cr, uid, first_mandate_ids, - {'recurrent_sequence_type': 'recurring'}, context=context) + cr, uid, first_mandate_ids, { + 'recurrent_sequence_type': 'recurring', + 'sepa_migrated': True, + }, context=context) return {'type': 'ir.actions.act_window_close'}