mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[FIX] change warning method + add test for date
This commit is contained in:
@@ -30,16 +30,14 @@ class AccountMove(models.Model):
|
||||
def write(self, vals):
|
||||
for move in self:
|
||||
if move.locked:
|
||||
raise exceptions.Warning(_('Move Locked!'),
|
||||
move.name)
|
||||
raise exceptions.UserError(_('Move Locked! %s') % (move.name))
|
||||
return super(AccountMove, self).write(vals)
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
for move in self:
|
||||
if move.locked:
|
||||
raise exceptions.Warning(_('Move Locked!'),
|
||||
move.name)
|
||||
raise exceptions.UserError(_('Move Locked! %s') % (move.name))
|
||||
return super(AccountMove, self).unlink()
|
||||
|
||||
@api.multi
|
||||
@@ -48,6 +46,5 @@ class AccountMove(models.Model):
|
||||
# so we need to test manualy if the move is locked
|
||||
for move in self:
|
||||
if move.locked:
|
||||
raise exceptions.Warning(_('Move Locked!'),
|
||||
move.name)
|
||||
raise exceptions.UserError(_('Move Locked! %s') % (move.name))
|
||||
return super(AccountMove, self).button_cancel()
|
||||
|
||||
@@ -36,6 +36,9 @@ class lock_account_move(models.TransientModel):
|
||||
|
||||
@api.multi
|
||||
def lock_move(self, data):
|
||||
if self.date_start > self.date_end:
|
||||
raise exceptions.UserError(_('Date start need to be \
|
||||
before Date end'))
|
||||
obj_move = self.env['account.move']
|
||||
draft_move = obj_move.search([('state', '=', 'draft'),
|
||||
('journal_id',
|
||||
@@ -47,10 +50,9 @@ class lock_account_move(models.TransientModel):
|
||||
self.date_end)],
|
||||
order='date')
|
||||
if draft_move:
|
||||
raise exceptions.Warning(_('Warning!'),
|
||||
_('Unposted move in period/jounal \
|
||||
selected, please post it before \
|
||||
locking them'))
|
||||
raise exceptions.UserError(_('Unposted move in period/jounal \
|
||||
selected, please post it before \
|
||||
locking them'))
|
||||
move = obj_move.search([('state', '=', 'posted'),
|
||||
('locked', '=', False),
|
||||
('journal_id', 'in', self.journal_ids.ids),
|
||||
@@ -58,7 +60,6 @@ class lock_account_move(models.TransientModel):
|
||||
('date', '<=', self.date_end)],
|
||||
order='date')
|
||||
if not move:
|
||||
raise exceptions.Warning(_('Warning!'),
|
||||
_('No move to locked found'))
|
||||
raise exceptions.UserError(_('No move to locked found'))
|
||||
move.write({'locked': True})
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
Reference in New Issue
Block a user