summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/barcoding_product.py
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2025-02-24 11:32:06 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2025-02-24 11:32:06 +0700
commit7df979b8d5312bb90d13d338f2a787dc35373f17 (patch)
tree12a5fd7b487781b52900505a2cffa999da692f9f /indoteknik_custom/models/barcoding_product.py
parenta9c4cd0c5ac694074f0e3a4359182a97f27f542e (diff)
parent38f8ddd9aaaad58c8d7ea27235cd109ba288693d (diff)
Merge branch 'odoo-production' into feature/integrasi_biteship
# Conflicts: # indoteknik_custom/models/__init__.py # indoteknik_custom/models/product_template.py # indoteknik_custom/models/sale_order.py # indoteknik_custom/security/ir.model.access.csv
Diffstat (limited to 'indoteknik_custom/models/barcoding_product.py')
-rw-r--r--indoteknik_custom/models/barcoding_product.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py
new file mode 100644
index 00000000..e1b8f41f
--- /dev/null
+++ b/indoteknik_custom/models/barcoding_product.py
@@ -0,0 +1,45 @@
+from odoo import models, api, fields
+from odoo.exceptions import AccessError, UserError, ValidationError
+from datetime import timedelta, date, datetime
+import logging
+
+_logger = logging.getLogger(__name__)
+
+class BarcodingProduct(models.Model):
+ _name = "barcoding.product"
+ _description = "Barcoding Product"
+
+ barcoding_product_line = fields.One2many('barcoding.product.line', 'barcoding_product_id', string='Barcoding Product Lines', auto_join=True)
+ product_id = fields.Many2one('product.product', string="Product", tracking=3)
+ quantity = fields.Float(string="Quantity", tracking=3)
+ type = fields.Selection([('print', 'Print Barcode'), ('barcoding', 'Add Barcode To Product')], string='Type', default='print')
+ barcode = fields.Char(string="Barcode")
+
+ @api.constrains('barcode')
+ def _send_barcode_to_product(self):
+ for record in self:
+ if record.barcode and not record.product_id.barcode:
+ record.product_id.barcode = record.barcode
+
+ @api.onchange('product_id', 'quantity')
+ def _onchange_product_or_quantity(self):
+ """Update barcoding_product_line based on product_id and quantity"""
+ if self.product_id and self.quantity > 0:
+ # Clear existing lines
+ self.barcoding_product_line = [(5, 0, 0)]
+
+ # Add a new line with the current product and quantity
+ self.barcoding_product_line = [(0, 0, {
+ 'product_id': self.product_id.id,
+ 'barcoding_product_id': self.id,
+ }) for _ in range(int(self.quantity))]
+
+
+class BarcodingProductLine(models.Model):
+ _name = 'barcoding.product.line'
+ _description = 'Barcoding Product Line'
+ _order = 'barcoding_product_id, id'
+
+ barcoding_product_id = fields.Many2one('barcoding.product', string='Barcoding Product Ref', required=True, ondelete='cascade', index=True, copy=False)
+ product_id = fields.Many2one('product.product', string="Product")
+ qr_code_variant = fields.Binary("QR Code Variant", related='product_id.qr_code_variant') \ No newline at end of file