-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by dessanhemrayev
- Loading branch information
Showing
1 changed file
with
11 additions
and
16 deletions.
There are no files selected for viewing
27 changes: 11 additions & 16 deletions
27
barcodes_generator_product_multi_barcode/models/barcode_generate_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
) |