From 5670a102acde112115dbdc7a98b2aa39a89b6970 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 27 Jul 2020 13:41:57 +0000 Subject: [PATCH] [FIX] repair: sequence at creation - Create a repair order - Cancel the creation - Create another repair order There is a gap in the sequence number. The gap is due to the fact that the sequence number is consumed by the `default_get`. Although this is a change of behavior, the actual one is not really expected. Even if a gap is possible with the sequence, we don't want to consume a number every time we get the default values. opw-2301412 closes odoo/odoo#55005 X-original-commit: 9d7d618220e27024321a75be0058db2289115af2 Signed-off-by: Nicolas Martinelli (nim) --- addons/repair/models/repair.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py index 6a28defd8d2..20c5a003d31 100644 --- a/addons/repair/models/repair.py +++ b/addons/repair/models/repair.py @@ -22,7 +22,7 @@ class Repair(models.Model): name = fields.Char( 'Repair Reference', - default=lambda self: self.env['ir.sequence'].next_by_code('repair.order'), + default='/', copy=False, required=True, states={'confirmed': [('readonly', True)]}) product_id = fields.Many2one( @@ -203,6 +203,12 @@ class Repair(models.Model): raise UserError(_('You can not delete a repair order which is linked to an invoice which has been posted once.')) return super().unlink() + @api.model + def create(self, vals): + if vals.get('name', '/') == '/': + vals['name'] = self.env['ir.sequence'].next_by_code('repair.order') or '/' + return super(Repair, self).create(vals) + def button_dummy(self): # TDE FIXME: this button is very interesting return True