From b22f4d7b3b15b553ba03a89ed8d3c01e1c81a982 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 14 Sep 2020 08:19:11 +0000 Subject: [PATCH] [FIX] repair: sequence at creation Fine-tuning of 9d7d618220e27024321a75be0058db2289115af2 Although the mentioned commit delays the consumption of a sequence number at creation, it has the drawback to not generate one if the user modifies the name. In practice, we still want to generate a RMA number even if there is a custom name. A good balance is to generate the RMA number if the user leaves the `/` at the beginning of the name. If the user removes the `/`, we don't generate the RMA number. opw-2301412 closes odoo/odoo#57932 X-original-commit: 2ad9b4b2b5780c20a0cd77c48b24dcb76d69f912 Signed-off-by: Nicolas Martinelli (nim) --- addons/repair/models/repair.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py index 487d2240d1f..093678ef8e0 100644 --- a/addons/repair/models/repair.py +++ b/addons/repair/models/repair.py @@ -206,8 +206,12 @@ class Repair(models.Model): @api.model def create(self, vals): - if vals.get('name', '/') == '/': - vals['name'] = self.env['ir.sequence'].next_by_code('repair.order') or '/' + # To avoid consuming a sequence number when clicking on 'Create', we preprend it if the + # the name starts with '/'. + vals['name'] = vals.get('name') or '/' + if vals['name'].startswith('/'): + vals['name'] = (self.env['ir.sequence'].next_by_code('repair.order') or '/') + vals['name'] + vals['name'] = vals['name'][:-1] if vals['name'].endswith('/') and vals['name'] != '/' else vals['name'] return super(Repair, self).create(vals) def button_dummy(self):