Skip to content

Commit

Permalink
[IMP] l10n_it_fatturapa_out_welfare: pre-commit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
odooNextev committed Oct 18, 2024
1 parent bed88dd commit 6c6baaa
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 148 deletions.
31 changes: 19 additions & 12 deletions l10n_it_fatturapa_out_welfare/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ ITA - Fattura elettronica - Cassa previdenziale
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-italy/tree/12.0/l10n_it_fatturapa_out_welfare
:target: https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_fatturapa_out_welfare
:alt: OCA/l10n-italy
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-italy-12-0/l10n-italy-12-0-l10n_it_fatturapa_out_welfare
:target: https://translation.odoo-community.org/projects/l10n-italy-16-0/l10n-italy-16-0-l10n_it_fatturapa_out_welfare
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&target_branch=12.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

**Italiano**

Aggiungere la cassa previdenziale alla fattura e alla fattura elettronica.
Aggiungere la cassa previdenziale alla fattura e alla fattura
elettronica.

**English**

Expand All @@ -46,43 +47,49 @@ Configuration

**Italiano**

In Fatturazione > Configurazione > Contabilità > Fiscalità italiana > Fatturazione elettronica > Importi cassa previdenziale, creare le casse previdenziali.
In Fatturazione > Configurazione > Contabilità > Fiscalità italiana >
Fatturazione elettronica > Importi cassa previdenziale, creare le casse
previdenziali.

**English**

In Accounting > Configuration > Accounting > Italian Localization > Electronic invoicing > Welfare Fund Type Amounts, create the welfare amounts.
In Accounting > Configuration > Accounting > Italian Localization >
Electronic invoicing > Welfare Fund Type Amounts, create the welfare
amounts.

Usage
=====

**Italiano**

Nella fattura, impostare le casse previdenziali configurate e cliccare su "Genera righe cassa previdenziale".
Nella fattura, impostare le casse previdenziali configurate e cliccare
su "Genera righe cassa previdenziale".

**English**

In the invoice, set the configured welfares and click on "Generate Welfare Lines".
In the invoice, set the configured welfares and click on "Generate
Welfare Lines".

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-italy/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_fatturapa_out_welfare%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_fatturapa_out_welfare%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~
-------

