Skip to content

Commit

Permalink
[MIG] l10n_ch_pain_base: Migration to 16.0
Browse files Browse the repository at this point in the history
Remove dependency on l10n_ch_base_bank since it is obsolete
  • Loading branch information
BT-anieto committed Jun 13, 2024
1 parent 38f5891 commit 92d8c1a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 106 deletions.
4 changes: 2 additions & 2 deletions l10n_ch_pain_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
{
"name": "Switzerland - ISO 20022",
"summary": "ISO 20022 base module for Switzerland",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Finance",
"website": "https://github.com/OCA/l10n-switzerland",
"author": "Akretion,Camptocamp,Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["account_banking_pain_base", "l10n_ch_base_bank"],
"depends": ["account_banking_pain_base"],
"data": ["views/account_payment_line.xml"],
"installable": True,
}
6 changes: 1 addition & 5 deletions l10n_ch_pain_base/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ def _prepare_payment_line_vals(self, payment_order):
and self.move_id._has_isr_ref()
and self.move_id.partner_bank_id
):
if self.move_id.partner_bank_id._is_qr_iban():
vals["communication_type"] = "qrr"
else:
vals["local_instrument"] = "CH01"
vals["communication_type"] = "isr"
vals["communication_type"] = "qrr"

Check warning on line 17 in l10n_ch_pain_base/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

l10n_ch_pain_base/models/account_move_line.py#L17

Added line #L17 was not covered by tests
if vals["communication"]:
vals["communication"] = vals["communication"].replace(" ", "")
return vals

Check warning on line 20 in l10n_ch_pain_base/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

l10n_ch_pain_base/models/account_move_line.py#L19-L20

Added lines #L19 - L20 were not covered by tests
12 changes: 2 additions & 10 deletions l10n_ch_pain_base/models/account_payment_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@
class AccountPaymentLine(models.Model):
_inherit = "account.payment.line"

local_instrument = fields.Selection(
selection_add=[("CH01", "CH01 (ISR)")], ondelete={"CH01": "set null"}
)
communication_type = fields.Selection(
selection_add=[("isr", "ISR"), ("qrr", "QRR")],
ondelete={"isr": "set default", "qrr": "set default"},
selection_add=[("qrr", "QRR")],
ondelete={"qrr": "set default"},
)

def invoice_reference_type2communication_type(self):
res = super().invoice_reference_type2communication_type()
res["isr"] = "isr"
return res
90 changes: 1 addition & 89 deletions l10n_ch_pain_base/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

from lxml import etree

from odoo import _, api, models
from odoo.exceptions import UserError
from odoo import api, models


class AccountPaymentOrder(models.Model):
Expand Down Expand Up @@ -71,93 +70,6 @@ def generate_start_payment_info_block(
gen_args,
)

@api.model
def generate_party_agent(
self, parent_node, party_type, order, partner_bank, gen_args, bank_line=None
):
if gen_args.get("pain_flavor") == "pain.001.001.03.ch.02" and bank_line:
if bank_line.payment_line_ids[:1].local_instrument == "CH01":
# Don't set the creditor agent on ISR/CH01 payments
return True
elif not partner_bank.bank_bic:
raise UserError(
_(
"For pain.001.001.03.ch.02, for non-ISR payments, "
"the BIC is required on the bank '%(name)s' related to the "
"bank account '%(account)s'",
name=partner_bank.bank_id.name,
account=partner_bank.acc_number,
)
)
return super().generate_party_agent(
parent_node,
party_type,
order,
partner_bank,
gen_args,
bank_line=bank_line,
)

@api.model
def generate_party_acc_number(
self, parent_node, party_type, order, partner_bank, gen_args, bank_line=None
):
if (
gen_args.get("pain_flavor") == "pain.001.001.03.ch.02"
and bank_line
and bank_line.payment_line_ids[:1].local_instrument == "CH01"
):
if not partner_bank.l10n_ch_postal:
raise UserError(
_(
"The field 'Postal account' is not set on the bank "
"account '%s'."
)
% partner_bank.acc_number
)
party_account = etree.SubElement(parent_node, "%sAcct" % party_type)
party_account_id = etree.SubElement(party_account, "Id")
party_account_other = etree.SubElement(party_account_id, "Othr")
party_account_other_id = etree.SubElement(party_account_other, "Id")
party_account_other_id.text = partner_bank.l10n_ch_postal
return True
else:
return super().generate_party_acc_number(
parent_node,
party_type,
order,
partner_bank,
gen_args,
bank_line=bank_line,
)

@api.model
def generate_address_block(self, parent_node, partner, gen_args):
"""Generate the piece of the XML corresponding to PstlAdr"""
if partner.country_id:
postal_address = etree.SubElement(parent_node, "PstlAdr")

country = etree.SubElement(postal_address, "Ctry")
country.text = self._prepare_field(
"Country",
"partner.country_id.code",
{"partner": partner},
2,
gen_args=gen_args,
)

if partner.street or partner.street2:
adrline1 = etree.SubElement(postal_address, "AdrLine")
adrline1.text = ", ".join(
filter(None, [partner.street, partner.street2])
)

if partner.zip and partner.city:
adrline2 = etree.SubElement(postal_address, "AdrLine")
adrline2.text = " ".join([partner.zip, partner.city])

return True

@api.model
def generate_remittance_info_block(self, parent_node, line, gen_args):
if line.payment_line_ids[:1].communication_type == "qrr":
Expand Down
1 change: 1 addition & 0 deletions l10n_ch_pain_base/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Alexis de Lattre <[email protected]>
* Denis Leemann <[email protected]>
* Mykhailo Panarin <[email protected]>
* Alberto Nieto <[email protected]>

0 comments on commit 92d8c1a

Please sign in to comment.