mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[IMP] Add transfer lines automatically to balance the bank statement
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
from openerp.osv import fields, orm, osv
|
from openerp.osv import fields, orm, osv
|
||||||
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AccountStatementProfile(orm.Model):
|
class AccountStatementProfile(orm.Model):
|
||||||
@@ -30,6 +32,11 @@ class AccountStatementProfile(orm.Model):
|
|||||||
'Group Journal Items',
|
'Group Journal Items',
|
||||||
help="Only one Journal Entry will be generated on the "
|
help="Only one Journal Entry will be generated on the "
|
||||||
"validation of the bank statement."),
|
"validation of the bank statement."),
|
||||||
|
'split_transfer_line': fields.boolean(
|
||||||
|
'Split Transfer Line',
|
||||||
|
help="Two transfer lines will be automatically generated : one "
|
||||||
|
"for the refunds and one for the payments.")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class account_bank_statement(orm.Model):
|
class account_bank_statement(orm.Model):
|
||||||
@@ -125,11 +132,85 @@ class account_bank_statement(orm.Model):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def create_statement_payment_line(self, cr, uid, st, payment_amount, context=None):
|
||||||
|
st_line_obj = self.pool.get('account.bank.statement.line')
|
||||||
|
payment_account_id = st.profile_id.journal_id.default_credit_account_id.id
|
||||||
|
partner_id = st.profile_id.partner_id and profile.partner_id.id or False
|
||||||
|
vals = {
|
||||||
|
'name': _('Payment Transfer'),
|
||||||
|
'date': st.date,
|
||||||
|
'amount': -payment_amount,
|
||||||
|
'partner_id': partner_id,
|
||||||
|
'type': 'general',
|
||||||
|
'statement_id': st.id,
|
||||||
|
'account_id': payment_account_id,
|
||||||
|
'ref': _('Transfer'),
|
||||||
|
'already_completed': True
|
||||||
|
}
|
||||||
|
payment_line_id = st_line_obj.create(cr, uid, vals, context=context)
|
||||||
|
return payment_line_id
|
||||||
|
|
||||||
|
|
||||||
|
def create_statement_refund_line(self, cr, uid, st, refund_amount, context=None):
|
||||||
|
st_line_obj = self.pool.get('account.bank.statement.line')
|
||||||
|
refund_account_id = st.profile_id.journal_id.default_credit_account_id.id
|
||||||
|
partner_id = st.profile_id.partner_id and profile.partner_id.id or False
|
||||||
|
vals = {
|
||||||
|
'name': _('Refund Transfer'),
|
||||||
|
'date': st.date,
|
||||||
|
'amount': -refund_amount,
|
||||||
|
'partner_id': partner_id,
|
||||||
|
'type': 'general',
|
||||||
|
'statement_id': st.id,
|
||||||
|
'account_id': refund_account_id,
|
||||||
|
'ref': _('Transfer'),
|
||||||
|
'already_completed': True
|
||||||
|
}
|
||||||
|
refund_line_id = st_line_obj.create(cr, uid, vals, context=context)
|
||||||
|
return refund_line_id
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_statement_transfer_lines(self, cr, uid, st, context=None):
|
||||||
|
refund_amount = 0.0
|
||||||
|
payment_amount = 0.0
|
||||||
|
transfer_line_ids = []
|
||||||
|
#Calculate the part of the refund amount and the payment amount
|
||||||
|
for st_line in st.line_ids:
|
||||||
|
if st_line.amount < 0.0:
|
||||||
|
refund_amount += st_line.amount
|
||||||
|
else:
|
||||||
|
payment_amount += st_line.amount
|
||||||
|
#Create 2 Transfer lines or One global tranfer line
|
||||||
|
if st.profile_id.split_transfer_line:
|
||||||
|
transfer_line_ids.append(self.create_statement_refund_line(cr, uid, st,
|
||||||
|
refund_amount,
|
||||||
|
context=context))
|
||||||
|
transfer_line_ids.append(self.create_statement_payment_line(cr, uid, st,
|
||||||
|
payment_amount,
|
||||||
|
context=context))
|
||||||
|
else:
|
||||||
|
global_amount = refund_amount + payment_amount
|
||||||
|
#The global transfer line can be a refund or a payment transfer
|
||||||
|
if global_amount < 0.00:
|
||||||
|
transfer_line_ids.append(self.create_statement_refund_line(cr, uid, st,
|
||||||
|
global_amount,
|
||||||
|
context=context))
|
||||||
|
else:
|
||||||
|
transfer_line_ids.append(self.create_statement_payment_line(cr, uid, st,
|
||||||
|
global_amount,
|
||||||
|
context=context))
|
||||||
|
return transfer_line_ids
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def button_confirm_bank(self, cr, uid, ids, context=None):
|
def button_confirm_bank(self, cr, uid, ids, context=None):
|
||||||
st_line_obj = self.pool.get('account.bank.statement.line')
|
st_line_obj = self.pool.get('account.bank.statement.line')
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
for st in self.browse(cr, uid, ids, context=context):
|
for st in self.browse(cr, uid, ids, context=context):
|
||||||
|
if st.profile_id.one_move:
|
||||||
|
refund_line_ids = self.prepare_statement_transfer_lines(cr, uid, st,
|
||||||
|
context=context)
|
||||||
super(account_bank_statement, self).button_confirm_bank(cr, uid, ids,
|
super(account_bank_statement, self).button_confirm_bank(cr, uid, ids,
|
||||||
context=context)
|
context=context)
|
||||||
if st.profile_id.one_move:
|
if st.profile_id.one_move:
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="balance_check" position="after">
|
<field name="balance_check" position="after">
|
||||||
<field name="one_move"/>
|
<field name="one_move"/>
|
||||||
|
<field name="split_transfer_line" attrs="{'invisible': [('one_move', '=', False)]}"/>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
Reference in New Issue
Block a user