diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/stock/wizard/stock_assign_serial_numbers.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/stock/wizard/stock_assign_serial_numbers.py')
| -rw-r--r-- | addons/stock/wizard/stock_assign_serial_numbers.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/stock/wizard/stock_assign_serial_numbers.py b/addons/stock/wizard/stock_assign_serial_numbers.py new file mode 100644 index 00000000..1429f445 --- /dev/null +++ b/addons/stock/wizard/stock_assign_serial_numbers.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class StockAssignSerialNumbers(models.TransientModel): + _name = 'stock.assign.serial' + _description = 'Stock Assign Serial Numbers' + + def _default_next_serial_count(self): + move = self.env['stock.move'].browse(self.env.context.get('default_move_id')) + if move.exists(): + filtered_move_lines = move.move_line_ids.filtered(lambda l: not l.lot_name and not l.lot_id) + return len(filtered_move_lines) + + product_id = fields.Many2one('product.product', 'Product', + related='move_id.product_id', required=True) + move_id = fields.Many2one('stock.move', required=True) + next_serial_number = fields.Char('First SN', required=True) + next_serial_count = fields.Integer('Number of SN', + default=_default_next_serial_count, required=True) + + @api.constrains('next_serial_count') + def _check_next_serial_count(self): + for wizard in self: + if wizard.next_serial_count < 1: + raise ValidationError(_("The number of Serial Numbers to generate must greater than zero.")) + + def generate_serial_numbers(self): + self.ensure_one() + self.move_id.next_serial = self.next_serial_number or "" + return self.move_id._generate_serial_numbers(next_serial_count=self.next_serial_count) |
