Merge branch 'feature/内部调拨作业详情添加Rfid字段' into feature/库存模块优化

# Conflicts:
#	sf_manufacturing/models/mrp_production.py
#	sf_manufacturing/models/mrp_workorder.py
This commit is contained in:
yuxianghui
2024-04-19 10:54:36 +08:00
15 changed files with 213 additions and 46 deletions

View File

@@ -10,6 +10,7 @@
<field name='categ_id' class="custom_required" attrs="{'readonly': [('id', '!=', False)]}"/>
<field name='is_bfm' invisible="1"/>
<field name='categ_type' invisible="1"/>
<field name='manual_quotation' attrs="{'invisible':[('upload_model_file', '=', [])]}"/>
<field name="upload_model_file"
widget="many2many_binary"
attrs="{'invisible': ['|', '|',('categ_type', '!=', '成品'),('categ_type', '=', False),('is_bfm','=', True)]}"/>

View File

@@ -57,7 +57,7 @@ class MrpProduction(models.Model):
production_line_state = fields.Selection([('待上产线', '待上产线'), ('已上产线', '已上产线'), ('已下产线', '已下产线')],
string='上/下产线', default='待上产线')
manual_quotation = fields.Boolean('人工编程', default=False)
manual_quotation = fields.Boolean('人工编程', default=False, readonly=True)
@api.depends(
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state',

View File

@@ -46,7 +46,7 @@ class ResMrpWorkOrder(models.Model):
], string="工序类型")
results = fields.Char('结果')
manual_quotation = fields.Boolean('人工编程', default=False)
manual_quotation = fields.Boolean('人工编程', default=False, readonly=True)
@api.onchange('users_ids')
def get_user_permissions(self):

View File

@@ -10,7 +10,6 @@ from OCC.Extend.DataExchange import read_step_file
from OCC.Extend.DataExchange import write_stl_file
class ResProductMo(models.Model):
_inherit = 'product.template'
@@ -522,6 +521,9 @@ class ResProductMo(models.Model):
string='注册状态', default='未注册')
industry_code = fields.Char('行业编码', readonly=True)
# bfm下单
manual_quotation = fields.Boolean('人工编程', default=False, readonly=True)
@api.constrains('tool_length')
def _check_tool_length_size(self):
if self.tool_length > 1000000:
@@ -616,6 +618,7 @@ class ResProductMo(models.Model):
'process_parameters_code') else self.get_process_parameters_id(item['process_parameters_code']),
'model_remark': item['remark'],
'default_code': '%s-%s' % (order_number, i),
'manual_quotation': item['manual_quotation'] or False,
'active': True,
}
copy_product_id.sudo().write(vals)

View File

