[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) <nim@odoo.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user