61 lines
2.5 KiB
Python
61 lines
2.5 KiB
Python
from odoo import api, fields, models, _
|
|
|
|
|
|
class ShelfLocation(models.Model):
|
|
_inherit = 'sf.shelf.location'
|
|
|
|
tool_rfid = fields.Char('Rfid', compute='_compute_tool', store=True)
|
|
tool_name_id = fields.Many2one('sf.functional.cutting.tool.entity', string='功能刀具名称', compute='_compute_tool',
|
|
store=True)
|
|
|
|
@api.depends('product_id')
|
|
def _compute_tool(self):
|
|
for item in self:
|
|
if item.product_id:
|
|
if item.product_id.categ_id.name == '功能刀具':
|
|
tool_id = self.env['sf.functional.cutting.tool.entity'].sudo().search(
|
|
[('barcode_id', '=', item.product_sn_id.id)])
|
|
if tool_id:
|
|
item.tool_rfid = tool_id.rfid
|
|
item.tool_name_id = tool_id.id
|
|
continue
|
|
item.tool_rfid = ''
|
|
item.tool_name_id = False
|
|
|
|
|
|
class StockMoveLine(models.Model):
|
|
_inherit = 'stock.move.line'
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
records = super(StockMoveLine, self).create(vals_list)
|
|
move_lines = records.filtered(lambda a: a.product_id.categ_id.name == '功能刀具' and a.state == 'done')
|
|
if move_lines: # 校验是否为功能刀具移动历史
|
|
self.button_function_tool_use_verify(move_lines)
|
|
return records
|
|
|
|
def button_function_tool_use_verify(self, move_lines):
|
|
"""
|
|
对所有从【刀具房】到【制造前】的功能刀具进行校验(校验是否为制造订单所缺的刀)
|
|
"""
|
|
location_id = self.env['stock.location'].search([('name', '=', '刀具房')])
|
|
location_dest_id = self.env['stock.location'].search([('name', '=', '制造前')])
|
|
line_ids = move_lines.filtered(
|
|
lambda a: a.location_id == location_id and a.location_dest_id == location_dest_id)
|
|
for line_id in line_ids:
|
|
if line_id.lot_id:
|
|
self.env['sf.functional.cutting.tool.entity'].sudo().search(
|
|
[('barcode_id', '=', line_id.lot_id.id),
|
|
('functional_tool_status', '=', '正常')]).cnc_function_tool_use_verify()
|
|
|
|
|
|
class StockPicking(models.Model):
|
|
_inherit = 'stock.picking'
|
|
|
|
def button_validate(self):
|
|
res = super().button_validate()
|
|
move_lines = self.move_line_ids.filtered(lambda a: a.product_id.categ_id.name == '功能刀具')
|
|
if move_lines:
|
|
self.env['stock.move.line'].sudo().button_function_tool_use_verify(move_lines)
|
|
return res
|