bfm分配工厂:
1.销售页面:客户的值为业务平台, 2.没有原材料,事务回滚 3.去掉注释和没用到的代码
This commit is contained in:
@@ -1,13 +1,27 @@
|
|||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
<data>
|
||||||
<record model="ir.module.category" id="module_category_employee">
|
|
||||||
<field name="name">员工</field>
|
<record model="ir.module.category" id="module_category_partner">
|
||||||
|
<field name="name">合作伙伴</field>
|
||||||
<field name="sequence">1</field>
|
<field name="sequence">1</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.module.category" id="module_category_manage">
|
<record id="group_master_data_manager" model="res.groups">
|
||||||
<field name="name">管理</field>
|
<field name="name">加工工厂</field>
|
||||||
<field name="sequence">2</field>
|
<field name="category_id" ref="base.module_category_administration"/>
|
||||||
|
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="group_business_process" model="res.groups">
|
||||||
|
<field name="name">供应商</field>
|
||||||
|
<field name="category_id" ref="module_category_business"/>
|
||||||
|
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="group_partner_manager" model="res.groups">
|
||||||
|
<field name="name">编程中心</field>
|
||||||
|
<field name="category_id" ref="module_category_partner"/>
|
||||||
|
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from datetime import date, timedelta
|
|
||||||
from odoo import http
|
from odoo import http
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
|
|
||||||
@@ -19,27 +18,18 @@ class Sf_Bf_Connect(http.Controller):
|
|||||||
res = {'status': 1, 'factory_order_no': ''}
|
res = {'status': 1, 'factory_order_no': ''}
|
||||||
logging.info('get_bfm_process_order_list:%s' % kw)
|
logging.info('get_bfm_process_order_list:%s' % kw)
|
||||||
try:
|
try:
|
||||||
# datas = request.httprequest.data
|
|
||||||
# ret = json.loads(datas)
|
|
||||||
# ret = json.loads(ret['result'])
|
|
||||||
product_id = request.env.ref('sf_dlm.product_template_sf').sudo()
|
product_id = request.env.ref('sf_dlm.product_template_sf').sudo()
|
||||||
self_machining_id = request.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo()
|
self_machining_id = request.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo()
|
||||||
outsource_id = request.env.ref('sf_dlm.product_embryo_sf_outsource').sudo()
|
outsource_id = request.env.ref('sf_dlm.product_embryo_sf_outsource').sudo()
|
||||||
purchase_id = request.env.ref('sf_dlm.product_embryo_sf_purchase').sudo()
|
purchase_id = request.env.ref('sf_dlm.product_embryo_sf_purchase').sudo()
|
||||||
company_id = request.env.ref('base.main_company').sudo()
|
company_id = request.env.ref('base.main_company').sudo()
|
||||||
user_id = request.env.ref('base.user_admin').sudo()
|
# user_id = request.env.ref('base.user_admin').sudo()
|
||||||
bfm_process_order_list = json.loads(kw['bfm_process_order_list'])
|
bfm_process_order_list = json.loads(kw['bfm_process_order_list'])
|
||||||
order_id = request.env['sale.order'].with_user(request.env.ref("base.user_admin")).sale_order_create(
|
order_id = request.env['sale.order'].with_user(request.env.ref("base.user_admin")).sale_order_create(
|
||||||
company_id, kw['delivery_name'], kw['delivery_telephone'], kw['delivery_address'],
|
company_id, kw['delivery_name'], kw['delivery_telephone'], kw['delivery_address'],
|
||||||
kw['delivery_end_date'], user_id)
|
kw['delivery_end_date'])
|
||||||
i = 1
|
i = 1
|
||||||
for item in bfm_process_order_list:
|
for item in bfm_process_order_list:
|
||||||
# product_has = request.env['product.template'].with_user(request.env.ref("base.user_admin")).search([('barcode','=', item['barcode'])])
|
|
||||||
# if product_has:
|
|
||||||
# logging.info('product_has:%s' % product_has)
|
|
||||||
# logging.info('barcode:%s' % item['barcode'])
|
|
||||||
# order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product_has, item)
|
|
||||||
# else:
|
|
||||||
product = request.env['product.template'].sudo().product_create(product_id, item, order_id,
|
product = request.env['product.template'].sudo().product_create(product_id, item, order_id,
|
||||||
kw['order_number'], i)
|
kw['order_number'], i)
|
||||||
bom_data = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).get_bom(product)
|
bom_data = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).get_bom(product)
|
||||||
@@ -61,8 +51,14 @@ class Sf_Bf_Connect(http.Controller):
|
|||||||
request.env.ref("base.user_admin")).bom_create(
|
request.env.ref("base.user_admin")).bom_create(
|
||||||
self_machining_embryo, 'normal', False)
|
self_machining_embryo, 'normal', False)
|
||||||
# 创建胚料里bom的组件
|
# 创建胚料里bom的组件
|
||||||
self_machining_bom.with_user(request.env.ref("base.user_admin")).bom_create_line(
|
self_machining_bom_line = self_machining_bom.with_user(
|
||||||
|
request.env.ref("base.user_admin")).bom_create_line(
|
||||||
self_machining_embryo)
|
self_machining_embryo)
|
||||||
|
if self_machining_bom_line == False:
|
||||||
|
res['status'] = 2
|
||||||
|
res['message'] = '该订单模型的材料型号在您分配的工厂里暂未有原材料,请先配置再进行分配'
|
||||||
|
request.cr.rollback()
|
||||||
|
return json.JSONEncoder().encode(res)
|
||||||
# 产品配置bom
|
# 产品配置bom
|
||||||
product_bom_self_machining = request.env['mrp.bom'].with_user(
|
product_bom_self_machining = request.env['mrp.bom'].with_user(
|
||||||
request.env.ref("base.user_admin")).bom_create(
|
request.env.ref("base.user_admin")).bom_create(
|
||||||
@@ -81,7 +77,13 @@ class Sf_Bf_Connect(http.Controller):
|
|||||||
outsource_embryo,
|
outsource_embryo,
|
||||||
'subcontract', True)
|
'subcontract', True)
|
||||||
# 创建胚料的bom的组件
|
# 创建胚料的bom的组件
|
||||||
outsource_bom.with_user(request.env.ref("base.user_admin")).bom_create_line(outsource_embryo)
|
outsource_bom_line = outsource_bom.with_user(
|
||||||
|
request.env.ref("base.user_admin")).bom_create_line(outsource_embryo)
|
||||||
|
if outsource_bom_line == False:
|
||||||
|
res['status'] = 2
|
||||||
|
res['message'] = '该订单模型的材料型号在您分配的工厂里暂未有原材料,请先配置再进行分配'
|
||||||
|
request.cr.rollback()
|
||||||
|
return json.JSONEncoder().encode(res)
|
||||||
# 产品配置bom
|
# 产品配置bom
|
||||||
product_bom_outsource = request.env['mrp.bom'].with_user(
|
product_bom_outsource = request.env['mrp.bom'].with_user(
|
||||||
request.env.ref("base.user_admin")).bom_create(product, 'normal', False)
|
request.env.ref("base.user_admin")).bom_create(product, 'normal', False)
|
||||||
@@ -100,6 +102,7 @@ class Sf_Bf_Connect(http.Controller):
|
|||||||
order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item)
|
order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item)
|
||||||
i += 1
|
i += 1
|
||||||
res['factory_order_no'] = order_id.name
|
res['factory_order_no'] = order_id.name
|
||||||
|
return json.JSONEncoder().encode(res)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.info('get_bfm_process_order_list error:%s' % e)
|
logging.info('get_bfm_process_order_list error:%s' % e)
|
||||||
res['status'] = -1
|
res['status'] = -1
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import logging
|
|||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
import hashlib
|
import hashlib
|
||||||
from odoo import fields, models, api
|
from odoo import models
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
|
|
||||||
__author__ = 'jinling.yang'
|
__author__ = 'jinling.yang'
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import string
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
from odoo import fields, models, api
|
from odoo import fields, models
|
||||||
|
|
||||||
__author__ = 'jinling.yang'
|
__author__ = 'jinling.yang'
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from odoo import models, fields, api
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
class ResSupplierInfo(models.Model):
|
class ResSupplierInfo(models.Model):
|
||||||
@@ -7,5 +7,6 @@ class ResSupplierInfo(models.Model):
|
|||||||
def _compute_is_subcontractor(self):
|
def _compute_is_subcontractor(self):
|
||||||
for supplier in self:
|
for supplier in self:
|
||||||
boms = supplier.product_id.variant_bom_ids
|
boms = supplier.product_id.variant_bom_ids
|
||||||
boms |= supplier.product_tmpl_id.bom_ids.filtered(lambda b: not b.product_id or b.product_id in (supplier.product_id or supplier.product_tmpl_id.product_variant_ids))
|
boms |= supplier.product_tmpl_id.bom_ids.filtered(lambda b: not b.product_id or b.product_id in (
|
||||||
|
supplier.product_id or supplier.product_tmpl_id.product_variant_ids))
|
||||||
supplier.is_subcontractor = supplier.partner_id in boms.subcontractor_id
|
supplier.is_subcontractor = supplier.partner_id in boms.subcontractor_id
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
from odoo import models, fields, api
|
from odoo import models, fields
|
||||||
from odoo.exceptions import ValidationError
|
|
||||||
import logging
|
import logging
|
||||||
import base64
|
import base64
|
||||||
import os
|
|
||||||
# from OCC.Extend.DataExchange import read_step_file, write_stl_file
|
|
||||||
from odoo.modules import get_resource_path
|
|
||||||
|
|
||||||
|
|
||||||
class ResProductTemplate(models.Model):
|
class ResProductTemplate(models.Model):
|
||||||
@@ -12,6 +8,8 @@ class ResProductTemplate(models.Model):
|
|||||||
|
|
||||||
# 模型的长,宽,高,体积,精度,材料
|
# 模型的长,宽,高,体积,精度,材料
|
||||||
model_name = fields.Char('模型名称')
|
model_name = fields.Char('模型名称')
|
||||||
|
categ_type = fields.Selection(
|
||||||
|
[("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料")], string='产品的类别', related='categ_id.type', store=True)
|
||||||
model_long = fields.Float('模型长[mm]', digits=(16, 3))
|
model_long = fields.Float('模型长[mm]', digits=(16, 3))
|
||||||
model_width = fields.Float('模型宽[mm]', digits=(16, 3))
|
model_width = fields.Float('模型宽[mm]', digits=(16, 3))
|
||||||
model_height = fields.Float('模型高[mm]', digits=(16, 3))
|
model_height = fields.Float('模型高[mm]', digits=(16, 3))
|
||||||
@@ -223,7 +221,7 @@ class ResMrpBom(models.Model):
|
|||||||
'product_qty': 1,
|
'product_qty': 1,
|
||||||
'product_uom_id': 1
|
'product_uom_id': 1
|
||||||
})
|
})
|
||||||
if bom_type == 'subcontract' and product_type != False:
|
if bom_type == 'subcontract' and product_type is not False:
|
||||||
subcontract = self.get_supplier(product.materials_type_id)
|
subcontract = self.get_supplier(product.materials_type_id)
|
||||||
bom_id.subcontractor_id = subcontract.partner_id.id
|
bom_id.subcontractor_id = subcontract.partner_id.id
|
||||||
return bom_id
|
return bom_id
|
||||||
@@ -233,15 +231,18 @@ class ResMrpBom(models.Model):
|
|||||||
# 胚料所需原材料公式:当前的胚料的体积(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
# 胚料所需原材料公式:当前的胚料的体积(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
||||||
def bom_create_line(self, embryo):
|
def bom_create_line(self, embryo):
|
||||||
# 选取当前胚料原材料
|
# 选取当前胚料原材料
|
||||||
bom_line = self.get_raw_bom(embryo)
|
raw_bom_line = self.get_raw_bom(embryo)
|
||||||
vals = {
|
if raw_bom_line:
|
||||||
|
bom_line = self.env['mrp.bom.line'].create({
|
||||||
'bom_id': self.id,
|
'bom_id': self.id,
|
||||||
'product_id': bom_line.id,
|
'product_id': raw_bom_line.id,
|
||||||
'product_tmpl_id': bom_line.product_tmpl_id.id,
|
'product_tmpl_id': raw_bom_line.product_tmpl_id.id,
|
||||||
'product_qty': bom_line.volume * bom_line.materials_type_id.density * 1000,
|
'product_qty': round(embryo.volume / 1000000000 * raw_bom_line.materials_type_id.density, 2),
|
||||||
'product_uom_id': bom_line.uom_id.id
|
'product_uom_id': raw_bom_line.uom_id.id,
|
||||||
}
|
})
|
||||||
return self.env['mrp.bom.line'].create(vals)
|
return bom_line
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
# 查询材料型号默认排第一的供应商
|
# 查询材料型号默认排第一的供应商
|
||||||
def get_supplier(self, materials_type):
|
def get_supplier(self, materials_type):
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
<!-- </field>-->
|
<!-- </field>-->
|
||||||
|
|
||||||
<field name="invoice_policy" position="after">
|
<field name="invoice_policy" position="after">
|
||||||
<!-- <field name="model_file" widget="model_viewer" attrs="{'invisible': [('categ_id', 'child_of', '成品')]}"/>-->
|
<!-- <field name="model_file" widget="model_viewer"-->
|
||||||
<field name="embryo_model_type_id"/>
|
<!-- attrs="{'invisible': [('categ_type', '!=', '成品')]}"/>-->
|
||||||
|
<!-- <field name="embryo_model_type_id" string="模型类型"-->
|
||||||
|
<!-- attrs="{'invisible': [('categ_type', '=', '胚料')]}"/>-->
|
||||||
<field name="materials_id" string="材料"/>
|
<field name="materials_id" string="材料"/>
|
||||||
<field name="materials_type_id" string="型号"
|
<field name="materials_type_id" string="型号"
|
||||||
domain="[('materials_id', '=', materials_id)]"/>
|
domain="[('materials_id', '=', materials_id)]"/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from odoo import api, fields, models
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
class ModelType(models.Model):
|
class ModelType(models.Model):
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from odoo import fields, models, api
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
class ResMrpRoutingWorkcenter(models.Model):
|
class ResMrpRoutingWorkcenter(models.Model):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from odoo import api, fields, models, _
|
from odoo import api, fields, models
|
||||||
|
from datetime import datetime
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from odoo.addons.resource.models.resource import Intervals
|
from odoo.addons.resource.models.resource import Intervals
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -1,7 +1,5 @@
|
|||||||
from odoo import models, fields
|
from odoo import models, fields
|
||||||
from odoo.exceptions import ValidationError
|
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
class ReSaleOrder(models.Model):
|
class ReSaleOrder(models.Model):
|
||||||
@@ -15,16 +13,16 @@ class ReSaleOrder(models.Model):
|
|||||||
# 业务平台分配工厂后在智能工厂先创建销售订单
|
# 业务平台分配工厂后在智能工厂先创建销售订单
|
||||||
|
|
||||||
def sale_order_create(self, company_id, delivery_name, delivery_telephone, delivery_address,
|
def sale_order_create(self, company_id, delivery_name, delivery_telephone, delivery_address,
|
||||||
deadline_of_delivery, user_id):
|
deadline_of_delivery):
|
||||||
now_time = datetime.datetime.now()
|
now_time = datetime.datetime.now()
|
||||||
partner = self.env.user.partner_id
|
partner = self.get_customer()
|
||||||
order_id = self.env['sale.order'].sudo().create({
|
order_id = self.env['sale.order'].sudo().create({
|
||||||
'company_id': company_id.id,
|
'company_id': company_id.id,
|
||||||
'date_order': now_time,
|
'date_order': now_time,
|
||||||
'name': self.env['ir.sequence'].next_by_code('sale.order', sequence_date=now_time),
|
'name': self.env['ir.sequence'].next_by_code('sale.order', sequence_date=now_time),
|
||||||
'partner_id': partner.id,
|
'partner_id': partner.id,
|
||||||
'state': 'draft',
|
'state': 'draft',
|
||||||
'user_id': user_id.id,
|
# 'user_id': user_id.id,
|
||||||
'person_of_delivery': delivery_name,
|
'person_of_delivery': delivery_name,
|
||||||
'telephone_of_delivery': delivery_telephone,
|
'telephone_of_delivery': delivery_telephone,
|
||||||
'address_of_delivery': delivery_address,
|
'address_of_delivery': delivery_address,
|
||||||
@@ -32,16 +30,24 @@ class ReSaleOrder(models.Model):
|
|||||||
})
|
})
|
||||||
return order_id
|
return order_id
|
||||||
|
|
||||||
|
def get_customer(self):
|
||||||
|
customer = self.env['res.partner'].search([('name', '=', '业务平台')])
|
||||||
|
if customer:
|
||||||
|
return customer
|
||||||
|
else:
|
||||||
|
partner = self.env['res.partner'].create({'name': '业务平台'})
|
||||||
|
return partner
|
||||||
|
|
||||||
# 业务平台分配工厂时在创建完产品后再创建销售明细信息
|
# 业务平台分配工厂时在创建完产品后再创建销售明细信息
|
||||||
def sale_order_create_line(self, product, item):
|
def sale_order_create_line(self, product, item):
|
||||||
vals = {
|
vals = {
|
||||||
'order_id': self.id,
|
'order_id': self.id,
|
||||||
'product_id': product.id,
|
'product_id': product.id,
|
||||||
'name': '%s/%s/%s/%s/%s/%s' % (
|
'name': '%s/%s/%s/%s/±%s/%s' % (
|
||||||
product.model_long, product.model_width, product.model_height, product.model_volume,
|
product.model_long, product.model_width, product.model_height, product.model_volume,
|
||||||
product.model_machining_precision,
|
product.model_machining_precision,
|
||||||
product.materials_id.name),
|
product.materials_id.name),
|
||||||
'price_unit': product.list_price,
|
'price_unit': product.list_price,
|
||||||
'product_uom_qty': item['number']
|
'product_uom_qty': item['number'],
|
||||||
}
|
}
|
||||||
return self.env['sale.order.line'].create(vals)
|
return self.env['sale.order.line'].create(vals)
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
<field name="payment_term_id" position="after">
|
<field name="payment_term_id" position="after">
|
||||||
<field name="deadline_of_delivery"/>
|
<field name="deadline_of_delivery"/>
|
||||||
</field>
|
</field>
|
||||||
|
<xpath expr="//field[@name='order_line']/tree/field[@name='name']" position="replace">
|
||||||
|
<field name="name" widget="section_and_note_text" optional="show"
|
||||||
|
string="参数说明(长宽高,体积,精度,材质)"/>
|
||||||
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user