@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import logging
from datetime import timedelta
from odoo import SUPERUSER_ID
from odoo import fields, models, api
@@ -191,7 +193,7 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
machine_table_name_id = fields.Many2one('maintenance.equipment', string='机床名称',
domain="[('production_line_id', '=', production_line_id)]")
machine_table_name = fields.Char(string='机台号', readonly=True, related='machine_table_name_id.name')
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号', required=True,
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号',
domain="[('equipment_id', '=', machine_table_name_id)]")
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True)
need_knife_time = fields.Datetime(string='用刀时间', readonly=False)
@@ -201,19 +203,20 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号',
domain=[('product_id.name', '=', '功能刀具')])
functional_tool_name = fields.Char(string='功能刀具名称', compute='_compute_functional_tool_name')
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=False)
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组')
diameter = fields.Integer(string='刀具直径(mm)', readonly=False)
tool_included_angle = fields.Float(string='尖R角(mm)', readonly=False)
tool_loading_length = fields.Float(string='总长度(mm)', readonly=False)
functional_tool_name = fields.Char(string='功能刀具名称', readonly=True)
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型',
compute='_compute_tool_number', store=True)
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', compute='_compute_tool_number', store=True)
diameter = fields.Integer(string='具直径(mm)', compute='_compute_tool_number', store=True)
tool_included_angle = fields.Float(string='刀尖R角(mm)', compute='_compute_tool_number', store=True)
tool_loading_length = fields.Float(string='总长度(mm)', compute='_compute_tool_number', store=True)
extension_length = fields.Float(string='伸出长(mm)')
effective_length = fields.Float(string='有效长(mm)')
new_former = fields.Selection([('0', ''), ('1', '')], string='新/旧', readonly=False, default='0')
coarse_middle_thin = fields.Selection([("1", ""), ('2', ''), ('3', '')], default='3',
string='粗/中/精', readonly=False)
L_D = fields.Float(string='L/D值', readonly=False)
clearance_length = fields.Float(string='避空长(mm)', readonly=False)
clearance_length = fields.Float(string='避空长(mm)', compute='_compute_tool_number', store=True)
required_cutting_time = fields.Integer(string='需切削时长', readonly=False)
process_type = fields.Char('加工类型')
margin_x_y = fields.Float('余量_X/Y')
@@ -229,15 +232,24 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
active = fields.Boolean(string='已归档', default=True)
@api.depends('diameter', 'tool_included_angle', 'tool_groups_id')
def _compute_functional_tool_name(self):
for obj in self:
if obj.tool_groups_id:
obj.functional_tool_name = '%s-D%sR%s' % (
obj.tool_groups_id.name, obj.diameter,
obj.tool_included_angle)
@api.depends('functional_tool_name')
def _compute_tool_number(self):
for item in self:
inventory = self.env['sf.tool.inventory'].sudo().search([('name', '=', item.functional_tool_name)])
if inventory:
item.functional_tool_type_id = inventory.functional_cutting_tool_model_id.id
item.tool_groups_id = inventory.tool_groups_id.id
item.diameter = int(inventory.diameter)
item.tool_included_angle = inventory.angle
item.tool_loading_length = inventory.tool_length
item.clearance_length = inventory.blade_length
else:
obj.functional_tool_name = None
item.functional_tool_type_id = False
item.tool_groups_id = False
item.diameter = 0
item.tool_included_angle = 0
item.tool_loading_length = 0
item.clearance_length = 0
@api.model
def _read_group_names(self, categories, domain, order):
@@ -311,10 +323,9 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
根据传入的工单信息查询是否有需要的功能刀具如果没有则生成CAM工单程序用刀计划
"""
status = False
if cnc_processing.functional_tool_type_id and cnc_processing.cutting_tool_name:
if cnc_processing.cutting_tool_name:
functional_tools = self.env['sf.real.time.distribution.of.functional.tools'].sudo().search(
[('sf_cutting_tool_type_id', '=', cnc_processing.functional_tool_type_id.id),
('name', '=', cnc_processing.cutting_tool_name)])
[('name', '=', cnc_processing.cutting_tool_name)])
if functional_tools:
for functional_tool in functional_tools:
if functional_tool.on_tool_stock_num == 0:
@@ -327,7 +338,6 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
'name': cnc_processing.workorder_id.production_id.name,
'cam_procedure_code': cnc_processing.program_name,
'filename': cnc_processing.cnc_id.name,
'functional_tool_type_id': cnc_processing.functional_tool_type_id.id,
'functional_tool_name': cnc_processing.cutting_tool_name,
'cam_cutter_spacing_code': cnc_processing.cutting_tool_no,
'process_type': cnc_processing.processing_type,
@@ -338,8 +348,11 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
'shank_model': cnc_processing.cutting_tool_handle_type,
'estimated_processing_time': cnc_processing.estimated_processing_time,
})
logging.info('CAM工单程序用刀计划创建成功')
# 创建装刀请求
knife_plan.apply_for_tooling()
else:
logging.info('功能刀具【%s】满足CNC用刀需求')
class FunctionalToolAssembly(models.Model):

View File

@@ -36,6 +36,7 @@ class CNCprocessing(models.Model):
obj = super(CNCprocessing, self).create(vals)
# 调用CAM工单程序用刀计划创建方法
self.env['sf.cam.work.order.program.knife.plan'].create_cam_work_plan(obj)
logging.info('成功调用CAM工单程序用刀计划创建方法')
return obj

View File

@@ -1,2 +1,3 @@
# -*-coding:utf-8-*-
from . import models
from . import wizard

View File

@@ -15,6 +15,7 @@
'data/ir_cron_data.xml',
'security/sf_stock_security.xml',
'security/ir.model.access.csv',
'wizard/wizard_view.xml',
'views/view.xml',
'views/shelf_location.xml',
'views/change_stock_move_views.xml',

View File

@@ -191,6 +191,7 @@ class SfLocation(models.Model):
# return res
# 生成货位
def create_location(self):
"""
当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量
@@ -429,7 +430,6 @@ class ShelfLocation(models.Model):
}
return action
# # 仓库类别selection库区、库位、货位
# location_type = fields.Selection([
# ('货架', '货架'),
@@ -516,6 +516,19 @@ class ShelfLocation(models.Model):
else:
raise UserError("该库位无产品")
@api.model_create_multi
def create(self, vals_list):
# 编码重复校验
barcode_list = []
for val in vals_list:
location = self.search([('barcode', '=', val['barcode'])])
if location:
barcode_list.append(val['name'])
if barcode_list:
raise UserError("货位编码【%s】存在重复" % barcode_list)
records = super(ShelfLocation, self).create(vals_list)
return records
class Sf_stock_move_line(models.Model):
_name = 'stock.move.line'
@@ -531,7 +544,7 @@ class Sf_stock_move_line(models.Model):
current_product_id = fields.Integer(compute='_compute_location_dest_id_value', store=True)
there_is_no_sn = fields.Boolean('是否有序列号', default=False)
rfid = fields.Char('Rfid', readonly=True)
rfid = fields.Char('Rfid')
rfid_barcode = fields.Char('Rfid', compute='_compute_rfid')
@api.depends('lot_id')
@@ -812,35 +825,39 @@ class Sf_stock_move_line(models.Model):
destination_location_id = fields.Many2one(
'sf.shelf.location', string='目标货位')
@api.onchange('destination_location_id')
def _compute_destination_location_id(self):
def compute_destination_location_id(self):
for record in self:
obj = self.env['sf.shelf.location'].search([('name', '=',
self.destination_location_id.name)])
if record.lot_id:
shelf_location_obj = self.env['sf.shelf.location'].search(
[('product_sn_id', '=', record.lot_id.id)])
if shelf_location_obj:
shelf_location_obj.product_sn_id = False
# obj = self.env['sf.shelf.location'].search([('location_id', '=',
# self.destination_location_id.id)])
obj = self.env['sf.shelf.location'].search([('name', '=',
self.destination_location_id.name)])
if obj:
obj.product_sn_id = record.lot_id.id
else:
pass
else:
obj = self.env['sf.shelf.location'].search([('name', '=',
self.destination_location_id.name)])
if obj:
obj.product_sn_id = record.lot_id.id
else:
obj = self.env['sf.shelf.location'].search([('name', '=',
self.destination_location_id.name)])
if obj:
obj.product_id = record.product_id.id
# obj.location_status = '占用'
obj.product_num += record.reserved_uom_qty
@api.onchange('destination_location_id')
def _check_destination_location_id(self):
for item in self:
if item:
i = 0
barcode = item.destination_location_id.barcode
for line in item.picking_id.move_line_ids_without_package:
if barcode and barcode == line.destination_location_id.barcode:
i += 1
if i > 1:
raise ValidationError(
'%s】货位已经被占用,请重新选择!!!' % item.destination_location_id.barcode)
class SfStockPicking(models.Model):
_inherit = 'stock.picking'
@@ -863,12 +880,15 @@ class SfStockPicking(models.Model):
res = super(SfStockPicking, self).button_validate()
for line in self.move_line_ids:
if line:
# 调用入库方法进行入库
line.compute_destination_location_id()
if line.current_location_id:
if line.current_location_id.product_sn_id:
line.current_location_id.product_sn_id = False
# line.current_location_id.location_status = '空闲'
line.current_location_id.product_num = 0
# 对入库作业的刀柄和托盘进行Rfid绑定校验
for move in self.move_ids:
if move and move.product_id.cutting_tool_material_id.name == '刀柄' or '托盘' in (
move.product_id.fixture_material_id.name or ''):

