Skip to content

Commit 5c74479

Browse files
[FIX] partner_supplier_ref_sequence: do not set sequence when copying
The field is_supplier is not copied, therefore any supplier copied should not have, at first, any suppler reference. However the observed behaviour was the opposite, the supplier was being copied with is_supplier=False and with supplier_ref. The issue is that the is_supplier is not in the vals_to_check when calling _needs_supplier_ref from the copy so the current partner, the one being copied and self, value was used to see if the sequence was needed. This is an error, we can not use the self value if this value is not the one that is being set on the copied partner. To solve this we have first removed the copy inherit, as it is indeed not relevant. The copy will later trigger the create, and in the vals we will have already what we need. Then, in the create inherit we call _needs_supplier_ref with an empty self, as we don't want to use the values of any possible self already set. That only makes sense on the write.
1 parent 3b8396a commit 5c74479

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

partner_supplier_ref_sequence/models/res_partner.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class ResPartner(models.Model):
99
_inherit = "res.partner"
1010

11-
supplier_ref = fields.Char(readonly=True)
11+
supplier_ref = fields.Char(readonly=True, copy=False)
1212

1313
def _get_next_supplier_ref(self, vals=None):
1414
return self.env["ir.sequence"].next_by_code("res.partner.supplier")
@@ -38,16 +38,10 @@ def _needs_supplier_ref(self, vals=None):
3838
@api.model_create_multi
3939
def create(self, vals_list):
4040
for vals in vals_list:
41-
if not vals.get("supplier_ref") and self._needs_supplier_ref(vals=vals):
41+
if not vals.get("supplier_ref") and self.browse()._needs_supplier_ref(vals=vals):
4242
vals["supplier_ref"] = self._get_next_supplier_ref(vals=vals)
4343
return super().create(vals_list)
4444

45-
def copy(self, default=None):
46-
default = default or {}
47-
if self._needs_supplier_ref():
48-
default["supplier_ref"] = self._get_next_supplier_ref()
49-
return super().copy(default=default)
50-
5145
def write(self, vals):
5246
for partner in self:
5347
partner_vals = vals.copy()

0 commit comments

Comments
 (0)