diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py
index 0e09b018..f1086c41 100644
--- a/sf_manufacturing/models/product_template.py
+++ b/sf_manufacturing/models/product_template.py
@@ -105,18 +105,13 @@ class ResProductMo(models.Model):
'压紧方式', domain=[('type', '=', '压紧方式')])
name = fields.Char('产品名称', compute='_compute_tool_name', store=True, required=False)
- default_code = fields.Char('内部参考', compute='_onchange_tool_default_code', store=True)
- @api.depends('cutting_tool_model_id', 'specification_id')
+ @api.depends('categ_id', 'cutting_tool_material_id', 'cutting_tool_model_id', 'specification_id')
def _compute_tool_name(self):
for item in self:
if item.cutting_tool_model_id and item.specification_id:
name = '%s%s' % (item.cutting_tool_model_id.name, item.specification_id.name)
item.name = name
-
- @api.depends('categ_id', 'cutting_tool_material_id', 'cutting_tool_model_id')
- def _onchange_tool_default_code(self):
- for item in self:
if item.categ_id and item.cutting_tool_material_id and item.cutting_tool_model_id:
if item.cutting_tool_model_id.code:
default_code = '%s-T-DJWL-%s' % (
diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py
index d8a5f41f..2ff965d9 100644
--- a/sf_manufacturing/models/stock.py
+++ b/sf_manufacturing/models/stock.py
@@ -668,12 +668,14 @@ class ReStockMove(models.Model):
else:
view = self.env.ref('stock.view_stock_move_nosuggest_operations')
- if self.product_id.tracking == "serial" and self.state == "assigned":
- print(self.origin)
- if self.product_id.categ_id.name == '刀具':
- self.next_serial = self._get_tool_next_serial(self.company_id, self.product_id, self.origin)
- else:
- self.next_serial = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id)
+ if self.state == "assigned":
+ if self.product_id.tracking == "serial":
+ if self.product_id.categ_id.name == '刀具':
+ self.next_serial = self._get_tool_next_serial(self.company_id, self.product_id, self.origin)
+ else:
+ self.next_serial = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id)
+ elif self.product_id.tracking == "lot":
+ self._put_tool_lot(self.company_id, self.product_id, self.origin)
return {
'name': _('Detailed Operations'),
@@ -698,6 +700,16 @@ class ReStockMove(models.Model):
),
}
+ def _put_tool_lot(self, company, product, origin):
+ if product.tracking == "lot" and self.product_id.categ_id.name == '刀具':
+ if not self.move_line_nosuggest_ids:
+ lot_names = self.env['stock.lot'].generate_lot_names(
+ '%s-%s-%s' % ('%s-T-DJWL-%s' % (
+ product.cutting_tool_model_id.code.split('-')[0], product.cutting_tool_material_id.code),
+ datetime.now().strftime("%Y%m%d"), origin), 1)
+ move_lines_commands = self._generate_serial_move_line_commands_tool_lot(lot_names)
+ self.write({'move_line_nosuggest_ids': move_lines_commands})
+
def _get_tool_next_serial(self, company, product, origin):
"""Return the next serial number to be attributed to the product."""
if product.tracking == "serial":
@@ -711,6 +723,67 @@ class ReStockMove(models.Model):
else:
return "%s-T-%s-%s-%03d" % (split_codes[0], origin, product.specification_id.name, 1)
+ def _generate_serial_move_line_commands_tool_lot(self, lot_names, origin_move_line=None):
+ """Return a list of commands to update the move lines (write on
+ existing ones or create new ones).
+ Called when user want to create and assign multiple serial numbers in
+ one time (using the button/wizard or copy-paste a list in the field).
+
+ :param lot_names: A list containing all serial number to assign.
+ :type lot_names: list
+ :param origin_move_line: A move line to duplicate the value from, default to None
+ :type origin_move_line: record of :class:`stock.move.line`
+ :return: A list of commands to create/update :class:`stock.move.line`
+ :rtype: list
+ """
+ self.ensure_one()
+
+ # Select the right move lines depending of the picking type configuration.
+ move_lines = self.env['stock.move.line']
+ if self.picking_type_id.show_reserved:
+ move_lines = self.move_line_ids.filtered(lambda ml: not ml.lot_id and not ml.lot_name)
+ else:
+ move_lines = self.move_line_nosuggest_ids.filtered(lambda ml: not ml.lot_id and not ml.lot_name)
+
+ loc_dest = origin_move_line and origin_move_line.location_dest_id
+ move_line_vals = {
+ 'picking_id': self.picking_id.id,
+ 'location_id': self.location_id.id,
+ 'product_id': self.product_id.id,
+ 'product_uom_id': self.product_id.uom_id.id,
+ 'qty_done': self.product_uom_qty,
+ }
+ if origin_move_line:
+ # `owner_id` and `package_id` are taken only in the case we create
+ # new move lines from an existing move line. Also, updates the
+ # `qty_done` because it could be usefull for products tracked by lot.
+ move_line_vals.update({
+ 'owner_id': origin_move_line.owner_id.id,
+ 'package_id': origin_move_line.package_id.id,
+ 'qty_done': origin_move_line.qty_done or 1,
+ })
+
+ move_lines_commands = []
+ qty_by_location = defaultdict(float)
+ for lot_name in lot_names:
+ # We write the lot name on an existing move line (if we have still one)...
+ if move_lines:
+ move_lines_commands.append((1, move_lines[0].id, {
+ 'lot_name': lot_name,
+ 'qty_done': 1,
+ }))
+ qty_by_location[move_lines[0].location_dest_id.id] += 1
+ move_lines = move_lines[1:]
+ # ... or create a new move line with the serial name.
+ else:
+ loc = loc_dest or self.location_dest_id._get_putaway_strategy(self.product_id, quantity=1,
+ packaging=self.product_packaging_id,
+ additional_qty=qty_by_location)
+ move_line_cmd = dict(move_line_vals, lot_name=lot_name, location_dest_id=loc.id)
+ move_lines_commands.append((0, 0, move_line_cmd))
+ qty_by_location[loc.id] += 1
+ return move_lines_commands
+
class ReStockQuant(models.Model):
_inherit = 'stock.quant'
diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py
index 1a7ba1e0..9e4eada4 100644
--- a/sf_warehouse/models/model.py
+++ b/sf_warehouse/models/model.py
@@ -452,8 +452,9 @@ class ShelfLocation(models.Model):
# product_id = fields.Many2one('product.template', string='产品')
product_id = fields.Many2one('product.product', string='产品', compute='_compute_product_id', store=True)
product_sn_id = fields.Many2one('stock.lot', string='产品序列号')
+ product_sn_ids = fields.Many2many('stock.lot', 'shelf_location_stock_lot', string='产品批次号')
# 产品数量
- product_num = fields.Integer('数量')
+ product_num = fields.Integer('总数量')
@api.depends('product_num')
def _compute_product_num(self):
diff --git a/sf_warehouse/views/shelf_location.xml b/sf_warehouse/views/shelf_location.xml
index a284f288..49cc1ce8 100644
--- a/sf_warehouse/views/shelf_location.xml
+++ b/sf_warehouse/views/shelf_location.xml
@@ -169,8 +169,14 @@
-
+
+
+
+
+
+
+