diff --git a/sf_base/models/common.py b/sf_base/models/common.py
index 758a9950..f741c0ed 100644
--- a/sf_base/models/common.py
+++ b/sf_base/models/common.py
@@ -65,7 +65,6 @@ class MrsProductionProcess(models.Model):
category_id = fields.Many2one('sf.production.process.category')
# workcenter_ids = fields.Many2many('mrp.workcenter', 'rel_workcenter_process', required=True)
-
class MrsProcessingTechnology(models.Model):
_name = 'sf.processing.technology'
_description = '加工工艺'
@@ -115,6 +114,7 @@ class SupplierSort(models.Model):
class MrsProductionProcessParameter(models.Model):
_name = 'sf.production.process.parameter'
_description = '可选参数'
+ # _display_name = 'name'
code = fields.Char("编码")
name = fields.Char('名称')
@@ -124,6 +124,13 @@ class MrsProductionProcessParameter(models.Model):
materials_model_ids = fields.Many2many('sf.materials.model', 'applicable_material', string='适用材料')
active = fields.Boolean('有效', default=True)
+ def name_get(self):
+ result = []
+ for parameter in self:
+ name = parameter.process_id.name + ',' + parameter.name
+ result.append((parameter.id, name))
+ return result
+
# 获取表面工艺的获取方式
def get_gain_way(self, item):
process_parameter = self.env['sf.production.process.parameter'].search([('id', '=', item.id)])
diff --git a/sf_base/security/ir.model.access.csv b/sf_base/security/ir.model.access.csv
index 816341ee..7c13d58d 100644
--- a/sf_base/security/ir.model.access.csv
+++ b/sf_base/security/ir.model.access.csv
@@ -13,7 +13,6 @@ access_sf_materials_model,sf_materials_model,model_sf_materials_model,base.group
access_sf_processing_technology,sf_processing_technology,model_sf_processing_technology,base.group_user,1,1,1,1
access_sf_tray,sf_tray,model_sf_tray,base.group_user,1,1,1,1
access_sf_supplier_sort,sf_supplier_sort,model_sf_supplier_sort,base.group_user,1,1,1,1
-
access_sf_production_process_parameter,sf_production_process_parameter,model_sf_production_process_parameter,base.group_user,1,1,1,1
access_sf_production_process_category,sf_production_process_category,model_sf_production_process_category,base.group_user,1,1,1,1
diff --git a/sf_dlm/data/product_data.xml b/sf_dlm/data/product_data.xml
index 8e01b270..04e16c70 100644
--- a/sf_dlm/data/product_data.xml
+++ b/sf_dlm/data/product_data.xml
@@ -15,10 +15,10 @@
原材料
-
-
-
-
+
+ 表面工艺
+ 表面工艺
+
CNC加工产品模板
diff --git a/sf_dlm/models/product_template.py b/sf_dlm/models/product_template.py
index d37e2887..3e3bdfb2 100644
--- a/sf_dlm/models/product_template.py
+++ b/sf_dlm/models/product_template.py
@@ -15,7 +15,8 @@ class ResProductTemplate(models.Model):
# 模型的长,宽,高,体积,精度,材料
model_name = fields.Char('模型名称')
categ_type = fields.Selection(
- [("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料")], string='产品的类别', related='categ_id.type',
+ [("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料"), ("表面工艺", "表面工艺"), ("服务", "服务")],
+ string='产品的类别', related='categ_id.type',
store=True)
model_long = fields.Float('模型长[mm]', digits=(16, 3))
model_width = fields.Float('模型宽[mm]', digits=(16, 3))
@@ -31,9 +32,11 @@ class ResProductTemplate(models.Model):
embryo_model_type_id = fields.Many2one('sf.model.type', string='胚料模型类型')
model_processing_panel = fields.Char('模型加工面板')
# model_surface_process_category_id = fields.Many2one('sf.production.process.category', string='表面工艺类别')
- model_surface_process_ids = fields.Many2many('sf.production.process', 'rel_product_process', string='表面工艺')
- model_process_parameters_ids = fields.Many2many('sf.production.process.parameter', 'rel_product_parameter',
- string='工艺参数')
+ # model_surface_process_ids = fields.Many2many('sf.production.process', 'rel_product_process', string='表面工艺')
+ server_product_process_parameters_id = fields.Many2one('sf.production.process.parameter',
+ string='表面工艺参数(服务产品)')
+ model_process_parameters_ids = fields.Many2many('sf.production.process.parameter', 'process_parameter_rel',
+ string='表面工艺参数')
# model_price = fields.Float('模型单价', digits=(16, 3))
model_remark = fields.Char('模型备注说明')
length = fields.Float('长[mm]', digits=(16, 3))
@@ -109,7 +112,7 @@ class ResProductTemplate(models.Model):
[('materials_no', '=', item['texture_code'])]).id,
'materials_type_id': self.env['sf.materials.model'].search(
[('materials_no', '=', item['texture_type_code'])]).id,
- 'model_surface_process_ids': self.get_production_process_id(item['surface_process_code']),
+ # 'model_surface_process_ids': self.get_production_process_id(item['surface_process_code']),
'model_process_parameters_ids': self.get_process_parameters_id(item['process_parameters_code']),
'model_remark': item['remark'],
'default_code': '%s-%s' % (order_number, i),
@@ -121,12 +124,12 @@ class ResProductTemplate(models.Model):
# product_id.product_tmpl_id.active = False
return copy_product_id
- def get_production_process_id(self, surface_process_code):
- production_process_ids = []
- for item in surface_process_code:
- production_process = self.env['sf.production.process'].search([('process_encode', '=', item)])
- production_process_ids.append(production_process.id)
- return [(6, 0, production_process_ids)]
+ # def get_production_process_id(self, surface_process_code):
+ # production_process_ids = []
+ # for item in surface_process_code:
+ # production_process = self.env['sf.production.process'].search([('process_encode', '=', item)])
+ # production_process_ids.append(production_process.id)
+ # return [(6, 0, production_process_ids)]
def get_process_parameters_id(self, process_parameters_code):
process_parameters_ids = []
@@ -340,7 +343,7 @@ class ResProductCategory(models.Model):
_inherit = "product.category"
type = fields.Selection(
- [("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料")],
+ [("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料"), ("表面工艺", "表面工艺"), ("服务", "服务")],
default="", string="类型")
# @api.constrains('type')
diff --git a/sf_dlm/views/product_template_view.xml b/sf_dlm/views/product_template_view.xml
index 75345845..8a01ce61 100644
--- a/sf_dlm/views/product_template_view.xml
+++ b/sf_dlm/views/product_template_view.xml
@@ -22,17 +22,13 @@
-
+
-
-
-
-
-
-
+ domain="[('materials_id', '=', materials_id)]"
+ attrs="{'invisible': [('categ_type', '=', '表面工艺')]}"/>
+
@@ -73,8 +69,9 @@
-
-
+
+
diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py
index d027b157..ec4c4e56 100644
--- a/sf_manufacturing/models/mrp_production.py
+++ b/sf_manufacturing/models/mrp_production.py
@@ -136,7 +136,7 @@ class MrpProduction(models.Model):
route_workcenter_arr = []
for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
surface_technics_arr.append(item.route_workcenter_id.surface_technics_id.id)
- route_workcenter_arr.append(item.route_workcenter_id)
+ route_workcenter_arr.append(item.route_workcenter_id.id)
if surface_technics_arr:
production_process = self.env['sf.production.process.category'].search(
[('production_process_ids.id', 'in', surface_technics_arr)],
@@ -146,16 +146,18 @@ class MrpProduction(models.Model):
for p in production_process:
for pitem in p.production_process_ids:
if pitem.id in surface_technics_arr:
- process_parameter = self.env['sf.production.process.parameter'].search(
- [('id', '=', pitem.id)])
- for ritem in route_workcenter_arr:
- route_production_process = self.env['mrp.routing.workcenter'].search(
- [('surface_technics_id', '=', pitem.id), ('id', '=', ritem)])
- if route_production_process:
- workorders_values.append(
- self.env['mrp.workorder']._json_workorder_surface_process_str(
- production, route_production_process,
- process_parameter))
+ for param in production.product_id.model_process_parameters_ids:
+ process_parameter = self.env['sf.production.process.parameter'].search(
+ [('process_id.id', '=', pitem.id), ('id', '=', param.id)])
+ if process_parameter:
+ for ritem in route_workcenter_arr:
+ route_production_process = self.env['mrp.routing.workcenter'].search(
+ [('surface_technics_id', '=', pitem.id), ('id', '=', ritem)])
+ if route_production_process:
+ workorders_values.append(
+ self.env['mrp.workorder']._json_workorder_surface_process_str(
+ production, route_production_process,
+ process_parameter))
elif production.product_id.categ_id.type == '胚料':
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
[('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)],
diff --git a/sf_manufacturing/models/mrp_routing_workcenter.py b/sf_manufacturing/models/mrp_routing_workcenter.py
index 7f7a98d7..1ab52f61 100644
--- a/sf_manufacturing/models/mrp_routing_workcenter.py
+++ b/sf_manufacturing/models/mrp_routing_workcenter.py
@@ -60,7 +60,7 @@ class ResMrpRoutingWorkcenter(models.Model):
order by count(*),workcenter_id asc limit 1 """, [tuple(workcenter_ids)])
res = self.env.cr.fetchone()
if res:
- workcenter_id = self.env.cr.dictfetchall()[0].get('workcenter_id')
+ workcenter_id = res[0]
else:
workcenter_id = workcenter_ids[0]
return workcenter_id
diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py
index 5a049d0d..0efdc981 100644
--- a/sf_manufacturing/models/mrp_workorder.py
+++ b/sf_manufacturing/models/mrp_workorder.py
@@ -91,6 +91,8 @@ class ResMrpWorkOrder(models.Model):
cnc_ids = fields.One2many("sf.cnc.processing", 'workorder_id', string="CNC加工")
tray_code = fields.Char(string="托盘")
glb_file = fields.Binary("glb模型文件")
+ is_subcontract = fields.Boolean(string='是否外协')
+ surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数")
# 计算配料中心点和与x轴倾斜度方法
def getcenter(self):
@@ -163,10 +165,12 @@ class ResMrpWorkOrder(models.Model):
'product_uom_id': production.product_uom_id.id,
'qty_producing': 0,
'operation_id': False,
- 'name': route.name,
+ 'name': '%s-%s' % (route.name, process_parameter.name),
'processing_panel': '',
'routing_type': '表面工艺',
+ 'surface_technics_parameters_id': process_parameter.id,
'work_state': '',
+ 'is_subcontract': True if process_parameter.gain_way == '外协' else False,
'workcenter_id': self.env[
'mrp.workcenter'].get_process_outsourcing_workcenter() if process_parameter.gain_way == '外协' else
self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids,
@@ -465,6 +469,51 @@ class ResMrpWorkOrder(models.Model):
else:
raise UserError(_('请先完成上一步工单'))
+ def button_finish(self):
+ end_date = datetime.now()
+ for workorder in self:
+ if workorder.state in ('done', 'cancel'):
+ continue
+ workorder.end_all()
+ vals = {
+ 'qty_produced': workorder.qty_produced or workorder.qty_producing or workorder.qty_production,
+ 'state': 'done',
+ 'date_finished': end_date,
+ 'date_planned_finished': end_date,
+ 'costs_hour': workorder.workcenter_id.costs_hour
+ }
+ if not workorder.date_start:
+ vals['date_start'] = end_date
+ if not workorder.date_planned_start or end_date < workorder.date_planned_start:
+ vals['date_planned_start'] = end_date
+ workorder.with_context(bypass_duration_calculation=True).write(vals)
+ self.env.cr.commit()
+ finish_workorder_count = self.env['mrp.workorder'].search_count(
+ [('production_id', '=', workorder.production_id.id),
+ ('is_subcontract', '=', True)])
+ subcontract_workorder_count = self.env['mrp.workorder'].search_count(
+ [('production_id', '=', workorder.production_id.id), ('is_subcontract', '=', True),
+ ('state', '=', 'done')])
+ if len(finish_workorder_count) == len(subcontract_workorder_count):
+ subcontract_workorder = self.env['mrp.workorder'].search(
+ [('production_id', '=', workorder.production_id.id), ('is_subcontract', '=', True),
+ ('state', '=', 'done')])
+ for item in subcontract_workorder:
+ order_line_ids = []
+ server_product = self.env['product.template'].search(
+ [('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id),
+ ('categ_type', '=', '服务'), ('detailed_type', '=', 'service')])
+ order_line_ids.append((0, 0, {
+ 'product_id': server_product.id,
+ 'product_qty': 1,
+ 'product_uom': server_product.uom_id.id
+ }))
+ self.env['purchase.order'].create({
+ 'partner_id': server_product.seller_ids[0].id,
+ 'state': 'draft',
+ 'order_line': order_line_ids,
+ })
+
class CNCprocessing(models.Model):
_name = 'sf.cnc.processing'
@@ -569,6 +618,25 @@ class CNCprocessing(models.Model):
else:
return False
+ # end_date = datetime.now()
+ # for workorder in self:
+ # if workorder.state in ('done', 'cancel'):
+ # continue
+ # workorder.end_all()
+ # vals = {
+ # 'qty_produced': workorder.qty_produced or workorder.qty_producing or workorder.qty_production,
+ # 'state': 'done',
+ # 'date_finished': end_date,
+ # 'date_planned_finished': end_date,
+ # 'costs_hour': workorder.workcenter_id.costs_hour
+ # }
+ # if not workorder.date_start:
+ # vals['date_start'] = end_date
+ # if not workorder.date_planned_start or end_date < workorder.date_planned_start:
+ # vals['date_planned_start'] = end_date
+ # workorder.with_context(bypass_duration_calculation=True).write(vals)
+ return True
+
class SfWorkOrderBarcodes(models.Model):
"""