View File

@@ -132,6 +132,9 @@ access_sf_cutting_tool_material_group_sf_stock_manager,sf_cutting_tool_material_
access_sf_cutting_tool_standard_library_group_sf_stock_manager,sf_cutting_tool_standard_library_group_sf_stock_manager,sf_base.model_sf_cutting_tool_standard_library,sf_warehouse.group_sf_stock_manager,1,0,1,0
access_sf_tool_materials_basic_parameters_group_sf_stock_manager,sf_tool_materials_basic_parameters_group_sf_stock_manager,sf_base.model_sf_tool_materials_basic_parameters,sf_warehouse.group_sf_stock_manager,1,0,1,0
access_sf_shelf_location_wizard_group_plan_dispatch,sf_shelf_location_wizard_group_plan_dispatch,model_sf_shelf_location_wizard,sf_base.group_plan_dispatch,1,0,0,0
access_sf_shelf_location_wizard_group_sf_stock_user_group_sf_stock_user,sf_shelf_location_wizard_group_sf_stock_user_group_sf_stock_user,model_sf_shelf_location_wizard,sf_warehouse.group_sf_stock_user,1,0,0,0
access_sf_shelf_location_wizard_group_sf_stock_manager,sf_shelf_location_wizard_group_sf_stock_manager,model_sf_shelf_location_wizard,sf_warehouse.group_sf_stock_manager,1,1,1,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
132
133
134
135
136
137
138
139
140

