Skip to content

Commit

Permalink
[MIG] l10n_it_split_payment: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Borruso committed Jun 16, 2023
1 parent 2498edd commit f31ec42
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 210 deletions.
22 changes: 11 additions & 11 deletions l10n_it_split_payment/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ ITA - Scissione pagamenti
: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/14.0/l10n_it_split_payment
:target: https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_split_payment
: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-14-0/l10n-italy-14-0-l10n_it_split_payment
:target: https://translation.odoo-community.org/projects/l10n-italy-16-0/l10n-italy-16-0-l10n_it_split_payment
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/122/14.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/l10n-italy&target_branch=16.0
:alt: Try me on Runboat

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

Expand Down Expand Up @@ -57,7 +57,7 @@ To configure this module, you need to:

* go to Accounting → Configuration → Settings and configure 'Split Payment Write-off account' (like 'IVA n/debito sospesa SP'). Write-off account should be different from standard debit VAT, in order to separately add it in VAT statement.

.. figure:: https://raw.githubusercontent.com/OCA/l10n-italy/14.0/l10n_it_split_payment/static/settings.png
.. figure:: https://raw.githubusercontent.com/OCA/l10n-italy/16.0/l10n_it_split_payment/static/settings.png
:alt: Configuration
:width: 600 px

Expand All @@ -72,11 +72,11 @@ To configure this module, you need to:
* add a new tax (Accounting → Configuration → Accounting → Taxes). IVA al 22% SPL should be configured like the following:


.. figure:: https://raw.githubusercontent.com/OCA/l10n-italy/14.0/l10n_it_split_payment/static/SP.png
.. figure:: https://raw.githubusercontent.com/OCA/l10n-italy/16.0/l10n_it_split_payment/static/SP.png
:alt: 22SPL
:width: 600 px

.. figure:: https://raw.githubusercontent.com/OCA/l10n-italy/14.0/l10n_it_split_payment/static/SP2.png
.. figure:: https://raw.githubusercontent.com/OCA/l10n-italy/16.0/l10n_it_split_payment/static/SP2.png
:alt: 22SPL
:width: 600 px

Expand All @@ -91,7 +91,7 @@ To configure this module, you need to:
* configure the fiscal position (Accounting → Configuration → Accounting → Fiscal Positions) used for split payment, setting 'Split Payment' flag. In fiscal position, map standard VAT with SP VAT, like the following:


.. figure:: https://raw.githubusercontent.com/OCA/l10n-italy/14.0/l10n_it_split_payment/static/fiscal_position.png
.. figure:: https://raw.githubusercontent.com/OCA/l10n-italy/16.0/l10n_it_split_payment/static/fiscal_position.png
:alt: Fiscal position
:width: 600 px

Expand All @@ -112,7 +112,7 @@ 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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_split_payment%0Aversion:%2014.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_split_payment%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.

Expand Down Expand Up @@ -153,6 +153,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/14.0/l10n_it_split_payment>`_ project on GitHub.
This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/16.0/l10n_it_split_payment>`_ 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_split_payment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{
"name": "ITA - Scissione pagamenti",
"version": "14.0.1.0.7",
"version": "16.0.1.0.0",
"category": "Localization/Italy",
"summary": "Scissione pagamenti",
"author": "Abstract, Agile Business Group, Odoo Community Association (OCA)",
Expand Down
33 changes: 0 additions & 33 deletions l10n_it_split_payment/migrations/14.0.1.0.0/post-migration.py

This file was deleted.

This file was deleted.

189 changes: 76 additions & 113 deletions l10n_it_split_payment/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# Copyright 2016 Alessio Gerace - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_compare


class AccountFiscalPosition(models.Model):
_inherit = "account.fiscal.position"

split_payment = fields.Boolean("Split Payment")
split_payment = fields.Boolean()


class AccountMove(models.Model):
Expand All @@ -29,20 +29,30 @@ class AccountMove(models.Model):
)

def _compute_amount(self):
super()._compute_amount()
res = super()._compute_amount()
for move in self:
if move.split_payment:
if move.is_purchase_document():
continue
move.amount_sp = move.amount_tax
move.amount_tax = 0.0
if move.tax_totals:
move.amount_sp = move.tax_totals["amount_total"] - move.tax_totals["amount_untaxed"]
else:
move.amount_sp = 0.0
move.amount_total = move.amount_untaxed
move._compute_split_payments()
else:
move.amount_sp = 0.0
return res


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

is_split_payment = fields.Boolean()

def _build_debit_line(self):
if not self.company_id.sp_account_id:
self.ensure_one()

