This commit is contained in:
jinling.yang
2022-11-21 20:04:56 +08:00
parent c4876e9631
commit 830f3bb35e
87 changed files with 1785 additions and 2711 deletions

1
sf_dlm/__init__.py Normal file
View File

@@ -0,0 +1 @@
from . import models

25
sf_dlm/__manifest__.py Normal file
View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': '机企猫智能工厂 产品模块',
'version': '1.0',
'summary': '智能工厂产品模块',
'sequence': 1,
'description': """
在本模块,为业务平台传过来的订单信息
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
'depends': ['product', 'base'],
'data': [
'data/product_data.xml',
'views/product_template_view.xml'
],
'demo': [
],
'qweb': [
],
'installable': True,
'application': False,
'auto_install': False,
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data noupdate="0">
<record id="product_template_sf" model="product.product">
<field name="name">CNC加工产品模板</field>
<field name="categ_id" ref="product.product_category_5"/>
<field name="invoice_policy">delivery</field>
<field name="detailed_type">product</field>
<field name="purchase_ok">false</field>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="company_id" ref="base.main_company"/>
<field name="active">false</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,3 @@
from. import product_template

View File

@@ -0,0 +1,123 @@
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))
model_precision = fields.Float('精度要求', digits=(16, 3))
model_type_id = fields.Many2one('sf.model.type', string='模型类型')
model_processing_panel = fields.Char('模型加工面板')
model_surface_process_id = fields.Many2one('sf.production.process', string='表面工艺')
model_process_parameters_id = fields.Many2one('sf.processing.technology', string='工艺参数')
model_price = fields.Float('模型单价', digits=(16, 3))
model_total_amount = fields.Float('模型金额', digits=(16, 3))
model_number = fields.Integer('模型数量', default=1)
model_remark = fields.Char('模型备注说明')
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('sf.production.materials', string='材料')
materials_type_id = fields.Many2one('sf.materials.model', string='材料型号')
volume = fields.Float(compute='_compute_volume', store=True)
single_manufacturing = fields.Boolean(string="单个制造")
@api.depends('long', 'width', 'height')
def _compute_volume(self):
self.volume = self.long * self.width * self.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'],
'model_price': item['price'],
'model_total_amount': item['total_amount'],
'model_number': item['number'],
'list_price': item['price'],
'materials_id': self.env['sf.production.materials'].search(
[('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_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,
'model_remark': item['remark'],
'default_code': '%s-%s' % (order_number, i),
'barcode': item['barcode'],
'active': True
}
copy_product_id.sudo().write(vals)
return copy_product_id
# 根据模型类型默认给模型的长高宽加配置的长度;
@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 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), ('materials_type_id', '=', product.materials_type_id.id),
('long', '>', product.long), ('width', '>', product.width),
('height', '>', product.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)
class ResProductCategory(models.Model):
_inherit = "product.category"
is_embryo = fields.Boolean('胚料')

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<record model="ir.ui.view" id="view_product_template_form_inherit_sf">
<field name="name">product.template.form.inherit.sf</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<field name="invoice_policy" position="after">
<field name="materials_id" string="材料"/>
<field name="materials_type_id" string="型号"
domain="[('materials_id', '=', materials_id)]"/>
</field>
<xpath expr="//label[@for='volume']" position="before">
<label for="long" string="尺寸"
attrs="{'invisible':[('product_variant_count', '>', 1), ('is_product_variant', '=', False)]}"/>
<div class="o_address_format"
attrs="{'invisible':[('product_variant_count', '>', 1), ('is_product_variant', '=', False)]}">
<label for="long" string="长"/>
<field name="long" class="o_address_zip"/>
<span>&amp;nbsp;</span>
<label for="width" string="宽"/>
<field name="width" class="o_address_zip"/>
<span>&amp;nbsp;</span>
<label for="height" string="高"/>
<field name="height" class="o_address_zip"/>
</div>
</xpath>
<xpath expr="//page[last()]" position="after">
<page string="加工参数">
<group string="模型">
<field name="model_long" string="长[mm]"/>
<field name="model_width" string="宽[mm]"/>
<field name="model_height" string="高[mm]"/>
<field name="model_volume" string="体积[mm]"/>
<field name="model_type_id" string="模板类型"/>
<field name="model_processing_panel" placeholder="例如A,B" string="加工面板"/>
<field name="model_precision" string="精度要求"/>
<field name="model_surface_process_id" string="表面工艺"/>
<field name="model_process_parameters_id" string="工艺参数"
domain="[('processing_order_ids', '=', model_surface_process_id)]"/>
<field name="model_price" string="单价"/>
<field name="model_total_amount" string="金额"/>
<field name="model_number" string="数量"/>
<field name="model_remark" string="备注说明"/>
</group>
</page>
</xpath>
</field>
</record>
<record id="view_product_category_form_inherit_sf" model="ir.ui.view">
<field name="name">product.category.form.inherit.sf</field>
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view"/>
<field name="arch" type="xml">
<field name="parent_id" position="before">
<field name="is_embryo"/>
</field>
</field>
</record>
<record id="view_template_property_form" model="ir.ui.view">
<field name="name">product.template.stock.property.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='operations']" position="inside">
<group>
</group>
<group string="订单规则">
<field name="single_manufacturing" string="单个制造" widget="checkbox"/>
</group>
</xpath>
<page name="inventory" position="inside">
<group>
<group string="Description for Receipts">
<field name="description_pickingin" nolabel="1"
placeholder="This note is added to receipt orders (e.g. where to store the product in the warehouse)."/>
</group>
<group string="Description for Delivery Orders">
<field name="description_pickingout" nolabel="1"
placeholder="This note is added to delivery orders."/>
</group>
<group string="Description for Internal Transfers" groups="stock.group_stock_multi_locations">
<field name="description_picking"
placeholder="This note is added to internal transfer orders (e.g. where to pick the product in the warehouse)."
nolabel="1"/>
</group>
</group>
</page>
<page name="inventory" position="attributes">
<attribute name="groups">stock.group_stock_user,product.group_stock_packaging</attribute>
</page>
</field>
</record>
</data>
</odoo>