创建胚料的bug修复

This commit is contained in:
jinling.yang
2022-12-26 10:25:16 +08:00
parent dd5c387585
commit a4be58098e
8 changed files with 268 additions and 185 deletions

View File

@@ -23,41 +23,78 @@ class Sf_Bf_Connect(http.Controller):
ret = json.loads(datas)
ret = json.loads(ret['result'])
product_id = request.env.ref('sf_dlm.product_template_sf').sudo()
logging.info('product_id:%s' % product_id)
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()
purchase_id = request.env.ref('sf_dlm.product_embryo_sf_purchase').sudo()
company_id = request.env.ref('base.main_company').sudo()
user_id = request.env.ref('base.user_admin').sudo()
logging.info('user_id:%s' % user_id)
order_id = request.env['sale.order'].with_user(request.env.ref("base.user_admin")).sale_order_create(
company_id, ret['delivery_name'], ret['delivery_telephone'], ret['delivery_address'],
ret['delivery_end_date'])
ret['delivery_end_date'], user_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.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)
logging.info('order_id:%s' % order_id)
logging.info('product:%s' % product)
bom_data = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).get_bom(product)
logging.info('bom_data:%s' % bom_data)
if bom_data:
bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create(product,
'normal')
bom.with_user(request.env.ref("base.user_admin")).bom_create_Line(product)
'normal',
False)
bom.with_user(request.env.ref("base.user_admin")).bom_create_line_has(bom_data)
else:
if product.materials_id.gain_way == '自加工':
self_machining = request.env['product.template'].sudo().no_bom_product_create(self_machining_id,
if product.materials_type_id.gain_way == '自加工':
# 创建胚料
self_machining_embryo = request.env['product.template'].sudo().no_bom_product_create(
self_machining_id,
item,
order_i)
bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create(
self_machining, 'normal')
bom.with_user(request.env.ref("base.user_admin")).bom_create_Line(self_machining)
elif product.materials_id.gain_way == '外协':
outsource = request.env['product.template'].sudo().no_bom_product_create(outsource_id, item,
order_id)
bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create(outsource)
bom.with_user(request.env.ref("base.user_admin")).bom_create_Line(outsource, 'subcontract')
elif product.materials_id.gain_way == '采购':
purchase = request.env['product.template'].sudo().no_bom_product_create(purchase_id, item,
order_id)
order_id, 'self_machining')
# 创建胚料的bom
self_machining_bom = request.env['mrp.bom'].with_user(
request.env.ref("base.user_admin")).bom_create(
self_machining_embryo, 'normal')
# 创建胚料里bom的组件
self_machining_bom.with_user(request.env.ref("base.user_admin")).bom_create_line(
self_machining_embryo)
# 产品配置bom
product_bom_self_machining = request.env['mrp.bom'].with_user(
request.env.ref("base.user_admin")).bom_create(
product, 'normal', False)
product_bom_self_machining.with_user(request.env.ref("base.user_admin")).bom_create_line_has(
self_machining_embryo)
elif product.materials_type_id.gain_way == '外协':
# 创建胚料
outsource_embryo = request.env['product.template'].sudo().no_bom_product_create(outsource_id,
item,
order_id,
'subcontract')
# 创建胚料的bom
outsource_bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create(
outsource_embryo,
'subcontract', True)
# 创建胚料的bom的组件
outsource_bom.with_user(request.env.ref("base.user_admin")).bom_create_line(outsource_embryo)
# 产品配置bom
product_bom_outsource = request.env['mrp.bom'].with_user(
request.env.ref("base.user_admin")).bom_create(product, 'normal', False)
product_bom_outsource.with_user(request.env.ref("base.user_admin")).bom_create_line_has(
outsource_embryo)
elif product.materials_type_id.gain_way == '采购':
purchase_embryo = request.env['product.template'].sudo().no_bom_product_create(purchase_id,
item,
order_id,
'purchase')
# 产品配置bom
product_bom_purchase = request.env['mrp.bom'].with_user(
request.env.ref("base.user_admin")).bom_create(product, 'normal', False)
product_bom_purchase.with_user(request.env.ref("base.user_admin")).bom_create_line_has(
purchase_embryo)
order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item)
i += 1
res['factory_order_no'] = order_id.name
return json.JSONEncoder().encode(res)

