diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc index b5e3dca..39e3b77 100644 Binary files a/__pycache__/__init__.cpython-312.pyc and b/__pycache__/__init__.cpython-312.pyc differ diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc index a7341e9..93ddb1c 100644 Binary files a/models/__pycache__/__init__.cpython-312.pyc and b/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/models/__pycache__/mrp_production.cpython-312.pyc b/models/__pycache__/mrp_production.cpython-312.pyc index e83d3f5..a6a86fd 100644 Binary files a/models/__pycache__/mrp_production.cpython-312.pyc and b/models/__pycache__/mrp_production.cpython-312.pyc differ diff --git a/models/__pycache__/product_template.cpython-312.pyc b/models/__pycache__/product_template.cpython-312.pyc index bd0e794..54df751 100644 Binary files a/models/__pycache__/product_template.cpython-312.pyc and b/models/__pycache__/product_template.cpython-312.pyc differ diff --git a/models/__pycache__/stock_lot.cpython-312.pyc b/models/__pycache__/stock_lot.cpython-312.pyc index 1d02112..baabfd1 100644 Binary files a/models/__pycache__/stock_lot.cpython-312.pyc and b/models/__pycache__/stock_lot.cpython-312.pyc differ diff --git a/models/__pycache__/stock_move.cpython-312.pyc b/models/__pycache__/stock_move.cpython-312.pyc index 4a68854..c50dd49 100644 Binary files a/models/__pycache__/stock_move.cpython-312.pyc and b/models/__pycache__/stock_move.cpython-312.pyc differ diff --git a/models/__pycache__/stock_move_line.cpython-312.pyc b/models/__pycache__/stock_move_line.cpython-312.pyc index a00a711..6901acd 100644 Binary files a/models/__pycache__/stock_move_line.cpython-312.pyc and b/models/__pycache__/stock_move_line.cpython-312.pyc differ diff --git a/models/stock_quant.py b/models/stock_quant.py new file mode 100644 index 0000000..1f13d57 --- /dev/null +++ b/models/stock_quant.py @@ -0,0 +1,39 @@ +from odoo import api, models, fields, _ +from odoo.tools.float_utils import float_compare + + +class StockQuant(models.Model): + _inherit = 'stock.quant' + + def _get_inventory_move_values(self, qty, location_id, location_dest_id, package_id=False, package_dest_id=False): + """Override to handle automatic lot generation for inventory adjustments.""" + # Check if we need to generate a lot for this inventory adjustment + if (self.product_id.tracking in ['lot', 'serial'] and + float_compare(qty, 0, precision_rounding=self.product_uom_id.rounding) > 0 and + not self.lot_id and + self.product_id.product_tmpl_id.lot_sequence_id): + + # Generate lot number using the product's sequence + lot_sequence = self.product_id.product_tmpl_id.lot_sequence_id + lot_name = lot_sequence.next_by_id() + + # Create the lot record + lot = self.env['stock.lot'].create({ + 'name': lot_name, + 'product_id': self.product_id.id, + 'company_id': self.company_id.id, + }) + + # Update the quant with the new lot BEFORE creating the move + self.lot_id = lot.id + + # Call the original method to get the move values + move_vals = super()._get_inventory_move_values(qty, location_id, location_dest_id, package_id, package_dest_id) + + # Make sure the lot_id is properly set in the move line values + if self.lot_id and 'move_line_ids' in move_vals: + for line_command in move_vals['move_line_ids']: + if line_command[0] in [0, 1] and line_command[2]: # create or update command + line_command[2]['lot_id'] = self.lot_id.id + + return move_vals \ No newline at end of file