mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[ADD] Set company_id in context to ensure that the right period is found.
[FIX] Set local_currency on the transaction lines from the statement local_currency. [ADD} Allow selection of analytic account for the statement line move and the write-off. [FIX] Use currency name lookup on the journal, not currency id.
This commit is contained in:
@@ -351,8 +351,10 @@ class account_bank_statement(osv.osv):
|
||||
st = st_line.statement_id
|
||||
|
||||
context.update({'date': st_line.date})
|
||||
ctxt = context.copy() # AB
|
||||
ctxt['company_id'] = st_line.company_id.id # AB
|
||||
period_id = self._get_period(
|
||||
cr, uid, st_line.date, context=context) # AB
|
||||
cr, uid, st_line.date, context=ctxt) # AB
|
||||
|
||||
move_id = account_move_obj.create(cr, uid, {
|
||||
'journal_id': st.journal_id.id,
|
||||
@@ -364,6 +366,7 @@ class account_bank_statement(osv.osv):
|
||||
'move_ids': [(4, move_id, False)]
|
||||
})
|
||||
|
||||
torec = []
|
||||
if st_line.amount >= 0:
|
||||
account_id = st.journal_id.default_credit_account_id.id
|
||||
else:
|
||||
@@ -411,7 +414,7 @@ class account_bank_statement(osv.osv):
|
||||
|
||||
move_line_id = account_move_line_obj.create(
|
||||
cr, uid, val, context=context)
|
||||
torec = move_line_id
|
||||
torec.append(move_line_id)
|
||||
|
||||
# Fill the secondary amount/currency
|
||||
# if currency is not the same than the company
|
||||
@@ -454,7 +457,7 @@ class account_bank_statement(osv.osv):
|
||||
- Pay invoices through workflow
|
||||
"""
|
||||
if st_line.reconcile_id:
|
||||
account_move_line_obj.write(cr, uid, [torec], {
|
||||
account_move_line_obj.write(cr, uid, torec, {
|
||||
(st_line.reconcile_id.line_partial_ids and
|
||||
'reconcile_partial_id' or 'reconcile_id'):
|
||||
st_line.reconcile_id.id }, context=context)
|
||||
|
||||
@@ -810,15 +810,19 @@ class banking_import_transaction(osv.osv):
|
||||
move_line_obj = self.pool.get('account.move.line')
|
||||
move_obj = self.pool.get('account.move')
|
||||
for trans in self.browse(cr, uid, ids, context=context):
|
||||
# Get the period for the company and date
|
||||
ctxt = context.copy()
|
||||
ctxt['company_id'] = trans.company_id.id
|
||||
periods = self.pool.get('account.period').find(
|
||||
cr, uid, trans.statement_line_id.date)
|
||||
cr, uid, trans.statement_line_id.date, context=ctxt)
|
||||
period_id = periods and periods[0] or False
|
||||
|
||||
move_id = move_obj.create(cr, uid, {
|
||||
'journal_id': trans.writeoff_journal_id.id,
|
||||
'period_id': period_id,
|
||||
'date': trans.statement_line_id.date,
|
||||
'name': '(write-off) %s' % (
|
||||
trans.move_line_id.move_id.name or '')
|
||||
trans.move_line_id.move_id.name or ''),
|
||||
}, context=context)
|
||||
if trans.residual > 0:
|
||||
writeoff_debit = trans.residual
|
||||
@@ -839,6 +843,7 @@ class banking_import_transaction(osv.osv):
|
||||
'journal_id': trans.writeoff_journal_id.id,
|
||||
'period_id': period_id,
|
||||
'currency_id': trans.statement_line_id.statement_id.currency.id,
|
||||
'analytic_account_id': trans.writeoff_analytic_id.id,
|
||||
}
|
||||
move_line_id = move_line_obj.create(
|
||||
cr, uid, vals, context=context)
|
||||
@@ -1143,7 +1148,7 @@ class banking_import_transaction(osv.osv):
|
||||
if not injected:
|
||||
i += 1
|
||||
continue
|
||||
if 'journal_id' not in account_info:
|
||||
if 'journal_id' not in account_info.keys():
|
||||
results['log'].append(
|
||||
_('Transaction found for account %(bank_account)s, '
|
||||
'but no default journal was defined.'
|
||||
@@ -1603,6 +1608,8 @@ class banking_import_transaction(osv.osv):
|
||||
'account.journal', 'Write-off journal'),
|
||||
'writeoff_move_line_id': fields.many2one(
|
||||
'account.move.line', 'Write off move line'),
|
||||
'writeoff_analytic_id': fields.many2one(
|
||||
'account.analytic.account', 'Write off analytic account'),
|
||||
}
|
||||
_defaults = {
|
||||
'company_id': lambda s,cr,uid,c:
|
||||
@@ -1707,7 +1714,7 @@ class account_bank_statement_line(osv.osv):
|
||||
statement_obj.write(
|
||||
cr, uid, [st_line.statement_id.id],
|
||||
{'name': st_number}, context=context)
|
||||
|
||||
|
||||
st_line_number = statement_obj.get_next_st_line_number(
|
||||
cr, uid, st_number, st_line, context)
|
||||
company_currency_id = st_line.statement_id.journal_id.company_id.currency_id.id
|
||||
|
||||
@@ -202,7 +202,7 @@ class banking_import(osv.osv_memory):
|
||||
error_accounts[statement.local_account] = True
|
||||
results.error_cnt += 1
|
||||
continue
|
||||
if 'journal_id' not in account_info:
|
||||
if 'journal_id' not in account_info.keys():
|
||||
results.log.append(
|
||||
_('Statements found for account %(bank_account)s, '
|
||||
'but no default journal was defined.'
|
||||
@@ -292,6 +292,7 @@ class banking_import(osv.osv_memory):
|
||||
values['statement_id'] = statement_id
|
||||
values['bank_country_code'] = bank_country_code
|
||||
values['local_account'] = statement.local_account
|
||||
values['local_currency'] = statement.local_currency
|
||||
|
||||
transaction_id = import_transaction_obj.create(cursor, uid, values, context=context)
|
||||
if transaction_id:
|
||||
|
||||
@@ -329,9 +329,17 @@ class banking_transaction_wizard(osv.osv_memory):
|
||||
'account.move.line', 'Or match this entry',
|
||||
domain=[('account_id.reconcile', '=', True),
|
||||
('reconcile_id', '=', False)],
|
||||
),
|
||||
'writeoff_analytic_id': fields.related(
|
||||
'import_transaction_id', 'writeoff_analytic_id',
|
||||
type='many2one', relation='account.analytic.account',
|
||||
string='Write-off analytic account'),
|
||||
'analytic_account_id': fields.related(
|
||||
'statement_line_id', 'analytic_account_id',
|
||||
type='many2one', relation='account.analytic.account',
|
||||
string="Analytic Account"),
|
||||
#'manual_payment_order_id': fields.many2one(
|
||||
# 'payment.order', "Payment order to reconcile"),
|
||||
),
|
||||
}
|
||||
banking_transaction_wizard()
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<field name='payment_line_id'
|
||||
attrs="{'invisible': [('match_type', '!=', 'storno'),('match_type', '!=', 'payment')]}"
|
||||
/>
|
||||
<group attrs="{'readonly': [('match_multi', '!=', True)]}">
|
||||
<group attrs="{'readonly': [('match_multi', '!=', True)]}" col="8">
|
||||
<!-- show if we have an invoice type match (but the user may need to select from multiple options)
|
||||
or whenever there is an invoice_id (e.g. in case of a manual match)
|
||||
-->
|
||||
@@ -54,6 +54,7 @@
|
||||
attrs="{'readonly': [('match_multi', '=', False)], 'invisible': [('match_type', '!=', 'payment_order')]}"
|
||||
domain="[('id', 'in', payment_order_ids[0][2])]"
|
||||
/>
|
||||
<field name='analytic_account_id' />
|
||||
</group>
|
||||
<button colspan="1"
|
||||
name="trigger_write"
|
||||
@@ -77,20 +78,6 @@
|
||||
string="Remove duplicate flag"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Write-Off" attrs="{'invisible': [('match_type', '=', False)]}">
|
||||
<group colspan="2" col="2">
|
||||
<label string="If the amount exceeds the match, you must set a write-off account and journal for the residual of this reconciliation. If the amount is smaller than the match, this is optional. If you do not set a write-off account in this case, the result will be a partial reconciliation." colspan="2"/>
|
||||
<!-- no luck with these lt/gt calculations in attrs -->
|
||||
<field name="writeoff_account_id"
|
||||
attrs="{'required': ['|','&',('residual', '<', 0),('amount', '>', 0),'&',('residual', '>', 0),('amount', '<', 0)]}"/>
|
||||
<field name="writeoff_journal_id"
|
||||
attrs="{'required': ['|','&',('residual', '<', 0),('amount', '>', 0),'&',('residual', '>', 0),('amount', '<', 0)]}"/>
|
||||
<button colspan="1"
|
||||
name="trigger_write"
|
||||
type="object"
|
||||
string="Set write-off account"/>
|
||||
</group>
|
||||
</page>
|
||||
<!-- Redo automatic match -->
|
||||
<page string="Match again">
|
||||
<label string="You can let the system try to match this bank statement line again after you have made any changes in the database (for instance, add an invoice or a bank account)." colspan="2"/>
|
||||
@@ -110,6 +97,21 @@
|
||||
type="object"
|
||||
string="Match"/>
|
||||
</page>
|
||||
<page string="Write-Off" attrs="{'invisible': [('match_type', '=', False)]}">
|
||||
<group colspan="2" col="2">
|
||||
<label string="If the amount exceeds the match, you must set a write-off account and journal for the residual of this reconciliation. If the amount is smaller than the match, this is optional. If you do not set a write-off account in this case, the result will be a partial reconciliation." colspan="2"/>
|
||||
<!-- no luck with these lt/gt calculations in attrs -->
|
||||
<field name="writeoff_account_id"
|
||||
attrs="{'required': ['|','&',('residual', '<', 0),('amount', '>', 0),'&',('residual', '>', 0),('amount', '<', 0)]}"/>
|
||||
<field name="writeoff_journal_id"
|
||||
attrs="{'required': ['|','&',('residual', '<', 0),('amount', '>', 0),'&',('residual', '>', 0),('amount', '<', 0)]}"/>
|
||||
<field name="writeoff_analytic_id" />
|
||||
<button colspan="1"
|
||||
name="trigger_write"
|
||||
type="object"
|
||||
string="Set write-off account"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Disable reconciliation" attrs="{'invisible': [('match_type', '==', False)]}">
|
||||
<group colspan="2" col="2">
|
||||
<label string="You can disable the reconciliation of this bank transfer" colspan="2"/>
|
||||
|
||||
@@ -218,8 +218,9 @@ def get_company_bank_account(pool, cursor, uid, account_number, currency,
|
||||
journal_obj = pool.get('account.journal')
|
||||
journal_ids = journal_obj.search(cursor, uid, [
|
||||
('type', '=', 'bank'),
|
||||
('currency', '=', currency or company.currency_id.name)
|
||||
('currency.name', '=', currency or company.currency_id.name)
|
||||
])
|
||||
print "---journal_ids:", account_number, journal_ids
|
||||
if not journal_ids and currency == company.currency_id.name:
|
||||
journal_ids = journal_obj.search(cursor, uid, [
|
||||
('type', '=', 'bank'), ('currency', '=', False)
|
||||
@@ -228,11 +229,13 @@ def get_company_bank_account(pool, cursor, uid, account_number, currency,
|
||||
criteria.append(('journal_id', 'in', journal_ids))
|
||||
|
||||
# Find bank account settings
|
||||
print "---criteria:", criteria
|
||||
bank_settings_ids = bank_settings_obj.search(cursor, uid, criteria)
|
||||
if bank_settings_ids:
|
||||
settings = bank_settings_obj.browse(cursor, uid, bank_settings_ids)[0]
|
||||
results.company_id = company
|
||||
results.journal_id = settings.journal_id
|
||||
print "---journal_id", settings.journal_id
|
||||
# Take currency from settings or from company
|
||||
if settings.journal_id.currency.id:
|
||||
results.currency_id = settings.journal_id.currency
|
||||
|
||||
Reference in New Issue
Block a user