View File

@@ -10,7 +10,7 @@
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
'depends': ['mrp', 'base', 'sf_manufacturing'],
'depends': ['mrp', 'base', 'sf_manufacturing', 'purchase', 'mrp_subcontracting'],
'data': [
'data/product_data.xml',
'views/product_template_view.xml'

View File

@@ -1,57 +1,82 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data noupdate="1">
<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>
<record id="product_category_embryo_sf" model="product.category">
<field name="name">胚料</field>
<field name="type">胚料</field>
</record>
<record id="product_embryo_sf_self_machining" model="product.product">
<field name="name">自加工</field>
<!-- <field name="categ_id" ref="product_category_embryo_sf"/>-->
<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 id="product_category_finished_sf" model="product.category">
<field name="name">成品</field>
<field name="type">成品</field>
</record>
<record id="product_embryo_sf_outsource" model="product.product">
<field name="name">外协</field>
<!-- <field name="categ_id" ref="product_category_embryo_sf"/>-->
<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 id="product_category_raw_sf" model="product.category">
<field name="name">原材料</field>
<field name="type">原材料</field>
</record>
<record id="product_embryo_sf_purchase" model="product.product">
<field name="name">采购</field>
<!-- <field name="categ_id" ref="product_category_embryo_sf"/>-->
<record id="product_template_sf" model="product.template">
<field name="name">CNC加工产品模板</field>
<field name="active" eval="False"/>
<field name="categ_id" ref="product_category_finished_sf"/>
<field name="route_ids"
eval="[ref('stock.route_warehouse0_mto'), ref('mrp.route_warehouse0_manufacture')]"/>
<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>
<field name="single_manufacturing">true</field>
<field name="tracking">serial</field>
</record>
<record id="product_embryo_sf_self_machining" model="product.template">
<field name="name">胚料自加工模板</field>
<field name="active" eval="False"/>
<field name="categ_id" ref="product_category_embryo_sf"/>
<field name="route_ids"
eval="[ref('stock.route_warehouse0_mto'), ref('mrp.route_warehouse0_manufacture')]"/>
<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="single_manufacturing">true</field>
<field name="tracking">serial</field>
<!-- <field name="active" eval="False"/>-->
</record>
<record id="product_embryo_sf_outsource" model="product.template">
<field name="name">胚料外协加工模板</field>
<field name="active" eval="False"/>
<field name="categ_id" ref="product_category_embryo_sf"/>
<field name="route_ids"
eval="[ref('stock.route_warehouse0_mto'), ref('purchase_stock.route_warehouse0_buy'),ref('mrp_subcontracting.route_resupply_subcontractor_mto')]"/>
<field name="invoice_policy">delivery</field>
<field name="detailed_type">product</field>
<field name="purchase_ok">true</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="tracking">serial</field>
<!-- <field name="active" eval="False"/>-->
</record>
<record id="product_embryo_sf_purchase" model="product.template">
<field name="name">胚料采购模板</field>
<field name="active" eval="False"/>
<field name="categ_id" ref="product_category_embryo_sf"/>
<field name="route_ids"
eval="[ref('stock.route_warehouse0_mto'), ref('purchase_stock.route_warehouse0_buy')]"/>
<field name="invoice_policy">delivery</field>
<field name="detailed_type">product</field>
<field name="purchase_ok">true</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="tracking">serial</field>
<!-- <field name="active" eval="False"/>-->
</record>
</data>
</odoo>

View File

@@ -21,64 +21,55 @@ class ResProductTemplate(models.Model):
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_price = fields.Float('模型单价', digits=(16, 3))
model_remark = fields.Char('模型备注说明')
length = fields.Float('长[mm]', digits=(16, 3))
width = fields.Float('宽[mm]', digits=(16, 3))
height = fields.Float('高[mm]', digits=(16, 3))
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 _get_routes(self, route_type):
# route_manufacture = self.env.ref('mrp.route_warehouse0_manufacture', raise_if_not_found=False).sudo()
# route_mto = self.env.ref('stock.route_warehouse0_mto', raise_if_not_found=False).sudo()
# route_purchase = self.env.ref('purchase_stock.route_warehouse0_buy', raise_if_not_found=False).sudo()
# if route_manufacture and route_mto:
# # 外协
# if route_type == 'subcontract':
# route_subcontract = self.env.ref('mrp_subcontracting.route_resupply_subcontractor_mto',
# raise_if_not_found=False).sudo()
# return [route_mto.id, route_purchase.id, route_subcontract.id]
# elif route_type == 'purchase':
# # 采购
# return [route_mto.id, route_purchase.id]
# else:
# return [route_mto.id, route_manufacture.id]
# return []
single_manufacturing = fields.Boolean(string="单个制造")
@api.model
def _get_route(self):
route_manufacture = self.env.ref('stock.warehouse0', raise_if_not_found=False).manufacture_pull_id.route_id.id
route_mto = self.env.ref('stock.warehouse0', raise_if_not_found=False).mto_pull_id.route_id.id
if route_manufacture and route_mto:
return [route_manufacture, route_mto]
return []
route_ids = fields.Many2many(default=lambda self: self._get_route())
# @api.depends('long', 'width', 'height')
# def _compute_volume(self):
# self.volume = self.long * self.width * self.height
# @api.depends('model_long', 'model_width', 'model_height')
# def _compute_model_volume(self):
# self.model_volume = self.model_long * self.model_width * self.model_height
# route_ids = fields.Many2many(default=lambda self: self._get_route())
# 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品
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
logging.info('product_create:%s' % item)
# 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'],
'length': item['long'],
'width': item['width'],
'height': item['height'],
'volume': item['long'] * item['width'] * item['height'],
'model_price': item['price'],
'model_type_id': 1,
'model_machining_precision': item['model_machining_precision'],
'model_processing_panel': 'R,U',
'length': item['model_long'],
'width': item['model_width'],
'height': item['model_height'],
'volume': item['model_long'] * item['model_width'] * item['model_height'],
'model_price': item['price'],
'tracking': 'serial',
'single_manufacturing': True,
'volume': (item['model_long'] * item['model_width'] * item['model_height']),
# 'model_price': item['price'],
# 'single_manufacturing': True,
'list_price': item['price'],
# 'categ_id': self.env.ref('sf_dlm.product_category_finished_sf').id,
'materials_id': self.env['sf.production.materials'].search(
[('materials_no', '=', item['texture_code'])]).id,
'materials_type_id': self.env['sf.materials.model'].search(
@@ -88,49 +79,60 @@ class ResProductTemplate(models.Model):
# 'model_process_parameters_id': self.env['sf.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
'default_code': '%s-%s' % (order_number, i),
'barcode': item['barcode'],
'active': True,
# 'route_ids': self._get_routes('')
}
logging.info('product_create1:%s' % item)
copy_product_id.sudo().write(vals)
# product_id.active = False
return copy_product_id
def no_bom_product_create(self, product_id, item, order_id):
copy_product_id = product_id.with_user(self.env.ref("base.user_admin")).copy()
copy_product_id.product_tmpl_id.active = True
logging.info('no_bom_product_create:%s' % item)
# 创建胚料
def no_bom_product_create(self, product_id, item, order_id, route_type):
no_bom_copy_product_id = product_id.with_user(self.env.ref("base.user_admin")).copy()
# no_bom_copy_product_id.product_tmpl_id.active = True
materials_id = self.env['sf.production.materials'].search(
[('materials_no', '=', item['texture_code'])]).id
[('materials_no', '=', item['texture_code'])])
materials_type_id = self.env['sf.materials.model'].search(
[('materials_no', '=', item['texture_type_code'])]).id
[('materials_no', '=', item['texture_type_code'])])
supplier = self.env['mrp.bom'].get_supplier(materials_type_id)
logging.info('no_bom_copy_product_supplier-vals:%s' % supplier)
vals = {
'name': '%s %s %s %s * %s * %s' % (
order_id.name, materials_id.name, materials_type_id.name, item['model_long'], item['model_width'],
item['model_height']),
'model_long': item['model_long'],
'model_width': item['model_width'],
'model_height': item['model_height'],
'model_volume': item['model_long'] * item['model_width'] * item['model_height'],
'length': item['model_long'],
'width': item['model_width'],
'height': item['model_height'],
'volume': item['model_long'] * item['model_width'] * item['model_height'],
'model_price': item['price'],
'tracking': 'serial',
'single_manufacturing': True,
# 'model_price': item['price'],
'list_price': item['price'],
'materials_id': materials_id.id,
'materials_type_id': materials_type_id.id,
# 'route_ids': self._get_routes(route_type),
# 'categ_id': self.env.ref('sf_dlm.product_category_embryo_sf').id,
# 'model_surface_process_id': self.env['sf.production.process'].search(
# [('process_encode', '=', item['surface_process_code'])]).id,
# 'model_process_parameters_id': self.env['sf.processing.technology'].search(
# [('process_encode', '=', item['process_parameters_code'])]).id,
'active': True
}
logging.info('product_create1:%s' % item)
copy_product_id.sudo().write(vals)
return copy_product_id
# 外协和采购生成的胚料需要根据材料型号绑定供应商
if route_type == 'subcontract':
no_bom_copy_product_id.purchase_ok = True
no_bom_copy_product_id.seller_ids = [
(0, 0, {'partner_id': supplier.partner_id.id, 'delay': 1.0, 'is_subcontractor': True})]
logging.info('no_bom_copy_product_id-seller_ids-vals:%s' % no_bom_copy_product_id.seller_ids)
elif route_type == 'purchase':
no_bom_copy_product_id.purchase_ok = True
no_bom_copy_product_id.seller_ids = [
(0, 0, {'partner_id': supplier.partner_id.id, 'delay': 1.0})]
logging.info('no_bom_copy_product_id-seller_ids-vals:%s' % no_bom_copy_product_id.seller_ids)
no_bom_copy_product_id.write(vals)
logging.info('no_bom_copy_product_id-vals:%s' % vals)
# product_id.active = False
return no_bom_copy_product_id
# 根据模型类型默认给模型的长高宽加配置的长度;
@api.onchange('model_type_id')
@@ -143,13 +145,6 @@ class ResProductTemplate(models.Model):
self.model_long = self.model_long + 1
self.model_width = self.model_width + 1
self.model_height = self.model_width + 1
# for item in self:
# print(item.model_long)
# print(item.model_width)
# print(item.model_height)
# item.model_long = item.model_long + 1
# item.model_width = item.model_width + 1
# item.model_height = item.model_width + 1
else:
return
@@ -157,27 +152,40 @@ class ResProductTemplate(models.Model):
class ResMrpBom(models.Model):
_inherit = 'mrp.bom'
subcontractor_id = fields.Many2one('res.partner', string='外包商')
def bom_create_line_has(self, embryo):
vals = {
'bom_id': self.id,
'product_id': embryo.id,
'product_tmpl_id': embryo.product_tmpl_id.id,
'product_qty': 1,
'product_uom_id': 1
}
logging.info('bom_create_line_has-vals:%s' % vals)
return self.env['mrp.bom.line'].create(vals)
# 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品后再次进行创建bom
def bom_create(self, product, bom_type):
def bom_create(self, product, bom_type, product_type):
bom_id = self.env['mrp.bom'].create({
'product_tmpl_id': product.product_tmpl_id.id,
'type': bom_type,
# 'subcontractor_id': '' or subcontract.partner_id.id,
'product_qty': 1,
'product_uom_id': 1
})
if bom_type == 'subcontract' and product_type != False:
subcontract = self.get_supplier(product.materials_type_id)
bom_id.subcontractor_id = subcontract.partner_id.id
logging.info('bom_create-vals:%s' % bom_id)
return bom_id
# 生成产品BOM匹配胚料胚料的匹配规则
# 一、匹配的胚料类别需要带有胚料的标签;
# 二、胚料的材料型号与生成产品的材料型号一致;
# 三、胚料的长宽高均要大于模型的长宽高;
# 四、如果匹配成功多个胚料,则选取体积最小的胚料;
# 创建新的胚料,根据胚料材料型号的获取方式(
# 自加工,外协,采购) 的配置, 选择不同的库存路线,一种材料型号配置一个路线相关的配置:
# 材料型号配置不同的获取方式: (自加工, 外协, 采购);
# 原材料重量KG公斤= 胚料的体积立方米m³ * 材料密度 * 1000
def bom_create_Line(self, embryo, materials):
bom_line = self.get_raw_bom(embryo, materials)
# 胚料BOM组件选取当前胚料原材料
# 然后根据当前的胚料的体积得出需要的原材料重量立方米m³ *材料密度 * 1000 = 所需原材料重量KG公斤
# 胚料所需原材料公式当前的胚料的体积立方米m³ *材料密度 * 1000 = 所需原材料重量KG公斤
def bom_create_line(self, embryo):
# 选取当前胚料原材料
bom_line = self.get_raw_bom(embryo)
vals = {
'bom_id': self.id,
'product_id': bom_line.id,
@@ -185,10 +193,23 @@ class ResMrpBom(models.Model):
'product_qty': bom_line.volume * bom_line.materials_type_id.density * 1000,
'product_uom_id': bom_line.uom_id.id
}
logging.info('bom_create_line-vals1:%s' % vals)
return self.env['mrp.bom.line'].create(vals)
# 查询材料型号默认排第一的供应商
def get_supplier(self, materials_type):
seller_id = self.env['sf.supplier.sort'].search(
[('materials_model_id', '=', materials_type.id)],
limit=1,
order='sequence asc')
logging.info('get_supplier-vals:%s' % seller_id)
return seller_id
# 匹配bom
def get_bom(self, product):
embryo = self.env['product.product'].search(
logging.info('get_bom-product:%s' % product)
logging.info('get_bom-product:%s' % product.materials_type_id.id)
embryo_has = self.env['product.product'].search(
[('categ_id.type', '=', '胚料'), ('materials_type_id', '=', product.materials_type_id.id),
('length', '>', product.length), ('width', '>', product.width),
('height', '>', product.height)
@@ -196,10 +217,11 @@ class ResMrpBom(models.Model):
limit=1,
order='volume desc'
)
if embryo:
rate_of_waste = ((embryo.volume - product.model_volume) % embryo.volume) * 100
if rate_of_waste <= 20:
return embryo
logging.info('get_bom-vals:%s' % embryo_has)
if embryo_has:
rate_of_waste = ((embryo_has.volume - product.model_volume) % embryo_has.volume) * 100
if rate_of_waste >= 20:
return embryo_has
else:
return
@@ -223,5 +245,3 @@ class ResProductCategory(models.Model):
# [('type', '=', self.type)])
# if category:
# raise ValidationError("该类别已存在,请选择其他类别")

View File

@@ -48,16 +48,16 @@
</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="type"/>-->
<!-- </field>-->
<!-- </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="type"/>
</field>
</field>
</record>
<record id="view_template_property_form" model="ir.ui.view">
<field name="name">product.template.stock.property.form.inherit</field>
@@ -94,5 +94,17 @@
</page>
</field>
</record>
<record id="view_mrp_bom_form_inherit_sf" model="ir.ui.view">
<field name="name">mrp.bom.form.inherit.sf</field>
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<field name="subcontractor_ids" position="replace">
<field name="subcontractor_id" widget="many2one_tags" readonly="1"
attrs="{'invisible':[('type', 'in', ['normal','phantom'])]}"/>
</field>
</field>
</record>
</data>
</odoo>

View File

@@ -390,26 +390,12 @@ class CNCprocessing(models.Model):
if os.path.exists(nc_file_path):
with open(nc_file_path, 'rb') as file:
data_bytes = file.read()
attachment = self.attachment_create(cnc.program_name + '.NC', data_bytes)
attachment = self.attachment_create(cnc.program_name, data_bytes)
cnc.write({'cnc_id': attachment.id})
file.close()
else:
return False
# 将nc文件对应的excel清单转为pdf
# def to_pdf(self, excel_path, pdf_path):
# """
# 需要在linux中下载好libreoffice
# """
# logging.info('pdf_path:%s' % pdf_path)
# logging.info('pdf_path:%s' % excel_path)
# # 注意cmd中的libreoffice要和linux中安装的一致
# cmd = 'soffice --headless --convert-to pdf'.split() + [excel_path] + ['--outdir'] + [pdf_path]
# p = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, bufsize=1)
# # p.wait(timeout=30) # 停顿30秒等待转化
# # stdout, stderr = p.communicate()
# p.communicate()
class SfWorkOrderBarcodes(models.Model):
"""

View File

@@ -32,16 +32,15 @@ class Sf_Mrs_Connect(http.Controller):
logging.info('model_code:%s' % model_code)
server_dir = cnc.with_user(request.env.ref("base.user_admin")).download_file_tmp(model_code,
processing_panel)
cnc_file_path = os.path.join(server_dir, cnc.program_name + '.NC')
cnc_file_path = os.path.join('/', server_dir, cnc.program_name + '.nc')
logging.info('cnc_file_path:%s' % cnc_file_path)
cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc)
# logging.info('get_cnc_processing_create:%s' % '111111111111111')
logging.info('get_cnc_processing_create:%s' % '111111111111111')
# for root, dirs, files in os.walk(server_dir):
# for file in files:
# if os.path.splitext(file)[1] == '.xlsx' or os.path.splitext(file)[1] == ".xls":
# for f in files:
# if os.path.splitext(f)[1] == ".pdf":
# pdf_path = os.path.splitext(file)[1] + '.PDF'
# cnc_pdf_path = request.env['sf.cnc.processing'].with_user(
# request.env.ref("base.user_admin")).to_pdf(os.path.join(root, file), pdf_path)
#
# if pdf_path != False:
# if not cnc.workorder_id.cnc_worksheet:
# cnc.workorder_id.cnc_worksheet = base64.b64encode(open(cnc_pdf_path, 'rb').read())

View File

@@ -15,20 +15,23 @@ class ReSaleOrder(models.Model):
# 业务平台分配工厂后在智能工厂先创建销售订单
def sale_order_create(self, company_id, delivery_name, delivery_telephone, delivery_address,
deadline_of_delivery):
deadline_of_delivery,user_id):
now_time = datetime.datetime.now()
partner = self.env.user.partner_id
logging.info('partner:%s' % partner)
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': 1,
'state': 'sale',
'user_id': 1,
'partner_id': partner.id,
'state': 'draft',
'user_id': user_id.id,
'person_of_delivery': delivery_name,
'telephone_of_delivery': delivery_telephone,
'address_of_delivery': delivery_address,
'deadline_of_delivery': deadline_of_delivery
})
logging.info('sale_order_create:%s' % order_id)
return order_id
# 业务平台分配工厂时在创建完产品后再创建销售明细信息
@@ -36,10 +39,11 @@ 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'],
'name': '%s/%s/%s/%s/%s/%s' % (
product.model_long, product.model_width, product.model_height, product.model_volume,
product.model_machining_precision,
product.materials_id.name),
'price_unit': item['price'],
'price_unit': product.list_price,
'product_uom_qty': item['number']
}
return self.env['sale.order.line'].create(vals)