86 lines
4.2 KiB
Python
86 lines
4.2 KiB
Python
# # -*- coding: utf-8 -*-
|
|
# import logging
|
|
# from odoo import fields, models, api
|
|
# from odoo.exceptions import UserError
|
|
# from odoo.tools import str2bool
|
|
#
|
|
#
|
|
# class SfProductionProcessParameter(models.Model):
|
|
# _inherit = 'sf.production.process.parameter'
|
|
#
|
|
#
|
|
# @api.model
|
|
# def create(self, vals):
|
|
# # if vals.get('code', '/') == '/' or vals.get('code', '/') is False:
|
|
# # vals['code'] = '101'+self.routing_id.code +self.env['ir.sequence'].next_by_code('sf.production.process.parameter')
|
|
# if vals.get('routing_id'):
|
|
# # vals['gain_way'] = '外协'
|
|
# routing_id = self.env['mrp.routing.workcenter'].browse(vals.get('routing_id'))
|
|
# if routing_id.surface_technics_id and not vals.get('process_id'):
|
|
# vals['process_id'] = routing_id.surface_technics_id.id
|
|
# if vals.get('code', '/') == '/' or vals.get('code', '/') is False:
|
|
# vals['code'] = '101' + routing_id.code + self.env['ir.sequence'].next_by_code(
|
|
# 'sf.production.process.parameter')
|
|
# obj = super(SfProductionProcessParameter, self).create(vals)
|
|
# return obj
|
|
# def create_service_product(self):
|
|
# service_categ = self.env.ref(
|
|
# 'sf_dlm.product_category_surface_technics_sf').sudo()
|
|
#
|
|
# product_name = f"{self.process_id.name}_{self.name}"
|
|
# product_id = self.env['product.template'].search(
|
|
# [("name", '=', product_name)])
|
|
# if product_id:
|
|
# product_id.server_product_process_parameters_id = self.id
|
|
# else:
|
|
# res_partner = self.env['res.partner'].search([('name','=','湖南傲派自动化设备有限公司')])
|
|
# self.env['product.template'].create({
|
|
# 'detailed_type': 'service',
|
|
# 'name': product_name,
|
|
# 'invoice_policy': 'delivery',
|
|
# 'categ_id': service_categ.id,
|
|
# 'description': f"基于{self.name}创建的服务产品",
|
|
# 'sale_ok': True, # 可销售
|
|
# 'purchase_ok': True, # 可采购
|
|
# 'server_product_process_parameters_id': self.id,
|
|
# 'seller_ids': [(0, 0, {
|
|
# # 'delay': 1,
|
|
# 'partner_id': res_partner.id,
|
|
# 'price': 1, })],
|
|
# })
|
|
#
|
|
# def create_work_center(self):
|
|
# production_process_parameter = self
|
|
# if not production_process_parameter.process_id:
|
|
# return
|
|
# if not production_process_parameter.routing_id:
|
|
# workcenter_id = self.env['mrp.routing.workcenter'].search(
|
|
# [("surface_technics_id", '=', production_process_parameter.process_id.id)])
|
|
# if not workcenter_id:
|
|
# outsourcing_work_center = self.env['mrp.workcenter'].search(
|
|
# [("name", '=', '外协工作中心')])
|
|
# routing_id = self.env['mrp.routing.workcenter'].create({
|
|
# 'workcenter_ids': [(6, 0, outsourcing_work_center.ids)],
|
|
# 'routing_tag': 'special',
|
|
# 'routing_type': '表面工艺',
|
|
# 'is_outsource': True,
|
|
# 'surface_technics_id': production_process_parameter.process_id.id,
|
|
# 'name': production_process_parameter.process_id.name,
|
|
# })
|
|
# production_process_parameter.routing_id = routing_id.id
|
|
# else:
|
|
# production_process_parameter.routing_id = workcenter_id.id
|
|
#
|
|
# def init(self):
|
|
# super(SfProductionProcessParameter, self).init()
|
|
# # 在模块初始化时触发计算字段的更新
|
|
# records = self.search([])
|
|
# if str2bool(self.env['ir.config_parameter'].get_param('sf.production.process.parameter.is_init_process',
|
|
# default='False')):
|
|
# return
|
|
# for record in records:
|
|
# if not record.outsourced_service_products:
|
|
# record.create_service_product()
|
|
# record.create_work_center()
|
|
# self.env['ir.config_parameter'].set_param('sf.production.process.parameter.is_init_process', True)
|