生成bom
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
""",
|
||||
'category': 'YZ',
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': ['account', 'base', 'mrp', 'sf_bpm_api'],
|
||||
'depends': ['account', 'base', 'mrp'],
|
||||
'data': [
|
||||
'security/group_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
|
||||
@@ -91,13 +91,13 @@
|
||||
sequence="1"
|
||||
action="mrs_processing_technology"/>
|
||||
|
||||
<menuitem
|
||||
id="menu_sf_partner_views"
|
||||
name="工厂token"
|
||||
parent="menu_mrs_base"
|
||||
sequence="1"
|
||||
action="token_factory_view"
|
||||
/>
|
||||
<!-- <menuitem-->
|
||||
<!-- id="menu_sf_partner_views"-->
|
||||
<!-- name="工厂token"-->
|
||||
<!-- parent="menu_mrs_base"-->
|
||||
<!-- sequence="1"-->
|
||||
<!-- action="token_factory_view"-->
|
||||
<!-- />-->
|
||||
|
||||
|
||||
<menuitem
|
||||
|
||||
@@ -30,6 +30,8 @@ class Sf_Bf_Connect(http.Controller):
|
||||
product = request.env['product.template'].sudo().product_create(product_id, item, order_id,
|
||||
ret['order_number'], i)
|
||||
order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item)
|
||||
bom = request.env['mrp.bom'].sudo().bom_create(product)
|
||||
bom.sudo().bom_create_Line(product)
|
||||
i += 1
|
||||
res['factory_order_no'] = order_id.name
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
@@ -5,12 +5,20 @@ 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))
|
||||
materials_id = fields.Many2one('mrs.production.materials', string='材料')
|
||||
model_materials_id = fields.Many2one('mrs.production.materials', string='材料')
|
||||
model_materials_type_id = fields.Many2one('mrs.materials.model', string='型号')
|
||||
# 胚料的长,宽,高
|
||||
embryo_long = fields.Float('长[mm]', digits=(16, 3))
|
||||
embryo_width = fields.Float('宽[mm]', digits=(16, 3))
|
||||
embryo_height = fields.Float('高[mm]', digits=(16, 3))
|
||||
embryo_materials_id = fields.Many2one('mrs.production.materials', string='材料')
|
||||
embryo_materials_type_id = fields.Many2one('mrs.materials.model', string='型号')
|
||||
|
||||
# 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品
|
||||
def product_create(self, product_id, item, order_id, order_number, i):
|
||||
@@ -23,10 +31,54 @@ class ResProductTemplate(models.Model):
|
||||
'model_height': item['model_height'],
|
||||
'model_volume': item['model_volume'],
|
||||
'list_price': item['price'],
|
||||
'materials_id': self.env['mrs.production.materials'].search(
|
||||
'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,
|
||||
'default_code': '%s-%s' % (order_number, i),
|
||||
'barcode': item['barcode'],
|
||||
# 'barcode': item['barcode'],
|
||||
'active': True
|
||||
}
|
||||
return copy_product_id.sudo().create(vals)
|
||||
copy_product_id.sudo().write(vals)
|
||||
return copy_product_id
|
||||
|
||||
|
||||
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'].sudo().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.template'].sudo().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_qty': 1,
|
||||
'product_uom_id': 1
|
||||
}
|
||||
return self.env['mrp.bom.line'].create(vals)
|
||||
|
||||
@@ -27,7 +27,7 @@ class ReSaleOrder(models.Model):
|
||||
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.materials_id.name),
|
||||
'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']
|
||||
}
|
||||
|
||||
@@ -10,18 +10,59 @@
|
||||
<page string="CNC加工">
|
||||
<group string="模型">
|
||||
<group>
|
||||
<field name="model_long" />
|
||||
<field name="model_width" />
|
||||
<field name="model_height" />
|
||||
<field name="model_volume" />
|
||||
<field name="model_long"/>
|
||||
<field name="model_width"/>
|
||||
<field name="model_height"/>
|
||||
<field name="model_volume"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="model_precision"/>
|
||||
<field name="materials_id" />
|
||||
<field name="model_materials_id"/>
|
||||
<field name="model_materials_type_id"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
<xpath expr="//label[@for='volume']" position="before">
|
||||
<label for="embryo_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="embryo_long" string="长"/>
|
||||
<field name="embryo_long" class="o_address_zip"/>
|
||||
<span>&nbsp;</span>
|
||||
<label for="embryo_width" string="宽"/>
|
||||
<field name="embryo_width" class="o_address_zip"/>
|
||||
<span>&nbsp;</span>
|
||||
<label for="embryo_height" string="高"/>
|
||||
<field name="embryo_height" class="o_address_zip"/>
|
||||
</div>
|
||||
</xpath>
|
||||
<xpath expr="//label[@for='produce_delay']" position="before">
|
||||
<label for="embryo_materials_id"
|
||||
attrs="{'invisible':[('product_variant_count', '>', 1), ('is_product_variant', '=', False)]}"/>
|
||||
<div class="o_row"
|
||||
attrs="{'invisible':[('product_variant_count', '>', 1), ('is_product_variant', '=', False)]}">
|
||||
<field name="embryo_materials_id"/>
|
||||
</div>
|
||||
<label for="embryo_materials_type_id"
|
||||
attrs="{'invisible':[('product_variant_count', '>', 1), ('is_product_variant', '=', False)]}"/>
|
||||
<div class="o_row"
|
||||
attrs="{'invisible':[('product_variant_count', '>', 1), ('is_product_variant', '=', False)]}">
|
||||
<field name="embryo_materials_type_id" domain="[('materials_id', '=', embryo_materials_id)]"/>
|
||||
</div>
|
||||
</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>
|
||||
</data>
|
||||
|
||||
Reference in New Issue
Block a user