Skip to content

Commit

Permalink
Merge branch '14.0-super-merge' of git+ssh://github.com/aion-tech/l10…
Browse files Browse the repository at this point in the history
…n-italy into 14.0-super-merge-rb
  • Loading branch information
gabriele-baldessari committed Oct 16, 2023
2 parents ba1140c + 5c830d7 commit a5c9611
Show file tree
Hide file tree
Showing 23 changed files with 370 additions and 25 deletions.
10 changes: 9 additions & 1 deletion assets_management/report/asset_previsional.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,21 @@ def generate_previsional_lines(self):
else:
lines_grouped[dep] += line

ctx = dict(force_prorata=True)
ctx = dict(force_prorata=False)
for lines in lines_grouped.values():
lines = lines.sorted()
last_line = lines[-1]
for line in lines - last_line:
dep_id = line.report_depreciation_id.depreciation_id
if dep_id.pro_rata_temporis:
ctx = dict(force_prorata=True)
line.generate_previsional_line_single()
ctx = dict(force_prorata=False)
dep_id = last_line.report_depreciation_id.depreciation_id
if dep_id.pro_rata_temporis:
ctx = dict(force_prorata=True)
last_line.with_context(**ctx).generate_previsional_line_single()
ctx = dict(force_prorata=False)

def generate_previsional_line_single(self):
self.ensure_one()
Expand Down
Empty file.
1 change: 1 addition & 0 deletions l10n_it_account_banking_sepa_credit_transfer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions l10n_it_account_banking_sepa_credit_transfer/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Addebito diretto SEPA per l'Italia",
"summary": "Crea file SEPA per l'addebito diretto",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Carlo Vettore, berim, Ooops404, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-italy",
"category": "Banking addons",
"external_dependencies": {"python": ["fintech>=7.2.10"]},
"depends": ["account_banking_sepa_credit_transfer", "account_payment_order"],
"data": [
"data/account_payment_method.xml",
"views/account_payment_line.xml",
"views/res_partner_bank.xml",
],
"installable": True,
"auto_install": False,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="sepa_credit_transfer_it" model="account.payment.method">
<field name="name">SEPA CBI Credit Transfer to suppliers</field>
<field name="code">sepa_credit_transfer_it</field>
<field name="payment_type">outbound</field>
<field name="bank_account_required" eval="True" />
<field name="pain_version">pain.00.04.00</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import account_payment_line
from . import account_payment_method
from . import account_payment_order
from . import res_partner_bank
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import logging

from odoo import fields, models

_logger = logging.getLogger(__name__)


class AccountPaymentLine(models.Model):
_inherit = "account.payment.line"

line_sequence = fields.Integer(string="#", compute="_compute_line_sequence")

