修改人工线下加工状态的继承位置
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
'data/stock_routes.xml',
|
'data/stock_routes.xml',
|
||||||
'data/product_data.xml',
|
'data/product_data.xml',
|
||||||
'views/sale_order_views.xml',
|
'views/sale_order_views.xml',
|
||||||
# 'views/product_product_views.xml',
|
'views/product_product_views.xml',
|
||||||
],'assets': {
|
],'assets': {
|
||||||
# 'web.assets_backend': [
|
# 'web.assets_backend': [
|
||||||
# 'jikimo_sale_multiple_supply_methods/static/src/**/*'
|
# 'jikimo_sale_multiple_supply_methods/static/src/**/*'
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ class SaleOrder(models.Model):
|
|||||||
'model_height': product.height,
|
'model_height': product.height,
|
||||||
'price': product.list_price,
|
'price': product.list_price,
|
||||||
}
|
}
|
||||||
|
# 获取成品名结尾-n的n
|
||||||
|
product_seria = int(product.name.split('-')[-1])
|
||||||
# 成品供货方式为采购则不生成bom
|
# 成品供货方式为采购则不生成bom
|
||||||
if line.supply_method != 'purchase':
|
if line.supply_method != 'purchase':
|
||||||
bom_data = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).get_bom(product)
|
bom_data = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).get_bom(product)
|
||||||
@@ -71,7 +73,7 @@ class SaleOrder(models.Model):
|
|||||||
material_customer_provided_embryo = self.env['product.template'].sudo().no_bom_product_create(
|
material_customer_provided_embryo = self.env['product.template'].sudo().no_bom_product_create(
|
||||||
customer_provided_embryo.with_context(active_test=False).product_variant_id,
|
customer_provided_embryo.with_context(active_test=False).product_variant_id,
|
||||||
item,
|
item,
|
||||||
order_id, 'material_customer_provided', 0, product)
|
order_id, 'material_customer_provided', product_seria, product)
|
||||||
# 成品配置bom
|
# 成品配置bom
|
||||||
product_bom_material_customer_provided = self.env['mrp.bom'].with_user(
|
product_bom_material_customer_provided = self.env['mrp.bom'].with_user(
|
||||||
self.env.ref("base.user_admin")).bom_create(
|
self.env.ref("base.user_admin")).bom_create(
|
||||||
@@ -84,7 +86,7 @@ class SaleOrder(models.Model):
|
|||||||
self_machining_embryo = self.env['product.template'].sudo().no_bom_product_create(
|
self_machining_embryo = self.env['product.template'].sudo().no_bom_product_create(
|
||||||
self_machining_id,
|
self_machining_id,
|
||||||
item,
|
item,
|
||||||
order_id, 'self_machining', 0, product)
|
order_id, 'self_machining', product_seria, product)
|
||||||
# 创建坯料的bom
|
# 创建坯料的bom
|
||||||
self_machining_bom = self.env['mrp.bom'].with_user(
|
self_machining_bom = self.env['mrp.bom'].with_user(
|
||||||
self.env.ref("base.user_admin")).bom_create(
|
self.env.ref("base.user_admin")).bom_create(
|
||||||
@@ -108,7 +110,7 @@ class SaleOrder(models.Model):
|
|||||||
item,
|
item,
|
||||||
order_id,
|
order_id,
|
||||||
'subcontract',
|
'subcontract',
|
||||||
0, product)
|
product_seria, product)
|
||||||
if outsource_embryo == -3:
|
if outsource_embryo == -3:
|
||||||
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
|
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
|
||||||
# 创建坯料的bom
|
# 创建坯料的bom
|
||||||
@@ -130,7 +132,7 @@ class SaleOrder(models.Model):
|
|||||||
purchase_embryo = self.env['product.template'].sudo().no_bom_product_create(purchase_id,
|
purchase_embryo = self.env['product.template'].sudo().no_bom_product_create(purchase_id,
|
||||||
item,
|
item,
|
||||||
order_id,
|
order_id,
|
||||||
'purchase', 0,
|
'purchase', product_seria,
|
||||||
product)
|
product)
|
||||||
if purchase_embryo == -3:
|
if purchase_embryo == -3:
|
||||||
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
|
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<!-- 由于该模块不能依赖sf_dlm_management, 该功能只能在sf_dlm_management中实现,并且依赖该模块-->
|
<record id="product_template_only_form_view" model="ir.ui.view">
|
||||||
<record id="view_product_product_form_inherit_sf" model="ir.ui.view">
|
|
||||||
<field name="name">view.product.template.form.inherit.sf</field>
|
<field name="name">view.product.template.form.inherit.sf</field>
|
||||||
<field name="model">product.template</field>
|
<field name="model">product.template</field>
|
||||||
<field name="inherit_id" ref="sf_dlm_management.view_sale_product_template_form_inherit_sf"/>
|
<field name="inherit_id" ref="product.product_template_only_form_view"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='manual_quotation']" position="after">
|
<xpath expr="//field[@name='uom_id']" position="before">
|
||||||
<field name="is_customer_provided" attrs="{'invisible': [('categ_type', 'not in', ['成品', '坯料'])], 'readonly': True}" />
|
<field name="categ_type" invisible="1"/>
|
||||||
|
<field name="is_manual_processing" attrs="{'invisible': [('categ_type', 'not in', ['成品', '坯料'])], 'readonly': True}" />
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
@@ -65,9 +65,6 @@
|
|||||||
attrs="{'invisible': [('categ_type', '!=', '夹具')],'required': [('categ_type', '=', '夹具')]}"
|
attrs="{'invisible': [('categ_type', '!=', '夹具')],'required': [('categ_type', '=', '夹具')]}"
|
||||||
domain="[('fixture_model_id','=',fixture_model_id)]"/>
|
domain="[('fixture_model_id','=',fixture_model_id)]"/>
|
||||||
</field>
|
</field>
|
||||||
<xpath expr="//field[@name='uom_id']" position="before">
|
|
||||||
<field name="is_manual_processing" attrs="{'invisible': [('categ_type', 'not in', ['成品', '坯料'])], 'readonly': True}" />
|
|
||||||
</xpath>
|
|
||||||
<xpath expr="//label[@for='volume']" position="before">
|
<xpath expr="//label[@for='volume']" position="before">
|
||||||
<label for="length" string="尺寸"
|
<label for="length" string="尺寸"
|
||||||
attrs="{'invisible':[('product_variant_count', '>', 1), ('is_product_variant', '=', False)]}"/>
|
attrs="{'invisible':[('product_variant_count', '>', 1), ('is_product_variant', '=', False)]}"/>
|
||||||
|
|||||||
@@ -66,75 +66,28 @@ class stockWarehouse(models.Model):
|
|||||||
class StockRule(models.Model):
|
class StockRule(models.Model):
|
||||||
_inherit = 'stock.rule'
|
_inherit = 'stock.rule'
|
||||||
|
|
||||||
# @api.model
|
@api.model
|
||||||
# def _run_pull(self, procurements):
|
def _run_pull(self, procurements):
|
||||||
# logging.info(procurements)
|
logging.info(procurements)
|
||||||
# moves_values_by_company = defaultdict(list)
|
moves_values_by_company = defaultdict(list)
|
||||||
# mtso_products_by_locations = defaultdict(list)
|
mtso_products_by_locations = defaultdict(list)
|
||||||
|
|
||||||
# # To handle the `mts_else_mto` procure method, we do a preliminary loop to
|
# To handle the `mts_else_mto` procure method, we do a preliminary loop to
|
||||||
# # isolate the products we would need to read the forecasted quantity,
|
# isolate the products we would need to read the forecasted quantity,
|
||||||
# # in order to to batch the read. We also make a sanitary check on the
|
# in order to to batch the read. We also make a sanitary check on the
|
||||||
# # `location_src_id` field.
|
# `location_src_id` field.
|
||||||
|
|
||||||
# # list1 = []
|
# list1 = []
|
||||||
# # for item in procurements:
|
|
||||||
# # num = int(item[0].product_qty)
|
|
||||||
# # if num > 1:
|
|
||||||
# # for no in range(1, num+1):
|
|
||||||
# #
|
|
||||||
# # Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
|
|
||||||
# # 'product_uom', 'location_id', 'name', 'origin',
|
|
||||||
# # 'company_id',
|
|
||||||
# # 'values'])
|
|
||||||
# # s = Procurement(product_id=item[0].product_id,product_qty=1.0,product_uom=item[0].product_uom,
|
|
||||||
# # location_id=item[0].location_id,
|
|
||||||
# # name=item[0].name,
|
|
||||||
# # origin=item[0].origin,
|
|
||||||
# # company_id=item[0].company_id,
|
|
||||||
# # values=item[0].values,
|
|
||||||
# # )
|
|
||||||
# # item1 = list(item)
|
|
||||||
# # item1[0]=s
|
|
||||||
# #
|
|
||||||
# # list1.append(tuple(item1))
|
|
||||||
# # else:
|
|
||||||
# # list1.append(item)
|
|
||||||
|
|
||||||
# for procurement, rule in procurements:
|
|
||||||
# if not rule.location_src_id:
|
|
||||||
# msg = _('No source location defined on stock rule: %s!') % (rule.name,)
|
|
||||||
# raise ProcurementException([(procurement, msg)])
|
|
||||||
|
|
||||||
# if rule.procure_method == 'mts_else_mto':
|
|
||||||
# mtso_products_by_locations[rule.location_src_id].append(procurement.product_id.id)
|
|
||||||
|
|
||||||
# # Get the forecasted quantity for the `mts_else_mto` procurement.
|
|
||||||
# forecasted_qties_by_loc = {}
|
|
||||||
# for location, product_ids in mtso_products_by_locations.items():
|
|
||||||
# products = self.env['product.product'].browse(product_ids).with_context(location=location.id)
|
|
||||||
# forecasted_qties_by_loc[location] = {product.id: product.free_qty for product in products}
|
|
||||||
|
|
||||||
# # Prepare the move values, adapt the `procure_method` if needed.
|
|
||||||
# procurements = sorted(procurements, key=lambda proc: float_compare(proc[0].product_qty, 0.0,
|
|
||||||
# precision_rounding=proc[
|
|
||||||
# 0].product_uom.rounding) > 0)
|
|
||||||
# list2 = []
|
|
||||||
# for item in procurements:
|
# for item in procurements:
|
||||||
# num = int(item[0].product_qty)
|
# num = int(item[0].product_qty)
|
||||||
|
|
||||||
# product = self.env['product.product'].search(
|
|
||||||
# [("id", '=', item[0].product_id.id)])
|
|
||||||
# product_tmpl = self.env['product.template'].search(
|
|
||||||
# ["&", ("id", '=', product.product_tmpl_id.id), ('single_manufacturing', "!=", False)])
|
|
||||||
# if product_tmpl:
|
|
||||||
# if num > 1:
|
# if num > 1:
|
||||||
# for no in range(1, num + 1):
|
# for no in range(1, num+1):
|
||||||
|
#
|
||||||
# Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
|
# Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
|
||||||
# 'product_uom', 'location_id', 'name', 'origin',
|
# 'product_uom', 'location_id', 'name', 'origin',
|
||||||
# 'company_id',
|
# 'company_id',
|
||||||
# 'values'])
|
# 'values'])
|
||||||
# s = Procurement(product_id=item[0].product_id, product_qty=1.0, product_uom=item[0].product_uom,
|
# s = Procurement(product_id=item[0].product_id,product_qty=1.0,product_uom=item[0].product_uom,
|
||||||
# location_id=item[0].location_id,
|
# location_id=item[0].location_id,
|
||||||
# name=item[0].name,
|
# name=item[0].name,
|
||||||
# origin=item[0].origin,
|
# origin=item[0].origin,
|
||||||
@@ -142,282 +95,329 @@ class StockRule(models.Model):
|
|||||||
# values=item[0].values,
|
# values=item[0].values,
|
||||||
# )
|
# )
|
||||||
# item1 = list(item)
|
# item1 = list(item)
|
||||||
# item1[0] = s
|
# item1[0]=s
|
||||||
|
#
|
||||||
# list2.append(tuple(item1))
|
# list1.append(tuple(item1))
|
||||||
# else:
|
# else:
|
||||||
# list2.append(item)
|
# list1.append(item)
|
||||||
# else:
|
|
||||||
# list2.append(item)
|
|
||||||
|
|
||||||
# for procurement, rule in list2:
|
for procurement, rule in procurements:
|
||||||
# procure_method = rule.procure_method
|
if not rule.location_src_id:
|
||||||
# if rule.procure_method == 'mts_else_mto':
|
msg = _('No source location defined on stock rule: %s!') % (rule.name,)
|
||||||
# qty_needed = procurement.product_uom._compute_quantity(procurement.product_qty,
|
raise ProcurementException([(procurement, msg)])
|
||||||
# procurement.product_id.uom_id)
|
|
||||||
# if float_compare(qty_needed, 0, precision_rounding=procurement.product_id.uom_id.rounding) <= 0:
|
|
||||||
# procure_method = 'make_to_order'
|
|
||||||
# for move in procurement.values.get('group_id', self.env['procurement.group']).stock_move_ids:
|
|
||||||
# if move.rule_id == rule and float_compare(move.product_uom_qty, 0,
|
|
||||||
# precision_rounding=move.product_uom.rounding) > 0:
|
|
||||||
# procure_method = move.procure_method
|
|
||||||
# break
|
|
||||||
# forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id] -= qty_needed
|
|
||||||
# elif float_compare(qty_needed, forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id],
|
|
||||||
# precision_rounding=procurement.product_id.uom_id.rounding) > 0:
|
|
||||||
# procure_method = 'make_to_order'
|
|
||||||
# else:
|
|
||||||
# forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id] -= qty_needed
|
|
||||||
# procure_method = 'make_to_stock'
|
|
||||||
# move_values = rule._get_stock_move_values(*procurement)
|
|
||||||
# move_values['procure_method'] = procure_method
|
|
||||||
# moves_values_by_company[procurement.company_id.id].append(move_values)
|
|
||||||
|
|
||||||
# for company_id, moves_values in moves_values_by_company.items():
|
if rule.procure_method == 'mts_else_mto':
|
||||||
# # create the move as SUPERUSER because the current user may not have the rights to do it (mto product
|
mtso_products_by_locations[rule.location_src_id].append(procurement.product_id.id)
|
||||||
# # launched by a sale for example)
|
|
||||||
# moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
|
# Get the forecasted quantity for the `mts_else_mto` procurement.
|
||||||
# moves_values)
|
forecasted_qties_by_loc = {}
|
||||||
# # Since action_confirm launch following procurement_group we should activate it.
|
for location, product_ids in mtso_products_by_locations.items():
|
||||||
# moves._action_confirm()
|
products = self.env['product.product'].browse(product_ids).with_context(location=location.id)
|
||||||
# return True
|
forecasted_qties_by_loc[location] = {product.id: product.free_qty for product in products}
|
||||||
|
|
||||||
|
# Prepare the move values, adapt the `procure_method` if needed.
|
||||||
|
procurements = sorted(procurements, key=lambda proc: float_compare(proc[0].product_qty, 0.0,
|
||||||
|
precision_rounding=proc[
|
||||||
|
0].product_uom.rounding) > 0)
|
||||||
|
list2 = []
|
||||||
|
for item in procurements:
|
||||||
|
num = int(item[0].product_qty)
|
||||||
|
|
||||||
|
product = self.env['product.product'].search(
|
||||||
|
[("id", '=', item[0].product_id.id)])
|
||||||
|
product_tmpl = self.env['product.template'].search(
|
||||||
|
["&", ("id", '=', product.product_tmpl_id.id), ('single_manufacturing', "!=", False)])
|
||||||
|
if product_tmpl:
|
||||||
|
if num > 1:
|
||||||
|
for no in range(1, num + 1):
|
||||||
|
Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
|
||||||
|
'product_uom', 'location_id', 'name', 'origin',
|
||||||
|
'company_id',
|
||||||
|
'values'])
|
||||||
|
s = Procurement(product_id=item[0].product_id, product_qty=1.0, product_uom=item[0].product_uom,
|
||||||
|
location_id=item[0].location_id,
|
||||||
|
name=item[0].name,
|
||||||
|
origin=item[0].origin,
|
||||||
|
company_id=item[0].company_id,
|
||||||
|
values=item[0].values,
|
||||||
|
)
|
||||||
|
item1 = list(item)
|
||||||
|
item1[0] = s
|
||||||
|
|
||||||
|
list2.append(tuple(item1))
|
||||||
|
else:
|
||||||
|
list2.append(item)
|
||||||
|
else:
|
||||||
|
list2.append(item)
|
||||||
|
|
||||||
|
for procurement, rule in list2:
|
||||||
|
procure_method = rule.procure_method
|
||||||
|
if rule.procure_method == 'mts_else_mto':
|
||||||
|
qty_needed = procurement.product_uom._compute_quantity(procurement.product_qty,
|
||||||
|
procurement.product_id.uom_id)
|
||||||
|
if float_compare(qty_needed, 0, precision_rounding=procurement.product_id.uom_id.rounding) <= 0:
|
||||||
|
procure_method = 'make_to_order'
|
||||||
|
for move in procurement.values.get('group_id', self.env['procurement.group']).stock_move_ids:
|
||||||
|
if move.rule_id == rule and float_compare(move.product_uom_qty, 0,
|
||||||
|
precision_rounding=move.product_uom.rounding) > 0:
|
||||||
|
procure_method = move.procure_method
|
||||||
|
break
|
||||||
|
forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id] -= qty_needed
|
||||||
|
elif float_compare(qty_needed, forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id],
|
||||||
|
precision_rounding=procurement.product_id.uom_id.rounding) > 0:
|
||||||
|
procure_method = 'make_to_order'
|
||||||
|
else:
|
||||||
|
forecasted_qties_by_loc[rule.location_src_id][procurement.product_id.id] -= qty_needed
|
||||||
|
procure_method = 'make_to_stock'
|
||||||
|
move_values = rule._get_stock_move_values(*procurement)
|
||||||
|
move_values['procure_method'] = procure_method
|
||||||
|
moves_values_by_company[procurement.company_id.id].append(move_values)
|
||||||
|
|
||||||
|
for company_id, moves_values in moves_values_by_company.items():
|
||||||
|
# create the move as SUPERUSER because the current user may not have the rights to do it (mto product
|
||||||
|
# launched by a sale for example)
|
||||||
|
moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
|
||||||
|
moves_values)
|
||||||
|
# Since action_confirm launch following procurement_group we should activate it.
|
||||||
|
moves._action_confirm()
|
||||||
|
return True
|
||||||
|
|
||||||
def attachment_update(self, name, res_id, res_field):
|
def attachment_update(self, name, res_id, res_field):
|
||||||
attachment_info = self.env['ir.attachment'].sudo().search(
|
attachment_info = self.env['ir.attachment'].sudo().search(
|
||||||
[('res_id', '=', res_id), ('res_field', '=', res_field)], limit=1)
|
[('res_id', '=', res_id), ('res_field', '=', res_field)], limit=1)
|
||||||
attachment_info.write({'name': name})
|
attachment_info.write({'name': name})
|
||||||
|
|
||||||
# @api.model
|
@api.model
|
||||||
# def _run_manufacture(self, procurements):
|
def _run_manufacture(self, procurements):
|
||||||
# productions_values_by_company = defaultdict(list)
|
productions_values_by_company = defaultdict(list)
|
||||||
# errors = []
|
errors = []
|
||||||
# for procurement, rule in procurements:
|
for procurement, rule in procurements:
|
||||||
# if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) <= 0:
|
if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) <= 0:
|
||||||
# # If procurement contains negative quantity, don't create a MO that would be for a negative value.
|
# If procurement contains negative quantity, don't create a MO that would be for a negative value.
|
||||||
# continue
|
continue
|
||||||
# bom = rule._get_matching_bom(procurement.product_id, procurement.company_id, procurement.values)
|
bom = rule._get_matching_bom(procurement.product_id, procurement.company_id, procurement.values)
|
||||||
|
|
||||||
# productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom))
|
productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom))
|
||||||
|
|
||||||
# if errors:
|
if errors:
|
||||||
# raise ProcurementException(errors)
|
raise ProcurementException(errors)
|
||||||
|
|
||||||
# for company_id, productions_values in productions_values_by_company.items():
|
for company_id, productions_values in productions_values_by_company.items():
|
||||||
# # create the MO as SUPERUSER because the current user may not have the rights to do it
|
# create the MO as SUPERUSER because the current user may not have the rights to do it
|
||||||
# # (mto product launched by a sale for example)
|
# (mto product launched by a sale for example)
|
||||||
# '''创建制造订单'''
|
'''创建制造订单'''
|
||||||
# productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
|
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
|
||||||
# productions_values)
|
productions_values)
|
||||||
|
|
||||||
# # self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
||||||
# # self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
|
||||||
|
|
||||||
# '''
|
|
||||||
# 创建工单
|
|
||||||
# '''
|
|
||||||
# # productions._create_workorder()
|
|
||||||
# #
|
|
||||||
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||||
# productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
|
|
||||||
# (
|
|
||||||
# p.move_dest_ids.procure_method != 'make_to_order' and not
|
|
||||||
# p.move_raw_ids and not p.workorder_ids)).action_confirm()
|
|
||||||
# # 处理 根据制造订单生成的采购单坯料入库时到原材料库,手动将原材料位置该为坯料存货区
|
|
||||||
# for production in productions:
|
|
||||||
# if production.picking_ids:
|
|
||||||
# product_type_id = production.picking_ids[0].move_ids[0].product_id.categ_id
|
|
||||||
# if product_type_id.name == '坯料':
|
|
||||||
# location_id = self.env['stock.location'].search([('name', '=', '坯料存货区')])
|
|
||||||
# if not location_id:
|
|
||||||
# logging.info(f'没有搜索到【坯料存货区】: {location_id}')
|
|
||||||
# break
|
|
||||||
# for picking_id in production.picking_ids:
|
|
||||||
# if picking_id.picking_type_id.name == '内部调拨':
|
|
||||||
# if picking_id.location_dest_id.product_type != product_type_id:
|
|
||||||
# picking_id.location_dest_id = location_id.id
|
|
||||||
# elif picking_id.picking_type_id.name == '生产发料':
|
|
||||||
# if picking_id.location_id.product_type != product_type_id:
|
|
||||||
# picking_id.location_id = location_id.id
|
|
||||||
|
|
||||||
# for production in productions:
|
'''
|
||||||
# '''
|
创建工单
|
||||||
# 创建制造订单时生成序列号
|
'''
|
||||||
# '''
|
# productions._create_workorder()
|
||||||
# production.action_generate_serial()
|
#
|
||||||
# origin_production = production.move_dest_ids and production.move_dest_ids[
|
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||||
# 0].raw_material_production_id or False
|
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
|
||||||
# orderpoint = production.orderpoint_id
|
(
|
||||||
# if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
|
p.move_dest_ids.procure_method != 'make_to_order' and not
|
||||||
# production.message_post(
|
p.move_raw_ids and not p.workorder_ids)).action_confirm()
|
||||||
# body=_('This production order has been created from Replenishment Report.'),
|
# 处理 根据制造订单生成的采购单坯料入库时到原材料库,手动将原材料位置该为坯料存货区
|
||||||
# message_type='comment',
|
for production in productions:
|
||||||
# subtype_xmlid='mail.mt_note')
|
if production.picking_ids:
|
||||||
# elif orderpoint:
|
product_type_id = production.picking_ids[0].move_ids[0].product_id.categ_id
|
||||||
# production.message_post_with_view(
|
if product_type_id.name == '坯料':
|
||||||
# 'mail.message_origin_link',
|
location_id = self.env['stock.location'].search([('name', '=', '坯料存货区')])
|
||||||
# values={'self': production, 'origin': orderpoint},
|
if not location_id:
|
||||||
# subtype_id=self.env.ref('mail.mt_note').id)
|
logging.info(f'没有搜索到【坯料存货区】: {location_id}')
|
||||||
# elif origin_production:
|
break
|
||||||
# production.message_post_with_view(
|
for picking_id in production.picking_ids:
|
||||||
# 'mail.message_origin_link',
|
if picking_id.picking_type_id.name == '内部调拨':
|
||||||
# values={'self': production, 'origin': origin_production},
|
if picking_id.location_dest_id.product_type != product_type_id:
|
||||||
# subtype_id=self.env.ref('mail.mt_note').id)
|
picking_id.location_dest_id = location_id.id
|
||||||
|
elif picking_id.picking_type_id.name == '生产发料':
|
||||||
|
if picking_id.location_id.product_type != product_type_id:
|
||||||
|
picking_id.location_id = location_id.id
|
||||||
|
|
||||||
# '''
|
for production in productions:
|
||||||
# 创建生产计划
|
'''
|
||||||
# '''
|
创建制造订单时生成序列号
|
||||||
# # 工单耗时
|
'''
|
||||||
# workorder_duration = 0
|
production.action_generate_serial()
|
||||||
# for workorder in production.workorder_ids:
|
origin_production = production.move_dest_ids and production.move_dest_ids[
|
||||||
# workorder_duration += workorder.duration_expected
|
0].raw_material_production_id or False
|
||||||
|
orderpoint = production.orderpoint_id
|
||||||
|
if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
|
||||||
|
production.message_post(
|
||||||
|
body=_('This production order has been created from Replenishment Report.'),
|
||||||
|
message_type='comment',
|
||||||
|
subtype_xmlid='mail.mt_note')
|
||||||
|
elif orderpoint:
|
||||||
|
production.message_post_with_view(
|
||||||
|
'mail.message_origin_link',
|
||||||
|
values={'self': production, 'origin': orderpoint},
|
||||||
|
subtype_id=self.env.ref('mail.mt_note').id)
|
||||||
|
elif origin_production:
|
||||||
|
production.message_post_with_view(
|
||||||
|
'mail.message_origin_link',
|
||||||
|
values={'self': production, 'origin': origin_production},
|
||||||
|
subtype_id=self.env.ref('mail.mt_note').id)
|
||||||
|
|
||||||
# sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
|
'''
|
||||||
# if sale_order:
|
创建生产计划
|
||||||
# # sale_order.write({'schedule_status': 'to schedule'})
|
'''
|
||||||
# self.env['sf.production.plan'].sudo().with_company(company_id).create({
|
# 工单耗时
|
||||||
# 'name': production.name,
|
workorder_duration = 0
|
||||||
# 'order_deadline': sale_order.deadline_of_delivery,
|
for workorder in production.workorder_ids:
|
||||||
# 'production_id': production.id,
|
workorder_duration += workorder.duration_expected
|
||||||
# 'date_planned_start': production.date_planned_start,
|
|
||||||
# 'origin': production.origin,
|
|
||||||
# 'product_qty': production.product_qty,
|
|
||||||
# 'product_id': production.product_id.id,
|
|
||||||
# 'state': 'draft',
|
|
||||||
# })
|
|
||||||
# technology_design_values = []
|
|
||||||
# all_production = productions
|
|
||||||
# grouped_product_ids = {k: list(g) for k, g in groupby(all_production, key=lambda x: x.product_id.id)}
|
|
||||||
# # 初始化一个字典来存储每个product_id对应的生产订单名称列表
|
|
||||||
# product_id_to_production_names = {}
|
|
||||||
# # 对于每个product_id,获取其所有生产订单的名称
|
|
||||||
# for product_id, all_production in grouped_product_ids.items():
|
|
||||||
# # 为同一个product_id创建一个生产订单名称列表
|
|
||||||
# product_id_to_production_names[product_id] = [production.name for production in all_production]
|
|
||||||
# for production_item in productions:
|
|
||||||
# # production_programming = self.env['mrp.production'].search(
|
|
||||||
# # [('product_id.id', '=', production_item.product_id.id),
|
|
||||||
# # ('origin', '=', production_item.origin)],
|
|
||||||
# # limit=1, order='id asc')
|
|
||||||
# if production_item.product_id.id in product_id_to_production_names:
|
|
||||||
# if production_item.product_id.model_process_parameters_ids:
|
|
||||||
# is_purchase = False
|
|
||||||
# sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids,
|
|
||||||
# key=lambda w: w.id)
|
|
||||||
|
|
||||||
# consecutive_process_parameters = []
|
sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
|
||||||
# m = 0
|
if sale_order:
|
||||||
# for i in range(len(sorted_process_parameters) - 1):
|
# sale_order.write({'schedule_status': 'to schedule'})
|
||||||
# if m == 0:
|
self.env['sf.production.plan'].sudo().with_company(company_id).create({
|
||||||
# is_purchase = False
|
'name': production.name,
|
||||||
# if self.env['product.template']._get_process_parameters_product(
|
'order_deadline': sale_order.deadline_of_delivery,
|
||||||
# sorted_process_parameters[i]).partner_id == self.env[
|
'production_id': production.id,
|
||||||
# 'product.template']._get_process_parameters_product(sorted_process_parameters[
|
'date_planned_start': production.date_planned_start,
|
||||||
# i + 1]).partner_id and \
|
'origin': production.origin,
|
||||||
# sorted_process_parameters[i].gain_way == '外协':
|
'product_qty': production.product_qty,
|
||||||
# if sorted_process_parameters[i] not in consecutive_process_parameters:
|
'product_id': production.product_id.id,
|
||||||
# consecutive_process_parameters.append(sorted_process_parameters[i])
|
'state': 'draft',
|
||||||
# consecutive_process_parameters.append(sorted_process_parameters[i + 1])
|
})
|
||||||
# m += 1
|
technology_design_values = []
|
||||||
# continue
|
all_production = productions
|
||||||
|
grouped_product_ids = {k: list(g) for k, g in groupby(all_production, key=lambda x: x.product_id.id)}
|
||||||
|
# 初始化一个字典来存储每个product_id对应的生产订单名称列表
|
||||||
|
product_id_to_production_names = {}
|
||||||
|
# 对于每个product_id,获取其所有生产订单的名称
|
||||||
|
for product_id, all_production in grouped_product_ids.items():
|
||||||
|
# 为同一个product_id创建一个生产订单名称列表
|
||||||
|
product_id_to_production_names[product_id] = [production.name for production in all_production]
|
||||||
|
for production_item in productions:
|
||||||
|
# production_programming = self.env['mrp.production'].search(
|
||||||
|
# [('product_id.id', '=', production_item.product_id.id),
|
||||||
|
# ('origin', '=', production_item.origin)],
|
||||||
|
# limit=1, order='id asc')
|
||||||
|
if production_item.product_id.id in product_id_to_production_names:
|
||||||
|
if production_item.product_id.model_process_parameters_ids:
|
||||||
|
is_purchase = False
|
||||||
|
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_process_parameters) - 1):
|
||||||
|
if m == 0:
|
||||||
|
is_purchase = False
|
||||||
|
if self.env['product.template']._get_process_parameters_product(
|
||||||
|
sorted_process_parameters[i]).partner_id == self.env[
|
||||||
|
'product.template']._get_process_parameters_product(sorted_process_parameters[
|
||||||
|
i + 1]).partner_id and \
|
||||||
|
sorted_process_parameters[i].gain_way == '外协':
|
||||||
|
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['purchase.order'].get_purchase_order(consecutive_process_parameters,
|
||||||
|
production_item,
|
||||||
|
product_id_to_production_names)
|
||||||
|
if sorted_process_parameters[i] in consecutive_process_parameters:
|
||||||
|
is_purchase = True
|
||||||
|
consecutive_process_parameters = []
|
||||||
|
m = 0
|
||||||
|
# 当前面的连续外协采购单生成再生成当前外协采购单
|
||||||
|
if is_purchase is False:
|
||||||
|
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
|
||||||
|
production_item,
|
||||||
|
product_id_to_production_names)
|
||||||
|
if m == len(consecutive_process_parameters) - 1 and m != 0:
|
||||||
|
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
|
||||||
|
production_item,
|
||||||
|
product_id_to_production_names)
|
||||||
|
if sorted_process_parameters[i] in consecutive_process_parameters:
|
||||||
|
is_purchase = True
|
||||||
|
consecutive_process_parameters = []
|
||||||
|
m = 0
|
||||||
|
if m == len(consecutive_process_parameters) - 1 and m != 0:
|
||||||
|
self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
|
||||||
|
production_item,
|
||||||
|
product_id_to_production_names)
|
||||||
|
if is_purchase is False and m == 0:
|
||||||
|
if len(sorted_process_parameters) == 1:
|
||||||
|
self.env['purchase.order'].get_purchase_order(sorted_process_parameters,
|
||||||
|
production_item,
|
||||||
|
product_id_to_production_names)
|
||||||
|
else:
|
||||||
|
self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i],
|
||||||
|
production_item,
|
||||||
|
product_id_to_production_names)
|
||||||
|
if not technology_design_values:
|
||||||
|
if production.product_id.categ_id.type == '成品':
|
||||||
|
production.product_id.model_processing_panel = 'ZM,FM'
|
||||||
|
# 根据加工面板的面数及成品工序模板生成工序设计
|
||||||
|
i = 0
|
||||||
|
for k in (production.product_id.model_processing_panel.split(',')):
|
||||||
|
product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search(
|
||||||
|
[('product_model_type_id', '=', production.product_id.product_model_type_id.id)],
|
||||||
|
order='sequence asc'
|
||||||
|
)
|
||||||
|
for route in product_routing_workcenter:
|
||||||
|
i += 1
|
||||||
|
technology_design_values.append(
|
||||||
|
self.env['sf.technology.design'].json_technology_design_str(k, route, i))
|
||||||
|
surface_technics_arr = []
|
||||||
|
route_workcenter_arr = []
|
||||||
|
for process_param in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids.filtered(
|
||||||
|
lambda st: st.id in production.product_id.model_process_parameters_ids.ids):
|
||||||
|
# if item.route_workcenter_id.surface_technics_id.id:
|
||||||
|
# for process_param in production.product_id.model_process_parameters_ids:
|
||||||
|
logging.info('process_param:%s%s' % (process_param.id, process_param.name))
|
||||||
|
if item.route_workcenter_id.surface_technics_id == process_param.process_id:
|
||||||
|
logging.info(
|
||||||
|
'surface_technics_id:%s%s' % (
|
||||||
|
item.route_workcenter_id.surface_technics_id.id,
|
||||||
|
item.route_workcenter_id.surface_technics_id.name))
|
||||||
|
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'].search(
|
||||||
|
[('id', 'in', surface_technics_arr)],
|
||||||
|
order='sequence asc'
|
||||||
|
)
|
||||||
|
for p in production_process:
|
||||||
|
logging.info('production_process:%s' % p.name)
|
||||||
|
process_parameter = production.product_id.model_process_parameters_ids.filtered(
|
||||||
|
lambda pm: pm.process_id.id == p.id)
|
||||||
|
product_production_process = self.env['product.template'].search(
|
||||||
|
[('server_product_process_parameters_id', '=',
|
||||||
|
process_parameter.id)])
|
||||||
|
if process_parameter:
|
||||||
|
i += 1
|
||||||
|
route_production_process = self.env[
|
||||||
|
'mrp.routing.workcenter'].search(
|
||||||
|
[('surface_technics_id', '=', p.id),
|
||||||
|
('id', 'in', route_workcenter_arr)])
|
||||||
|
technology_design_values.append(
|
||||||
|
self.env['sf.technology.design'].json_technology_design_str(k,
|
||||||
|
route_production_process,
|
||||||
|
product_production_process,
|
||||||
|
i))
|
||||||
|
productions.technology_design_ids = technology_design_values
|
||||||
|
|
||||||
|
# # 同一个产品多个制造订单对应一个编程单和模型库
|
||||||
|
# # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递
|
||||||
|
# if not production_item.programming_no:
|
||||||
|
# if not production_programming.programming_no:
|
||||||
|
# production_item.fetchCNC(
|
||||||
|
# ', '.join(product_id_to_production_names[production_item.product_id.id]))
|
||||||
# else:
|
# else:
|
||||||
# if m == len(consecutive_process_parameters) - 1 and m != 0:
|
# production_item.write({'programming_no': production_programming.programming_no,
|
||||||
# self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
|
# 'programming_state': '编程中'})
|
||||||
# production_item,
|
return True
|
||||||
# product_id_to_production_names)
|
|
||||||
# if sorted_process_parameters[i] in consecutive_process_parameters:
|
|
||||||
# is_purchase = True
|
|
||||||
# consecutive_process_parameters = []
|
|
||||||
# m = 0
|
|
||||||
# # 当前面的连续外协采购单生成再生成当前外协采购单
|
|
||||||
# if is_purchase is False:
|
|
||||||
# self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
|
|
||||||
# production_item,
|
|
||||||
# product_id_to_production_names)
|
|
||||||
# if m == len(consecutive_process_parameters) - 1 and m != 0:
|
|
||||||
# self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
|
|
||||||
# production_item,
|
|
||||||
# product_id_to_production_names)
|
|
||||||
# if sorted_process_parameters[i] in consecutive_process_parameters:
|
|
||||||
# is_purchase = True
|
|
||||||
# consecutive_process_parameters = []
|
|
||||||
# m = 0
|
|
||||||
# if m == len(consecutive_process_parameters) - 1 and m != 0:
|
|
||||||
# self.env['purchase.order'].get_purchase_order(consecutive_process_parameters,
|
|
||||||
# production_item,
|
|
||||||
# product_id_to_production_names)
|
|
||||||
# if is_purchase is False and m == 0:
|
|
||||||
# if len(sorted_process_parameters) == 1:
|
|
||||||
# self.env['purchase.order'].get_purchase_order(sorted_process_parameters,
|
|
||||||
# production_item,
|
|
||||||
# product_id_to_production_names)
|
|
||||||
# else:
|
|
||||||
# self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i],
|
|
||||||
# production_item,
|
|
||||||
# product_id_to_production_names)
|
|
||||||
# if not technology_design_values:
|
|
||||||
# if production.product_id.categ_id.type == '成品':
|
|
||||||
# production.product_id.model_processing_panel = 'ZM,FM'
|
|
||||||
# # 根据加工面板的面数及成品工序模板生成工序设计
|
|
||||||
# i = 0
|
|
||||||
# for k in (production.product_id.model_processing_panel.split(',')):
|
|
||||||
# product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search(
|
|
||||||
# [('product_model_type_id', '=', production.product_id.product_model_type_id.id)],
|
|
||||||
# order='sequence asc'
|
|
||||||
# )
|
|
||||||
# for route in product_routing_workcenter:
|
|
||||||
# i += 1
|
|
||||||
# technology_design_values.append(
|
|
||||||
# self.env['sf.technology.design'].json_technology_design_str(k, route, i))
|
|
||||||
# surface_technics_arr = []
|
|
||||||
# route_workcenter_arr = []
|
|
||||||
# for process_param in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids.filtered(
|
|
||||||
# lambda st: st.id in production.product_id.model_process_parameters_ids.ids):
|
|
||||||
# # if item.route_workcenter_id.surface_technics_id.id:
|
|
||||||
# # for process_param in production.product_id.model_process_parameters_ids:
|
|
||||||
# logging.info('process_param:%s%s' % (process_param.id, process_param.name))
|
|
||||||
# if item.route_workcenter_id.surface_technics_id == process_param.process_id:
|
|
||||||
# logging.info(
|
|
||||||
# 'surface_technics_id:%s%s' % (
|
|
||||||
# item.route_workcenter_id.surface_technics_id.id,
|
|
||||||
# item.route_workcenter_id.surface_technics_id.name))
|
|
||||||
# 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'].search(
|
|
||||||
# [('id', 'in', surface_technics_arr)],
|
|
||||||
# order='sequence asc'
|
|
||||||
# )
|
|
||||||
# for p in production_process:
|
|
||||||
# logging.info('production_process:%s' % p.name)
|
|
||||||
# process_parameter = production.product_id.model_process_parameters_ids.filtered(
|
|
||||||
# lambda pm: pm.process_id.id == p.id)
|
|
||||||
# product_production_process = self.env['product.template'].search(
|
|
||||||
# [('server_product_process_parameters_id', '=',
|
|
||||||
# process_parameter.id)])
|
|
||||||
# if process_parameter:
|
|
||||||
# i += 1
|
|
||||||
# route_production_process = self.env[
|
|
||||||
# 'mrp.routing.workcenter'].search(
|
|
||||||
# [('surface_technics_id', '=', p.id),
|
|
||||||
# ('id', 'in', route_workcenter_arr)])
|
|
||||||
# technology_design_values.append(
|
|
||||||
# self.env['sf.technology.design'].json_technology_design_str(k,
|
|
||||||
# route_production_process,
|
|
||||||
# product_production_process,
|
|
||||||
# i))
|
|
||||||
# productions.technology_design_ids = technology_design_values
|
|
||||||
|
|
||||||
# # # 同一个产品多个制造订单对应一个编程单和模型库
|
|
||||||
# # # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递
|
|
||||||
# # if not production_item.programming_no:
|
|
||||||
# # if not production_programming.programming_no:
|
|
||||||
# # production_item.fetchCNC(
|
|
||||||
# # ', '.join(product_id_to_production_names[production_item.product_id.id]))
|
|
||||||
# # else:
|
|
||||||
# # production_item.write({'programming_no': production_programming.programming_no,
|
|
||||||
# # 'programming_state': '编程中'})
|
|
||||||
# return True
|
|
||||||
|
|
||||||
|
|
||||||
class ProductionLot(models.Model):
|
class ProductionLot(models.Model):
|
||||||
|
|||||||
Reference in New Issue
Block a user