This commit is contained in:
胡尧
2024-11-11 10:22:53 +08:00
parent 2798ce6183
commit 0f37b45b30
26 changed files with 70 additions and 357 deletions

View File

@@ -28,18 +28,18 @@ class SaleOrder(models.Model):
# 根据供货方式修改成品模板
if line.supply_method == 'automation':
bom_type = 'normal'
product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo().product_tmpl_id
product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo()
elif line.supply_method == 'outsourcing':
bom_type = 'subcontract'
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_outsourcing').sudo()
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_product_outsourcing').sudo()
elif line.supply_method == 'purchase':
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_purchase').sudo()
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_product_purchase').sudo()
elif line.supply_method == 'manual':
bom_type = 'normal'
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo()
product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_product_manual_processing').sudo()
# 复制成品模板上的属性
line.product_id.product_tmpl_id.copy_template(product_template_id)
line.product_id.product_tmpl_id.copy_template(product_template_id.product_tmpl_id)
order_id = self
product = line.product_id
@@ -63,21 +63,16 @@ class SaleOrder(models.Model):
# 当成品上带有客供料选项时,生成坯料时选择“客供料”路线
if line.is_incoming_material:
# 将成品模板的内容复制到成品上
embryo_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_raw_material_customer_provided').sudo()
embryo_id = self.env['product.product'].search(
[('product_tmpl_id', '=', embryo_template_id.id), ('active', '=', False)],
limit=1,
order='id asc'
)
customer_provided_embryo = self.env.ref('jikimo_sale_multiple_supply_methods.product_product_raw_material_customer_provided').sudo()
# 创建坯料客供料的批量不需要创建bom
material_customer_provided_embryo = self.env['product.template'].sudo().no_bom_product_create(
embryo_id,
customer_provided_embryo,
item,
order_id, 'material_customer_provided', 0, product)
# 成品配置bom
product_bom_material_customer_provided = self.env['mrp.bom'].with_user(
self.env.ref("base.user_admin")).bom_create(
product, bom_type, True)
product, bom_type, 'product')
product_bom_material_customer_provided.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
material_customer_provided_embryo)
elif line.product_id.materials_type_id.gain_way == '自加工':
@@ -100,7 +95,7 @@ class SaleOrder(models.Model):
# 产品配置bom
product_bom_self_machining = self.env['mrp.bom'].with_user(
self.env.ref("base.user_admin")).bom_create(
product, bom_type, True)
product, bom_type, 'product')
product_bom_self_machining.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
self_machining_embryo)
elif line.product_id.materials_type_id.gain_way == '外协':
@@ -124,7 +119,7 @@ class SaleOrder(models.Model):
raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配')
# 产品配置bom
product_bom_outsource = self.env['mrp.bom'].with_user(
self.env.ref("base.user_admin")).bom_create(product, bom_type, True)
self.env.ref("base.user_admin")).bom_create(product, bom_type, 'product')
product_bom_outsource.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
outsource_embryo)
elif line.product_id.materials_type_id.gain_way == '采购':
@@ -132,14 +127,14 @@ class SaleOrder(models.Model):
purchase_embryo = self.env['product.template'].sudo().no_bom_product_create(purchase_id,
item,
order_id,
'purchase', i,
'purchase', 0,
product)
if purchase_embryo == -3:
raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配')
else:
# 产品配置bom
product_bom_purchase = self.env['mrp.bom'].with_user(
self.env.ref("base.user_admin")).bom_create(product, bom_type, True)
self.env.ref("base.user_admin")).bom_create(product, bom_type, 'product')
product_bom_purchase.with_user(self.env.ref("base.user_admin")).bom_create_line_has(
purchase_embryo)
return super(SaleOrder, self).action_confirm()