智能工厂创建产品
This commit is contained in:
@@ -12,8 +12,10 @@
|
||||
'website': 'https://www.sf.cs.jikimo.com',
|
||||
'depends': ['sale', 'product'],
|
||||
'data': [
|
||||
'data/product_data.xml',
|
||||
'views/product_template_view.xml',
|
||||
'views/sale_order_view.xml',
|
||||
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
|
||||
@@ -16,10 +16,17 @@ class Sf_Bf_Connect(http.Controller):
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
res = {'status': 1}
|
||||
datas = request.httprequest.data
|
||||
ret = json.loads(datas)
|
||||
ret = json.loads(ret['result'])
|
||||
request.env['sale.order'].sudo().sale_order_create(ret['delivery_end_date'])
|
||||
order_line_ids = []
|
||||
# for item in ret['bfm_process_order_list']:
|
||||
|
||||
product_id = request.env.ref('sf_bpm_api.product_template_sf').sudo()
|
||||
company_id = request.env.ref('base.main_company').sudo()
|
||||
order_id = request.env['sale.order'].sudo().sale_order_create(ret['delivery_end_date'], company_id)
|
||||
i = 1
|
||||
for item in ret['bfm_process_order_list']:
|
||||
product = request.env['product.template'].sudo().product_create(product_id, item, order_id, ret['order_number'], i)
|
||||
order_id.sale_order_create_line(product, item)
|
||||
i += 1
|
||||
res['factory_order_no'] = order_id.name
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
17
sf_bpm_api/data/product_data.xml
Normal file
17
sf_bpm_api/data/product_data.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<data>
|
||||
<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="image_1920" type="base64" file="product/static/img/product_product_5-image.png"/>
|
||||
<field name="company_id" ref="base.main_company"/>
|
||||
<field name="active">false</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -4,33 +4,28 @@ from odoo.exceptions import ValidationError
|
||||
|
||||
class ResProductTemplate(models.Model):
|
||||
_inherit = 'product.template'
|
||||
# sale_order_id = fields.Many2one('sale.order')
|
||||
|
||||
purchase_ok = fields.Boolean(default=False)
|
||||
detailed_type = fields.Selection(default='product')
|
||||
list_price = fields.Float(digits=(16, 3))
|
||||
invoice_policy = fields.Selection(default='delivery')
|
||||
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='材料')
|
||||
# materials_type_id = fields.Many2one('mrs.materials.model', string='型号')
|
||||
# surface_technics_id = fields.Many2one('mrs.production.process', string='表面工艺')
|
||||
# technological_parameter_id = fields.Char('工艺参数')
|
||||
unit_price = fields.Float('单价')
|
||||
amount = fields.Integer('数量')
|
||||
|
||||
# 业务平台分配工厂时调用该方法创建产品
|
||||
def product_create(self, products):
|
||||
self.env['product.template'].create({
|
||||
'name': products['order_number'],
|
||||
'model_long': products['length'],
|
||||
'model_width': products['width'],
|
||||
'model_height': products['height'],
|
||||
'model_volume': products['volume'],
|
||||
'materials_id': products['materials_id'],
|
||||
'unit_price': products['unit_price'],
|
||||
'amount': products['amount'],
|
||||
'barcode':products['barcode'],
|
||||
})
|
||||
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'],
|
||||
'default_code': '%s-%s' % (order_number, i),
|
||||
'barcode': 'cf0bbe2fdad6339d138cdee732750e3e502140c2',
|
||||
# 'barcode': item['barcode'],
|
||||
'active': True
|
||||
}
|
||||
return copy_product_id.sudo().create(vals)
|
||||
|
||||
@@ -7,14 +7,39 @@ class ReSaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
deadline_of_delivery = fields.Date('交货截止日期')
|
||||
# product_line_ids = fields.One2many('product.template', 'sale_order_id')
|
||||
|
||||
# 业务平台分配工厂时调用该方法先创建销售订单
|
||||
def sale_order_create(self, deadline_of_delivery):
|
||||
now = datetime.datetime.now()
|
||||
self.env['sale.order'].sudo().create({
|
||||
'company_id': 1,
|
||||
'date_order': now,
|
||||
'name': '12',
|
||||
'partner_id': 1,
|
||||
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': product.name,
|
||||
'price_unit': item['price'],
|
||||
'product_uom_qty': item['number']
|
||||
}
|
||||
return self.env['sale.order.line'].create(vals)
|
||||
|
||||
|
||||
class ReSaleOrderLine(models.Model):
|
||||
_inherit = 'sale.order.line'
|
||||
|
||||
|
||||
# 重设name,且只针对于在页面上显示
|
||||
def name_get(self):
|
||||
return [(record.id, '%s/%s/%s/%s/%s' % (
|
||||
record.order_id.model_long, record.order_id.model_width, record.order_id.model_height,
|
||||
record.order_id.model_volume, record.order_id.materials_id.name)) for record in self]
|
||||
|
||||
Reference in New Issue
Block a user