forked from OCA/l10n-italy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing sp_type as 1-entry would produce wrong invoice
Removing superfluous method Refactoring action_move_create with reconciliation handling invoice cancel ADD README and copyright REF _compute_amount : clearer ADD tests FIX README, import, icon and manifest ADD _unreconcile_sp
- Loading branch information
1 parent
1e16a12
commit 6d84d87
Showing
9 changed files
with
234 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
==================================== | ||
Italian Localization - split payment | ||
==================================== | ||
|
||
Law: http://goo.gl/1riAwt (Articolo 17 ter) | ||
|
||
Module to generate Split Payment accounting entries | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you need to: | ||
|
||
* go to Settings, Configuration, Accounting and configure 'Split Payment Write-off account' and 'Split Payment Write-off Journal'. Write-off account should be different from standard debit VAT, in order to separately add it in VAT statement. | ||
* configure the fiscale position used for split payment, setting 'Split Payment' flag | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to select the correct fiscal position in invoices | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/122/8.0 | ||
|
||
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 | ||
`here <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_split_payment%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Davide Corio <[email protected]> | ||
* Lorenzo Battistini <[email protected]> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
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. | ||
|
||
To contribute to this module, please visit http://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# | ||
# Copyright (C) 2015 Abstract (http://www.abstract.it) | ||
# Author: Davide Corio <[email protected]> | ||
# Copyright 2015 Lorenzo Battistini - Agile Business Group | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -21,11 +22,9 @@ | |
|
||
{ | ||
'name': 'Split Payment', | ||
'version': '1.0', | ||
'version': '8.0.1.0.0', | ||
'category': 'Localization/Italy', | ||
'summary': 'Split Payment', | ||
'description': """ | ||
""", | ||
'author': 'Abstract', | ||
'website': 'http://www.abstract.it', | ||
'depends': [ | ||
|
@@ -35,5 +34,4 @@ | |
'views/config_view.xml', | ||
], | ||
'installable': True, | ||
'active': False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# | ||
# Copyright (C) 2015 Abstract (http://www.abstract.it) | ||
# Author: Davide Corio <[email protected]> | ||
# Copyright 2015 Lorenzo Battistini - Agile Business Group | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -29,25 +30,6 @@ class AccountFiscalPosition(models.Model): | |
split_payment = fields.Boolean('Split Payment') | ||
|
||
|
||
class AccountInvoiceTax(models.Model): | ||
_inherit = 'account.invoice.tax' | ||
|
||
@api.v8 | ||
def compute(self, invoice): | ||
res = super(AccountInvoiceTax, self).compute(invoice) | ||
fp = invoice.fiscal_position | ||
if fp and fp.split_payment: | ||
for group in res: | ||
account_id = res[group]['account_id'] | ||
for map in fp.account_ids: | ||
if map.account_src_id.id == account_id: | ||
res[group]['account_id'] = map.account_dest_id.id | ||
new_group = (group[0], group[1], map.account_dest_id.id) | ||
res[new_group] = res[group] | ||
res.pop(group) | ||
return res | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = 'account.invoice' | ||
|
||
|
@@ -60,85 +42,109 @@ class AccountInvoice(models.Model): | |
split_payment = fields.Boolean( | ||
'Split Payment', | ||
related='fiscal_position.split_payment') | ||
sp_type = fields.Selection( | ||
string='Split Payment Type', related='company_id.sp_type') | ||
sp_move_id = fields.Many2one( | ||
'account.move', | ||
string='Split Payment Write-off') | ||
|
||
@api.one | ||
@api.depends('invoice_line.price_subtotal', 'tax_line.amount') | ||
def _compute_amount(self): | ||
self.amount_untaxed = sum( | ||
line.price_subtotal for line in self.invoice_line) | ||
super(AccountInvoice, self)._compute_amount() | ||
if self.fiscal_position.split_payment: | ||
self.amount_sp = sum(line.amount for line in self.tax_line) | ||
self.amount_sp = self.amount_tax | ||
self.amount_tax = 0 | ||
else: | ||
self.amount_tax = sum(line.amount for line in self.tax_line) | ||
self.amount_sp = 0 | ||
self.amount_total = self.amount_untaxed + self.amount_tax | ||
|
||
def reconcile_sp(self, sp_line): | ||
reconcile_set = sp_line | ||
for line in self.move_id.line_id: | ||
if line.account_id.id == sp_line.account_id.id: | ||
reconcile_set += line | ||
reconcile_set.reconcile_partial() | ||
|
||
def _build_credit_vals(self): | ||
return { | ||
'name': _('Split Payment Write Off'), | ||
'partner_id': self.partner_id.id, | ||
'account_id': self.account_id.id, | ||
'journal_id': self.journal_id.id, | ||
'period_id': self.period_id.id, | ||
'date': self.date_invoice, | ||
'credit': self.amount_sp, | ||
'debit': 0, | ||
} | ||
|
||
def _build_debit_line(self): | ||
return { | ||
'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, | ||
'period_id': self.period_id.id, | ||
'date': self.date_invoice, | ||
'debit': self.amount_sp, | ||
'credit': 0, | ||
} | ||
|
||
@api.multi | ||
def action_move_create(self): | ||
res = super(AccountInvoice, self).action_move_create() | ||
if self.fiscal_position and self.fiscal_position.split_payment: | ||
line_model = self.env['account.move.line'] | ||
sp_type = self.company_id.sp_type | ||
sp_account_id = self.company_id.sp_account_id | ||
if sp_type == '1-entry': | ||
credit_line = { | ||
'name': _('Split Payment Write Off'), | ||
'move_id': self.move_id.id, | ||
'partner_id': self.partner_id.id, | ||
'account_id': self.account_id.id, | ||
'journal_id': self.journal_id.id, | ||
'period_id': self.period_id.id, | ||
'date': self.date_invoice, | ||
'credit': self.amount_sp, | ||
'debit': 0} | ||
line_model.create(credit_line) | ||
write_off_line = { | ||
'name': _('Split Payment Write Off'), | ||
'move_id': self.move_id.id, | ||
'partner_id': self.partner_id.id, | ||
'account_id': sp_account_id.id, | ||
'journal_id': self.journal_id.id, | ||
'period_id': self.period_id.id, | ||
'date': self.date_invoice, | ||
'debit': self.amount_sp, | ||
'credit': 0} | ||
line_model.create(write_off_line) | ||
else: | ||
sp_journal_id = self.company_id.sp_journal_id | ||
for invoice in self: | ||
if ( | ||
invoice.fiscal_position and | ||
invoice.fiscal_position.split_payment | ||
): | ||
line_model = self.env['account.move.line'] | ||
credit_line_vals = invoice._build_credit_vals() | ||
write_off_line_vals = invoice._build_debit_line() | ||
sp_journal_id = invoice.company_id.sp_journal_id | ||
move_model = self.env['account.move'] | ||
move_data = { | ||
'journal_id': sp_journal_id.id, | ||
'date': self.date_invoice, | ||
'period_id': self.period_id.id, | ||
'date': invoice.date_invoice, | ||
'period_id': invoice.period_id.id, | ||
} | ||
move = move_model.create(move_data) | ||
credit_line = { | ||
'name': _('Split Payment Write Off'), | ||
'move_id': move.id, | ||
'partner_id': self.partner_id.id, | ||
'account_id': self.account_id.id, | ||
'journal_id': move.journal_id.id, | ||
'period_id': move.period_id.id, | ||
'date': move.date, | ||
'credit': self.amount_sp, | ||
'debit': 0} | ||
line_model.create(credit_line) | ||
write_off_line = { | ||
'name': _('Split Payment Write Off'), | ||
'move_id': move.id, | ||
'partner_id': self.partner_id.id, | ||
'account_id': sp_account_id.id, | ||
'journal_id': move.journal_id.id, | ||
'period_id': move.period_id.id, | ||
'date': move.date, | ||
'debit': self.amount_sp, | ||
'credit': 0} | ||
line_model.create(write_off_line) | ||
self.sp_move_id = move.id | ||
credit_line_vals['move_id'] = move.id | ||
write_off_line_vals['move_id'] = move.id | ||
invoice.sp_move_id = move.id | ||
credit_line = line_model.create(credit_line_vals) | ||
line_model.create(write_off_line_vals) | ||
move.post() | ||
invoice.reconcile_sp(credit_line) | ||
return res | ||
|
||
def _is_unreconciliable(self): | ||
inv_credit_lines = 0 | ||
for line in self.move_id.line_id: | ||
if line.account_id.type == 'receivable': | ||
inv_credit_lines += 1 | ||
for line in self.sp_move_id.line_id: | ||
if line.account_id.type == 'receivable': | ||
if line.reconcile_partial_id: | ||
if len( | ||
line.reconcile_partial_id.line_partial_ids | ||
) == inv_credit_lines + 1: | ||
# if reconciliation only contains invoice credit | ||
# + split payment | ||
return True | ||
return False | ||
|
||
def _unreconcile_sp(self): | ||
for line in self.sp_move_id.line_id: | ||
if line.account_id.type == 'receivable': | ||
line.reconcile_partial_id.unlink() | ||
|
||
@api.multi | ||
def action_cancel(self): | ||
for inv in self: | ||
if inv._is_unreconciliable(): | ||
inv._unreconcile_sp() | ||
res = super(AccountInvoice, self).action_cancel() | ||
moves = self.env['account.move'] | ||
for inv in self: | ||
moves += inv.sp_move_id | ||
if moves: | ||
moves.button_cancel() | ||
moves.unlink() | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# | ||
# Copyright (C) 2015 Abstract (http://www.abstract.it) | ||
# Author: Davide Corio <[email protected]> | ||
# Copyright 2015 Lorenzo Battistini - Agile Business Group | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -19,16 +20,11 @@ | |
# | ||
############################################################################## | ||
|
||
from openerp import models, fields, api | ||
from openerp import models, fields | ||
|
||
|
||
class res_company(models.Model): | ||
_inherit = 'res.company' | ||
sp_type = fields.Selection( | ||
(('1-entry', 'Write-off on invoice journal entry'), | ||
('2-entries', 'Write-off on dedicated journal entry')), | ||
string='Split payment write-off method', | ||
help='Method used to post the split payment journal entry') | ||
sp_account_id = fields.Many2one( | ||
'account.account', | ||
string='Split Payment Write-off Account', | ||
|
@@ -42,10 +38,6 @@ class res_company(models.Model): | |
class account_config_settings(models.TransientModel): | ||
_inherit = 'account.config.settings' | ||
|
||
sp_type = fields.Selection( | ||
related='company_id.sp_type', | ||
string="Split payment write-off method", | ||
help='Method used to post the split payment journal entry') | ||
sp_account_id = fields.Many2one( | ||
related='company_id.sp_account_id', | ||
string='Split Payment Write-off account', | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# About license, see __openerp__.py | ||
# | ||
############################################################################## | ||
|
||
from . import test_splitpayment |
Oops, something went wrong.