* TAKOBI

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -94,6 +101,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/12.0/l10n_it_fatturapa_out_welfare>`_ project on GitHub.
This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_fatturapa_out_welfare>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out_welfare/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "ITA - Fattura elettronica - Cassa previdenziale",
"summary": "Registrazione della cassa previdenziale "
"nelle fatture elettroniche in uscita",
"nelle fatture elettroniche in uscita",
"version": "12.0.1.0.1",
"development_status": "Beta",
"category": "Localization/Italy",
Expand Down
28 changes: 13 additions & 15 deletions l10n_it_fatturapa_out_welfare/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
from odoo.exceptions import UserError


class AccountInvoice (models.Model):
_inherit = 'account.invoice'
class AccountInvoice(models.Model):
_inherit = "account.invoice"

should_regenerate_welfare_lines = fields.Boolean(
compute='_compute_should_regenerate_welfare_lines',
compute="_compute_should_regenerate_welfare_lines",
store=True,
)

@api.depends(
'invoice_line_ids.welfare_grouped_invoice_line_ids',
'invoice_line_ids.welfare_fund_type_amount_ids',
"invoice_line_ids.welfare_grouped_invoice_line_ids",
"invoice_line_ids.welfare_fund_type_amount_ids",
)
def _compute_should_regenerate_welfare_lines(self):
for invoice in self:
Expand All @@ -31,19 +31,18 @@ def button_regenerate_welfare_lines(self):
self.ensure_one()
invoice_lines = self.invoice_line_ids
# Remove previous grouping lines
grouping_lines = invoice_lines.filtered(
'welfare_grouping_fund_type_amount_id'
)
grouping_lines = invoice_lines.filtered("welfare_grouping_fund_type_amount_id")
grouping_lines.unlink()
invoice_lines = invoice_lines.exists()

# Create new grouping lines
welfare_grouped_lines = invoice_lines.welfare_group_lines()
grouping_lines_sequence = max(invoice_lines.mapped('sequence')) + 1
grouping_lines_sequence = max(invoice_lines.mapped("sequence")) + 1
welfare_grouping_lines_values = list()
for welfare_amount, welfare_lines in welfare_grouped_lines.items():
welfare_grouping_line_values = \
welfare_grouping_line_values = (
welfare_amount._prepare_grouping_invoice_line(welfare_lines)
)
welfare_grouping_line_values.update(
sequence=grouping_lines_sequence,
)
Expand All @@ -56,13 +55,12 @@ def button_regenerate_welfare_lines(self):
return welfare_grouping_lines

def action_invoice_open(self):
need_welfare_invoices = self.filtered('should_regenerate_welfare_lines')
need_welfare_invoices = self.filtered("should_regenerate_welfare_lines")
if need_welfare_invoices:
raise UserError(
_("Please regenerate Welfare Lines for invoices: {invoices}")
.format(
invoices=', '.join(
need_welfare_invoices.mapped('display_name'),
_("Please regenerate Welfare Lines for invoices: {invoices}").format(
invoices=", ".join(
need_welfare_invoices.mapped("display_name"),
)
)
)
Expand Down
34 changes: 17 additions & 17 deletions l10n_it_fatturapa_out_welfare/models/account_invoice_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
from odoo import fields, models


class AccountInvoiceLine (models.Model):
_inherit = 'account.invoice.line'
class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"

welfare_fund_type_amount_ids = fields.Many2many(
comodel_name='welfare.fund.type.amount',
comodel_name="welfare.fund.type.amount",
string="Welfare Fund Type Amounts",
help="Welfare Amounts to be applied on this Invoice Line."
help="Welfare Amounts to be applied on this Invoice Line.",
)
welfare_grouping_fund_type_amount_id = fields.Many2one(
comodel_name='welfare.fund.type.amount',
comodel_name="welfare.fund.type.amount",
string="Grouped Welfare Amount",
help="Welfare Amount represented by this Invoice Line."
help="Welfare Amount represented by this Invoice Line.",
)
welfare_grouping_invoice_line_ids = fields.Many2many(
comodel_name='account.invoice.line',
relation='welfare_group_invoice_line_rel',
column1='grouping_line',
column2='grouped_line',
comodel_name="account.invoice.line",
relation="welfare_group_invoice_line_rel",
column1="grouping_line",
column2="grouped_line",
string="Grouping Welfare Invoice Lines",
help="Invoice Lines that represent this Line's Welfare Amount."
help="Invoice Lines that represent this Line's Welfare Amount.",
)
welfare_grouped_invoice_line_ids = fields.Many2many(
comodel_name='account.invoice.line',
relation='welfare_group_invoice_line_rel',
column1='grouped_line',
column2='grouping_line',
comodel_name="account.invoice.line",
relation="welfare_group_invoice_line_rel",
column1="grouped_line",
column2="grouping_line",
string="Grouped Welfare Invoice Lines",
help="Invoice Lines whose Welfare Amount is represented by this Line.",
)
Expand All @@ -53,8 +53,8 @@ def _get_to_be_grouped_welfare_lines(self):
Get invoice lines of `self` whose Welfare Amount
has to be represented by another invoice line.
"""
grouped_lines = self.mapped('welfare_grouped_invoice_line_ids')
welfare_lines = self.filtered('welfare_fund_type_amount_ids')
grouped_lines = self.mapped("welfare_grouped_invoice_line_ids")
welfare_lines = self.filtered("welfare_fund_type_amount_ids")

to_be_grouped_lines = welfare_lines - grouped_lines
return to_be_grouped_lines
41 changes: 21 additions & 20 deletions l10n_it_fatturapa_out_welfare/models/welfare_fund_type_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
from odoo.fields import first


class WelfareFundTypeAmount (models.Model):
_name = 'welfare.fund.type.amount'
_description = 'Welfare Fund Type Amount'
class WelfareFundTypeAmount(models.Model):
_name = "welfare.fund.type.amount"
_description = "Welfare Fund Type Amount"

name = fields.Char(
compute='_compute_name',
compute="_compute_name",
store=True,
)
welfare_fund_type_id = fields.Many2one(
comodel_name='welfare.fund.type',
comodel_name="welfare.fund.type",
required=True,
)
amount = fields.Float(
Expand All @@ -25,15 +25,15 @@ class WelfareFundTypeAmount (models.Model):

_sql_constraints = [
(
'welfare_amount_unique',
'UNIQUE(welfare_fund_type_id, amount)',
"welfare_amount_unique",
"UNIQUE(welfare_fund_type_id, amount)",
"Welfare Type and amount must be unique.",
),
]

@api.depends(
'welfare_fund_type_id.name',
'amount',
"welfare_fund_type_id.name",
"amount",
)
def _compute_name(self):
for welfare_amount in self:
Expand All @@ -52,33 +52,34 @@ def _prepare_grouping_invoice_line(self, invoice_lines):
for invoice_line in invoice_lines:
if self not in invoice_line.welfare_fund_type_amount_ids:
raise UserError(
_("Welfare '{welfare}' should be present "
"in Invoice Line '{line}'")
.format(
_(
"Welfare '{welfare}' should be present "
"in Invoice Line '{line}'"
).format(
welfare=self.display_name,
line=invoice_line.display_name,
)
)

first_line = first(invoice_lines)
return {
'name': self.display_name,
'account_id': first_line.account_id.id,
'invoice_line_tax_ids': [
"name": self.display_name,
"account_id": first_line.account_id.id,
"invoice_line_tax_ids": [
(6, 0, first_line.invoice_line_tax_ids.ids),
],
'invoice_id': first_line.invoice_id.id,
'welfare_grouping_fund_type_amount_id': self.id,
'welfare_grouped_invoice_line_ids': [
"invoice_id": first_line.invoice_id.id,
"welfare_grouping_fund_type_amount_id": self.id,
"welfare_grouped_invoice_line_ids": [
(6, 0, invoice_lines.ids),
],
'price_unit': self._get_welfare_amount(invoice_lines),
"price_unit": self._get_welfare_amount(invoice_lines),
}

def _get_welfare_amount(self, invoice_lines):
"""
Calculate the Welfare Amount of invoice_lines`.
"""
self.ensure_one()
lines_subtotal = sum(invoice_lines.mapped('price_subtotal'))
lines_subtotal = sum(invoice_lines.mapped("price_subtotal"))
return self.amount * lines_subtotal / 100
3 changes: 3 additions & 0 deletions l10n_it_fatturapa_out_welfare/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
11 changes: 11 additions & 0 deletions l10n_it_fatturapa_out_welfare/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**Italiano**

In Fatturazione \> Configurazione \> Contabilità \> Fiscalità italiana
\> Fatturazione elettronica \> Importi cassa previdenziale, creare le
casse previdenziali.

**English**

In Accounting \> Configuration \> Accounting \> Italian Localization \>
Electronic invoicing \> Welfare Fund Type Amounts, create the welfare
amounts.
7 changes: 0 additions & 7 deletions l10n_it_fatturapa_out_welfare/readme/CONFIGURE.rst

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
**Italiano**

Aggiungere la cassa previdenziale alla fattura e alla fattura elettronica.
Aggiungere la cassa previdenziale alla fattura e alla fattura
elettronica.

**English**

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
**Italiano**

Nella fattura, impostare le casse previdenziali configurate e cliccare su "Genera righe cassa previdenziale".
Nella fattura, impostare le casse previdenziali configurate e cliccare
su "Genera righe cassa previdenziale".

**English**

In the invoice, set the configured welfares and click on "Generate Welfare Lines".
In the invoice, set the configured welfares and click on "Generate
Welfare Lines".
Loading

0 comments on commit 6c6baaa

Please sign in to comment.