1.优化sf的产品页面展示:新增服务产品的工艺参数字段,当产品类别为服务时,该字段出现出现,材料和型号隐藏;加工参数里的表面工艺参数字段的值显示为表面工艺+可选参数

2.修复sf的表面工艺工单及完成后的询价单
This commit is contained in:
jinling.yang
2023-04-03 17:42:31 +08:00
parent a008dbb76a
commit 6ff307f364
8 changed files with 119 additions and 43 deletions

View File

@@ -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)])

View File

@@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
13 access_sf_processing_technology sf_processing_technology model_sf_processing_technology base.group_user 1 1 1 1
14 access_sf_tray sf_tray model_sf_tray base.group_user 1 1 1 1
15 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
16 access_sf_production_process_category access_sf_production_process_parameter sf_production_process_category sf_production_process_parameter model_sf_production_process_category model_sf_production_process_parameter base.group_user 1 1 1 1
17 access_sf_production_process_category sf_production_process_category model_sf_production_process_category base.group_user 1 1 1 1
18

View File

@@ -15,10 +15,10 @@
<field name="type">原材料</field>
</record>
<!-- <record id="product_category_server_sf" model="product.category">-->
<!-- <field name="name">服务</field>-->
<!-- <field name="type">服务</field>-->
<!-- </record>-->
<record id="product_category_surface_technics_sf" model="product.category">
<field name="name">表面工艺</field>
<field name="type">表面工艺</field>
</record>
<record id="product_template_sf" model="product.product">
<field name="name">CNC加工产品模板</field>

View File

@@ -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')

View File

@@ -22,17 +22,13 @@
<field name="invoice_policy" position="after">
<field name="embryo_model_type_id" string="模型类型"
attrs="{'invisible': ['|',('categ_type', '!=', '胚料'),('categ_type', '=', False)]}"/>
<field name="materials_id" string="材料"/>
<field name="materials_id" string="材料" attrs="{'invisible': [('categ_type', '=', '表面工艺')]}"/>
<field name="materials_type_id" string="型号"
domain="[('materials_id', '=', materials_id)]"/>
<field name="model_surface_process_ids" string="表面工艺" widget="many2many_tags"
>
<tree>
<field name="name"></field>
</tree>
</field>
<field name="model_process_parameters_ids" string="工艺参数" widget="many2many_tags"
options="{'no_create': True}"/>
domain="[('materials_id', '=', materials_id)]"
attrs="{'invisible': [('categ_type', '=', '表面工艺')]}"/>
<field name="server_product_process_parameters_id" string="表面工艺参数"
options="{'no_create': True}"
attrs="{'invisible': ['|',('categ_type', '!=', '服务'),('categ_type', '=', False)]}"/>
</field>
<xpath expr="//label[@for='volume']" position="before">
@@ -73,8 +69,9 @@
<field name="product_model_type_id" string="模型类型"/>
<field name="model_processing_panel" placeholder="例如R,U" string="加工面板"/>
<field name="model_machining_precision"/>
<field name="model_surface_process_ids" string="表面工艺"/>
<field name="model_process_parameters_ids" string="工艺参数"/>
<!-- <field name="model_surface_process_ids" string="表面工艺"/>-->
<field name="model_process_parameters_ids" string="表面工艺参数" widget="many2many_tags"
options="{'no_create': True}"/>
<field name="model_remark" string="备注说明"/>
</group>
</group>

View File

@@ -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)],

View File

@@ -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

View File

@@ -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):
"""