View File

@@ -19,7 +19,7 @@
<!-- ]"/> -->
<field name="destination_location_id" domain="[('location_id', '=', location_dest_id_value), '|',
('location_status', '=', '空闲'), ('product_id', '=', current_product_id), ('product_sn_id',
'=', there_is_no_sn)]"/>
'=', there_is_no_sn)]" options="{'no_create': True,'no_create_edit':True}"/>
<field name="rfid_barcode" string="Rfid"/>
<!-- <field name="location_dest_id_product_type"/> -->

View File

@@ -126,9 +126,19 @@
<field name="name">Shelf Location form</field>
<field name="model">sf.shelf.location</field>
<field name="arch" type="xml">
<form string="Shelf Location">
<form string="Shelf Location" create="0">
<header>
<button string="货位变更"
name="%(sf_warehouse.sf_shelf_location_wizard_act)d"
type="action"
context="{'default_name':name,
'default_current_name':name,
'default_current_shelf_id':shelf_id,
'default_current_location_id':location_id,
'default_current_barcode':barcode,
'default_current_product_id':product_id,
}"
class="btn-primary"/>
<field name="location_status" invisible="1"/>
<button string="禁用货位" name="action_location_status_disable" type="object"
class="oe_highlight"
@@ -155,11 +165,11 @@
</button>
</div>
<group>
<field name="barcode"/>
<field name="name"/>
<field name="shelf_id"/>
<field name="location_id"/>
<field name="product_sn_id"/>
<field name="barcode" readonly="1"/>
<field name="name" readonly="1"/>
<field name="shelf_id" readonly="1"/>
<field name="location_id" readonly="1"/>
<field name="product_sn_id" options="{'no_create': True}"/>
<field name="product_id"/>
<field name="product_num" readonly="1"/>
<field name="location_status"/>
@@ -175,7 +185,7 @@
<field name="name">shelf.location.kanban</field>
<field name="model">sf.shelf.location</field>
<field name="arch" type="xml">
<kanban class="o_kanban_mobile" js_class="custom_kanban">
<kanban class="o_kanban_mobile" js_class="custom_kanban" create="0">
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_card oe_kanban_global_click

View File

@@ -0,0 +1 @@
from . import wizard

View File

