Corrections

pull/272/head
Matthieu Dietrich 2016-05-26 16:38:20 +02:00 committed by Yannick Vaucher
parent 6211637f67
commit 48b47e70ac
4 changed files with 54 additions and 40 deletions

View File

@ -44,10 +44,9 @@ class AccountJournal(models.Model):
receivable_account_id = fields.Many2one( receivable_account_id = fields.Many2one(
comodel_name='account.account', comodel_name='account.account',
string='Force Receivable/Payable Account', string='Receivable/Payable Account',
help="Choose a receivable account to force the default " help="Choose a receivable/payable account to use as the default "
"debit/credit account (eg. an intermediat bank account " "debit/credit account.")
"instead of default debitors).")
used_for_completion = fields.Boolean( used_for_completion = fields.Boolean(
string="Journal used for completion") string="Journal used for completion")
@ -114,35 +113,49 @@ class AccountJournal(models.Model):
total_amount += global_commission_amount total_amount += global_commission_amount
partner_id = self.partner_id.id partner_id = self.partner_id.id
# Commission line # Commission line
if global_commission_amount < 0.0: if global_commission_amount > 0.0:
commission_account_id = self.commission_account_id.id raise UserError(_('Commission amount should not be positive.'))
comm_values = { elif global_commission_amount < 0.0:
'name': _('Commission line'), if not self.commission_account_id:
'date_maturity': parser.get_move_vals().get('date') or raise UserError(
fields.Date.today(), _('No commission account is set on the journal.'))
'debit': -global_commission_amount, else:
'partner_id': partner_id, commission_account_id = self.commission_account_id.id
'move_id': move.id, comm_values = {
'account_id': commission_account_id, 'name': _('Commission line'),
'already_completed': True, 'date_maturity': parser.get_move_vals().get('date') or
} fields.Date.today(),
move_line_obj.with_context( 'debit': -global_commission_amount,
check_move_validity=False 'partner_id': partner_id,
).create(comm_values) 'move_id': move.id,
'account_id': commission_account_id,
'already_completed': True,
}
move_line_obj.with_context(
check_move_validity=False
).create(comm_values)
# Counterpart line # Counterpart line
if total_amount > 0.0: if total_amount > 0.0:
receivable_account_id = self.receivable_account_id.id or False account_id = self.default_debit_account_id.id
counterpart_values = { credit = 0.0
'name': _('Counterpart line'), debit = total_amount
'date_maturity': parser.get_move_vals().get('date') or else:
fields.Date.today(), account_id = self.default_credit_account_id.id
'debit': total_amount, credit = -total_amount
'partner_id': partner_id, debit = 0.0
'move_id': move.id, counterpart_values = {
'account_id': receivable_account_id, 'name': _('/'),
'already_completed': True, 'date_maturity': parser.get_move_vals().get('date') or
} fields.Date.today(),
move_line_obj.create(counterpart_values) 'credit': credit,
'debit': debit,
'partner_id': partner_id,
'move_id': move.id,
'account_id': account_id,
'already_completed': True,
}
move_line_obj.create(counterpart_values)
@api.multi @api.multi
def write_logs_after_import(self, move, num_lines): def write_logs_after_import(self, move, num_lines):
@ -177,10 +190,7 @@ class AccountJournal(models.Model):
values['company_currency_id'] = self.company_id.currency_id.id values['company_currency_id'] = self.company_id.currency_id.id
values['journal_id'] = self.id values['journal_id'] = self.id
values['move_id'] = move.id values['move_id'] = move.id
if values['credit'] > 0.0: values['account_id'] = self.receivable_account_id.id
values['account_id'] = self.default_credit_account_id.id
else:
values['account_id'] = self.default_debit_account_id.id
values = move_line_obj._add_missing_default_values(values) values = move_line_obj._add_missing_default_values(values)
return values return values
@ -263,6 +273,9 @@ class AccountJournal(models.Model):
move.button_auto_completion() move.button_auto_completion()
# Write the needed log infos on profile # Write the needed log infos on profile
self.write_logs_after_import(move, len(result_row_list)) self.write_logs_after_import(move, len(result_row_list))
except UserError:
# "Clean" exception, raise as such
raise
except Exception: except Exception:
error_type, error_value, trbk = sys.exc_info() error_type, error_value, trbk = sys.exc_info()
st = "Error: %s\nDescription: %s\nTraceback:" % ( st = "Error: %s\nDescription: %s\nTraceback:" % (

View File

@ -99,7 +99,8 @@ class AccountMoveCompletionRule(models.Model):
invoice = self._find_invoice(line, inv_type) invoice = self._find_invoice(line, inv_type)
if invoice: if invoice:
partner_id = invoice.commercial_partner_id.id partner_id = invoice.commercial_partner_id.id
res = {'partner_id': partner_id} res = {'partner_id': partner_id,
'account_id': invoice.account_id.id}
return res return res
# Should be private but data are initialised with no update XML # Should be private but data are initialised with no update XML

View File

@ -46,7 +46,7 @@
<field name="name">account.move.completion.rule.view</field> <field name="name">account.move.completion.rule.view</field>
<field name="model">account.move.completion.rule</field> <field name="model">account.move.completion.rule</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Statement Completion Rule"> <tree string="Move Completion Rule">
<field name="sequence"/> <field name="sequence"/>
<field name="name" select="1" /> <field name="name" select="1" />
<field name="journal_ids" /> <field name="journal_ids" />

View File

@ -19,13 +19,13 @@
<field name="import_type" attrs="{'required': [('used_for_import', '=', True)]}"/> <field name="import_type" attrs="{'required': [('used_for_import', '=', True)]}"/>
</group> </group>
<group> <group>
<field name="commission_account_id" attrs="{'required': [('used_for_import', '=', True)]}"/> <field name="commission_account_id"/>
<field name="receivable_account_id" attrs="{'required': [('used_for_import', '=', True)]}"/> <field name="receivable_account_id" attrs="{'required': [('used_for_import', '=', True)]}"/>
<field name="partner_id" attrs="{'required': [('used_for_import', '=', True)]}"/> <field name="partner_id"/>
</group> </group>
<group> <group>
<button name="%(account_move_base_import.move_importer_action)d" <button name="%(account_move_base_import.move_importer_action)d"
string="Import Bank Statement" string="Import batch file"
type="action" icon="gtk-ok" type="action" icon="gtk-ok"
colspan = "2"/> colspan = "2"/>
</group> </group>