Files
test/sf_base/models/common.py
2024-08-29 19:53:37 +08:00

190 lines
7.2 KiB
Python

# -*- coding: utf-8 -*-
import logging
from urllib.parse import urlencode
from odoo import fields, models, api
from odoo.exceptions import UserError
_logger = logging.getLogger(__name__)
# 材料
class MrsProductionMaterials(models.Model):
_name = 'sf.production.materials'
_description = '材料'
materials_no = fields.Char("编码")
name = fields.Char('名称')
partner_ids = fields.Many2many('res.partner', 'materials_ids', '加工工厂')
materials_model_ids = fields.One2many('sf.materials.model', 'materials_id', '材料型号')
remark = fields.Text("备注")
active = fields.Boolean('有效', default=True)
def open_url_action(self):
url = 'http://192.168.50.127:8081'
params = {
'user_id': self._uid
}
url_params = urlencode(params)
return {
'type': 'ir.actions.act_url',
'url': url + '?' + url_params,
# 'url': url,
'target': 'new'
}
# 材料型号
class MrsMaterialModel(models.Model):
_name = 'sf.materials.model'
_description = '材料型号'
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('sf.production.materials', "材料名")
tensile_strength = fields.Char("拉伸强度(n/mm²)")
standards_id = fields.Many2one('sf.international.standards', '执行标准')
alloy_code = fields.Char('合金牌号')
price = fields.Float('单价/kg')
apply = fields.Many2many('material.apply', string='材料应用')
materials_code = fields.Char('材料代号')
hardness = fields.Integer("硬度(hrc)")
rough_machining = fields.Float("粗加工Vc(m/min)")
finish_machining = fields.Float("精加工Vc(m/min)")
remark = fields.Text("备注")
gain_way = fields.Selection(
[("自加工", "自加工"), ("外协", "外协"), ("采购", "采购")],
default="", string="获取方式")
supplier_ids = fields.One2many('sf.supplier.sort', 'materials_model_id', string='供应商')
active = fields.Boolean('有效', default=True)
@api.constrains("gain_way")
def _check_supplier_ids(self):
for item in self:
if item.gain_way in ('外协', '采购') and not item.supplier_ids:
raise UserError("请添加供应商")
class MrsProductionProcessCategory(models.Model):
_name = 'sf.production.process.category'
_description = '表面工艺类别'
order = 'id desc'
name = fields.Char('名称')
code = fields.Char("编码")
sequence = fields.Integer('排序')
production_process_ids = fields.One2many('sf.production.process', 'category_id', string="表面工艺")
active = fields.Boolean('有效', default=True)
# 工艺 编码,名称,备注
class MrsProductionProcess(models.Model):
_name = 'sf.production.process'
_description = '表面工艺'
order = 'sequence asc'
code = fields.Char("编码")
name = fields.Char('名称')
remark = fields.Text("备注")
sequence = fields.Integer('排序')
# 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)
parameter_ids = fields.One2many('sf.production.process.parameter', 'process_id', string='可选参数')
category_id = fields.Many2one('sf.production.process.category', string='表面工艺类别')
# workcenter_ids = fields.Many2many('mrp.workcenter', 'rel_workcenter_process', required=True)
processing_day = fields.Float('加工天数/d')
travel_day = fields.Float('路途天数/d')
sequence = fields.Integer('排序')
# class MrsProcessingTechnology(models.Model):
# _name = 'sf.processing.technology'
# _description = '加工工艺'
#
# name = fields.Char('名称', index=True)
# remark = fields.Text('备注', index=True)
# code = fields.Char("编码")
# processing_order_ids = fields.Many2many('sf.processing.order', 'sf_associated_processes',
# index=True, string='工序')
# active = fields.Boolean('有效', default=True)
# class MrsProcessingOrder(models.Model):
# _name = 'sf.processing.order'
# _description = '工序'
# sequence = fields.Integer('Sequence')
# processing_technology_ids = fields.Many2many('sf.processing.technology', 'sf_associated_processes',
# index=True, string='加工工艺')
# production_process_id = fields.Many2one('sf.production.process', string="表面工艺")
class SupplierSort(models.Model):
_name = 'sf.supplier.sort'
_description = '供应商排序'
sequence = fields.Integer('Sequence')
partner_id = fields.Many2one('res.partner', domain="[('is_company', '=', True),('supplier_rank', '!=', 0)]")
materials_model_id = fields.Many2one('sf.materials.model')
_sql_constraints = [
('supplier_sort_uniq', 'unique (partner_id,materials_model_id)', '排序不能重复!')
]
class MrsProductionProcessParameter(models.Model):
_name = 'sf.production.process.parameter'
_description = '可选参数'
# _display_name = 'name'
code = fields.Char("编码")
name = fields.Char('名称')
gain_way = fields.Selection([("自加工", "自加工"), ("外协", "外协")], default="", string="获取方式")
is_check = fields.Boolean(default=False)
# price = fields.Float('单价')
process_id = fields.Many2one('sf.production.process', string='表面工艺')
process_description = fields.Char(string='工艺描述')
materials_model_ids = fields.Many2many('sf.materials.model', 'applicable_material', string='适用材料')
processing_day = fields.Float('加工天数/d')
travel_day = fields.Float('路途天数/d')
active = fields.Boolean('有效', default=True)
processing_mm = fields.Char('加工厚度/mm')
def name_get(self):
result = []
for parameter in self:
if parameter.process_id:
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)])
return process_parameter
def _json_production_process_item_code(self, item):
code_arr = []
for i in item.parameter_ids:
code_arr.append(i.code)
return code_arr
class ModelInternationalStandards(models.Model):
_name = 'sf.international.standards'
_description = '制造标准'
code = fields.Char('编码')
name = fields.Char('名称')
active = fields.Boolean('有效', default=True)
class MrsMaterialApply(models.Model):
_name = 'material.apply'
_description = '材料应用'
name = fields.Char('名称', default=True)
active = fields.Boolean('有效', default=True)