@@ -0,0 +1,64 @@
from odoo import fields, models, api
from odoo.exceptions import UserError, ValidationError
class ShelfLocationWizard(models.TransientModel):
_name = 'sf.shelf.location.wizard'
_description = '货位变更'
name = fields.Char('')
current_location_id = fields.Many2one('stock.location', string='所属库区', readonly=True)
current_shelf_id = fields.Many2one('sf.shelf', string='当前货架', readonly=True)
current_barcode = fields.Char('当前货位编码', readonly=True)
current_name = fields.Char('当前货位名称', readonly=True)
current_product_id = fields.Many2one('product.product', string='产品', readonly=True)
destination_shelf_id = fields.Many2one('sf.shelf', string='目标货架', compute='_compute_destination_name')
destination_barcode_id = fields.Many2one('sf.shelf.location', string='目标货位编码', required=True,
domain="")
destination_name = fields.Char('目标货位名称', compute='_compute_destination_name')
def return_domain(self):
val = [('location_status', '=', '空闲')]
if self.current_product_id:
val = ['|', ('location_status', '=', '空闲'), ('product_id', '=', self.current_product_id)]
if self.destination_shelf_id:
val.append(('shelf_id', '=', self.destination_shelf_id))
return "%s" % val
@api.depends('destination_barcode_id')
def _compute_destination_name(self):
if self.destination_barcode_id:
self.destination_name = self.destination_barcode_id.name
self.destination_shelf_id = self.destination_barcode_id.shelf_id.id
else:
self.destination_name = ''
self.destination_shelf_id = False
#
# @api.onchange('destination_barcode_id')
# def _onchange_destination_shelf_id(self):
# if self.destination_barcode_id:
# self.destination_shelf_id = self.destination_barcode_id.shelf_id.id
def confirm_the_change(self):
shelf_location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.current_barcode)])
# 变更货位
if self.destination_barcode_id and shelf_location:
if self.destination_barcode_id.product_id and self.destination_barcode_id.product_id == shelf_location.current_product_id and not self.destination_barcode_id.product_sn_id:
self.destination_barcode_id.product_num += shelf_location.product_num
else:
self.destination_barcode_id.product_sn_id = shelf_location.product_sn_id.id
self.destination_barcode_id.product_id = shelf_location.product_id.id
self.destination_barcode_id.product_num = shelf_location.product_num
shelf_location.product_sn_id = False
shelf_location.product_id = False
shelf_location.product_num = 0
else:
raise ValidationError('目标货位出错,请联系管理员!')
# 关闭弹出窗口
return {'type': 'ir.actions.act_window_close'}

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="sf_shelf_location_wizard_form" model="ir.ui.view">
<field name="name">货位变更</field>
<field name="model">sf.shelf.location.wizard</field>
<field name="arch" type="xml">
<form string="货位变更">
<sheet>
<group>
<group string="初始货位">
<group>
<field name="current_location_id"/>
<field name="current_shelf_id" string="货架"/>
<field name="current_barcode" string="编码"/>
<field name="current_name" string="名称"/>
</group>
</group>
<group string="目标货位">
<group>
<field name="current_location_id"/>
<field name="destination_shelf_id" string="货架" options="{'no_create': True}"
placeholder="请选择目标货架"/>
<field name="destination_barcode_id" string="编码" options="{'no_create': True}"
placeholder="请选择目标货位"
domain="['|', ('location_status', '=', '空闲'), ('product_id', '=', current_product_id)]"/>
<field name="destination_name" string="名称"/>
<field name="current_product_id" invisible="1"/>
</group>
</group>
</group>
</sheet>
<footer>
<button string="确定" name="confirm_the_change" type="object" class="btn-primary"
confirm="是否确认变更货位"/>
<button string="取消" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="sf_shelf_location_wizard_act" model="ir.actions.act_window">
<field name="name">货位变更</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sf.shelf.location.wizard</field>
<field name="view_mode">form</field>
<field name="view_id" ref="sf_shelf_location_wizard_form"/>
<field name="target">new</field>
</record>
</odoo>