[FIX] Account : Validation of moves should create relavent account analytic entries

lp bug: https://launchpad.net/bugs/582988 fixed

bzr revid: jvo@tinyerp.com-20100707141120-1wqscl1r5t8u6thi
This commit is contained in:
Borja López Soilán (Pexego) 2010-07-07 19:41:20 +05:30 committed by Jay (Open ERP)
parent 35cc919184
commit 65ddf755de
3 changed files with 49 additions and 50 deletions

View File

@ -1202,9 +1202,11 @@ class account_move(osv.osv):
def validate(self, cr, uid, ids, context={}):
if context and ('__last_update' in context):
del context['__last_update']
ok = True
valid_moves = [] #Maintains a list of moves which can be responsible to create analytic entries
for move in self.browse(cr, uid, ids, context):
#unlink analytic lines on move_lines
# Unlink old analytic lines on move_lines
for obj_line in move.line_id:
for obj in obj_line.analytic_lines:
self.pool.get('account.analytic.line').unlink(cr,uid,obj.id)
@ -1213,7 +1215,7 @@ class account_move(osv.osv):
amount = 0
line_ids = []
line_draft_ids = []
company_id=None
company_id = None
for line in move.line_id:
amount += line.debit - line.credit
line_ids.append(line.id)
@ -1230,45 +1232,59 @@ class account_move(osv.osv):
raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different from the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""" % (line.account_id.code, line.account_id.name)))
if abs(amount) < 10 ** -4:
# If the move is balanced
# Add to the list of valid moves
# (analytic lines will be created later for valid moves)
valid_moves.append(move)
# Check whether the move lines are confirmed
if not len(line_draft_ids):
continue
# Update the move lines (set them as valid)
self.pool.get('account.move.line').write(cr, uid, line_draft_ids, {
'journal_id': move.journal_id.id,
'period_id': move.period_id.id,
'state': 'valid'
}, context, check=False)
todo = []
account = {}
account2 = {}
if journal.type not in ('purchase','sale'):
continue
if journal.type in ('purchase','sale'):
for line in move.line_id:
code = amount = 0
key = (line.account_id.id, line.tax_code_id.id)
if key in account2:
code = account2[key][0]
amount = account2[key][1] * (line.debit + line.credit)
elif line.account_id.id in account:
code = account[line.account_id.id][0]
amount = account[line.account_id.id][1] * (line.debit + line.credit)
if (code or amount) and not (line.tax_code_id or line.tax_amount):
self.pool.get('account.move.line').write(cr, uid, [line.id], {
'tax_code_id': code,
'tax_amount': amount
}, context, check=False)
elif journal.centralisation:
# If the move is not balanced, it must be centralised...
# Add to the list of valid moves
# (analytic lines will be created later for valid moves)
valid_moves.append(move)
for line in move.line_id:
code = amount = 0
key = (line.account_id.id, line.tax_code_id.id)
if key in account2:
code = account2[key][0]
amount = account2[key][1] * (line.debit + line.credit)
elif line.account_id.id in account:
code = account[line.account_id.id][0]
amount = account[line.account_id.id][1] * (line.debit + line.credit)
if (code or amount) and not (line.tax_code_id or line.tax_amount):
self.pool.get('account.move.line').write(cr, uid, [line.id], {
'tax_code_id': code,
'tax_amount': amount
}, context, check=False)
#
# Compute VAT
# Update the move lines (set them as valid)
#
continue
if journal.centralisation:
self._centralise(cr, uid, move, 'debit', context=context)
self._centralise(cr, uid, move, 'credit', context=context)
self.pool.get('account.move.line').write(cr, uid, line_draft_ids, {
'state': 'valid'
}, context, check=False)
continue
else:
# We can't validate it (it's unbalanced)
# Setting the lines as draft
self.pool.get('account.move.line').write(cr, uid, line_ids, {
'journal_id': move.journal_id.id,
'period_id': move.period_id.id,
@ -1276,13 +1292,12 @@ class account_move(osv.osv):
#'tax_amount': False,
'state': 'draft'
}, context, check=False)
ok = False
if ok:
list_ids = []
for tmp in move.line_id:
list_ids.append(tmp.id)
self.pool.get('account.move.line').create_analytic_lines(cr, uid, list_ids, context)
return ok
# Create analytic lines for the valid moves
for record in valid_moves:
self.pool.get('account.move.line').create_analytic_lines(cr, uid, [line.id for line in record.line_id], context)
return len(valid_moves) > 0
account_move()
class account_move_reconcile(osv.osv):

View File

@ -1194,7 +1194,7 @@
<!-- <menuitem id="next_id_29" name="Search Entries" parent="account.menu_finance_entries" sequence="40"/>-->
<!-- <menuitem action="action_move_line_form" id="menu_action_move_line_form" parent="next_id_29"/>-->
<record id="action_move_line_form_encode_by_move" model="ir.actions.act_window">
<!-- <record id="action_move_line_form_encode_by_move" model="ir.actions.act_window">
<field name="name">Journal Entries</field>
<field name="res_model">account.move</field>
<field name="view_type">form</field>
@ -1203,7 +1203,7 @@
<field name="search_view_id" ref="view_account_move_filter"/>
</record>
<menuitem action="action_move_line_form_encode_by_move" id="menu_encode_entries_by_move" parent="menu_finance_entries"/>
<menuitem action="action_move_line_form_encode_by_move" id="menu_encode_entries_by_move" parent="menu_finance_entries"/>-->
<record id="action_account_moves_sale" model="ir.actions.act_window">
<field name="name">Journal Items</field>
@ -2237,22 +2237,6 @@
id="menu_action_account_fiscal_position_form_template"
parent="account_template_folder" sequence="20"/>
<record id="action_move_journal_line" model="ir.actions.act_window">
<field name="name">Journal Entries</field>
<field name="res_model">account.move</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_move_tree"/>
<field name="search_view_id" ref="view_account_move_filter"/>
</record>
<menuitem
icon="STOCK_JUSTIFY_FILL"
action="action_move_journal_line"
id="menu_action_move_journal_line_form"
parent="account.menu_finance_entries"
sequence="5"/>
<record id="action_account_moves_all" model="ir.actions.act_window">
<field name="name">Journal Items</field>
<field name="res_model">account.move.line</field>

View File

@ -8,7 +8,7 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Journal Select">
<label string="Are you sure you want to open Journal Entries!" colspan="4"/>
<label string="Are you sure you want to open Journal Entries?" colspan="4"/>
<separator string="" colspan="4" />
<group colspan="4" col="6">
<button icon="terp-gtk-stop" special="cancel" string="Cancel"/>