优化及调试表面工艺外协出入库单,‘胚料’修改为‘坯料’
This commit is contained in:
@@ -120,7 +120,7 @@ class MrsProductionProcessParameter(models.Model):
|
||||
code = fields.Char("编码")
|
||||
name = fields.Char('名称')
|
||||
gain_way = fields.Selection([("自加工", "自加工"), ("外协", "外协")], default="", string="获取方式")
|
||||
is_check = fields.Boolean(default=True)
|
||||
is_check = fields.Boolean(default=False)
|
||||
# price = fields.Float('单价')
|
||||
process_id = fields.Many2one('sf.production.process', string='表面工艺')
|
||||
materials_model_ids = fields.Many2many('sf.materials.model', 'applicable_material', string='适用材料')
|
||||
|
||||
@@ -11,7 +11,7 @@ class Sf_Bf_Connect(http.Controller):
|
||||
cors="*")
|
||||
def get_bfm_process_order_list(self, **kw):
|
||||
"""
|
||||
接收业务平台加工订单分配工厂时传送来的订单数据并生成销售订单和产品及胚料
|
||||
接收业务平台加工订单分配工厂时传送来的订单数据并生成销售订单和产品及坯料
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
@@ -52,16 +52,16 @@ class Sf_Bf_Connect(http.Controller):
|
||||
bom.with_user(request.env.ref("base.user_admin")).bom_create_line_has(bom_data)
|
||||
else:
|
||||
if product.materials_type_id.gain_way == '自加工':
|
||||
# 创建胚料
|
||||
# 创建坯料
|
||||
self_machining_embryo = request.env['product.template'].sudo().no_bom_product_create(
|
||||
self_machining_id,
|
||||
item,
|
||||
order_id, 'self_machining', i)
|
||||
# 创建胚料的bom
|
||||
# 创建坯料的bom
|
||||
self_machining_bom = request.env['mrp.bom'].with_user(
|
||||
request.env.ref("base.user_admin")).bom_create(
|
||||
self_machining_embryo, 'normal', False)
|
||||
# 创建胚料里bom的组件
|
||||
# 创建坯料里bom的组件
|
||||
self_machining_bom_line = self_machining_bom.with_user(
|
||||
request.env.ref("base.user_admin")).bom_create_line(
|
||||
self_machining_embryo)
|
||||
@@ -77,17 +77,17 @@ class Sf_Bf_Connect(http.Controller):
|
||||
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',
|
||||
i)
|
||||
# 创建胚料的bom
|
||||
# 创建坯料的bom
|
||||
outsource_bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create(
|
||||
outsource_embryo,
|
||||
'subcontract', True)
|
||||
# 创建胚料的bom的组件
|
||||
# 创建坯料的bom的组件
|
||||
outsource_bom_line = outsource_bom.with_user(
|
||||
request.env.ref("base.user_admin")).bom_create_line(outsource_embryo)
|
||||
if outsource_bom_line == False:
|
||||
|
||||
@@ -35,44 +35,7 @@ class StatusChange(models.Model):
|
||||
context = self._context.copy()
|
||||
context.pop('default_name', None)
|
||||
logging.info('函数已经执行=============4')
|
||||
|
||||
self.with_context(context)._action_confirm()
|
||||
self.env.cr.commit()
|
||||
print(self.mrp_production_ids)
|
||||
# 判断外协工序是否连续有多个外协工序为同一个供应商(产品为表面工艺服务的供应商),
|
||||
# 如果有的话,则将连续的多个外协工序(ID),绑定同一张外协出入库单,单独的供应商工序则生成单独的外协出入库单
|
||||
# 如果没有连续的外协工序为同一个供应商,则根据规则生成多张外协出入库单,并绑定不同的工序ID
|
||||
|
||||
#以下代码可转移至生成工单的该行代码production.workorder_ids = workorders_values前后左右
|
||||
for item in self.mrp_production_ids:
|
||||
process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', 83)])
|
||||
if process_parameter_workorder:
|
||||
consecutive_workorders = []
|
||||
m =0
|
||||
sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id)
|
||||
for i in range(len(sorted_workorders) - 1):
|
||||
if sorted_workorders[i].supplier_id == sorted_workorders[i + 1].supplier_id and \
|
||||
sorted_workorders[i].id == sorted_workorders[i + 1].id - 1:
|
||||
consecutive_workorders.append(sorted_workorders[i])
|
||||
consecutive_workorders.append(sorted_workorders[i + 1])
|
||||
m+1
|
||||
else:
|
||||
|
||||
if m != len(sorted_workorders):
|
||||
if consecutive_workorders:
|
||||
self.env['stock.move'].create_outcontract_stock_move(consecutive_workorders,item)
|
||||
# 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单,并将前面的consecutive_workorders和m置为初始值
|
||||
consecutive_workorders = []
|
||||
m =0
|
||||
self.env['stock.move'].create_outcontract_stock_move(consecutive_workorders, item)
|
||||
if m == len(sorted_workorders):
|
||||
self.env['stock.move'].create_outcontract_stock_move(consecutive_workorders, item)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if self.env.user.has_group('sale.group_auto_done_setting'):
|
||||
logging.info('函数已经执行=============5')
|
||||
self.action_done()
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<record id="product_category_embryo_sf" model="product.category">
|
||||
<field name="name">胚料</field>
|
||||
<field name="type">胚料</field>
|
||||
<field name="name">坯料</field>
|
||||
<field name="type">坯料</field>
|
||||
</record>
|
||||
<record id="product_category_finished_sf" model="product.category">
|
||||
<field name="name">成品</field>
|
||||
@@ -37,7 +37,7 @@
|
||||
<field name="is_bfm">false</field>
|
||||
</record>
|
||||
<record id="product_embryo_sf_self_machining" model="product.product">
|
||||
<field name="name">胚料自加工模板</field>
|
||||
<field name="name">坯料自加工模板</field>
|
||||
<field name="active" eval="False"/>
|
||||
<field name="categ_id" ref="product_category_embryo_sf"/>
|
||||
<field name="route_ids"
|
||||
@@ -54,7 +54,7 @@
|
||||
</record>
|
||||
|
||||
<record id="product_embryo_sf_outsource" model="product.product">
|
||||
<field name="name">胚料外协加工模板</field>
|
||||
<field name="name">坯料外协加工模板</field>
|
||||
<field name="active" eval="False"/>
|
||||
<field name="categ_id" ref="product_category_embryo_sf"/>
|
||||
<field name="route_ids"
|
||||
@@ -69,7 +69,7 @@
|
||||
<field name="is_bfm">false</field>
|
||||
</record>
|
||||
<record id="product_embryo_sf_purchase" model="product.product">
|
||||
<field name="name">胚料采购模板</field>
|
||||
<field name="name">坯料采购模板</field>
|
||||
<field name="active" eval="False"/>
|
||||
<field name="categ_id" ref="product_category_embryo_sf"/>
|
||||
<field name="route_ids"
|
||||
|
||||
@@ -15,7 +15,7 @@ class ResProductTemplate(models.Model):
|
||||
# 模型的长,宽,高,体积,精度,材料
|
||||
model_name = fields.Char('模型名称')
|
||||
categ_type = fields.Selection(
|
||||
[("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料"), ("表面工艺", "表面工艺")],
|
||||
[("成品", "成品"), ("坯料", "坯料"), ("原材料", "原材料"), ("表面工艺", "表面工艺")],
|
||||
string='产品的类别', related='categ_id.type',
|
||||
store=True)
|
||||
model_long = fields.Float('模型长[mm]', digits=(16, 3))
|
||||
@@ -29,7 +29,7 @@ class ResProductTemplate(models.Model):
|
||||
('0.02', '±0.02mm'),
|
||||
('0.01', '±0.01mm')], string='加工精度')
|
||||
product_model_type_id = fields.Many2one('sf.model.type', string='产品模型类型')
|
||||
embryo_model_type_id = fields.Many2one('sf.model.type', string='胚料模型类型')
|
||||
embryo_model_type_id = fields.Many2one('sf.model.type', string='坯料模型类型')
|
||||
model_processing_panel = fields.Char('模型加工面板')
|
||||
# model_surface_process_category_id = fields.Many2one('sf.production.process.category', string='表面工艺类别')
|
||||
# model_surface_process_ids = fields.Many2many('sf.production.process', 'rel_product_process', string='表面工艺')
|
||||
@@ -58,7 +58,7 @@ class ResProductTemplate(models.Model):
|
||||
|
||||
# model_file = fields.Binary('模型文件')
|
||||
|
||||
# 胚料的库存路线设置
|
||||
# 坯料的库存路线设置
|
||||
# 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()
|
||||
@@ -148,7 +148,7 @@ class ResProductTemplate(models.Model):
|
||||
})
|
||||
return attachment
|
||||
|
||||
# 创建胚料
|
||||
# 创建坯料
|
||||
def no_bom_product_create(self, product_id, item, order_id, route_type, i):
|
||||
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
|
||||
@@ -184,7 +184,7 @@ class ResProductTemplate(models.Model):
|
||||
# [('process_encode', '=', item['process_parameters_code'])]).id,
|
||||
'active': True
|
||||
}
|
||||
# 外协和采购生成的胚料需要根据材料型号绑定供应商
|
||||
# 外协和采购生成的坯料需要根据材料型号绑定供应商
|
||||
if route_type == 'subcontract' or route_type == 'purchase':
|
||||
no_bom_copy_product_id.purchase_ok = True
|
||||
no_bom_copy_product_id.seller_ids = [
|
||||
@@ -288,11 +288,11 @@ class ResMrpBom(models.Model):
|
||||
bom_id.subcontractor_id = subcontract.partner_id.id
|
||||
return bom_id
|
||||
|
||||
# 胚料BOM组件:选取当前胚料原材料,
|
||||
# 然后根据当前的胚料的体积得出需要的原材料重量(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
||||
# 胚料所需原材料公式:当前的胚料的体积(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
||||
# 坯料BOM组件:选取当前坯料原材料,
|
||||
# 然后根据当前的坯料的体积得出需要的原材料重量(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
||||
# 坯料所需原材料公式:当前的坯料的体积(立方米m³) *材料密度 * 1000 = 所需原材料重量KG(公斤)
|
||||
def bom_create_line(self, embryo):
|
||||
# 选取当前胚料原材料
|
||||
# 选取当前坯料原材料
|
||||
raw_bom_line = self.get_raw_bom(embryo)
|
||||
if raw_bom_line:
|
||||
bom_line = self.env['mrp.bom.line'].create({
|
||||
@@ -317,7 +317,7 @@ class ResMrpBom(models.Model):
|
||||
# 匹配bom
|
||||
def get_bom(self, product):
|
||||
embryo_has = self.env['product.product'].search(
|
||||
[('categ_id.type', '=', '胚料'), ('materials_type_id', '=', product.materials_type_id.id),
|
||||
[('categ_id.type', '=', '坯料'), ('materials_type_id', '=', product.materials_type_id.id),
|
||||
('length', '>', product.length), ('width', '>', product.width),
|
||||
('height', '>', product.height), ('is_bfm', '=', False)
|
||||
],
|
||||
@@ -343,7 +343,7 @@ class ResProductCategory(models.Model):
|
||||
_inherit = "product.category"
|
||||
|
||||
type = fields.Selection(
|
||||
[("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料"), ("表面工艺", "表面工艺"), ("服务", "服务")],
|
||||
[("成品", "成品"), ("坯料", "坯料"), ("原材料", "原材料"), ("表面工艺", "表面工艺")],
|
||||
default="", string="类型")
|
||||
|
||||
# @api.constrains('type')
|
||||
|
||||
@@ -5,8 +5,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
_inherit = 'mrp.workorder'
|
||||
_order = 'sequence'
|
||||
|
||||
product_tmpl_id_length = fields.Float(related='production_id.product_tmpl_id.length', readonly=True, store=True, check_company=True, string="胚料长度(mm)")
|
||||
product_tmpl_id_width = fields.Float(related='production_id.product_tmpl_id.width', readonly=True, store=True, check_company=True, string="胚料宽度(mm)")
|
||||
product_tmpl_id_height = fields.Float(related='production_id.product_tmpl_id.height', readonly=True, store=True, check_company=True, string="胚料高度(mm)")
|
||||
product_tmpl_id_length = fields.Float(related='production_id.product_tmpl_id.length', readonly=True, store=True, check_company=True, string="坯料长度(mm)")
|
||||
product_tmpl_id_width = fields.Float(related='production_id.product_tmpl_id.width', readonly=True, store=True, check_company=True, string="坯料宽度(mm)")
|
||||
product_tmpl_id_height = fields.Float(related='production_id.product_tmpl_id.height', readonly=True, store=True, check_company=True, string="坯料高度(mm)")
|
||||
product_tmpl_id_materials_id = fields.Many2one(related='production_id.product_tmpl_id.materials_id', readonly=True, store=True, check_company=True, string="材料")
|
||||
product_tmpl_id_materials_type_id = fields.Many2one(related='production_id.product_tmpl_id.materials_type_id', readonly=True, store=True, check_company=True, string="型号")
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</field>
|
||||
<field name="invoice_policy" position="after">
|
||||
<field name="embryo_model_type_id" string="模型类型"
|
||||
attrs="{'invisible': ['|',('categ_type', '!=', '胚料'),('categ_type', '=', False)]}"/>
|
||||
attrs="{'invisible': ['|',('categ_type', '!=', '坯料'),('categ_type', '=', False)]}"/>
|
||||
<field name="materials_id" string="材料" attrs="{'invisible': [('categ_type', '=', '表面工艺')]}"/>
|
||||
<field name="materials_type_id" string="型号"
|
||||
domain="[('materials_id', '=', materials_id)]"
|
||||
@@ -145,7 +145,7 @@
|
||||
<xpath expr="//filter[@name='consumable']" position="after">
|
||||
<separator/>
|
||||
<filter name="finish_product" string="成品" domain="[('categ_id.type','=','成品')]"/>
|
||||
<filter name="embryo" string="胚料" domain="[('categ_id.type','=','胚料')]"/>
|
||||
<filter name="embryo" string="坯料" domain="[('categ_id.type','=','坯料')]"/>
|
||||
<filter name="raw_bom" string="原材料" domain="[('categ_id.type','=','原材料')]"/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
@@ -6,11 +6,11 @@ class ModelType(models.Model):
|
||||
_description = '模型类型'
|
||||
|
||||
name = fields.Char('名称')
|
||||
embryo_tolerance = fields.Integer('胚料容余')
|
||||
embryo_tolerance = fields.Integer('坯料容余')
|
||||
product_routing_tmpl_ids = fields.One2many('sf.product.model.type.routing.sort', 'product_model_type_id',
|
||||
'成品工序模板')
|
||||
embryo_routing_tmpl_ids = fields.One2many('sf.embryo.model.type.routing.sort', 'embryo_model_type_id',
|
||||
'胚料工序模板')
|
||||
'坯料工序模板')
|
||||
surface_technics_routing_tmpl_ids = fields.One2many('sf.surface_technics.model.type.routing.sort',
|
||||
'surface_technics_model_type_id',
|
||||
'表面工艺工序模板')
|
||||
@@ -41,7 +41,7 @@ class ProductModelTypeRoutingSort(models.Model):
|
||||
|
||||
class EmbryoModelTypeRoutingSort(models.Model):
|
||||
_name = 'sf.embryo.model.type.routing.sort'
|
||||
_description = '胚料工序排序'
|
||||
_description = '坯料工序排序'
|
||||
|
||||
sequence = fields.Integer('Sequence')
|
||||
route_workcenter_id = fields.Many2one('mrp.routing.workcenter')
|
||||
@@ -58,7 +58,7 @@ class EmbryoModelTypeRoutingSort(models.Model):
|
||||
embryo_model_type_id = fields.Many2one('sf.model.type')
|
||||
|
||||
_sql_constraints = [
|
||||
('route_model_type_uniq', 'unique (route_workcenter_id,embryo_model_type_id)', '胚料工序不能重复!')
|
||||
('route_model_type_uniq', 'unique (route_workcenter_id,embryo_model_type_id)', '坯料工序不能重复!')
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -138,31 +138,35 @@ class MrpProduction(models.Model):
|
||||
surface_technics_arr.append(item.route_workcenter_id.surface_technics_id.id)
|
||||
route_workcenter_arr.append(item.route_workcenter_id.id)
|
||||
if surface_technics_arr:
|
||||
production_process = self.env['sf.production.process.category'].search(
|
||||
production_process_category = self.env['sf.production.process.category'].search(
|
||||
[('production_process_ids.id', 'in', surface_technics_arr)],
|
||||
order='sequence asc'
|
||||
)
|
||||
if production_process:
|
||||
for p in production_process:
|
||||
for pitem in p.production_process_ids:
|
||||
if pitem.id in surface_technics_arr:
|
||||
for param in production.product_id.model_process_parameters_ids:
|
||||
process_parameter = self.env['sf.production.process.parameter'].search(
|
||||
[('process_id.id', '=', pitem.id), ('id', '=', param.id)])
|
||||
# 产品为表面工艺服务的供应商
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', process_parameter.id)])
|
||||
if process_parameter:
|
||||
for ritem in route_workcenter_arr:
|
||||
route_production_process = self.env['mrp.routing.workcenter'].search(
|
||||
[('surface_technics_id', '=', pitem.id), ('id', '=', ritem)])
|
||||
if route_production_process:
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder']._json_workorder_surface_process_str(
|
||||
production, route_production_process,
|
||||
process_parameter,
|
||||
product_production_process.seller_ids[0].id))
|
||||
elif production.product_id.categ_id.type == '胚料':
|
||||
#用filter刷选表面工艺id'是否存在工艺类别对象里
|
||||
if production_process_category:
|
||||
for p in production_process_category:
|
||||
production_process = p.production_process_ids.filtered(
|
||||
lambda pp: pp.id in surface_technics_arr)
|
||||
if production_process:
|
||||
process_parameter = production.product_id.model_process_parameters_ids.filtered(
|
||||
lambda pm: pm.process_id.id == production_process.id)
|
||||
if process_parameter:
|
||||
# 产品为表面工艺服务的供应商
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', process_parameter.id)])
|
||||
if product_production_process:
|
||||
route_production_process = self.env[
|
||||
'mrp.routing.workcenter'].search(
|
||||
[('surface_technics_id', '=', production_process.id),
|
||||
('id', 'in', route_workcenter_arr)])
|
||||
if route_production_process:
|
||||
workorders_values.append(
|
||||
self.env[
|
||||
'mrp.workorder']._json_workorder_surface_process_str(
|
||||
production, route_production_process,
|
||||
process_parameter,
|
||||
product_production_process.seller_ids[0].partner_id.id))
|
||||
elif production.product_id.categ_id.type == '坯料':
|
||||
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
|
||||
[('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)],
|
||||
order='sequence asc'
|
||||
@@ -171,23 +175,49 @@ class MrpProduction(models.Model):
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str('', production, route))
|
||||
production.workorder_ids = workorders_values
|
||||
aa = self.env['mrp.workorder'].get_no_data(production.id)
|
||||
if aa:
|
||||
consecutive_workorders = []
|
||||
m =0
|
||||
sorted_workorders = sorted(aa, key=lambda w: w.id)
|
||||
for i in range(len(sorted_workorders) - 1):
|
||||
if sorted_workorders[i].supplier_id == sorted_workorders[i + 1].supplier_id and \
|
||||
sorted_workorders[i].id == sorted_workorders[i + 1].id - 1:
|
||||
consecutive_workorders.append(sorted_workorders[i])
|
||||
consecutive_workorders.append(sorted_workorders[i + 1])
|
||||
m+1
|
||||
process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id)])
|
||||
if process_parameter_workorder:
|
||||
is_pick = False
|
||||
consecutive_workorders = []
|
||||
m = 0
|
||||
sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id)
|
||||
for i in range(len(sorted_workorders) - 1):
|
||||
if m == 0:
|
||||
is_pick = False
|
||||
# if sorted_workorders[i].id in consecutive_workorders:
|
||||
# consecutive_workorders = [x for x in consecutive_workorders if x not in sorted_workorders[i].id]
|
||||
# continue
|
||||
if sorted_workorders[i].supplier_id == sorted_workorders[i + 1].supplier_id and \
|
||||
sorted_workorders[i].id == sorted_workorders[i + 1].id - 1:
|
||||
if sorted_workorders[i] not in consecutive_workorders:
|
||||
consecutive_workorders.append(sorted_workorders[i])
|
||||
consecutive_workorders.append(sorted_workorders[i + 1])
|
||||
m += 1
|
||||
continue
|
||||
else:
|
||||
if m == len(consecutive_workorders)-1 and m != 0:
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production)
|
||||
if sorted_workorders[i] in consecutive_workorders:
|
||||
is_pick = True
|
||||
consecutive_workorders = []
|
||||
m = 0
|
||||
# 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单
|
||||
if is_pick is False:
|
||||
self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production)
|
||||
if m == len(consecutive_workorders)-1 and m != 0:
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production)
|
||||
if sorted_workorders[i] in consecutive_workorders:
|
||||
is_pick = True
|
||||
consecutive_workorders = []
|
||||
m = 0
|
||||
if m == len(consecutive_workorders) - 1 and m != 0:
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production)
|
||||
if is_pick is False:
|
||||
self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production)
|
||||
for workorder in production.workorder_ids:
|
||||
workorder.duration_expected = workorder._get_duration_expected()
|
||||
|
||||
|
||||
# 在之前的销售单上重新生成制造订单
|
||||
def create_production1_values(self, production):
|
||||
production_values_str = {'origin': production.origin,
|
||||
@@ -210,6 +240,20 @@ class MrpProduction(models.Model):
|
||||
'user_id': production.user_id.id}
|
||||
return production_values_str
|
||||
|
||||
def _get_stock_move_values_Res(self,item,location_src_id,location_dest_id):
|
||||
move_values = {
|
||||
'name': item.name if item.name else '/',
|
||||
'company_id': item.company_id.id,
|
||||
'product_id': item.bom_id.bom_line_ids.product_id.id,
|
||||
'product_uom': item.bom_id.bom_line_ids.product_uom_id.id,
|
||||
'product_uom_qty': 1.0,
|
||||
'location_id': location_src_id,
|
||||
'location_dest_id': location_dest_id,
|
||||
'origin': item.origin,
|
||||
'picking_type_id': self.picking_type_id.id,
|
||||
}
|
||||
return move_values
|
||||
|
||||
# 工单排序
|
||||
def _reset_work_order_sequence1(self, k):
|
||||
sequen = 0
|
||||
|
||||
@@ -28,7 +28,7 @@ class ResMrpRoutingWorkcenter(models.Model):
|
||||
company_id = fields.Many2one('res.company', compute="get_company_id", related=False)
|
||||
|
||||
|
||||
# 排产的时候, 根据胚料的长宽高比对一下机床的最大加工尺寸.不符合就不要分配给这个加工中心(机床).
|
||||
# 排产的时候, 根据坯料的长宽高比对一下机床的最大加工尺寸.不符合就不要分配给这个加工中心(机床).
|
||||
# 工单对应的工作中心,根据工序中的工作中心去匹配,
|
||||
# 如果只配置了一个工作中心,则默认采用该工作中心;
|
||||
# 如果有多个工作中心,
|
||||
|
||||
@@ -54,7 +54,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
programming_state = fields.Char('编程状态')
|
||||
cnc_worksheet = fields.Binary(
|
||||
'工作指令', readonly=True)
|
||||
material_center_point = fields.Char(string='胚料中心点')
|
||||
material_center_point = fields.Char(string='坯料中心点')
|
||||
X1_axis = fields.Float(default=0)
|
||||
Y1_axis = fields.Float(default=0)
|
||||
Z1_axis = fields.Float(default=0)
|
||||
@@ -93,7 +93,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
glb_file = fields.Binary("glb模型文件")
|
||||
is_subcontract = fields.Boolean(string='是否外协')
|
||||
surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数")
|
||||
picking_id = fields.Many2one('stock.picking', string='外协出入库单')
|
||||
picking_in_id = fields.Many2one('stock.picking', string='外协入库单')
|
||||
picking_out_id = fields.Many2one('stock.picking', string='外协出库单')
|
||||
supplier_id = fields.Integer('供应商Id')
|
||||
|
||||
def get_no_data(self, production_id):
|
||||
|
||||
@@ -12,13 +12,6 @@ from odoo.exceptions import UserError
|
||||
class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
|
||||
# @api.model
|
||||
# def _run_pull(self, procurements):
|
||||
# res = super(StockRule, self)._run_pull(procurements)
|
||||
# # process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
# # [('surface_technics_parameters_id', '!=', False), ('production_id', '=', self.production_id)])
|
||||
# stock_move = self.env['stock.move'].search([('raw_material_production_id', '=', self.id)])
|
||||
|
||||
@api.model
|
||||
def _run_pull(self, procurements):
|
||||
moves_values_by_company = defaultdict(list)
|
||||
@@ -190,54 +183,6 @@ class StockRule(models.Model):
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
return True
|
||||
|
||||
def create_outcontract_stock_move(self, sorted_workorders, item):
|
||||
outcontract_stock_move = self.env['stock.move'].search(
|
||||
[('workorder_id', '=', sorted_workorders.id), ('production_id', '=', item.id)])
|
||||
if not outcontract_stock_move:
|
||||
location_id = self.env.ref(
|
||||
'sf_manufacturing.stock_location_locations_virtual_outcontract').id,
|
||||
location_dest_id = self.env['stock.location'].search(
|
||||
[('barcode', '=', 'WH-PREPRODUCTION')]).id,
|
||||
outcontract_picking_in = self.env['stock.rule'].create_outcontract_picking(item,
|
||||
location_id,
|
||||
location_dest_id)
|
||||
outcontract_picking_in.write({'workorder_id': outcontract_picking_in.id})
|
||||
outcontract_picking_out = self.env['stock.rule'].create_outcontract_picking(item,
|
||||
location_dest_id,
|
||||
location_id)
|
||||
outcontract_picking_out.write({'workorder_id': outcontract_picking_out.id})
|
||||
|
||||
# 生成外协出入库单
|
||||
def create_outcontract_picking(self, item, location_src_id, location_dest_id):
|
||||
moves_values_by_company = defaultdict(list)
|
||||
list2 = []
|
||||
Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
|
||||
'product_uom', 'location_id', 'location_dest_id', 'name', 'origin',
|
||||
'company_id',
|
||||
'values'])
|
||||
s = Procurement(product_id=item.bom_id.product_id, product_qty=1.0, product_uom=item.product_uom,
|
||||
location_id=location_src_id,
|
||||
location_dest_id=location_dest_id,
|
||||
name=item.name,
|
||||
origin=item.origin,
|
||||
company_id=item.company_id,
|
||||
values=item.values,
|
||||
)
|
||||
item1 = list(item)
|
||||
item1[0] = s
|
||||
list2.append(tuple(item1))
|
||||
for procurement in list2:
|
||||
move_values = self.env['stock.rule']._get_stock_move_values(*procurement)
|
||||
moves_values_by_company[procurement.company_id.id].append(move_values)
|
||||
for company_id, moves_values in moves_values_by_company.items():
|
||||
moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
|
||||
moves_values)
|
||||
new_picking = True
|
||||
picking = self.env['stock.picking'].create(moves._get_new_picking_values())
|
||||
moves.write({'picking_id': picking.id})
|
||||
moves._assign_picking_post_process(new=new_picking)
|
||||
return picking
|
||||
|
||||
|
||||
class ProductionLot(models.Model):
|
||||
_inherit = 'stock.lot'
|
||||
@@ -288,72 +233,31 @@ class ProductionLot(models.Model):
|
||||
class ResStockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
workorder_id = fields.One2many('mrp.workorder', 'picking_id')
|
||||
workorder_in_id = fields.One2many('mrp.workorder', 'picking_in_id')
|
||||
workorder_out_id = fields.One2many('mrp.workorder', 'picking_out_id')
|
||||
|
||||
def create_outcontract_picking(self, sorted_workorders_arr, item):
|
||||
m = 0
|
||||
for sorted_workorders in sorted_workorders_arr:
|
||||
if m == 0:
|
||||
outcontract_stock_move = self.env['stock.move'].search(
|
||||
[('workorder_id', '=', sorted_workorders.id), ('production_id', '=', item.id)])
|
||||
if not outcontract_stock_move:
|
||||
location_id = self.env.ref(
|
||||
'sf_manufacturing.stock_location_locations_virtual_outcontract').id,
|
||||
location_dest_id = self.env['stock.location'].search(
|
||||
[('barcode', '=', 'WH-PREPRODUCTION')]).id,
|
||||
moves_in = self.env['stock.move'].sudo().create(
|
||||
item._get_stock_move_values_Res(item, location_id, location_dest_id))
|
||||
moves_out = self.env['stock.move'].sudo().create(
|
||||
item._get_stock_move_values_Res(item, location_dest_id, location_id))
|
||||
new_picking = True
|
||||
picking_in = self.env['stock.picking'].create(moves_in._get_new_picking_values())
|
||||
picking_out = self.env['stock.picking'].create(moves_out._get_new_picking_values())
|
||||
moves_in.write({'picking_id': picking_in.id})
|
||||
moves_out.write({'picking_id': picking_out.id})
|
||||
moves_in._assign_picking_post_process(new=new_picking)
|
||||
moves_out._assign_picking_post_process(new=new_picking)
|
||||
m += 1
|
||||
sorted_workorders.write({'picking_in_id': picking_in.id, 'picking_out_id': picking_out.id})
|
||||
|
||||
class ResPurchaseOrder(models.Model):
|
||||
_inherit = 'purchase.order'
|
||||
|
||||
# 外协出库、入库单
|
||||
def _prepare_picking_outcontract(self, sequence_code):
|
||||
# if not self.group_id:
|
||||
# self.group_id = self.group_id.create({
|
||||
# 'name': self.name,
|
||||
# 'partner_id': self.partner_id.id
|
||||
# })
|
||||
# if not self.partner_id.property_stock_supplier.id:
|
||||
# raise UserError(_("You must set a Vendor Location for this partner %s", self.partner_id.name))
|
||||
|
||||
picking_type_id_oc = self.env['stock.picking.type'].search([('sequence_code', '=', sequence_code)])
|
||||
return {
|
||||
'picking_type_id': picking_type_id_oc.id if picking_type_id_oc else self.picking_type_id.id,
|
||||
'partner_id': self.partner_id.id,
|
||||
'user_id': False,
|
||||
'date': self.date_order,
|
||||
'origin': self.name,
|
||||
'location_dest_id': self._get_destination_location(),
|
||||
'location_id': self.partner_id.property_stock_supplier.id,
|
||||
'company_id': self.company_id.id,
|
||||
}
|
||||
|
||||
def _create_picking_outcontract(self):
|
||||
StockPicking = self.env['stock.picking']
|
||||
for order in self.filtered(lambda po: po.state in ('purchase', 'done')):
|
||||
if any(product.type in ['product', 'consu'] for product in order.order_line.product_id):
|
||||
order = order.with_company(order.company_id)
|
||||
pickings = order.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel'))
|
||||
if not pickings:
|
||||
res = order._prepare_picking_outcontract()
|
||||
picking = StockPicking.with_user(SUPERUSER_ID).create(res)
|
||||
pickings = picking
|
||||
else:
|
||||
picking = pickings[0]
|
||||
moves = order.order_line._create_stock_moves(picking)
|
||||
moves = moves.filtered(lambda x: x.state not in ('done', 'cancel'))._action_confirm()
|
||||
seq = 0
|
||||
for move in sorted(moves, key=lambda move: move.date):
|
||||
seq += 5
|
||||
move.sequence = seq
|
||||
moves._action_assign()
|
||||
# Get following pickings (created by push rules) to confirm them as well.
|
||||
forward_pickings = self.env['stock.picking']._get_impacted_pickings(moves)
|
||||
(pickings | forward_pickings).action_confirm()
|
||||
picking.message_post_with_view('mail.message_origin_link',
|
||||
values={'self': picking, 'origin': order},
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
return True
|
||||
|
||||
|
||||
class ResPurchaseOrderLine(models.Model):
|
||||
_inherit = 'purchase.order.line'
|
||||
|
||||
def _create_stock_moves(self, picking):
|
||||
values = []
|
||||
for line in self.filtered(lambda l: not l.display_type):
|
||||
for val in line._prepare_stock_moves(picking):
|
||||
# val['production_id'] = 10
|
||||
val['is_subcontract'] = True
|
||||
values.append(val)
|
||||
line.move_dest_ids.created_purchase_line_id = False
|
||||
|
||||
return self.env['stock.move'].create(values)
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<form string="模型类型">
|
||||
<group>
|
||||
<field name="name" required="1"/>
|
||||
<field name="embryo_tolerance" required="1" string="胚料容余(mm)"/>
|
||||
<field name="embryo_tolerance" required="1" string="坯料容余(mm)"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name='product_routing_tmpl_ids'>
|
||||
|
||||
Reference in New Issue
Block a user