diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2020-09-14 08:19:11 +0000 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2020-09-17 09:35:01 +0000 |
| commit | 84793f58d91aabf9eb9b2a1e003249cbf40aef3a (patch) | |
| tree | eb85cf3cce5163027e9b5f4ac871b144466f3d7b | |
| parent | 40b97b37e2188b082cd70eec1cdf14bf9366377e (diff) | |
[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#57929
X-original-commit: 2ad9b4b2b5780c20a0cd77c48b24dcb76d69f912
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
| -rw-r--r-- | addons/repair/models/repair.py | 8 |
1 files 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): |
