212
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from. import sf_base
|
||||
from. import sf_common
|
||||
from. import process
|
||||
from. import product_template
|
||||
from. import sale_order
|
||||
from . import base
|
||||
from . import common
|
||||
|
||||
|
||||
|
||||
@@ -13,29 +13,29 @@ _logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MachineBrandTags(models.Model):
|
||||
_name = 'mrs.machine.brand.tags'
|
||||
_name = 'sf.machine.brand.tags'
|
||||
_description = '标签'
|
||||
name = fields.Char('名称', size=50)
|
||||
color = fields.Integer('颜色', default=0)
|
||||
|
||||
|
||||
class MachineControlSystem(models.Model):
|
||||
_name = 'mrs.machine.control_system'
|
||||
_name = 'sf.machine.control_system'
|
||||
_description = '控制系统'
|
||||
|
||||
code = fields.Char('编码', size=10)
|
||||
name = fields.Char('名称', size=10)
|
||||
brand_id = fields.Many2one('mrs.machine.brand', '品牌')
|
||||
brand_id = fields.Many2one('sf.machine.brand', '品牌')
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
|
||||
# 品牌标签
|
||||
class MachineBrand(models.Model):
|
||||
_name = 'mrs.machine.brand'
|
||||
_name = 'sf.machine.brand'
|
||||
_description = '品牌'
|
||||
|
||||
name = fields.Char('名称')
|
||||
tag_ids = fields.Many2many('mrs.machine.brand.tags', 'rel_machine_brand_tags', string='类别')
|
||||
tag_ids = fields.Many2many('sf.machine.brand.tags', 'rel_machine_brand_tags', string='类别')
|
||||
image_brand = fields.Image("品牌图片")
|
||||
active = fields.Boolean('有效', default=True)
|
||||
code = fields.Char('编码')
|
||||
@@ -43,7 +43,7 @@ class MachineBrand(models.Model):
|
||||
|
||||
# 机床
|
||||
class MachineTool(models.Model):
|
||||
_name = 'mrs.machine_tool'
|
||||
_name = 'sf.machine_tool'
|
||||
_description = '机床'
|
||||
MTcode = fields.Char("编码")
|
||||
code = fields.Char('行业编码')
|
||||
@@ -64,11 +64,11 @@ class MachineTool(models.Model):
|
||||
c_axis = fields.Integer('C轴')
|
||||
remark = fields.Text('备注')
|
||||
precision = fields.Float('加工精度')
|
||||
control_system_id = fields.Many2one('mrs.machine.control_system',
|
||||
control_system_id = fields.Many2one('sf.machine.control_system',
|
||||
string="控制系统")
|
||||
# 多个机床型号对应一个机床
|
||||
type_id = fields.Many2one('mrs.machine_tool.type', '型号')
|
||||
brand_id = fields.Many2one('mrs.machine.brand', string='品牌')
|
||||
type_id = fields.Many2one('sf.machine_tool.type', '型号')
|
||||
brand_id = fields.Many2one('sf.machine.brand', string='品牌')
|
||||
state = fields.Selection(
|
||||
[("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")],
|
||||
default='正常', string="状态")
|
||||
@@ -145,10 +145,10 @@ class MachineTool(models.Model):
|
||||
def enroll_machine_tool(self):
|
||||
sf_sync_config = self.env['res.config.settings'].get_values()
|
||||
token = sf_sync_config['token']
|
||||
mrs_secret_key = sf_sync_config['mrs_secret_key']
|
||||
headers = Common.get_headers(self, token, mrs_secret_key)
|
||||
strurl = sf_sync_config['mrs_url'] + self.crea_url
|
||||
objs_all = request.env['mrs.machine_tool'].sudo().search([])
|
||||
sf_secret_key = sf_sync_config['sf_secret_key']
|
||||
headers = Common.get_headers(self, token, sf_secret_key)
|
||||
strurl = sf_sync_config['sf_url'] + self.crea_url
|
||||
objs_all = request.env['sf.machine_tool'].sudo().search([])
|
||||
machine_tool_list = []
|
||||
if objs_all:
|
||||
for item in objs_all:
|
||||
@@ -162,10 +162,10 @@ class MachineTool(models.Model):
|
||||
'number_of_knife_library': item.number_of_knife_library,
|
||||
'rotate_speed': item.rotate_speed,
|
||||
'number_of_axles': item.number_of_axles,
|
||||
'control_system_id': self.env['mrs.machine.control_system'].search(
|
||||
'control_system_id': self.env['sf.machine.control_system'].search(
|
||||
[('id', '=', item.control_system_id.id)]).code,
|
||||
'type_id': self.env['mrs.machine_tool.type'].search([('id', '=', item.type_id.id)]).code,
|
||||
'brand_id': self.env['mrs.machine.brand'].search([('id', '=', item.brand_id.id)]).code,
|
||||
'type_id': self.env['sf.machine_tool.type'].search([('id', '=', item.type_id.id)]).code,
|
||||
'brand_id': self.env['sf.machine.brand'].search([('id', '=', item.brand_id.id)]).code,
|
||||
'supplier_id': item.supplier_id.id,
|
||||
'x_axis': item.x_axis,
|
||||
'y_axis': item.y_axis,
|
||||
@@ -188,19 +188,19 @@ class MachineTool(models.Model):
|
||||
|
||||
|
||||
class MachineToolType(models.Model):
|
||||
_name = 'mrs.machine_tool.type'
|
||||
_name = 'sf.machine_tool.type'
|
||||
_description = '机床型号'
|
||||
# _order = 'priority desc, code, name, id'
|
||||
|
||||
name = fields.Char('名称')
|
||||
brand_id = fields.Many2one('mrs.machine.brand', string='品牌')
|
||||
brand_id = fields.Many2one('sf.machine.brand', string='品牌')
|
||||
knife_type = fields.Selection(
|
||||
[("BT40", "BT40"), ("BT30", "BT30")],
|
||||
default="", string="刀把类型")
|
||||
number_of_knife_library = fields.Integer('刀库数量')
|
||||
rotate_speed = fields.Integer('转速')
|
||||
# 多个型号对应一个机床
|
||||
machine_tool_id = fields.Many2one('mrs.machine_tool', '机床')
|
||||
machine_tool_id = fields.Many2one('sf.machine_tool', '机床')
|
||||
number_of_axles = fields.Selection(
|
||||
[("三轴", "三轴"), ("四轴", "四轴"), ("五轴", "五轴")],
|
||||
default="", string="轴数")
|
||||
@@ -212,7 +212,7 @@ class MachineToolType(models.Model):
|
||||
c_axis = fields.Integer('C轴')
|
||||
remark = fields.Text('备注')
|
||||
precision = fields.Float('加工精度')
|
||||
control_system_id = fields.Many2one('mrs.machine.control_system',
|
||||
control_system_id = fields.Many2one('sf.machine.control_system',
|
||||
string="控制系统")
|
||||
active = fields.Boolean('有效', default=True)
|
||||
code = fields.Char('编码')
|
||||
@@ -220,7 +220,7 @@ class MachineToolType(models.Model):
|
||||
|
||||
# 刀具
|
||||
class CuttingTool(models.Model):
|
||||
_name = 'mrs.cutting_tool.category'
|
||||
_name = 'sf.cutting_tool.category'
|
||||
_description = '刀具类别'
|
||||
|
||||
code = fields.Char('编码')
|
||||
@@ -231,7 +231,7 @@ class CuttingTool(models.Model):
|
||||
|
||||
|
||||
class CuttingToolType(models.Model):
|
||||
_name = 'mrs.cutting_tool.type'
|
||||
_name = 'sf.cutting_tool.type'
|
||||
_description = '刀具型号'
|
||||
|
||||
code = fields.Char('编码')
|
||||
@@ -243,26 +243,8 @@ class CuttingToolType(models.Model):
|
||||
taper_shank_length = fields.Integer('锥柄长')
|
||||
tool_length = fields.Integer('刀具总长')
|
||||
blade_number = fields.Integer('刃数')
|
||||
category_id = fields.Many2one('mrs.cutting_tool.category', string='刀具类别')
|
||||
brand_id = fields.Many2one('mrs.machine.brand', string='品牌')
|
||||
category_id = fields.Many2one('sf.cutting_tool.category', string='刀具类别')
|
||||
brand_id = fields.Many2one('sf.machine.brand', string='品牌')
|
||||
remark = fields.Text('备注')
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
|
||||
class CNCprocessing(models.Model):
|
||||
_name = 'cnc.processing'
|
||||
_description = "CNC加工"
|
||||
|
||||
cnc_id = fields.Many2one('ir.attachment')
|
||||
FNo = fields.Char(string="序号")
|
||||
FPGName = fields.Char(string="程序名")
|
||||
FKnifeName = fields.Char(string="刀具名称")
|
||||
FDNo = fields.Char(string="刀号")
|
||||
FWorkType = fields.Char(string="加工类型")
|
||||
FXY = fields.Char(string="余量_X/Y")
|
||||
FZ = fields.Char(string="余量_Z")
|
||||
FJGSD = fields.Char(string="加工深度(Z)")
|
||||
FSCCD = fields.Char(string="刀具伸出长度")
|
||||
FDJSpec = fields.Char(string="刀柄型号")
|
||||
FJGDate = fields.Datetime(string="预计加工时间")
|
||||
FComment = fields.Char(string="备注")
|
||||
@@ -7,64 +7,65 @@ _logger = logging.getLogger(__name__)
|
||||
|
||||
# 材料
|
||||
class MrsProductionMaterials(models.Model):
|
||||
_name = 'mrs.production.materials'
|
||||
_name = 'sf.production.materials'
|
||||
_description = '材料'
|
||||
remark = fields.Text("备注")
|
||||
|
||||
materials_no = fields.Char("编码")
|
||||
name = fields.Char('名称')
|
||||
partner_ids = fields.Many2many('res.partner', 'materials_ids', '加工工厂')
|
||||
materials_model_ids = fields.One2many('mrs.materials.model', 'materials_id', '材料型号')
|
||||
materials_no = fields.Char("编码")
|
||||
materials_model_ids = fields.One2many('sf.materials.model', 'materials_id', '材料型号')
|
||||
remark = fields.Text("备注")
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
|
||||
# 材料型号
|
||||
class MrsMaterialModel(models.Model):
|
||||
_name = 'mrs.materials.model'
|
||||
_name = 'sf.materials.model'
|
||||
_description = '材料型号'
|
||||
remark = fields.Text("备注")
|
||||
|
||||
materials_no = fields.Char("编码")
|
||||
materials_num = fields.Char("编码号")
|
||||
name = fields.Char('型号名')
|
||||
need_h = fields.Boolean("热处理", default="false")
|
||||
mf_materia_post = fields.Char("热处理后密度")
|
||||
density = fields.Float("密度(kg/m³)")
|
||||
materials_id = fields.Many2one('mrs.production.materials', "材料名")
|
||||
materials_num = fields.Char("编码号")
|
||||
materials_no = fields.Char("编码")
|
||||
materials_id = fields.Many2one('sf.production.materials', "材料名")
|
||||
remark = fields.Text("备注")
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
|
||||
# 工艺 编码,名称,备注
|
||||
class MrsProductionProcess(models.Model):
|
||||
_name = 'mrs.production.process'
|
||||
_name = 'sf.production.process'
|
||||
_description = '表面工艺'
|
||||
name = fields.Char('表面工艺')
|
||||
remark = fields.Text("备注")
|
||||
processing_order_ids = fields.One2many('mrs.processing.order', 'production_process_id', string='工序')
|
||||
partner_process_ids = fields.Many2many('res.partner', 'process_ids', '加工工厂')
|
||||
|
||||
process_encode = fields.Char("编码")
|
||||
name = fields.Char('名称')
|
||||
remark = fields.Text("备注")
|
||||
processing_order_ids = fields.One2many('sf.processing.order', 'production_process_id', string='工序')
|
||||
partner_process_ids = fields.Many2many('res.partner', 'process_ids', '加工工厂')
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
|
||||
class MrsProcessingTechnology(models.Model):
|
||||
_name = 'mrs.processing.technology'
|
||||
_name = 'sf.processing.technology'
|
||||
_description = '加工工艺'
|
||||
remark = fields.Text("备注")
|
||||
name = fields.Char('加工工艺', index=True)
|
||||
|
||||
name = fields.Char('名称', index=True)
|
||||
remark = fields.Text('备注', index=True)
|
||||
process_encode = fields.Char("编码")
|
||||
processing_order_ids = fields.Many2many('mrs.processing.order', 'mrs_associated_processes',
|
||||
processing_order_ids = fields.Many2many('sf.processing.order', 'sf_associated_processes',
|
||||
index=True, string='工序')
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
|
||||
class MrsProcessingOrder(models.Model):
|
||||
_name = 'mrs.processing.order'
|
||||
_name = 'sf.processing.order'
|
||||
_description = '工序'
|
||||
sequence = fields.Integer('Sequence')
|
||||
|
||||
processing_technology_ids = fields.Many2many('mrs.processing.technology', 'mrs_associated_processes',
|
||||
|
||||
processing_technology_ids = fields.Many2many('sf.processing.technology', 'sf_associated_processes',
|
||||
index=True, string='加工工艺')
|
||||
|
||||
production_process_id = fields.Many2one('mrs.production.process', string="表面工艺")
|
||||
|
||||
|
||||
@@ -72,7 +73,7 @@ class Tray(models.Model):
|
||||
_name = 'sf.tray'
|
||||
_description = '托盘'
|
||||
|
||||
code = fields.Char('编码',copy=False)
|
||||
code = fields.Char('编码', copy=False)
|
||||
name = fields.Char('名称')
|
||||
state = fields.Selection(
|
||||
[("空闲", "空闲"), ("占用", "占用"), ("报损", "报损")],
|
||||
@@ -1,72 +0,0 @@
|
||||
from odoo import fields, models, api
|
||||
|
||||
|
||||
class ModelType(models.Model):
|
||||
_name = 'sf.model.type'
|
||||
_description = '模型类型'
|
||||
|
||||
name = fields.Char('名称')
|
||||
embryo_tolerance = fields.Integer('胚料的容余量')
|
||||
routing_tmpl_ids = fields.One2many('sf.model.type.routing.sort', 'model_type_id', '工序模板')
|
||||
|
||||
|
||||
class ResMrpRoutingWorkcenter(models.Model):
|
||||
_inherit = 'mrp.routing.workcenter'
|
||||
|
||||
routing_type = fields.Selection([
|
||||
('获取CNC加工程序', '获取CNC加工程序'),
|
||||
('装夹', '装夹'),
|
||||
('前置三元定位检测', '前置三元定位检测'),
|
||||
('CNC加工', 'CNC加工'),
|
||||
('后置三元质量检测', '后置三元质量检测'),
|
||||
('解除装夹', '解除装夹'),
|
||||
], string="工序类型")
|
||||
is_repeat = fields.Boolean('重复', default=False)
|
||||
workcenter_id = fields.Many2one('mrp.workcenter', required=False)
|
||||
workcenter_ids = fields.Many2many('mrp.workcenter', 'rel_workcenter_route', required=True)
|
||||
bom_id = fields.Many2one('mrp.bom', required=False)
|
||||
|
||||
# 获得当前登陆者公司
|
||||
def get_company_id(self):
|
||||
self.company_id = self.env.user.company_id.id
|
||||
|
||||
company_id = fields.Many2one('res.company', compute="get_company_id", related=False)
|
||||
|
||||
# 工单对应的工作中心,根据工序中的工作中心去匹配,
|
||||
# 如果只配置了一个工作中心,则默认采用该工作中心;
|
||||
# 如果有多个工作中心,
|
||||
# 则根据该工作中心的工单个数进行分配(优先分配给工单个数最少的);
|
||||
def get_workcenter(self, workcenter_ids):
|
||||
if workcenter_ids:
|
||||
if len(workcenter_ids) == 1:
|
||||
return workcenter_ids[0]
|
||||
elif len(workcenter_ids) >= 2:
|
||||
# workcenter_ids_str = ','.join([str(s) for s in workcenter_ids])
|
||||
self.env.cr.execute("""
|
||||
SELECT workcenter_id FROM mrp_workorder where workcenter_id
|
||||
in %s group by workcenter_id
|
||||
order by count(*),workcenter_id asc limit 1 """, [tuple(workcenter_ids)])
|
||||
return self.env.cr.dictfetchall()[0].get('workcenter_id')
|
||||
|
||||
|
||||
class ModelTypeRoutingSort(models.Model):
|
||||
_name = 'sf.model.type.routing.sort'
|
||||
_description = '工序排序'
|
||||
|
||||
sequence = fields.Integer('Sequence')
|
||||
route_workcenter_id = fields.Many2one('mrp.routing.workcenter')
|
||||
is_repeat = fields.Boolean('重复', related='route_workcenter_id.is_repeat')
|
||||
routing_type = fields.Selection([
|
||||
('获取CNC加工程序', '获取CNC加工程序'),
|
||||
('装夹', '装夹'),
|
||||
('前置三元定位检测', '前置三元定位检测'),
|
||||
('CNC加工', 'CNC加工'),
|
||||
('后置三元质量检测', '后置三元质量检测'),
|
||||
('解除装夹', '解除装夹'),
|
||||
], string="工序类型", related='route_workcenter_id.routing_type')
|
||||
workcenter_ids = fields.Many2many('mrp.workcenter', required=False, related='route_workcenter_id.workcenter_ids')
|
||||
model_type_id = fields.Many2one('sf.model.type')
|
||||
|
||||
_sql_constraints = [
|
||||
('route_model_type_uniq', 'unique (route_workcenter_id,model_type_id)', '工序不能重复!')
|
||||
]
|
||||
@@ -1,157 +0,0 @@
|
||||
from odoo import models, fields, api
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ResProductTemplate(models.Model):
|
||||
_inherit = 'product.template'
|
||||
|
||||
# 模型的长,宽,高,体积,精度,材料
|
||||
model_long = fields.Float('模型长[mm]', digits=(16, 3))
|
||||
model_width = fields.Float('模型宽[mm]', digits=(16, 3))
|
||||
model_height = fields.Float('模型高[mm]', digits=(16, 3))
|
||||
model_volume = fields.Float('模型体积[mm³]', digits=(16, 3), compute='_compute_model_volume', store=True)
|
||||
model_precision = fields.Float('精度要求', digits=(16, 3))
|
||||
model_materials_id = fields.Many2one('mrs.production.materials', string='模型材料')
|
||||
model_materials_type_id = fields.Many2one('mrs.materials.model', string='模型材料型号')
|
||||
model_type_id = fields.Many2one('sf.model.type', string='模型类型')
|
||||
model_processing_panel = fields.Char('模型加工面板')
|
||||
model_surface_process_id = fields.Many2one('mrs.production.process', string='表面工艺')
|
||||
model_process_parameters_id = fields.Many2one('mrs.processing.technology', string='工艺参数')
|
||||
# price = fields.Float('单价', digits=(16, 3))
|
||||
# number = fields.Integer('数量', default=1)
|
||||
# total_amount = fields.Float('金额', digits=(16, 3), compute='_compute_total_amount')
|
||||
# model_number =
|
||||
|
||||
|
||||
# 胚料的长,宽,高
|
||||
embryo_long = fields.Float('胚料长[mm]', digits=(16, 3), onchange='count_embryo_size')
|
||||
embryo_width = fields.Float('胚料宽[mm]', digits=(16, 3), onchange='count_embryo_size')
|
||||
embryo_height = fields.Float('胚料高[mm]', digits=(16, 3), onchange='count_embryo_size')
|
||||
embryo_materials_id = fields.Many2one('mrs.production.materials', string='胚料材料')
|
||||
embryo_materials_type_id = fields.Many2one('mrs.materials.model', string='胚料材料型号')
|
||||
|
||||
long = fields.Float('长[mm]', digits=(16, 3), onchange='add_product_size')
|
||||
width = fields.Float('宽[mm]', digits=(16, 3), onchange='add_product_size')
|
||||
height = fields.Float('高[mm]', digits=(16, 3), onchange='add_product_size')
|
||||
materials_id = fields.Many2one('mrs.production.materials', string='材料')
|
||||
materials_type_id = fields.Many2one('mrs.materials.model', string='材料型号')
|
||||
|
||||
|
||||
volume = fields.Float(compute='_compute_volume', store=True)
|
||||
|
||||
@api.depends('embryo_long', 'embryo_width', 'embryo_height')
|
||||
def _compute_volume(self):
|
||||
self.volume = self.embryo_long * self.embryo_width * self.embryo_height
|
||||
|
||||
@api.depends('model_long', 'model_width', 'model_height')
|
||||
def _compute_model_volume(self):
|
||||
self.model_volume = self.model_long * self.model_width * self.model_height
|
||||
|
||||
# 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品
|
||||
def product_create(self, product_id, item, order_id, order_number, i):
|
||||
copy_product_id = product_id.with_user(self.env.ref("base.user_admin")).copy()
|
||||
copy_product_id.product_tmpl_id.active = True
|
||||
vals = {
|
||||
'name': '%s-%s' % (order_id.name, i),
|
||||
'model_long': item['model_long'],
|
||||
'model_width': item['model_width'],
|
||||
'model_height': item['model_height'],
|
||||
'model_volume': item['model_volume'],
|
||||
'list_price': item['price'],
|
||||
'model_materials_id': self.env['mrs.production.materials'].search(
|
||||
[('materials_no', '=', item['texture_code'])]).id,
|
||||
'model_materials_type_id': self.env['mrs.materials.model'].search(
|
||||
[('materials_no', '=', item['texture_type_code'])]).id,
|
||||
'model_surface_process_id': self.env['mrs.production.process'].search(
|
||||
[('process_encode', '=', item['surface_process_code'])]).id,
|
||||
'model_process_parameters_id': self.env['mrs.processing.technology'].search(
|
||||
[('process_encode', '=', item['process_parameters_code'])]).id,
|
||||
''
|
||||
'default_code': '%s-%s' % (order_number, i),
|
||||
'barcode': item['barcode'],
|
||||
'active': True
|
||||
}
|
||||
copy_product_id.sudo().write(vals)
|
||||
return copy_product_id
|
||||
|
||||
|
||||
# 在产品上增加模型类型和加工的面(例如:A、B) ,
|
||||
# 并根据模型类型计算出产品的胚料尺寸;
|
||||
@api.onchange('model_type_id')
|
||||
def count_embryo_size(self):
|
||||
if not self.model_type_id:
|
||||
return
|
||||
bom = self.env['product.product'].search(
|
||||
[('categ_id.is_embryo', '=', True), ('product_tmpl_id', '=', self.id)],
|
||||
limit=1,
|
||||
order='volume desc'
|
||||
)
|
||||
for item in self:
|
||||
item.embryo_long = bom.embryo_long + 1
|
||||
item.embryo_width = bom.embryo_width + 1
|
||||
item.embryo_height = bom.embryo_height + 1
|
||||
|
||||
|
||||
|
||||
|
||||
# 根据模型类型默认给模型的长高宽加配置的长度;
|
||||
@api.onchange('model_type_id')
|
||||
def add_product_size(self):
|
||||
if not self.model_type_id:
|
||||
return
|
||||
model_type = self.env['sf.model.type'].search(
|
||||
[('id', '=', self.model_type_id.id)])
|
||||
print(self.model_long)
|
||||
print(self.model_width)
|
||||
print(self.model_height)
|
||||
for item in self:
|
||||
print(item.model_long)
|
||||
print(item.model_width)
|
||||
print(item.model_height)
|
||||
item.model_long = item.model_long + model_type.embryo_tolerance
|
||||
item.model_width = item.model_width + model_type.embryo_tolerance
|
||||
item.model_height = item.model_width + model_type.embryo_tolerance
|
||||
|
||||
|
||||
|
||||
class ResProductCategory(models.Model):
|
||||
_inherit = "product.category"
|
||||
|
||||
is_embryo = fields.Boolean('胚料')
|
||||
|
||||
|
||||
class ResMrpBom(models.Model):
|
||||
_inherit = 'mrp.bom'
|
||||
|
||||
# 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品后再次进行创建bom
|
||||
def bom_create(self, product):
|
||||
bom_id = self.env['mrp.bom'].create({
|
||||
'product_tmpl_id': product.product_tmpl_id.id,
|
||||
'type': 'normal',
|
||||
'product_qty': 1,
|
||||
'product_uom_id': 1
|
||||
})
|
||||
return bom_id
|
||||
|
||||
# 生成产品BOM匹配胚料,胚料的匹配规则:
|
||||
# 一、匹配的胚料类别需要带有胚料的标签;
|
||||
# 二、胚料的材料型号与生成产品的材料型号一致;
|
||||
# 三、胚料的长宽高均要大于模型的长宽高;
|
||||
# 四、如果匹配成功多个胚料,则选取体积最小的胚料;
|
||||
def bom_create_Line(self, product):
|
||||
embryo = self.env['product.product'].search(
|
||||
[('categ_id.is_embryo', '=', True), ('embryo_materials_type_id', '=', product.model_materials_type_id.id),
|
||||
('embryo_long', '>', product.model_long), ('embryo_width', '>', product.model_width),
|
||||
('embryo_height', '>', product.model_height)
|
||||
],
|
||||
limit=1,
|
||||
order='volume desc'
|
||||
)
|
||||
vals = {
|
||||
'bom_id': self.id,
|
||||
'product_id': embryo.id,
|
||||
'product_tmpl_id': embryo.product_tmpl_id.id,
|
||||
'product_qty': 1,
|
||||
'product_uom_id': 1
|
||||
}
|
||||
return self.env['mrp.bom.line'].create(vals)
|
||||
@@ -1,34 +0,0 @@
|
||||
from odoo import models, fields
|
||||
from odoo.exceptions import ValidationError
|
||||
import datetime
|
||||
|
||||
|
||||
class ReSaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
deadline_of_delivery = fields.Date('交货截止日期')
|
||||
|
||||
# 业务平台分配工厂后在智能工厂先创建销售订单
|
||||
def sale_order_create(self, deadline_of_delivery, company_id):
|
||||
now_time = datetime.datetime.now()
|
||||
order_id = self.env['sale.order'].sudo().create({
|
||||
'company_id': company_id.id,
|
||||
'date_order': now_time,
|
||||
'name': self.env['ir.sequence'].next_by_code('sale.order', sequence_date=now_time),
|
||||
'partner_id': 8,
|
||||
'state': 'sale',
|
||||
'user_id': 6,
|
||||
'deadline_of_delivery': deadline_of_delivery
|
||||
})
|
||||
return order_id
|
||||
|
||||
# 业务平台分配工厂时在创建完产品后再创建销售明细信息
|
||||
def sale_order_create_line(self, product, item):
|
||||
vals = {
|
||||
'order_id': self.id,
|
||||
'product_id': product.id,
|
||||
'name': '%s/%s/%s/%s/%s' % (item['model_long'], item['model_width'], item['model_height'], item['model_volume'], product.model_materials_id.name),
|
||||
'price_unit': item['price'],
|
||||
'product_uom_qty': item['number']
|
||||
}
|
||||
return self.env['sale.order.line'].create(vals)
|
||||
Reference in New Issue
Block a user