summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqdp-odoo <qdp@odoo.com>2015-06-10 15:11:07 +0200
committerQuentin De Paoli <qdp@odoo.com>2015-06-10 15:11:19 +0200
commitb92bb1b15665cbbfe75abaafe94fd6b60d9fce5f (patch)
tree4d7596b0a656de09205df825737bcf6b0be58131
parentcec4e34146d17cfe61999618152ec2cd218bb05e (diff)
[IMP] account: modifying the short name of a journal now updates accordingly its sequence(s), if it doesn't contain any journal items (otherwise it raises an error)
-rw-r--r--addons/account/account.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/addons/account/account.py b/addons/account/account.py
index 665e1f98519..ed18ad60113 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -275,27 +275,40 @@ class AccountJournal(models.Model):
@api.multi
def write(self, vals):
for journal in self:
- if 'company_id' in vals and journal.company_id.id != vals['company_id']:
- if self.env['account.move.line'].search([('journal_id', 'in', self.ids)], limit=1):
- raise UserError(_('This journal already contains items, therefore you cannot modify its company field.'))
+ if ('company_id' in vals and journal.company_id.id != vals['company_id']):
+ if self.env['account.move'].search([('journal_id', 'in', self.ids)], limit=1):
+ raise UserError(_('This journal already contains items, therefore you cannot modify its company.'))
+ if ('code' in vals and journal.code != vals['code']):
+ if self.env['account.move'].search([('journal_id', 'in', self.ids)], limit=1):
+ raise UserError(_('This journal already contains items, therefore you cannot modify its short name.'))
+ new_prefix = self._get_sequence_prefix(vals['code'], refund=False)
+ journal.sequence_id.write({'prefix': new_prefix})
+ if journal.refund_sequence_id:
+ new_prefix = self._get_sequence_prefix(vals['code'], refund=True)
+ journal.refund_sequence_id.write({'prefix': new_prefix})
return super(AccountJournal, self).write(vals)
@api.model
+ def _get_sequence_prefix(self, code, refund=False):
+ prefix = code.upper()
+ if refund:
+ prefix = 'R' + prefix
+ return prefix + '/%(year)s/'
+
+ @api.model
def _create_sequence(self, vals, refund=False):
- """ Create new no_gap entry sequence for every new Joural
- """
- prefix = vals['code'].upper()
+ """ Create new no_gap entry sequence for every new Journal"""
+ prefix = self._get_sequence_prefix(vals['code'], refund)
if refund:
prefix = 'R' + prefix
seq = {
'name': vals['name'],
'implementation': 'no_gap',
- 'prefix': prefix + '/%(year)s/',
+ 'prefix': prefix,
'padding': 4,
'number_increment': 1,
'use_date_range': True,
}
-
if 'company_id' in vals:
seq['company_id'] = vals['company_id']
return self.env['ir.sequence'].create(seq)