mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[add] account_statement_cancel_line, initial work
This commit is contained in:
24
account_statement_cancel_line/__init__.py
Normal file
24
account_statement_cancel_line/__init__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
# #
|
||||
# Author: Leonardo Pistone
|
||||
# Copyright 2014 Camptocamp SA
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU Affero General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU Affero General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Affero General Public License #
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
###############################################################################
|
||||
"""Account Statement Cancel Line."""
|
||||
|
||||
import statement # noqa
|
||||
import statement_line # noqa
|
||||
52
account_statement_cancel_line/__openerp__.py
Normal file
52
account_statement_cancel_line/__openerp__.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
# #
|
||||
# Author: Leonardo Pistone #
|
||||
# Copyright 2014 Camptocamp SA #
|
||||
# #
|
||||
# Inspired by module account_banking by EduSense BV, Therp BV, Smile #
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU Affero General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU Affero General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Affero General Public License #
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
###############################################################################
|
||||
{
|
||||
'name': "Account Statement Cancel Line",
|
||||
'version': '0.1',
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Finance',
|
||||
'complexity': 'normal',
|
||||
'depends': [
|
||||
'account',
|
||||
'account_statement_ext',
|
||||
'account_default_draft_move',
|
||||
],
|
||||
'description': """
|
||||
Account Statement Cancel Line
|
||||
|
||||
This module allows to cancel one line of the statement without
|
||||
cancelling the whole thing.
|
||||
""",
|
||||
'website': 'http://www.camptocamp.com',
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
'statement_view.xml',
|
||||
],
|
||||
'demo_xml': [],
|
||||
'test': [
|
||||
],
|
||||
'installable': True,
|
||||
'images': [],
|
||||
'license': 'AGPL-3',
|
||||
}
|
||||
40
account_statement_cancel_line/statement.py
Normal file
40
account_statement_cancel_line/statement.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
# #
|
||||
# Author: Leonardo Pistone
|
||||
# Copyright 2014 Camptocamp SA
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU Affero General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU Affero General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Affero General Public License #
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
###############################################################################
|
||||
"""Account Statement Cancel Line."""
|
||||
|
||||
from openerp.osv import orm
|
||||
|
||||
|
||||
class Statement(orm.Model):
|
||||
|
||||
"""Bank Statement.
|
||||
|
||||
All logic is in the BankStatementLine
|
||||
|
||||
"""
|
||||
|
||||
_inherit = "account.bank.statement"
|
||||
|
||||
_columns = {
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
}
|
||||
124
account_statement_cancel_line/statement_line.py
Normal file
124
account_statement_cancel_line/statement_line.py
Normal file
@@ -0,0 +1,124 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
# #
|
||||
# Author: Leonardo Pistone
|
||||
# Copyright 2014 Camptocamp SA
|
||||
# #
|
||||
# This program is free software: you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU Affero General Public License as #
|
||||
# published by the Free Software Foundation, either version 3 of the #
|
||||
# License, or (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU Affero General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Affero General Public License #
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
###############################################################################
|
||||
"""Account Statement Cancel Line."""
|
||||
|
||||
from openerp.osv import fields, orm
|
||||
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
class StatementLine(orm.Model):
|
||||
|
||||
"""Add a state to the statement line."""
|
||||
|
||||
_inherit = "account.bank.statement.line"
|
||||
|
||||
_columns = {
|
||||
'state': fields.selection(
|
||||
[('draft', 'Draft'), ('confirmed', 'Confirmed')],
|
||||
'State',
|
||||
readonly=True,
|
||||
required=True
|
||||
),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'state': 'draft',
|
||||
}
|
||||
|
||||
def confirm(self, cr, uid, ids, context=None):
|
||||
"""Confirm just one statement line, return true.
|
||||
|
||||
The module account_banking does have a similar method, but at the
|
||||
moment it uses a different logic (for example, it uses vouchers, where
|
||||
the bank-statement-reconcile branch does not).
|
||||
|
||||
"""
|
||||
statement_pool = self.pool.get('account.bank.statement')
|
||||
|
||||
for st_line in self.browse(cr, uid, ids, context):
|
||||
if st_line.state != 'draft':
|
||||
continue
|
||||
st = st_line.statement_id
|
||||
curr_id = st.journal_id.company_id.currency_id.id
|
||||
|
||||
st_number = st.name
|
||||
st_line_number = statement_pool.get_next_st_line_number(
|
||||
cr, uid, st_number, st_line, context)
|
||||
|
||||
statement_pool.create_move_from_st_line(
|
||||
cr,
|
||||
uid,
|
||||
st_line.id,
|
||||
curr_id,
|
||||
st_line_number,
|
||||
context)
|
||||
self.write(cr, uid, st_line.id, {
|
||||
'state': 'confirmed'
|
||||
}, context)
|
||||
return True
|
||||
|
||||
def cancel(self, cr, uid, ids, context=None):
|
||||
"""Cancel one statement line, return True.
|
||||
|
||||
This is again similar to the method cancel in the account_banking
|
||||
module.
|
||||
|
||||
"""
|
||||
move_pool = self.pool.get('account.move')
|
||||
set_draft_ids = []
|
||||
move_unlink_ids = []
|
||||
# harvest ids for various actions
|
||||
for st_line in self.browse(cr, uid, ids, context):
|
||||
if st_line.state != 'confirmed':
|
||||
continue
|
||||
|
||||
for line in st_line.move_ids:
|
||||
# We allow for people canceling and removing
|
||||
# the associated payments, which can lead to confirmed
|
||||
# statement lines without an associated move
|
||||
move_unlink_ids.append(line.id)
|
||||
set_draft_ids.append(st_line.id)
|
||||
|
||||
if st_line.move_line.state != 'draft':
|
||||
raise orm.except_orm(
|
||||
_('Confirmed Journal Entry'),
|
||||
_('You cannot delete a confirmed Statement Line '
|
||||
'associated to a Journal Entry that is posted.'))
|
||||
move_pool.button_cancel(
|
||||
cr, uid, move_unlink_ids, context=context)
|
||||
move_pool.unlink(cr, uid, move_unlink_ids, context=context)
|
||||
self.write(
|
||||
cr, uid, set_draft_ids, {'state': 'draft'}, context=context)
|
||||
return True
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
"""Don't allow deletion of a confirmed statement line. Return super."""
|
||||
if type(ids) is int:
|
||||
ids = [ids]
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
if line.state == 'confirmed':
|
||||
raise orm.except_orm(
|
||||
_('Confirmed Statement Line'),
|
||||
_("You cannot delete a confirmed Statement Line"
|
||||
": '%s'") % line.name)
|
||||
return super(StatementLine, self).unlink(
|
||||
cr, uid, ids, context=context)
|
||||
28
account_statement_cancel_line/statement_view.xml
Normal file
28
account_statement_cancel_line/statement_view.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_bank_statement_form_cancel_line" model="ir.ui.view">
|
||||
<field name="name">account.bank.statement.form.</field>
|
||||
<field name="inherit_id" ref="account.view_bank_statement_form" />
|
||||
<field name="model">account.bank.statement</field>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//field[@name='line_ids']/tree/field[@name='amount']"
|
||||
position="after">
|
||||
<field name="state"/>
|
||||
<button name="confirm" states="draft"
|
||||
string="Confirm transaction"
|
||||
icon="gtk-ok"
|
||||
type="object"/>
|
||||
<button name="cancel" states="confirmed"
|
||||
string="Cancel transaction"
|
||||
icon="gtk-cancel"
|
||||
type="object"/>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
0
account_statement_cancel_line/test/cancel_line.yml
Normal file
0
account_statement_cancel_line/test/cancel_line.yml
Normal file
Reference in New Issue
Block a user