Skip to content

Commit

Permalink
Merge PR #570 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by dessanhemrayev
  • Loading branch information
OCA-git-bot committed Dec 29, 2023
2 parents 7b826bf + 767ac66 commit 602af68
Showing 1 changed file with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import barcode

from odoo import api, fields, models
from odoo import models


class BarcodeGenerateMixin(models.AbstractModel):
_inherit = "barcode.generate.mixin"
class ProductProduct(models.Model):
_inherit = "product.product"

def generate_barcode(self):
"""override to create a product.barcode instead"""
for item in self:
padding = item.barcode_rule_id.padding
str_base = str(item.barcode_base).rjust(padding, "0")
custom_code = self._get_custom_barcode(item)
if custom_code:
custom_code = custom_code.replace("." * padding, str_base)
self._create_barcode(item, custom_code)

@api.model
def _create_barcode(self, item, custom_code):
barcode_class = barcode.get_barcode_class(item.barcode_rule_id.encoding)
self.env["product.barcode"].create(
{
"product_id": self.id,
"name": barcode_class(
custom_code if custom_code else fields.Datetime.now().to_string()
),
}
)
barcode_class = barcode.get_barcode_class(item.barcode_rule_id.encoding)
self.env["product.barcode"].create(
{
"product_id": item.id,
"name": barcode_class(custom_code),
}
)

0 comments on commit 602af68

Please sign in to comment.