def _compute_line_sequence(self):
for _id, record in enumerate(self.order_id.payment_line_ids):
record.line_sequence = _id + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2016-2020 Akretion (Alexis de Lattre <[email protected]>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class AccountPaymentMethod(models.Model):
_inherit = "account.payment.method"

pain_version = fields.Selection(
selection_add=[
("pain.00.04.00", "pain.00.04.00 (credit transfer in Italy)"),
],
ondelete={
"pain.00.04.00": "set null",
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import logging

from odoo import _, models
from odoo.exceptions import RedirectWarning, ValidationError

_logger = logging.getLogger(__name__)
try:
import fintech

fintech.register()
from fintech.sepa import Account, SEPACreditTransfer

except ImportError:
_logger.debug("Cannot `import fintech`, use `pip install fintech`")


class AccountPaymentOrder(models.Model):
_inherit = "account.payment.order"

def generate_payment_file(self):

self.ensure_one()
if self.payment_method_id.pain_version != "pain.00.04.00":
return super().generate_payment_file()

# Create the debtor account from a tuple (ACCOUNT, BANKCODE)
iban = self.company_partner_bank_id.acc_number.replace(" ", "")
bic = self.company_partner_bank_id.bank_id.bic
cuc = self.company_partner_bank_id.cuc
acc_holder_name = (
self.company_partner_bank_id.acc_holder_name
or self.company_partner_bank_id.partner_id.name
)

if not cuc:
action = self.env.ref("base.action_res_partner_bank_account_form")
action_dict = action.read()[0]
action_dict.update(
{
"res_id": self.company_partner_bank_id.id,
"domain": [("id", "=", self.company_partner_bank_id.id)],
}
)
raise RedirectWarning(
message=_(
f"Incorrect CUC for '{self.company_partner_bank_id.display_name}'\n"
),
action=action_dict,
button_text=_("Bank Settings"),
)

if not bic:
action = self.env.ref("base.action_res_bank_form")
action_dict = action.read()[0]
action_dict.update(
{
"res_id": self.company_partner_bank_id.bank_id.id,
"domain": [("id", "=", self.company_partner_bank_id.bank_id.id)],
}
)
raise RedirectWarning(
message=_(
f"Incorrect BIC for '{self.company_partner_bank_id.bank_id.display_name}'\n"
),
action=action_dict,
button_text=_("Bank Settings"),
)

debtor = Account(iban=(iban, bic), name=acc_holder_name)
try:
debtor.set_originator_id(cuc=cuc)
except Exception as e:
raise ValidationError(_("Error while setting originator id: {}".format(e)))

# Create a SEPACreditTransfer instance
sct = SEPACreditTransfer(debtor, cat_purpose="SUPP")

for line in self.payment_line_ids:
sequence = line.line_sequence
if line.partner_bank_id.acc_type != "iban":
action = self.env.ref("base.action_res_partner_bank_account_form")
action_dict = action.read()[0]
action_dict.update(
{
"res_id": line.partner_bank_id.id,
}
)
raise RedirectWarning(
message=_(
f"Incorrect IBAN for '{line.partner_id.display_name}' line {sequence}"
),
action=action_dict,
button_text=_("Bank Settings"),
)

creditor_iban = line.partner_bank_id.acc_number.replace(" ", "")
creditor_name = line.partner_id.name
# Create the creditor account
creditor = Account(creditor_iban, creditor_name)
# Add the transaction
sct.add_transaction(
creditor,
amount=line.amount_currency,
purpose=line.communication,
eref=f"{sequence}",
due_date=line.date,
)

# Render the SEPA document
xml_string = sct.render()
filename = f"{self.name}.xml"
return xml_string, filename
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResPartnerBank(models.Model):
_inherit = "res.partner.bank"

cuc = fields.Char(
string="CUC Code",
size=35,
help="Unique CBI code provided by your bank",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**English**

This module allows to execute SEPA CBI payments, exporting a valid XML file accepted by italian banks.

This module extends :code:`bank-payment/account_banking_sepa_credit_transfer`, adding to it the schema pain.00.04.00 (credit transfer in Italy).

Configuration and usage are the same of module :code:`bank-payment/account_banking_sepa_credit_transfer`.

**Italiano**

Questo modulo consente di eseguire pagamenti SEPA CBI, ed esportare un file XML accettato dalle banche italiane.

Questo modulo estende :code:`bank-payment/account_banking_sepa_credit_transfer`, aggiungendovi lo schema pain.00.04.00 (bonifico per l'Italia).

La configurazione ed il funzionamento seguono quelle del modulo :code:`bank-payment/account_banking_sepa_credit_transfer`.
53 changes: 53 additions & 0 deletions l10n_it_account_banking_sepa_credit_transfer/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
English
~~~~~~~~~~~~~~~~~

**Configuration**

You need to configure a bank account for the company that makes the payment, having at least the following data:

- IBAN
- BIC
- CUC

In addition, it is necessary to create a payment *mode* dedicated to the SEPA Credit Transfer, selecting SEPA CBI Credit Transfer to Suppliers as a *method*, automatically created upon module installation.

This method is already configured to use the correct PAIN version (Pain.00.04.00).


**Operation**

When creating a supplier invoice, you must select the created SCT payment mode as a way of payment of the same.

The invoice field *Payment reference* contains information that will be reported in the payment order field *Communication*, which is a mandatory field for the payment to be issued.

Once the invoice is confirmed, it is necessary to add it to a payment order.

Confirming the payment order, you can create and export the XML file for the bank.



Italiano
~~~~~~~~~~~~~~~~~

**Configurazione**

È necessario configurare un conto bancario per l'azienda che esegue il pagamento, che abbia almeno le seguenti informazioni:

- IBAN
- BIC
- CUC

Inoltre è necessario creare una *modalità* di pagamento dedicata al bonifico SEPA, selezionando come *metodo* "Bonifico SEPA CBI a fornitori", creato automaticamente all'installazione del modulo.

Questo metodo è già configurato per utilizzare la corretta versione PAIN (pain.00.04.00).


**Operatività**

Quando si crea una fattura fornitore bisogna selezionare come modo di pagamento della stessa la modalità di pagamento SEPA SCT creata.

Il campo della fattura *Riferimento di pagamento* contiene informazioni che verranno riportate nel campo *Comunicazione* dell'ordine di pagamento, che è un campo obbligatorio perché il pagamento venga emesso.

Quindi, una volta confermata, è necessario aggiungere la fattura a un ordine di pagamento.

Una volta confermato l'ordine di pagamento, è possibile creare ed esportare il file XML da passare alla banca.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="account_payment_line_tree_inherit" model="ir.ui.view">
<field name="name">account.payment.line.tree.inherit</field>
<field name="model">account.payment.line</field>
<field
name="inherit_id"
ref="account_payment_order.account_payment_line_tree"
/>
<field name="arch" type="xml">
<field name="partner_id" position="before">
<field name="line_sequence" />
</field>

</field>
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record model="ir.ui.view" id="res_partner_bank_form_view">
<field name="name">res.partner.bank.form (add cuc)</field>
<field name="model">res.partner.bank</field>
<field name="inherit_id" ref="base.view_partner_bank_form" />
<field name="arch" type="xml">
<field name="acc_holder_name" position="before">
<field name="cuc" />
</field>
</field>
</record>

</odoo>
17 changes: 13 additions & 4 deletions l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,12 +1057,21 @@ def invoiceCreate(self, fatt, fatturapa_attachment, FatturaBody, partner_id):
for rel_doc in causLst:
comment += rel_doc + "\n"

if (
not fatturapa_attachment.env.context.get("tz")
and not fatturapa_attachment.env.user.tz
):
# Setting Italian timezone, otherwise e_invoice_received_date
# could be set the day before of the actual date.
fatturapa_attachment = fatturapa_attachment.with_context(tz="Europe/Rome")
if fatturapa_attachment.e_invoice_received_date:
e_invoice_received_date = (
fatturapa_attachment.e_invoice_received_date.date()
)
e_invoice_received_date = fields.Datetime.context_timestamp(
fatturapa_attachment, fatturapa_attachment.e_invoice_received_date
).date()
else:
e_invoice_received_date = fatturapa_attachment.create_date.date()
e_invoice_received_date = fields.Datetime.context_timestamp(
fatturapa_attachment, fatturapa_attachment.create_date
).date()

e_invoice_date = datetime.strptime(
FatturaBody.DatiGenerali.DatiGeneraliDocumento.Data, "%Y-%m-%d"
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out/wizard/efattura.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_id_fiscale_iva(partner, prefer_fiscalcode=False):
id_codice = partner.vat[2:]
else:
id_codice = partner.vat
elif partner.fiscalcode or id_paese == "IT":
elif id_paese == "IT" and not partner.vat and partner.fiscalcode:
id_codice = False
else:
id_codice = "99999999999"
Expand Down
Loading

0 comments on commit a5c9611

Please sign in to comment.