mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
account_check_deposit : Port to new API
Move description from __openerp__.py to README.rst
This commit is contained in:
committed by
Florian da Costa
parent
f1e3ea91d6
commit
9f7b49530e
69
account_check_deposit/README.rst
Normal file
69
account_check_deposit/README.rst
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
.. 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
|
||||||
|
|
||||||
|
=============
|
||||||
|
Check Deposit
|
||||||
|
=============
|
||||||
|
|
||||||
|
This module allows you to easily manage check deposits : you can select all
|
||||||
|
the checks you received and create a global deposit for the
|
||||||
|
selected checks. This module supports multi-currency ; each deposit has a currency
|
||||||
|
and all the checks of the deposit must have the same currency
|
||||||
|
(so, if you have checks in EUR and checks in USD, you must create 2 deposits :
|
||||||
|
one in EUR and one in USD).
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
A journal named *Check Received* is automatically created. It will be available as a payment method in Odoo. On this journal, you must configure the *Default Debit Account* and *Defaut Credit Account* ; this is the account via which the amounts of checks will transit between the reception of a check from a customer and the validation of the check deposit in Odoo.
|
||||||
|
|
||||||
|
On the company form view, you should configure the *Account for Check Deposits* ; this is the account via which the amounts of checks will transit between the validation of the check deposit in Odoo and the credit on the bank account.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
When you receive a check that pays a customer invoice, you can go to that invoice and click on the button *Register Payment* and select the *Check Received* journal as *Payment Method*.
|
||||||
|
|
||||||
|
When you want to deposit checks to the bank, go to the menu *Accounting > Bank and Cash > Check Deposit*, create a new check deposit and set the journal *Checks Received* and select the bank account on which you want to credit the checks. Then click on *Add an item* to select the checks you want to deposit at the bank. Eventually, validate the deposit and print the report (you probably want to customize this report).
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
:target: https://runbot.odoo-community.org/runbot/92/8.0
|
||||||
|
|
||||||
|
For further information, please visit:
|
||||||
|
|
||||||
|
* https://www.odoo.com/forum/help-1
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-tools/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/account-financial-tools/issues/new?body=module:%20account_check_deposit%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||||
|
* Chafique DELLI <chafique.delli@akretion.com>
|
||||||
|
* Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. image:: http://odoo-community.org/logo.png
|
||||||
|
:alt: Odoo Community Association
|
||||||
|
:target: http://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.
|
||||||
@@ -1,22 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
###############################################################################
|
|
||||||
#
|
|
||||||
# account_check_deposit for Odoo/OpenERP
|
|
||||||
# Copyright (C) 2012-2015 Akretion (http://www.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 . import account_deposit
|
from . import account_deposit
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# account_check_deposit for Odoo/OpenERP
|
# account_check_deposit for Odoo
|
||||||
# Copyright (C) 2012-2015 Akretion (http://www.akretion.com/)
|
# Copyright (C) 2012-2015 Akretion (http://www.akretion.com/)
|
||||||
# @author: Benoît GUILLOT <benoit.guillot@akretion.com>
|
# @author: Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||||
# @author: Chafique DELLI <chafique.delli@akretion.com>
|
# @author: Chafique DELLI <chafique.delli@akretion.com>
|
||||||
@@ -28,18 +28,6 @@
|
|||||||
'category': 'Accounting & Finance',
|
'category': 'Accounting & Finance',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'summary': 'Manage deposit of checks to the bank',
|
'summary': 'Manage deposit of checks to the bank',
|
||||||
'description': """
|
|
||||||
Account Check Deposit
|
|
||||||
=====================
|
|
||||||
This module allows you to easily manage check deposits : you can select all
|
|
||||||
the checks you received as payments and create a global deposit for the
|
|
||||||
selected checks.
|
|
||||||
|
|
||||||
A journal for received checks is automatically created.
|
|
||||||
You must configure on this journal the default debit account and the default
|
|
||||||
credit account. You must also configure on the company the account for
|
|
||||||
check deposits.
|
|
||||||
""",
|
|
||||||
'author': "Akretion,Odoo Community Association (OCA)",
|
'author': "Akretion,Odoo Community Association (OCA)",
|
||||||
'website': 'http://www.akretion.com/',
|
'website': 'http://www.akretion.com/',
|
||||||
'depends': [
|
'depends': [
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
account_check_deposit for Odoo/OpenERP
|
|
||||||
Copyright (C) 2014-2015 Akretion (http://www.akretion.com/)
|
Copyright (C) 2014-2015 Akretion (http://www.akretion.com/)
|
||||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
The licence is in the file __openerp__.py
|
The licence is in the file __openerp__.py
|
||||||
@@ -9,21 +8,12 @@
|
|||||||
<openerp>
|
<openerp>
|
||||||
<data noupdate="1">
|
<data noupdate="1">
|
||||||
|
|
||||||
|
|
||||||
<record id="check_received_journal_seq" model="ir.sequence">
|
|
||||||
<field name="name">Journal Check Received</field>
|
|
||||||
<field name="prefix">CHK/</field>
|
|
||||||
<field name="padding">6</field>
|
|
||||||
<field name="company_id" ref="base.main_company"/>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<!-- The user will have to configure manually the default_credit_account_id
|
<!-- The user will have to configure manually the default_credit_account_id
|
||||||
and default_debit_account_id, we can't do that for him -->
|
and default_debit_account_id, we can't do that for him -->
|
||||||
<record id="check_received_journal" model="account.journal">
|
<record id="check_received_journal" model="account.journal">
|
||||||
<field name="name">Check Received</field>
|
<field name="name">Check Received</field>
|
||||||
<field name="code">CHK</field>
|
<field name="code">CHK</field>
|
||||||
<field name="type">bank</field>
|
<field name="type">bank</field>
|
||||||
<field name="sequence_id" ref="check_received_journal_seq"/>
|
|
||||||
<field name="company_id" ref="base.main_company"/>
|
<field name="company_id" ref="base.main_company"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# account_check_deposit for Odoo/OpenERP
|
# account_check_deposit for Odoo
|
||||||
# Copyright (C) 2012-2015 Akretion (http://www.akretion.com/)
|
# Copyright (C) 2012-2015 Akretion (http://www.akretion.com/)
|
||||||
# @author: Benoît GUILLOT <benoit.guillot@akretion.com>
|
# @author: Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||||
# @author: Chafique DELLI <chafique.delli@akretion.com>
|
# @author: Chafique DELLI <chafique.delli@akretion.com>
|
||||||
@@ -22,19 +22,24 @@
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
from openerp.osv import fields, orm
|
from openerp import models, fields, api, _
|
||||||
from openerp.tools.translate import _
|
|
||||||
import openerp.addons.decimal_precision as dp
|
import openerp.addons.decimal_precision as dp
|
||||||
|
from openerp.exceptions import ValidationError
|
||||||
|
from openerp.exceptions import Warning as UserError
|
||||||
|
|
||||||
|
|
||||||
class account_check_deposit(orm.Model):
|
class AccountCheckDeposit(models.Model):
|
||||||
_name = "account.check.deposit"
|
_name = "account.check.deposit"
|
||||||
_description = "Account Check Deposit"
|
_description = "Account Check Deposit"
|
||||||
_order = 'deposit_date desc'
|
_order = 'deposit_date desc'
|
||||||
|
|
||||||
def _compute_check_deposit(self, cr, uid, ids, name, args, context=None):
|
@api.multi
|
||||||
res = {}
|
@api.depends(
|
||||||
for deposit in self.browse(cr, uid, ids, context=context):
|
'company_id', 'currency_id', 'check_payment_ids.debit',
|
||||||
|
'check_payment_ids.amount_currency',
|
||||||
|
'move_id.line_id.reconcile_id')
|
||||||
|
def _compute_check_deposit(self):
|
||||||
|
for deposit in self:
|
||||||
total = 0.0
|
total = 0.0
|
||||||
count = 0
|
count = 0
|
||||||
reconcile = False
|
reconcile = False
|
||||||
@@ -51,82 +56,70 @@ class account_check_deposit(orm.Model):
|
|||||||
for line in deposit.move_id.line_id:
|
for line in deposit.move_id.line_id:
|
||||||
if line.debit > 0 and line.reconcile_id:
|
if line.debit > 0 and line.reconcile_id:
|
||||||
reconcile = True
|
reconcile = True
|
||||||
res[deposit.id] = {
|
deposit.total_amount = total
|
||||||
'total_amount': total,
|
deposit.is_reconcile = reconcile
|
||||||
'is_reconcile': reconcile,
|
deposit.currency_none_same_company_id =\
|
||||||
'currency_none_same_company_id': currency_none_same_company_id,
|
currency_none_same_company_id
|
||||||
'check_count': count,
|
deposit.check_count = count
|
||||||
}
|
|
||||||
return res
|
|
||||||
|
|
||||||
_columns = {
|
name = fields.Char(string='Name', size=64, readonly=True, default='/')
|
||||||
'name': fields.char(
|
check_payment_ids = fields.One2many(
|
||||||
'Name', size=64, readonly=True),
|
'account.move.line', 'check_deposit_id', string='Check Payments',
|
||||||
'check_payment_ids': fields.one2many(
|
states={'done': [('readonly', '=', True)]})
|
||||||
'account.move.line', 'check_deposit_id', 'Check Payments',
|
deposit_date = fields.Date(
|
||||||
states={'done': [('readonly', '=', True)]}),
|
string='Deposit Date', required=True,
|
||||||
'deposit_date': fields.date(
|
states={'done': [('readonly', '=', True)]},
|
||||||
'Deposit Date', required=True,
|
default=fields.Date.context_today)
|
||||||
states={'done': [('readonly', '=', True)]}),
|
journal_id = fields.Many2one(
|
||||||
'journal_id': fields.many2one(
|
'account.journal', string='Journal', domain=[('type', '=', 'bank')],
|
||||||
'account.journal', 'Journal', domain=[('type', '=', 'bank')],
|
required=True, states={'done': [('readonly', '=', True)]})
|
||||||
required=True, states={'done': [('readonly', '=', True)]}),
|
journal_default_account_id = fields.Many2one(
|
||||||
'journal_default_account_id': fields.related(
|
'account.account', related='journal_id.default_debit_account_id',
|
||||||
'journal_id', 'default_debit_account_id', type='many2one',
|
string='Default Debit Account of the Journal')
|
||||||
relation='account.account',
|
currency_id = fields.Many2one(
|
||||||
string='Default Debit Account of the Journal'),
|
'res.currency', string='Currency', required=True,
|
||||||
'currency_id': fields.many2one(
|
states={'done': [('readonly', '=', True)]})
|
||||||
'res.currency', 'Currency', required=True,
|
currency_none_same_company_id = fields.Many2one(
|
||||||
states={'done': [('readonly', '=', True)]}),
|
'res.currency', compute='_compute_check_deposit',
|
||||||
'currency_none_same_company_id': fields.function(
|
string='Currency (False if same as company)')
|
||||||
_compute_check_deposit, type='many2one',
|
state = fields.Selection([
|
||||||
relation='res.currency', multi='deposit',
|
('draft', 'Draft'),
|
||||||
string='Currency (False if same as company)'),
|
('done', 'Done'),
|
||||||
'state': fields.selection([
|
], string='Status', default='draft', readonly=True)
|
||||||
('draft', 'Draft'),
|
move_id = fields.Many2one(
|
||||||
('done', 'Done'),
|
'account.move', string='Journal Entry', readonly=True)
|
||||||
], 'Status', readonly=True),
|
partner_bank_id = fields.Many2one(
|
||||||
'move_id': fields.many2one(
|
'res.partner.bank', string='Bank Account', required=True,
|
||||||
'account.move', 'Journal Entry', readonly=True),
|
domain="[('company_id', '=', company_id)]",
|
||||||
'partner_bank_id': fields.many2one(
|
states={'done': [('readonly', '=', True)]})
|
||||||
'res.partner.bank', 'Bank Account', required=True,
|
line_ids = fields.One2many(
|
||||||
domain="[('company_id', '=', company_id)]",
|
'account.move.line', related='move_id.line_id',
|
||||||
states={'done': [('readonly', '=', True)]}),
|
string='Lines', readonly=True)
|
||||||
'line_ids': fields.related(
|
company_id = fields.Many2one(
|
||||||
'move_id', 'line_id', relation='account.move.line',
|
'res.company', string='Company', required=True,
|
||||||
type='one2many', string='Lines', readonly=True),
|
states={'done': [('readonly', '=', True)]},
|
||||||
'company_id': fields.many2one(
|
default=lambda self: self.env['res.company']._company_default_get(
|
||||||
'res.company', 'Company', required=True,
|
'account.check.deposit'))
|
||||||
change_default=True,
|
total_amount = fields.Float(
|
||||||
states={'done': [('readonly', '=', True)]}),
|
compute='_compute_check_deposit',
|
||||||
'total_amount': fields.function(
|
string="Total Amount", readonly=True,
|
||||||
_compute_check_deposit, multi='deposit',
|
digits=dp.get_precision('Account'))
|
||||||
string="Total Amount", readonly=True,
|
check_count = fields.Integer(
|
||||||
type="float", digits_compute=dp.get_precision('Account')),
|
compute='_compute_check_deposit', readonly=True,
|
||||||
'check_count': fields.function(
|
string="Number of Checks")
|
||||||
_compute_check_deposit, multi='deposit', readonly=True,
|
is_reconcile = fields.Boolean(
|
||||||
string="Number of Checks", type="integer"),
|
compute='_compute_check_deposit', readonly=True,
|
||||||
'is_reconcile': fields.function(
|
string="Reconcile")
|
||||||
_compute_check_deposit, multi='deposit', readonly=True,
|
|
||||||
string="Reconcile", type="boolean"),
|
|
||||||
}
|
|
||||||
|
|
||||||
_defaults = {
|
@api.multi
|
||||||
'name': '/',
|
@api.constrains('currency_id', 'check_payment_ids', 'company_id')
|
||||||
'deposit_date': fields.date.context_today,
|
def _check_deposit(self):
|
||||||
'state': 'draft',
|
for deposit in self:
|
||||||
'company_id': lambda self, cr, uid, c: self.pool['res.company'].
|
|
||||||
_company_default_get(cr, uid, 'account.check.deposit', context=c),
|
|
||||||
}
|
|
||||||
|
|
||||||
def _check_deposit(self, cr, uid, ids):
|
|
||||||
for deposit in self.browse(cr, uid, ids):
|
|
||||||
deposit_currency = deposit.currency_id
|
deposit_currency = deposit.currency_id
|
||||||
if deposit_currency == deposit.company_id.currency_id:
|
if deposit_currency == deposit.company_id.currency_id:
|
||||||
for line in deposit.check_payment_ids:
|
for line in deposit.check_payment_ids:
|
||||||
if line.currency_id:
|
if line.currency_id:
|
||||||
raise orm.except_orm(
|
raise ValidationError(
|
||||||
_('Error:'),
|
|
||||||
_("The check with amount %s and reference '%s' "
|
_("The check with amount %s and reference '%s' "
|
||||||
"is in currency %s but the deposit is in "
|
"is in currency %s but the deposit is in "
|
||||||
"currency %s.") % (
|
"currency %s.") % (
|
||||||
@@ -136,35 +129,27 @@ class account_check_deposit(orm.Model):
|
|||||||
else:
|
else:
|
||||||
for line in deposit.check_payment_ids:
|
for line in deposit.check_payment_ids:
|
||||||
if line.currency_id != deposit_currency:
|
if line.currency_id != deposit_currency:
|
||||||
raise orm.except_orm(
|
raise ValidationError(
|
||||||
_('Error:'),
|
|
||||||
_("The check with amount %s and reference '%s' "
|
_("The check with amount %s and reference '%s' "
|
||||||
"is in currency %s but the deposit is in "
|
"is in currency %s but the deposit is in "
|
||||||
"currency %s.") % (
|
"currency %s.") % (
|
||||||
line.debit, line.ref or '',
|
line.debit, line.ref or '',
|
||||||
line.currency_id.name,
|
line.currency_id.name,
|
||||||
deposit_currency.name))
|
deposit_currency.name))
|
||||||
return True
|
|
||||||
|
|
||||||
_constraints = [(
|
@api.multi
|
||||||
_check_deposit,
|
def unlink(self):
|
||||||
"All the checks of the deposit must be in the currency of the deposit",
|
for deposit in self:
|
||||||
['currency_id', 'check_payment_ids', 'company_id']
|
|
||||||
)]
|
|
||||||
|
|
||||||
def unlink(self, cr, uid, ids, context=None):
|
|
||||||
for deposit in self.browse(cr, uid, ids, context=context):
|
|
||||||
if deposit.state == 'done':
|
if deposit.state == 'done':
|
||||||
raise orm.except_orm(
|
raise UserError(
|
||||||
_('Error!'),
|
|
||||||
_("The deposit '%s' is in valid state, so you must "
|
_("The deposit '%s' is in valid state, so you must "
|
||||||
"cancel it before deleting it.")
|
"cancel it before deleting it.")
|
||||||
% deposit.name)
|
% deposit.name)
|
||||||
return super(account_check_deposit, self).unlink(
|
return super(AccountCheckDeposit, self).unlink()
|
||||||
cr, uid, ids, context=context)
|
|
||||||
|
|
||||||
def backtodraft(self, cr, uid, ids, context=None):
|
@api.multi
|
||||||
for deposit in self.browse(cr, uid, ids, context=context):
|
def backtodraft(self):
|
||||||
|
for deposit in self:
|
||||||
if deposit.move_id:
|
if deposit.move_id:
|
||||||
# It will raise here if journal_id.update_posted = False
|
# It will raise here if journal_id.update_posted = False
|
||||||
deposit.move_id.button_cancel()
|
deposit.move_id.button_cancel()
|
||||||
@@ -175,29 +160,30 @@ class account_check_deposit(orm.Model):
|
|||||||
deposit.write({'state': 'draft'})
|
deposit.write({'state': 'draft'})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None):
|
@api.model
|
||||||
|
def create(self, vals):
|
||||||
if vals.get('name', '/') == '/':
|
if vals.get('name', '/') == '/':
|
||||||
vals['name'] = self.pool['ir.sequence'].\
|
vals['name'] = self.env['ir.sequence'].\
|
||||||
next_by_code(cr, uid, 'account.check.deposit')
|
next_by_code('account.check.deposit')
|
||||||
return super(account_check_deposit, self).\
|
return super(AccountCheckDeposit, self).create(vals)
|
||||||
create(cr, uid, vals, context=context)
|
|
||||||
|
|
||||||
def _prepare_account_move_vals(self, cr, uid, deposit, context=None):
|
@api.model
|
||||||
|
def _prepare_account_move_vals(self, deposit):
|
||||||
date = deposit.deposit_date
|
date = deposit.deposit_date
|
||||||
period_obj = self.pool['account.period']
|
period_obj = self.env['account.period']
|
||||||
period_ids = period_obj.find(cr, uid, dt=date, context=context)
|
period_ids = period_obj.find(dt=date)
|
||||||
# period_ids will always have a value, cf the code of find()
|
# period_ids will always have a value, cf the code of find()
|
||||||
move_vals = {
|
move_vals = {
|
||||||
'journal_id': deposit.journal_id.id,
|
'journal_id': deposit.journal_id.id,
|
||||||
'date': date,
|
'date': date,
|
||||||
'period_id': period_ids[0],
|
'period_id': period_ids[0].id,
|
||||||
'name': _('Check Deposit %s') % deposit.name,
|
'name': _('Check Deposit %s') % deposit.name,
|
||||||
'ref': deposit.name,
|
'ref': deposit.name,
|
||||||
}
|
}
|
||||||
return move_vals
|
return move_vals
|
||||||
|
|
||||||
def _prepare_move_line_vals(
|
@api.model
|
||||||
self, cr, uid, line, context=None):
|
def _prepare_move_line_vals(self, line):
|
||||||
assert (line.debit > 0), 'Debit must have a value'
|
assert (line.debit > 0), 'Debit must have a value'
|
||||||
return {
|
return {
|
||||||
'name': _('Check Deposit - Ref. Check %s') % line.ref,
|
'name': _('Check Deposit - Ref. Check %s') % line.ref,
|
||||||
@@ -209,9 +195,9 @@ class account_check_deposit(orm.Model):
|
|||||||
'amount_currency': line.amount_currency * -1,
|
'amount_currency': line.amount_currency * -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@api.model
|
||||||
def _prepare_counterpart_move_lines_vals(
|
def _prepare_counterpart_move_lines_vals(
|
||||||
self, cr, uid, deposit, total_debit, total_amount_currency,
|
self, deposit, total_debit, total_amount_currency):
|
||||||
context=None):
|
|
||||||
return {
|
return {
|
||||||
'name': _('Check Deposit %s') % deposit.name,
|
'name': _('Check Deposit %s') % deposit.name,
|
||||||
'debit': total_debit,
|
'debit': total_debit,
|
||||||
@@ -222,119 +208,74 @@ class account_check_deposit(orm.Model):
|
|||||||
'amount_currency': total_amount_currency,
|
'amount_currency': total_amount_currency,
|
||||||
}
|
}
|
||||||
|
|
||||||
def validate_deposit(self, cr, uid, ids, context=None):
|
@api.multi
|
||||||
am_obj = self.pool['account.move']
|
def validate_deposit(self):
|
||||||
aml_obj = self.pool['account.move.line']
|
am_obj = self.env['account.move']
|
||||||
if context is None:
|
aml_obj = self.env['account.move.line']
|
||||||
context = {}
|
for deposit in self:
|
||||||
for deposit in self.browse(cr, uid, ids, context=context):
|
move_vals = self._prepare_account_move_vals(deposit)
|
||||||
move_vals = self._prepare_account_move_vals(
|
move = am_obj.create(move_vals)
|
||||||
cr, uid, deposit, context=context)
|
|
||||||
context['journal_id'] = move_vals['journal_id']
|
|
||||||
context['period_id'] = move_vals['period_id']
|
|
||||||
move_id = am_obj.create(cr, uid, move_vals, context=context)
|
|
||||||
total_debit = 0.0
|
total_debit = 0.0
|
||||||
total_amount_currency = 0.0
|
total_amount_currency = 0.0
|
||||||
to_reconcile_line_ids = []
|
to_reconcile_lines = []
|
||||||
for line in deposit.check_payment_ids:
|
for line in deposit.check_payment_ids:
|
||||||
total_debit += line.debit
|
total_debit += line.debit
|
||||||
total_amount_currency += line.amount_currency
|
total_amount_currency += line.amount_currency
|
||||||
line_vals = self._prepare_move_line_vals(
|
line_vals = self._prepare_move_line_vals(line)
|
||||||
cr, uid, line, context=context)
|
line_vals['move_id'] = move.id
|
||||||
line_vals['move_id'] = move_id
|
move_line = aml_obj.create(line_vals)
|
||||||
move_line_id = aml_obj.create(
|
to_reconcile_lines.append(line + move_line)
|
||||||
cr, uid, line_vals, context=context)
|
|
||||||
to_reconcile_line_ids.append([line.id, move_line_id])
|
|
||||||
|
|
||||||
# Create counter-part
|
# Create counter-part
|
||||||
if not deposit.company_id.check_deposit_account_id:
|
if not deposit.company_id.check_deposit_account_id:
|
||||||
raise orm.except_orm(
|
raise UserError(
|
||||||
_('Configuration Error:'),
|
|
||||||
_("Missing Account for Check Deposits on the "
|
_("Missing Account for Check Deposits on the "
|
||||||
"company '%s'.") % deposit.company_id.name)
|
"company '%s'.") % deposit.company_id.name)
|
||||||
|
|
||||||
counter_vals = self._prepare_counterpart_move_lines_vals(
|
counter_vals = self._prepare_counterpart_move_lines_vals(
|
||||||
cr, uid, deposit, total_debit, total_amount_currency,
|
deposit, total_debit, total_amount_currency)
|
||||||
context=context)
|
counter_vals['move_id'] = move.id
|
||||||
counter_vals['move_id'] = move_id
|
aml_obj.create(counter_vals)
|
||||||
aml_obj.create(cr, uid, counter_vals, context=context)
|
|
||||||
|
|
||||||
am_obj.post(cr, uid, [move_id], context=context)
|
move.post()
|
||||||
deposit.write({'state': 'done', 'move_id': move_id})
|
deposit.write({'state': 'done', 'move_id': move.id})
|
||||||
# We have to reconcile after post()
|
# We have to reconcile after post()
|
||||||
for reconcile_line_ids in to_reconcile_line_ids:
|
for reconcile_lines in to_reconcile_lines:
|
||||||
aml_obj.reconcile(
|
reconcile_lines.reconcile()
|
||||||
cr, uid, reconcile_line_ids, context=context)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def onchange_company_id(
|
@api.onchange('company_id')
|
||||||
self, cr, uid, ids, company_id, currency_id, context=None):
|
def onchange_company_id(self):
|
||||||
vals = {}
|
if self.company_id:
|
||||||
if company_id:
|
partner_banks = self.env['res.partner.bank'].search(
|
||||||
company = self.pool['res.company'].browse(
|
[('company_id', '=', self.company_id.id)])
|
||||||
cr, uid, company_id, context=context)
|
if len(partner_banks) == 1:
|
||||||
if currency_id:
|
self.partner_bank_id = partner_banks[0]
|
||||||
if company.currency_id.id == currency_id:
|
|
||||||
vals['currency_none_same_company_id'] = False
|
|
||||||
else:
|
|
||||||
vals['currency_none_same_company_id'] = currency_id
|
|
||||||
partner_bank_ids = self.pool['res.partner.bank'].search(
|
|
||||||
cr, uid, [('company_id', '=', company_id)], context=context)
|
|
||||||
if len(partner_bank_ids) == 1:
|
|
||||||
vals['partner_bank_id'] = partner_bank_ids[0]
|
|
||||||
else:
|
else:
|
||||||
vals['currency_none_same_company_id'] = False
|
self.partner_bank_id = False
|
||||||
vals['partner_bank_id'] = False
|
|
||||||
return {'value': vals}
|
|
||||||
|
|
||||||
def onchange_journal_id(self, cr, uid, ids, journal_id, context=None):
|
@api.onchange('journal_id')
|
||||||
vals = {}
|
def onchange_journal_id(self):
|
||||||
if journal_id:
|
if self.journal_id:
|
||||||
journal = self.pool['account.journal'].browse(
|
if self.journal_id.currency:
|
||||||
cr, uid, journal_id, context=context)
|
self.currency_id = self.journal_id.currency
|
||||||
vals['journal_default_account_id'] = \
|
|
||||||
journal.default_debit_account_id.id
|
|
||||||
if journal.currency:
|
|
||||||
vals['currency_id'] = journal.currency.id
|
|
||||||
else:
|
else:
|
||||||
vals['currency_id'] = journal.company_id.currency_id.id
|
self.currency_id = self.journal_id.company_id.currency_id
|
||||||
else:
|
|
||||||
vals['journal_default_account_id'] = False
|
|
||||||
return {'value': vals}
|
|
||||||
|
|
||||||
def onchange_currency_id(
|
|
||||||
self, cr, uid, ids, currency_id, company_id, context=None):
|
|
||||||
vals = {}
|
|
||||||
if currency_id and company_id:
|
|
||||||
company = self.pool['res.company'].browse(
|
|
||||||
cr, uid, company_id, context=context)
|
|
||||||
if company.currency_id.id == currency_id:
|
|
||||||
vals['currency_none_same_company_id'] = False
|
|
||||||
else:
|
|
||||||
vals['currency_none_same_company_id'] = currency_id
|
|
||||||
else:
|
|
||||||
vals['currency_none_same_company_id'] = False
|
|
||||||
return {'value': vals}
|
|
||||||
|
|
||||||
|
|
||||||
class account_move_line(orm.Model):
|
class AccountMoveLine(models.Model):
|
||||||
_inherit = "account.move.line"
|
_inherit = "account.move.line"
|
||||||
|
|
||||||
_columns = {
|
check_deposit_id = fields.Many2one(
|
||||||
'check_deposit_id': fields.many2one(
|
'account.check.deposit', string='Check Deposit', copy=False)
|
||||||
'account.check.deposit',
|
|
||||||
'Check Deposit'),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class res_company(orm.Model):
|
class ResCompany(models.Model):
|
||||||
_inherit = 'res.company'
|
_inherit = 'res.company'
|
||||||
|
|
||||||
_columns = {
|
check_deposit_account_id = fields.Many2one(
|
||||||
'check_deposit_account_id': fields.many2one(
|
'account.account', string='Account for Check Deposits', copy=False,
|
||||||
'account.account', 'Account for Check Deposits',
|
domain=[
|
||||||
domain=[
|
('type', '<>', 'view'),
|
||||||
('type', '<>', 'view'),
|
('type', '<>', 'closed'),
|
||||||
('type', '<>', 'closed'),
|
('reconcile', '=', True)])
|
||||||
('reconcile', '=', True)]),
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
account_check_deposit for Odoo/OpenERP
|
account_check_deposit for Odoo
|
||||||
Copyright (C) 2012-2015 Akretion (http://www.akretion.com/)
|
Copyright (C) 2012-2015 Akretion (http://www.akretion.com/)
|
||||||
@author: Benoît GUILLOT <benoit.guillot@akretion.com>
|
@author: Benoît GUILLOT <benoit.guillot@akretion.com>
|
||||||
The licence is in the file __openerp__.py
|
The licence is in the file __openerp__.py
|
||||||
|
|||||||
@@ -34,18 +34,15 @@
|
|||||||
<group name="left">
|
<group name="left">
|
||||||
<field name="deposit_date" />
|
<field name="deposit_date" />
|
||||||
<field name="journal_id"
|
<field name="journal_id"
|
||||||
widget="selection"
|
widget="selection"/>
|
||||||
on_change="onchange_journal_id(journal_id, context)"/>
|
|
||||||
<field name="journal_default_account_id"
|
<field name="journal_default_account_id"
|
||||||
invisible="1"/>
|
invisible="1"/>
|
||||||
<field name="currency_id"
|
<field name="currency_id"
|
||||||
groups="base.group_multi_currency"
|
groups="base.group_multi_currency"/>
|
||||||
on_change="onchange_currency_id(currency_id, company_id, context)"/>
|
|
||||||
<field name="partner_bank_id"/>
|
<field name="partner_bank_id"/>
|
||||||
</group>
|
</group>
|
||||||
<group name="right">
|
<group name="right">
|
||||||
<field name="company_id"
|
<field name="company_id"
|
||||||
on_change="onchange_company_id(company_id, currency_id, context)"
|
|
||||||
groups="base.group_multi_company"/>
|
groups="base.group_multi_company"/>
|
||||||
<field name="currency_none_same_company_id"
|
<field name="currency_none_same_company_id"
|
||||||
invisible="1"/>
|
invisible="1"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user