Skip to content

Commit

Permalink
[FIX] barcode_generator_abstract: do not compute a new barcode_base, …
Browse files Browse the repository at this point in the history
…if the item has already a barcode_base defined.
  • Loading branch information
legalsylvain committed Oct 10, 2024
1 parent 69b9ef7 commit 5f142e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 9 additions & 9 deletions barcodes_generator_abstract/models/barcode_generate_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ def create(self, vals_list):
for rec in records:
rule = rec.barcode_rule_id
if rule and rule.generate_automate and rule.generate_type == "sequence":
if not rec.barcode_base:
rec.generate_base()
if not rec.barcode:
rec.generate_barcode()
rec.generate_base()
rec.generate_barcode()

Check warning on line 41 in barcodes_generator_abstract/models/barcode_generate_mixin.py

View check run for this annotation

Codecov / codecov/patch

barcodes_generator_abstract/models/barcode_generate_mixin.py#L40-L41

Added lines #L40 - L41 were not covered by tests
return records

def write(self, vals):
Expand All @@ -51,15 +49,17 @@ def write(self, vals):
rule = self.env["barcode.rule"].browse(vals["barcode_rule_id"])
if rule.generate_automate and rule.generate_type == "sequence":
for rec in self:
if not rec.barcode_base:
rec.generate_base()
if not rec.barcode:
rec.generate_barcode()
rec.generate_base()
rec.generate_barcode()
return res

# View Section
def generate_base(self):
for item in self:
"""Generate a base barcode, based on sequence, if the item
has no barcode defined.
Raise an exception if the generate_type of the barcode rule
is not set to 'sequence'."""
for item in self.filtered(lambda x: not x.barcode_base):
if item.generate_type != "sequence":
raise exceptions.UserError(
_(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def test_generate_sequence_sequence(self):
self.user_fake.generate_barcode()
self.assertEqual(self.user_fake.barcode, "2000001000007")

self.user_fake.barcode_base = False
self.user_fake.generate_base()
self.assertEqual(self.user_fake.barcode_base, 2)
self.user_fake.generate_barcode()
Expand Down

0 comments on commit 5f142e8

Please sign in to comment.