Use ensure_one to avoid loop on recordset
This commit is contained in:
parent
994a3246e1
commit
4e103b95f0
@ -47,22 +47,22 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def load_lines(self):
|
def load_lines(self):
|
||||||
for wizard in self:
|
self.ensure_one()
|
||||||
template = self.env['account.move.template'].browse(
|
template = self.env['account.move.template'].browse(
|
||||||
wizard.template_id.id)
|
self.template_id.id)
|
||||||
for line in template.template_line_ids:
|
for line in template.template_line_ids:
|
||||||
if line.type == 'input':
|
if line.type == 'input':
|
||||||
self.env['wizard.select.move.template.line'].create({
|
self.env['wizard.select.move.template.line'].create({
|
||||||
'template_id': wizard.id,
|
'template_id': self.id,
|
||||||
'sequence': line.sequence,
|
'sequence': line.sequence,
|
||||||
'name': line.name,
|
'name': line.name,
|
||||||
'amount': 0.0,
|
'amount': 0.0,
|
||||||
'account_id': line.account_id.id,
|
'account_id': line.account_id.id,
|
||||||
'move_line_type': line.move_line_type,
|
'move_line_type': line.move_line_type,
|
||||||
})
|
})
|
||||||
if not wizard.line_ids:
|
if not self.line_ids:
|
||||||
return self.load_template()
|
return self.load_template()
|
||||||
wizard.write({'state': 'template_selected'})
|
self.write({'state': 'template_selected'})
|
||||||
|
|
||||||
view_rec = self.env['ir.model.data'].get_object_reference(
|
view_rec = self.env['ir.model.data'].get_object_reference(
|
||||||
'account_move_template', 'wizard_select_template')
|
'account_move_template', 'wizard_select_template')
|
||||||
@ -73,7 +73,7 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
'view_id': [view_id],
|
'view_id': [view_id],
|
||||||
'view_mode': 'form',
|
'view_mode': 'form',
|
||||||
'res_model': 'wizard.select.move.template',
|
'res_model': 'wizard.select.move.template',
|
||||||
'res_id': wizard.id,
|
'res_id': self.id,
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'target': 'new',
|
'target': 'new',
|
||||||
'context': self.env.context,
|
'context': self.env.context,
|
||||||
@ -81,16 +81,16 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def load_template(self):
|
def load_template(self):
|
||||||
for wizard in self:
|
self.ensure_one()
|
||||||
template_model = self.env['account.move.template']
|
template_model = self.env['account.move.template']
|
||||||
account_period_model = self.env['account.period']
|
account_period_model = self.env['account.period']
|
||||||
if not template_model.check_zero_lines(wizard):
|
if not template_model.check_zero_lines(self):
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_('Error !'),
|
_('Error !'),
|
||||||
_('At least one amount has to be non-zero!')
|
_('At least one amount has to be non-zero!')
|
||||||
)
|
)
|
||||||
input_lines = {}
|
input_lines = {}
|
||||||
for template_line in wizard.line_ids:
|
for template_line in self.line_ids:
|
||||||
input_lines[template_line.sequence] = template_line.amount
|
input_lines[template_line.sequence] = template_line.amount
|
||||||
|
|
||||||
period = account_period_model.find()
|
period = account_period_model.find()
|
||||||
@ -101,16 +101,16 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
computed_lines = template_model.compute_lines(
|
computed_lines = template_model.compute_lines(
|
||||||
wizard.template_id.id, input_lines)
|
self.template_id.id, input_lines)
|
||||||
|
|
||||||
moves = {}
|
moves = {}
|
||||||
for line in wizard.template_id.template_line_ids:
|
for line in self.template_id.template_line_ids:
|
||||||
if line.journal_id.id not in moves:
|
if line.journal_id.id not in moves:
|
||||||
moves[line.journal_id.id] = self._make_move(
|
moves[line.journal_id.id] = self._make_move(
|
||||||
wizard.template_id.name,
|
self.template_id.name,
|
||||||
period.id,
|
period.id,
|
||||||
line.journal_id.id,
|
line.journal_id.id,
|
||||||
wizard.partner_id.id
|
self.partner_id.id
|
||||||
)
|
)
|
||||||
|
|
||||||
self._make_move_line(
|
self._make_move_line(
|
||||||
@ -118,17 +118,17 @@ class WizardSelectMoveTemplate(models.TransientModel):
|
|||||||
computed_lines,
|
computed_lines,
|
||||||
moves[line.journal_id.id],
|
moves[line.journal_id.id],
|
||||||
period.id,
|
period.id,
|
||||||
wizard.partner_id.id
|
self.partner_id.id
|
||||||
)
|
)
|
||||||
if wizard.template_id.cross_journals:
|
if self.template_id.cross_journals:
|
||||||
trans_account_id = wizard.template_id.transitory_acc_id.id
|
trans_account_id = self.template_id.transitory_acc_id.id
|
||||||
self._make_transitory_move_line(
|
self._make_transitory_move_line(
|
||||||
line,
|
line,
|
||||||
computed_lines,
|
computed_lines,
|
||||||
moves[line.journal_id.id],
|
moves[line.journal_id.id],
|
||||||
period.id,
|
period.id,
|
||||||
trans_account_id,
|
trans_account_id,
|
||||||
wizard.partner_id.id
|
self.partner_id.id
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user