if not self.move_id.company_id.sp_account_id:
raise UserError(
_(
"Please set 'Split Payment Write-off Account' field in"
Expand All @@ -51,117 +61,70 @@ def _build_debit_line(self):
)
vals = {
"name": _("Split Payment Write Off"),
"partner_id": self.partner_id.id,
"account_id": self.company_id.sp_account_id.id,
"journal_id": self.journal_id.id,
"date": self.invoice_date,
"price_unit": -self.amount_sp,
"amount_currency": self.amount_sp,
"debit": self.amount_sp,
"credit": 0.0,
"exclude_from_invoice_tab": True,
"partner_id": self.move_id.partner_id.id,
"account_id": self.move_id.company_id.sp_account_id.id,
"journal_id": self.move_id.journal_id.id,
"date": self.move_id.invoice_date,
"date_maturity": self.move_id.invoice_date,
"price_unit": -self.credit,
"amount_currency": self.credit,
"debit": self.credit,
"credit": self.debit,
"display_type": "tax",
"is_split_payment": True,
}
if self.move_type == "out_refund":
vals["amount_currency"] = -self.amount_sp
vals["debit"] = 0.0
vals["credit"] = self.amount_sp
if self.move_id.move_type == "out_refund":
vals["amount_currency"] = -self.debit
vals["debit"] = self.credit
vals["credit"] = self.debit
return vals

def set_receivable_line_ids(self):
"""Recompute all account move lines by _recompute_dynamic_lines()
and set correct receivable lines
"""
self._recompute_dynamic_lines()
line_client_ids = self.line_ids.filtered(
lambda l: l.account_id.id
== self.partner_id.property_account_receivable_id.id
)
if self.move_type == "out_invoice":
for line_client in line_client_ids:
inv_total = self.amount_sp + self.amount_total
if inv_total:
receivable_line_amount = (
self.amount_total * line_client.debit
) / inv_total
else:
receivable_line_amount = 0.0
line_client.with_context(check_move_validity=False).update(
{
"price_unit": -receivable_line_amount,
"amount_currency": receivable_line_amount,
"debit": receivable_line_amount,
"credit": 0.0,
}
)
elif self.move_type == "out_refund":
for line_client in line_client_ids:
inv_total = self.amount_sp + self.amount_total
if inv_total:
receivable_line_amount = (
self.amount_total * line_client.credit
) / inv_total
else:
receivable_line_amount = 0.0
line_client.with_context(check_move_validity=False).update(
{
"price_unit": -receivable_line_amount,
"amount_currency": -receivable_line_amount,
"debit": 0.0,
"credit": receivable_line_amount,
}
)

def _compute_split_payments(self):
write_off_line_vals = self._build_debit_line()
line_sp = self.line_ids.filtered(lambda l: l.is_split_payment)
if line_sp:
line_sp = line_sp[0].with_context(check_move_validity=False)
@api.model_create_multi
def create(self, vals_list):
lines = super().create(vals_list)
for line in lines:
if (
self.move_type == "out_invoice"
and float_compare(
line_sp.price_unit,
write_off_line_vals["price_unit"],
precision_rounding=self.currency_id.rounding,
)
!= 0
):
line_sp.update(
{
"price_unit": 0.0,
"amount_currency": 0.0,
"debit": 0.0,
"credit": 0.0,
}
)
self.set_receivable_line_ids()
line_sp.write(write_off_line_vals)
elif (
self.move_type == "out_refund"
and float_compare(
line_sp.price_unit,
write_off_line_vals["price_unit"],
precision_rounding=self.currency_id.rounding,
)
!= 0
line.display_type == "tax"
and line.move_id.split_payment
and not line.is_split_payment
and not any(ml.is_split_payment for ml in line.move_id.line_ids)
):
line_sp.update(
{
"price_unit": 0.0,
"amount_currency": 0.0,
"debit": 0.0,
"credit": 0.0,
}
write_off_line_vals = line._build_debit_line()
line.move_id.line_ids = [(0, 0, write_off_line_vals)]
line.move_id._sync_dynamic_lines(
container={"records": line.move_id, "self": line.move_id}
)
self.set_receivable_line_ids()
line_sp.write(write_off_line_vals)
else:
self.set_receivable_line_ids()
if self.amount_sp:
self.invoice_line_ids = [(0, 0, write_off_line_vals)]

return lines

class AccountMoveLine(models.Model):
_inherit = "account.move.line"

is_split_payment = fields.Boolean(string="Is Split Payment")
def write(self, vals):
res = super().write(vals)
for line in self:
if (
line.move_id.split_payment
and line.display_type == "tax"
and not line.is_split_payment
):
write_off_line_vals = line._build_debit_line()
if any(aml.is_split_payment for aml in line.move_id.line_ids):
line_sp = line.move_id.line_ids.filtered(
lambda l: l.is_split_payment
)
if (
float_compare(
line_sp[0].price_unit,
write_off_line_vals["price_unit"],
precision_rounding=line.move_id.currency_id.rounding,
)
!= 0
):
line_sp[0].write(write_off_line_vals)
line.move_id._sync_dynamic_lines(
container={"records": line.move_id, "self": line.move_id}
)
else:
if line.move_id.amount_sp:
line.move_id.line_ids = [(0, 0, write_off_line_vals)]
line.move_id._sync_dynamic_lines(
container={"records": line.move_id, "self": line.move_id}
)
return res
Loading

0 comments on commit f31ec42

Please sign in to comment.