Skip to content

Commit

Permalink
Merge PR #651 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Oct 11, 2024
2 parents 69b9ef7 + 5f142e8 commit f253a2d
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()
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 f253a2d

Please sign in to comment.