diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-04-23 14:29:06 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-04-23 14:29:06 +0700 |
| commit | 1981b2d576d916374c181c8089655ab59a3f7f20 (patch) | |
| tree | f95f60f600c76a3cba03cfbc8156075cb3e8266f | |
| parent | 962f12358b0b1689d02a2716b792dae526920edf (diff) | |
barcode box
| -rw-r--r-- | indoteknik_custom/models/barcoding_product.py | 11 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 49 | ||||
| -rw-r--r-- | indoteknik_custom/views/barcoding_product.xml | 5 | ||||
| -rwxr-xr-x | indoteknik_custom/views/product_template.xml | 2 | ||||
| -rw-r--r-- | indoteknik_custom/views/stock_picking.xml | 2 |
6 files changed, 52 insertions, 19 deletions
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""" diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 600dd90e..e6a01a04 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -421,6 +421,8 @@ class ProductProduct(models.Model): plafon_qty = fields.Float(string='Max Plafon', compute='_get_plafon_qty_product') merchandise_ok = fields.Boolean(string='Product Promotion') qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') + qty_pcs_box = fields.Float("Pcs Box") + barcode_box = fields.Char("Barcode Box") def generate_product_sla(self): product_variant_ids = self.env.context.get('active_ids', []) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index cd038f44..6168d3b2 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1621,21 +1621,44 @@ class CheckProduct(models.Model): copy=False, ) product_id = fields.Many2one('product.product', string='Product') - quantity = fields.Float(string='Quantity', default=1.0) + quantity = fields.Float(string='Quantity') status = fields.Char(string='Status', compute='_compute_status') code_product = fields.Char(string='Code Product') @api.onchange('code_product') def _onchange_code_product(self): - if self.code_product: - product = self.env['product.product'].search([('default_code', '=', self.code_product)], limit=1) - if not product: - product = self.env['product.product'].search([('barcode', '=', self.code_product)], limit=1) - - if product: - self.product_id = product.id - else: - raise UserError("Product tidak ditemukan") + if not self.code_product: + return + + # Cari product berdasarkan default_code, barcode, atau barcode_box + product = self.env['product.product'].search([ + '|', + ('default_code', '=', self.code_product), + '|', + ('barcode', '=', self.code_product), + ('barcode_box', '=', self.code_product) + ], limit=1) + + if not product: + raise UserError("Product tidak ditemukan") + + # Jika scan barcode_box, set quantity sesuai qty_pcs_box + if product.barcode_box == self.code_product: + self.product_id = product.id + self.quantity = product.qty_pcs_box + self.code_product = product.default_code or product.barcode + # return { + # 'warning': { + # 'title': 'Info',8994175025871 + + # 'message': f'Product box terdeteksi. Quantity di-set ke {product.qty_pcs_box}' + # } + # } + else: + # Jika scan biasa + self.product_id = product.id + self.code_product = product.default_code or product.barcode + self.quantity = 1 def unlink(self): # Get all affected pickings before deletion @@ -1763,7 +1786,7 @@ class CheckProduct(models.Model): # Find existing lines for the same product, excluding the current line existing_lines = record.picking_id.check_product_lines.filtered( - lambda line: line.product_id == record.product_id and line.id != record.id + lambda line: line.product_id == record.product_id ) if existing_lines: @@ -1771,9 +1794,9 @@ class CheckProduct(models.Model): first_line = existing_lines[0] # Calculate the total quantity after addition - total_quantity = sum(existing_lines.mapped('quantity')) - record.quantity + total_quantity = sum(existing_lines.mapped('quantity')) - if total_quantity == total_qty_in_moves: + if total_quantity > total_qty_in_moves: raise UserError(( "Quantity Product '%s' sudah melebihi quantity demand." ) % (record.product_id.display_name)) diff --git a/indoteknik_custom/views/barcoding_product.xml b/indoteknik_custom/views/barcoding_product.xml index c7473d39..92064ee5 100644 --- a/indoteknik_custom/views/barcoding_product.xml +++ b/indoteknik_custom/views/barcoding_product.xml @@ -34,12 +34,13 @@ <group> <field name="product_id" required="1"/> <field name="type" required="1"/> - <field name="quantity" attrs="{'invisible': [['type', 'in', ('barcoding')]], 'required': [['type', 'not in', ('barcoding')]]}"/> + <field name="quantity" attrs="{'invisible': [['type', 'in', ('barcoding','barcoding_box')]], 'required': [['type', 'not in', ('barcoding')]]}"/> <field name="barcode" attrs="{'invisible': [['type', 'in', ('print')]], 'required': [['type', 'not in', ('print')]]}"/> + <field name="qty_pcs_box" attrs="{'invisible': [['type', 'in', ('print','barcoding')]], 'required': [['type', 'not in', ('print')]]}"/> </group> </group> <notebook> - <page string="Line" attrs="{'invisible': [['type', 'in', ('barcoding')]]}"> + <page string="Line" attrs="{'invisible': [['type', 'in', ('barcoding','barcoding_box')]]}"> <field name="barcoding_product_line"/> </page> </notebook> diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index af21984a..076a8082 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -62,6 +62,8 @@ <field name="inherit_id" ref="product.product_normal_form_view"/> <field name="arch" type="xml"> <field name="last_update_solr" position="after"> + <field name="barcode_box" /> + <field name="qty_pcs_box" /> <field name="clean_website_description" /> <field name="qr_code_variant" widget="image" readonly="True"/> </field> diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index da35d768..e99f8653 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -280,7 +280,7 @@ <tree editable="bottom" decoration-warning="status == 'Pending'" decoration-success="status == 'Done'"> <field name="code_product"/> <field name="product_id"/> - <field name="quantity" readonly="1"/> + <field name="quantity"/> <field name="status" readonly="1"/> </tree> </field> |
