mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[INIT] init module to manage check deposits
This commit is contained in:
committed by
ps-tubtim
parent
2af6872610
commit
e46621ca9c
28
account_check_deposit/__init__.py
Normal file
28
account_check_deposit/__init__.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
# #
|
||||
# account_check_deposit for OpenERP #
|
||||
# Copyright (C) 2012 Akretion Benoît GUILLOT <benoit.guillot@akretion.com> #
|
||||
# #
|
||||
# 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/>. #
|
||||
# #
|
||||
###############################################################################
|
||||
|
||||
|
||||
|
||||
import account_deposit
|
||||
|
||||
|
||||
|
||||
|
||||
46
account_check_deposit/__openerp__.py
Normal file
46
account_check_deposit/__openerp__.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
# #
|
||||
# account_check_deposit for OpenERP #
|
||||
# Copyright (C) 2012 Akretion Benoît GUILLOT <benoit.guillot@akretion.com> #
|
||||
# #
|
||||
# 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_check_deposit',
|
||||
'version': '7.0',
|
||||
'category': 'Generic Modules/Others',
|
||||
'license': 'AGPL-3',
|
||||
'description': """This module allows you to use check deposits.
|
||||
With a new model : account_check_deposit you can select all
|
||||
the checks payments and create a global deposit for the selected checks.
|
||||
You may have to create an account for recieved checks and a journal for payment by checks.""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com/',
|
||||
'depends': ['account_accountant'],
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
'account_deposit_view.xml',
|
||||
'account_deposit_sequence.xml',
|
||||
'account_type_data.xml',
|
||||
],
|
||||
'demo_xml': [],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
}
|
||||
|
||||
142
account_check_deposit/account_deposit.py
Normal file
142
account_check_deposit/account_deposit.py
Normal file
@@ -0,0 +1,142 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
###############################################################################
|
||||
# #
|
||||
# account_check_deposit for OpenERP #
|
||||
# Copyright (C) 2012 Akretion Benoît GUILLOT <benoit.guillot@akretion.com> #
|
||||
# #
|
||||
# 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/>. #
|
||||
# #
|
||||
###############################################################################
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.osv.orm import Model
|
||||
from openerp.tools.translate import _
|
||||
|
||||
class account_check_deposit(Model):
|
||||
_name = "account.check.deposit"
|
||||
_description = "Account Check Deposit"
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64, required=True, readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'check_payment_ids': fields.many2many('account.move.line', 'account_move_line_deposit_rel',
|
||||
'check_deposit_id', 'move_line_id', 'Check Payments',
|
||||
readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'deposit_date': fields.date('Deposit Date', readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal', required=True, readonly=True,
|
||||
states={'draft':[('readonly',False)]}),
|
||||
'state': fields.selection([
|
||||
('draft','Draft'),
|
||||
('done','Done'),
|
||||
('cancel','Cancelled')
|
||||
],'Status', readonly=True),
|
||||
'move_id': fields.many2one('account.move', 'Journal Entry', readonly=True,
|
||||
states={'draft':[('readonly',False)]}),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'name': lambda self, cr, uid, context: '/',
|
||||
'deposit_date': fields.date.context_today,
|
||||
'state':'draft',
|
||||
}
|
||||
|
||||
def cancel(self, cr, uid, ids, context=None):
|
||||
for deposit in self.browse(cr, uid, ids, context=context):
|
||||
if not deposit.journal_id.update_posted:
|
||||
raise osv.except_osv(_('Error!'), _('You cannot modify a posted entry of this journal.\nFirst you should set the journal to allow cancelling entries.'))
|
||||
for line in deposit.check_payment_ids:
|
||||
line.reconcile_id.unlink()
|
||||
deposit.move_id.button_cancel()
|
||||
deposit.move_id.unlink()
|
||||
return True
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
if vals.get('name','/')=='/':
|
||||
vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'account.check.deposit') or '/'
|
||||
return super(account_check_deposit, self).create(cr, uid, vals, context=context)
|
||||
|
||||
def _prepare_account_move_vals(self, cr, uid, deposit, context=None):
|
||||
move_vals = {}
|
||||
move_lines = [[0, 0, self._prepare_sum_move_line_vals(cr, uid, deposit, move_vals, context=context)]]
|
||||
for line in deposit.check_payment_ids:
|
||||
move_lines.append([0, 0, self._prepare_move_line_vals(cr, uid, line, move_vals, context=context)])
|
||||
move_vals.update({
|
||||
'journal_id': deposit.journal_id.id,
|
||||
'line_id': move_lines,
|
||||
})
|
||||
return move_vals
|
||||
|
||||
def _prepare_move_line_vals(self, cr, uid, line, move_vals, context=None):
|
||||
move_line_vals = self.pool.get('account.move.line').default_get(cr, uid,
|
||||
['centralisation', 'date','date_created',
|
||||
'currency_id', 'journal_id', 'amount_currency',
|
||||
'account_id', 'period_id', 'company_id'],
|
||||
context=context)
|
||||
move_line_vals.update({
|
||||
'name': line.ref, #name ?
|
||||
'credit': line.debit,
|
||||
'account_id': line.account_id.id,
|
||||
'partner_id': line.partner_id.id,
|
||||
'ref': line.ref,
|
||||
})
|
||||
return move_line_vals
|
||||
|
||||
def _prepare_sum_move_line_vals(self, cr, uid, deposit, move_vals, context=None):
|
||||
move_line_vals = self.pool.get('account.move.line').default_get(cr, uid,
|
||||
['centralisation', 'date','date_created',
|
||||
'currency_id', 'journal_id', 'amount_currency',
|
||||
'account_id', 'period_id', 'company_id', 'state'],
|
||||
context=context)
|
||||
debit = 0.0
|
||||
for line in deposit.check_payment_ids:
|
||||
debit += line.debit
|
||||
move_line_vals.update({
|
||||
'name': deposit.name,
|
||||
'debit': debit,
|
||||
'ref': deposit.name,
|
||||
})
|
||||
|
||||
return move_line_vals
|
||||
|
||||
def _reconcile_checks(self, cr, uid, deposit, move_id, context=None):
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
for line in deposit.check_payment_ids:
|
||||
move_line_ids = move_line_obj.search(cr, uid, [('move_id', '=', move_id),
|
||||
('credit', '=', line.debit),
|
||||
('name', '=', line.ref)], context=context)
|
||||
if move_line_ids:
|
||||
move_line_obj.reconcile(cr, uid, [line.id, move_line_ids[0]], context=context)
|
||||
return True
|
||||
|
||||
def validate_deposit(self, cr, uid, ids, context=None):
|
||||
move_obj = self.pool.get('account.move')
|
||||
if context is None:
|
||||
context = {}
|
||||
for deposit in self.browse(cr, uid, ids, context=context):
|
||||
context['journal_id'] = deposit.journal_id.id
|
||||
move_vals = self._prepare_account_move_vals(cr, uid, deposit, context=context)
|
||||
print "move_vals ====>", move_vals
|
||||
import pdb; pdb.set_trace()
|
||||
move_id = move_obj.create(cr, uid, move_vals, context=context)
|
||||
move_obj.post(cr, uid, [move_id], context=context)
|
||||
self._reconcile_checks(cr, uid, deposit, move_id, context=context)
|
||||
deposit.write({'state':'done', 'move_id': move_id})
|
||||
return True
|
||||
|
||||
class account_move_line(Model):
|
||||
_inherit = "account.move.line"
|
||||
|
||||
_columns = {
|
||||
'check_deposit_id': fields.many2many('account.check.deposit', 'account_move_line_deposit_rel',
|
||||
'check_deposit_id', 'move_line_id', 'Check Deposit'),
|
||||
}
|
||||
26
account_check_deposit/account_deposit_sequence.xml
Normal file
26
account_check_deposit/account_deposit_sequence.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
account_check_deposit for OpenERP
|
||||
Copyright (C) 2012 Akretion Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
|
||||
<!-- Sequences for account.check.deposit -->
|
||||
<record id="seq_type_account_check_deposit" model="ir.sequence.type">
|
||||
<field name="name">Account Check Deposit</field>
|
||||
<field name="code">account.check.deposit</field>
|
||||
</record>
|
||||
|
||||
<record id="seq_account_check_deposit" model="ir.sequence">
|
||||
<field name="name">Account Check Deposit</field>
|
||||
<field name="code">account.check.deposit</field>
|
||||
<field name="prefix">DEP</field>
|
||||
<field name="padding">3</field>
|
||||
<field name="company_id" eval="False"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
102
account_check_deposit/account_deposit_view.xml
Normal file
102
account_check_deposit/account_deposit_view.xml
Normal file
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
account_check_deposit for OpenERP
|
||||
Copyright (C) 2012 Akretion Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- INHERITED VIEW FOR THE OBJECT : account_check_deposit -->
|
||||
|
||||
<record id="account_check_deposit_view_form" model="ir.ui.view">
|
||||
<field name="name">account_check_deposit.account_check_deposit.view_form</field>
|
||||
<field name="model">account.check.deposit</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Check Deposit" version="7.0">
|
||||
<header>
|
||||
<button name="validate_deposit" states="draft" string="Validate Deposit"
|
||||
type="object" class="oe_highlight"/>
|
||||
<button name="cancel" states="done" string="Cancel" type="object" />
|
||||
<field name="state" widget="statusbar" statusbar_visible="draft,done"
|
||||
statusbar_colors='{"draft":"blue"}'/>
|
||||
</header>
|
||||
<sheet>
|
||||
<h1>
|
||||
<label string="Deposit " />
|
||||
<field name="name" class="oe_inline" />
|
||||
</h1>
|
||||
<group name="deposit_fields">
|
||||
<field name="deposit_date" />
|
||||
<field name="journal_id" />
|
||||
<field name="move_id" />
|
||||
</group>
|
||||
<separator string="Check Payments"/>
|
||||
<field name="check_payment_ids" nolabel="1" colspan="4" widget="many2many"
|
||||
domain="[('reconcile_id','=',False),
|
||||
('account_id.user_type.code','=','recieved_check')]">
|
||||
<tree string="Check Payments">
|
||||
<field name="journal_id" />
|
||||
<field name="period_id" />
|
||||
<field name="date"/>
|
||||
<field name="name"/>
|
||||
<field name="ref"/>
|
||||
<field name="partner_id" />
|
||||
<field name="account_id" />
|
||||
<field name="move_id" />
|
||||
<field name="debit" sum="Total Debit"/>
|
||||
<field name="credit" sum="Total Credit"/>
|
||||
<field name="reconcile"/>
|
||||
</tree>
|
||||
</field>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="account_check_deposit_view_tree" model="ir.ui.view">
|
||||
<field name="name">account_check_deposit.account_check_deposit.view_tree</field>
|
||||
<field name="model">account.check.deposit</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Check Deposit">
|
||||
<field name="name"/>
|
||||
<field name="deposit_date"/>
|
||||
<field name="state"/>
|
||||
<field name="move_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_check_deposit_search" model="ir.ui.view">
|
||||
<field name="name">account.check.deposit.search</field>
|
||||
<field name="model">account.check.deposit</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Check deposits">
|
||||
<field name="name" string="Check Deposit"/>
|
||||
<field name="deposit_date" string="Date"/>
|
||||
<field name="state"/>
|
||||
<field name="move_id"/>
|
||||
<group expand="0" string="Group By...">
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_check_deposit_tree" model="ir.actions.act_window">
|
||||
<field name="name">Check Deposits</field>
|
||||
<field name="res_model">account.check.deposit</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form,graph</field>
|
||||
<field name="domain">[]</field>
|
||||
<field name="context">{}</field>
|
||||
<field name="search_view_id" ref="view_check_deposit_search"/>
|
||||
<field name="help" type="html"></field>
|
||||
</record>
|
||||
|
||||
<menuitem string="Check Deposit" action="action_check_deposit_tree" id="menu_check_deposit_tree" parent="account.menu_finance_bank_and_cash" sequence="20"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
20
account_check_deposit/account_type_data.xml
Normal file
20
account_check_deposit/account_type_data.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
account_check_deposit for OpenERP
|
||||
Copyright (C) 2012 Akretion Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
|
||||
<!-- New account.account.type -->
|
||||
|
||||
<record model="account.account.type" id="data_account_type_received_check">
|
||||
<field name="name">Recieved Checks</field>
|
||||
<field name="code">recieved_check</field>
|
||||
<field name="close_method">none</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user