优化表面工yi
This commit is contained in:
@@ -26,6 +26,7 @@ class StatusChange(models.Model):
|
||||
server_product_none.append(item.name)
|
||||
if server_product_none:
|
||||
raise UserError(_("请先至产品中创建表面工艺参数为%s的服务产品", ", ".join(server_product_none)))
|
||||
|
||||
# 使用super()来调用原始方法(在本例中为'sale.order'模型的'action_confirm'方法)
|
||||
res = super(StatusChange, self).action_confirm()
|
||||
|
||||
|
||||
@@ -135,3 +135,7 @@ class ResSupplierInfo(models.Model):
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -904,6 +904,7 @@ class MrpProduction(models.Model):
|
||||
if pre_workorder:
|
||||
pre_workorder.write(
|
||||
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
|
||||
|
||||
logging.info('更新程序完成:%s' % production.name)
|
||||
|
||||
else:
|
||||
|
||||
@@ -5,8 +5,10 @@ import base64
|
||||
import hashlib
|
||||
import os
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
from odoo.modules import get_resource_path
|
||||
|
||||
|
||||
# from OCC.Extend.DataExchange import read_step_file
|
||||
# from OCC.Extend.DataExchange import write_stl_file
|
||||
|
||||
@@ -106,6 +108,15 @@ class ResProductMo(models.Model):
|
||||
|
||||
name = fields.Char('产品名称', compute='_compute_tool_name', store=True, required=False)
|
||||
|
||||
@api.constrains('seller_ids')
|
||||
def _check_seller_ids(self):
|
||||
if self.categ_type == '表面工艺':
|
||||
if self.seller_ids:
|
||||
if self.seller_ids[0].price == 0.0:
|
||||
raise UserError("请在该产品【采购】中的【价格】进行输入")
|
||||
else:
|
||||
raise UserError("请在【采购】中输入供应商信息")
|
||||
|
||||
@api.depends('cutting_tool_model_id', 'specification_id')
|
||||
def _compute_tool_name(self):
|
||||
for item in self:
|
||||
|
||||
@@ -272,29 +272,72 @@ class StockRule(models.Model):
|
||||
product_id_to_production_names[product_id] = [production.name for production in all_production]
|
||||
for production_item in productions:
|
||||
if production_item.product_id.id in product_id_to_production_names:
|
||||
purchase_order = self.env['purchase.order'].search(
|
||||
[('state', '=', 'draft'), ('origin', 'ilike', production_item.name)])
|
||||
# for po in purchase_order.order_line:
|
||||
sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids, key=lambda w: w.id)
|
||||
consecutive_process_parameters = []
|
||||
m = 0
|
||||
for i in range(len(sorted_workorders) - 1):
|
||||
if m == 0:
|
||||
is_pick = False
|
||||
if sorted_process_parameters[i].supplier_id.id == sorted_process_parameters[i + 1].supplier_id.id :
|
||||
if sorted_process_parameters[i] not in consecutive_process_parameters:
|
||||
consecutive_process_parameters.append(sorted_process_parameters[i])
|
||||
consecutive_process_parameters.append(sorted_process_parameters[i + 1])
|
||||
m += 1
|
||||
continue
|
||||
else:
|
||||
if m == len(consecutive_process_parameters) - 1 and m != 0:
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_process_parameters,
|
||||
production_item)
|
||||
if sorted_process_parameters[i] in consecutive_workorders:
|
||||
is_pick = True
|
||||
consecutive_process_parameters = []
|
||||
m = 0
|
||||
# 当前面的连续工序生成对应的采购单再生成当前工序的外协采购单
|
||||
if is_pick is False:
|
||||
self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i],
|
||||
production_item)
|
||||
if m == len(consecutive_process_parameters) - 1 and m != 0:
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_process_parameters,
|
||||
production_item)
|
||||
if sorted_process_parameters[i] in consecutive_process_parameters:
|
||||
is_pick = True
|
||||
consecutive_process_parameters = []
|
||||
m = 0
|
||||
if m == len(consecutive_process_parameters) - 1 and m != 0:
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_process_parameters, production_item)
|
||||
if is_pick is False and m == 0:
|
||||
if len(sorted_process_parameters) == 1:
|
||||
self.env['stock.picking'].create_outcontract_picking(sorted_process_parameters, production_item)
|
||||
else:
|
||||
self.env['stock.picking'].create_outcontract_picking(sorted_process_parameters[i], production_item)
|
||||
for pp in production_item.product_id.model_process_parameters_ids:
|
||||
if pp.gain_way == '外协':
|
||||
purchase_order_line = self.env['purchase.order.line'].search(
|
||||
[('order_id', '=', po.order_id)])
|
||||
if not purchase_order_line:
|
||||
server_product = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', pp.id),
|
||||
('detailed_type', '=', 'service')])
|
||||
purchase_order_line = self.env['purchase.order.line'].search(
|
||||
[('product_id', '=', server_product.id)])
|
||||
if not purchase_order_line:
|
||||
is_exist = False
|
||||
else:
|
||||
for item in purchase_order_line:
|
||||
purchase_order = self.env['purchase.order'].search(
|
||||
[('state', '=', 'draft'), ('origin', 'ilike', production_item.name),
|
||||
('id', '=', item.order_id)])
|
||||
if not purchase_order:
|
||||
is_exist = False
|
||||
if is_exist is False:
|
||||
production_process = product_id_to_production_names.get(
|
||||
production_item.product_id.id)
|
||||
order_line_ids.append((0, 0, {
|
||||
'product_id': server_product.product_variant_id.id,
|
||||
'product_qty': len(production_process),
|
||||
'product_uom': server_product.uom_id.id
|
||||
}))
|
||||
self.env['purchase.order'].sudo().create({
|
||||
'partner_id': server_product.seller_ids.partner_id.id,
|
||||
'origin': ','.join(production_process),
|
||||
'state': 'draft',
|
||||
'order_line': order_line_ids,
|
||||
'order_line': [(0, 0, {
|
||||
'product_id': server_product.product_variant_id.id,
|
||||
'product_qty': len(production_process),
|
||||
'product_uom': server_product.uom_id.id
|
||||
})]
|
||||
})
|
||||
|
||||
# # 同一个产品多个制造订单对应一个编程单和模型库
|
||||
|
||||
Reference in New Issue
Block a user