From 2a47fdafcb12440c68e346d35d465b0a0c800945 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 23 Jan 2025 10:03:15 +0700 Subject: push --- indoteknik_custom/models/barcoding_product.py | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 indoteknik_custom/models/barcoding_product.py (limited to 'indoteknik_custom/models/barcoding_product.py') diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py new file mode 100644 index 00000000..41444646 --- /dev/null +++ b/indoteknik_custom/models/barcoding_product.py @@ -0,0 +1,36 @@ +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) + + @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") \ No newline at end of file -- cgit v1.2.3 From 8af596373c8eb997bbb96cf020f670b6b60b57ca Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 23 Jan 2025 10:06:29 +0700 Subject: push --- indoteknik_custom/models/barcoding_product.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/barcoding_product.py') diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py index 41444646..6bbf9fde 100644 --- a/indoteknik_custom/models/barcoding_product.py +++ b/indoteknik_custom/models/barcoding_product.py @@ -33,4 +33,5 @@ class BarcodingProductLine(models.Model): _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") \ No newline at end of file + 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 -- cgit v1.2.3 From dd0158651c5fa665cde6c534e7f4283f86adafc9 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 3 Feb 2025 14:46:38 +0700 Subject: add type on barcoding product --- indoteknik_custom/models/barcoding_product.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indoteknik_custom/models/barcoding_product.py') diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py index 6bbf9fde..e1b8f41f 100644 --- a/indoteknik_custom/models/barcoding_product.py +++ b/indoteknik_custom/models/barcoding_product.py @@ -12,6 +12,14 @@ class BarcodingProduct(models.Model): 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): -- cgit v1.2.3 From 1981b2d576d916374c181c8089655ab59a3f7f20 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 23 Apr 2025 14:29:06 +0700 Subject: barcode box --- indoteknik_custom/models/barcoding_product.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/barcoding_product.py') diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py index e1b8f41f..17057d1d 100644 --- a/indoteknik_custom/models/barcoding_product.py +++ b/indoteknik_custom/models/barcoding_product.py @@ -12,15 +12,20 @@ class BarcodingProduct(models.Model): 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') + type = fields.Selection([('print', 'Print Barcode'), ('barcoding', 'Add Barcode To Product'), ('barcoding_box', 'Add Barcode Box To Product')], string='Type', default='print') barcode = fields.Char(string="Barcode") + qty_pcs_box = fields.Char(string="Quantity Pcs Box") @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 - + if record.type == 'barcoding_box': + record.product_id.barcode_box = record.barcode + record.product_id.qty_pcs_box = record.qty_pcs_box + else: + 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""" -- cgit v1.2.3 From beb2ef24d462075dc390018afe1127db313fb404 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 24 Apr 2025 10:39:19 +0700 Subject: push --- indoteknik_custom/models/barcoding_product.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom/models/barcoding_product.py') diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py index 17057d1d..353f94d5 100644 --- a/indoteknik_custom/models/barcoding_product.py +++ b/indoteknik_custom/models/barcoding_product.py @@ -19,12 +19,11 @@ class BarcodingProduct(models.Model): @api.constrains('barcode') def _send_barcode_to_product(self): for record in self: - if record.barcode and not record.product_id.barcode: - if record.type == 'barcoding_box': - record.product_id.barcode_box = record.barcode - record.product_id.qty_pcs_box = record.qty_pcs_box - else: - record.product_id.barcode = record.barcode + if record.type == 'barcoding_box': + record.product_id.barcode_box = record.barcode + record.product_id.qty_pcs_box = record.qty_pcs_box + else: + record.product_id.barcode = record.barcode @api.onchange('product_id', 'quantity') def _onchange_product_or_quantity(self): -- cgit v1.2.3 From 4706b80d3d3b1e55c198d2b4cfb93f7fa47c9732 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 24 Apr 2025 13:49:35 +0700 Subject: validation duplicate barcode product and barcode box, cr date doc kirim, validation duplicate product id on so line --- indoteknik_custom/models/barcoding_product.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'indoteknik_custom/models/barcoding_product.py') diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py index 353f94d5..e28473ff 100644 --- a/indoteknik_custom/models/barcoding_product.py +++ b/indoteknik_custom/models/barcoding_product.py @@ -16,9 +16,22 @@ class BarcodingProduct(models.Model): barcode = fields.Char(string="Barcode") qty_pcs_box = fields.Char(string="Quantity Pcs Box") + def check_duplicate_barcode(self): + barcode_product = self.env['product.product'].search([('barcode', '=', self.barcode)]) + + if barcode_product: + raise UserError('Barcode sudah digunakan {}'.format(barcode_product.display_name)) + + barcode_box = self.env['product.product'].search([('barcode_box', '=', self.barcode)]) + + if barcode_box: + raise UserError('Barcode box sudah digunakan {}'.format(barcode_box.display_name)) + + @api.constrains('barcode') def _send_barcode_to_product(self): for record in self: + record.check_duplicate_barcode() if record.type == 'barcoding_box': record.product_id.barcode_box = record.barcode record.product_id.qty_pcs_box = record.qty_pcs_box -- cgit v1.2.3 From 2db8d058d5b7c291669240df90afc0312d509939 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 24 Apr 2025 14:29:33 +0700 Subject: fix bug --- indoteknik_custom/models/barcoding_product.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models/barcoding_product.py') diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py index e28473ff..204c6128 100644 --- a/indoteknik_custom/models/barcoding_product.py +++ b/indoteknik_custom/models/barcoding_product.py @@ -17,16 +17,16 @@ class BarcodingProduct(models.Model): qty_pcs_box = fields.Char(string="Quantity Pcs Box") def check_duplicate_barcode(self): - barcode_product = self.env['product.product'].search([('barcode', '=', self.barcode)]) + if self.type in ['barcoding_box', 'barcoding']: + barcode_product = self.env['product.product'].search([('barcode', '=', self.barcode)]) - if barcode_product: - raise UserError('Barcode sudah digunakan {}'.format(barcode_product.display_name)) - - barcode_box = self.env['product.product'].search([('barcode_box', '=', self.barcode)]) - - if barcode_box: - raise UserError('Barcode box sudah digunakan {}'.format(barcode_box.display_name)) + if barcode_product: + raise UserError('Barcode sudah digunakan {}'.format(barcode_product.display_name)) + + barcode_box = self.env['product.product'].search([('barcode_box', '=', self.barcode)]) + if barcode_box: + raise UserError('Barcode box sudah digunakan {}'.format(barcode_box.display_name)) @api.constrains('barcode') def _send_barcode_to_product(self): -- cgit v1.2.3