优化采购:一个制造订单对应一个采购单
This commit is contained in:
@@ -842,7 +842,7 @@ class MrpProduction(models.Model):
|
|||||||
# workorder.picking_ids.move_ids = False
|
# workorder.picking_ids.move_ids = False
|
||||||
workorder.picking_ids = False
|
workorder.picking_ids = False
|
||||||
purchase_order = self.env['purchase.order'].search(
|
purchase_order = self.env['purchase.order'].search(
|
||||||
[('state', '=', 'draft'), ('origin', '=', ','.join(production_process)),
|
[('state', '=', 'draft'), ('origin', '=', item.name),
|
||||||
('purchase_type', '=', 'consignment')])
|
('purchase_type', '=', 'consignment')])
|
||||||
for line in purchase_order.order_line:
|
for line in purchase_order.order_line:
|
||||||
server_template = self.env['product.template'].search(
|
server_template = self.env['product.template'].search(
|
||||||
@@ -850,7 +850,7 @@ class MrpProduction(models.Model):
|
|||||||
('detailed_type', '=', 'service')])
|
('detailed_type', '=', 'service')])
|
||||||
purchase_order_line = self.env['purchase.order.line'].search(
|
purchase_order_line = self.env['purchase.order.line'].search(
|
||||||
[('product_id', '=', server_template.product_variant_id.id), ('id', '=', line.id),
|
[('product_id', '=', server_template.product_variant_id.id), ('id', '=', line.id),
|
||||||
('product_qty', '=', len(production_process))], limit=1, order='id desc')
|
('product_qty', '=', 1)], limit=1, order='id desc')
|
||||||
if purchase_order_line:
|
if purchase_order_line:
|
||||||
line.unlink()
|
line.unlink()
|
||||||
|
|
||||||
|
|||||||
@@ -241,9 +241,9 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
('production_id', '=', workorder.production_id.id)])
|
('production_id', '=', workorder.production_id.id)])
|
||||||
if previous_workorder:
|
if previous_workorder:
|
||||||
if previous_workorder.supplier_id != workorder.supplier_id:
|
if previous_workorder.supplier_id != workorder.supplier_id:
|
||||||
process_product = self.env['product.template']._get_process_parameters_product(
|
# process_product = self.env['product.template']._get_process_parameters_product(
|
||||||
previous_workorder.surface_technics_parameters_id)
|
# previous_workorder.surface_technics_parameters_id)
|
||||||
domain += [('partner_id', '=', process_product.partner_id.id)]
|
domain += [('surface_technics_parameters_id', '=', workorder.surface_technics_parameters_id.id)]
|
||||||
else:
|
else:
|
||||||
domain += [('surface_technics_parameters_id', '=', workorder.surface_technics_parameters_id.id)]
|
domain += [('surface_technics_parameters_id', '=', workorder.surface_technics_parameters_id.id)]
|
||||||
picking_ids = self.env['stock.picking'].search(domain, order='id asc')
|
picking_ids = self.env['stock.picking'].search(domain, order='id asc')
|
||||||
@@ -270,55 +270,57 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
def _compute_surface_technics_purchase_ids(self):
|
def _compute_surface_technics_purchase_ids(self):
|
||||||
for order in self:
|
for order in self:
|
||||||
if order.routing_type == '表面工艺':
|
if order.routing_type == '表面工艺':
|
||||||
if order.production_id.production_type == '自动化产线加工':
|
# if order.production_id.production_type == '自动化产线加工':
|
||||||
domain = [('programming_no', '=', order.production_id.programming_no)]
|
# domain = [('programming_no', '=', order.production_id.programming_no)]
|
||||||
else:
|
# else:
|
||||||
domain = [('origin', '=', order.production_id.origin)]
|
# domain = [('origin', '=', order.production_id.origin)]
|
||||||
production_programming = self.env['mrp.production'].search(domain, order='name asc')
|
# production_programming = self.env['mrp.production'].search(domain, order='name asc')
|
||||||
production_list = [production.name for production in production_programming]
|
# production_list = [production.name for production in production_programming]
|
||||||
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
|
# production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
|
||||||
# technology_design = self.env['sf.technology.design'].search(
|
# technology_design = self.env['sf.technology.design'].search(
|
||||||
# [('process_parameters_id', '=', order.surface_technics_parameters_id.id),
|
# [('process_parameters_id', '=', order.surface_technics_parameters_id.id),
|
||||||
# ('production_id', '=', order.production_id.id)])
|
# ('production_id', '=', order.production_id.id)])
|
||||||
# if technology_design.is_auto is False:
|
# if technology_design.is_auto is False:
|
||||||
# domain = [('origin', '=', order.production_id.name)]
|
# domain = [('origin', '=', order.production_id.name)]
|
||||||
# else:
|
# else:
|
||||||
domain = [('purchase_type', '=', 'consignment'), ('origin', '=', ','.join(production_list))]
|
domain = [('purchase_type', '=', 'consignment'), ('origin', '=', order.production_id.name)]
|
||||||
purchase = self.env['purchase.order'].search(domain)
|
purchase = self.env['purchase.order'].search(domain)
|
||||||
purchase_num = 0
|
purchase_num = 0
|
||||||
if not purchase:
|
if not purchase:
|
||||||
order.surface_technics_purchase_count = 0
|
order.surface_technics_purchase_count = 0
|
||||||
for line in purchase.order_line:
|
for po in purchase:
|
||||||
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id:
|
for line in po.order_line:
|
||||||
if line.product_qty == len(production_no_remanufacture):
|
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id:
|
||||||
purchase_num += 1
|
if line.product_qty == 1:
|
||||||
order.surface_technics_purchase_count = purchase_num
|
purchase_num += 1
|
||||||
|
order.surface_technics_purchase_count = purchase_num
|
||||||
else:
|
else:
|
||||||
order.surface_technics_purchase_count = 0
|
order.surface_technics_purchase_count = 0
|
||||||
|
|
||||||
def action_view_surface_technics_purchase(self):
|
def action_view_surface_technics_purchase(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if self.routing_type == '表面工艺':
|
# if self.routing_type == '表面工艺':
|
||||||
if self.production_id.production_type == '自动化产线加工':
|
# if self.production_id.production_type == '自动化产线加工':
|
||||||
domain = [('programming_no', '=', self.production_id.programming_no)]
|
# domain = [('programming_no', '=', self.production_id.programming_no)]
|
||||||
else:
|
# else:
|
||||||
domain = [('origin', '=', self.production_id.origin)]
|
# domain = [('origin', '=', self.production_id.origin)]
|
||||||
production_programming = self.env['mrp.production'].search(domain, order='name asc')
|
# production_programming = self.env['mrp.production'].search(domain, order='name asc')
|
||||||
production_list = [production.name for production in production_programming]
|
# production_list = [production.name for production in production_programming]
|
||||||
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
|
# production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
|
||||||
# technology_design = self.env['sf.technology.design'].search(
|
# technology_design = self.env['sf.technology.design'].search(
|
||||||
# [('process_parameters_id', '=', self.surface_technics_parameters_id.id),
|
# [('process_parameters_id', '=', self.surface_technics_parameters_id.id),
|
||||||
# ('production_id', '=', self.production_id.id)])
|
# ('production_id', '=', self.production_id.id)])
|
||||||
# if technology_design.is_auto is False:
|
# if technology_design.is_auto is False:
|
||||||
# domain = [('origin', '=', self.production_id.name)]
|
# domain = [('origin', '=', self.production_id.name)]
|
||||||
# else:
|
# else:
|
||||||
domain = [('origin', '=', ','.join(production_list)), ('purchase_type', '=', 'consignment')]
|
domain = [('origin', '=', self.production_id.name), ('purchase_type', '=', 'consignment')]
|
||||||
purchase_orders = self.env['purchase.order'].search(domain)
|
purchase_orders = self.env['purchase.order'].search(domain)
|
||||||
purchase_orders_id = None
|
purchase_orders_id = None
|
||||||
for line in purchase_orders.order_line:
|
for po in purchase_orders:
|
||||||
if line.product_id.server_product_process_parameters_id == self.surface_technics_parameters_id:
|
for line in po.order_line:
|
||||||
if line.product_qty == len(production_no_remanufacture):
|
if line.product_id.server_product_process_parameters_id == self.surface_technics_parameters_id:
|
||||||
purchase_orders_id = line.order_id.id
|
if line.product_qty == 1:
|
||||||
|
purchase_orders_id = line.order_id.id
|
||||||
result = {
|
result = {
|
||||||
"type": "ir.actions.act_window",
|
"type": "ir.actions.act_window",
|
||||||
"res_model": "purchase.order",
|
"res_model": "purchase.order",
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ from odoo.exceptions import ValidationError, UserError
|
|||||||
from odoo.modules import get_resource_path
|
from odoo.modules import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
# from OCC.Extend.DataExchange import read_step_file
|
from OCC.Extend.DataExchange import read_step_file
|
||||||
# from OCC.Extend.DataExchange import write_stl_file
|
from OCC.Extend.DataExchange import write_stl_file
|
||||||
|
|
||||||
|
|
||||||
class ResProductMo(models.Model):
|
class ResProductMo(models.Model):
|
||||||
|
|||||||
@@ -283,7 +283,8 @@ class StockRule(models.Model):
|
|||||||
sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
|
sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)])
|
||||||
# 如果订单为空,则获取来源制造订单的销售单
|
# 如果订单为空,则获取来源制造订单的销售单
|
||||||
if not sale_order:
|
if not sale_order:
|
||||||
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)], limit=1)
|
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', production.origin)],
|
||||||
|
limit=1)
|
||||||
if mrp_production:
|
if mrp_production:
|
||||||
sale_order = self.env['sale.order'].sudo().search([('name', '=', mrp_production.origin)])
|
sale_order = self.env['sale.order'].sudo().search([('name', '=', mrp_production.origin)])
|
||||||
else:
|
else:
|
||||||
@@ -670,10 +671,14 @@ class StockPicking(models.Model):
|
|||||||
|
|
||||||
# 创建 外协出库入单
|
# 创建 外协出库入单
|
||||||
def create_outcontract_picking(self, sorted_workorders_arr, item):
|
def create_outcontract_picking(self, sorted_workorders_arr, item):
|
||||||
|
domain = [('origin', '=', item.name), ('name', 'ilike', 'OCOUT')]
|
||||||
if len(sorted_workorders_arr) > 1:
|
if len(sorted_workorders_arr) > 1:
|
||||||
sorted_workorders_arr = sorted_workorders_arr[0]
|
sorted_workorders_arr = sorted_workorders_arr[0]
|
||||||
stock_picking = self.env['stock.picking'].search([('origin', '=', item.name), ('name', 'ilike', 'OCOUT')])
|
else:
|
||||||
if not stock_picking or sorted_workorders_arr:
|
domain += [
|
||||||
|
('surface_technics_parameters_id', '=', sorted_workorders_arr[0].surface_technics_parameters_id.id)]
|
||||||
|
stock_picking = self.env['stock.picking'].search(domain)
|
||||||
|
if not stock_picking:
|
||||||
for sorted_workorders in sorted_workorders_arr:
|
for sorted_workorders in sorted_workorders_arr:
|
||||||
# pick_ids = []
|
# pick_ids = []
|
||||||
if not sorted_workorders.picking_ids:
|
if not sorted_workorders.picking_ids:
|
||||||
|
|||||||
@@ -99,7 +99,8 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
|
|||||||
if workorder.sequence == 1:
|
if workorder.sequence == 1:
|
||||||
workorder.blocked_by_workorder_ids = None
|
workorder.blocked_by_workorder_ids = None
|
||||||
else:
|
else:
|
||||||
workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0]
|
if workorder.blocked_by_workorder_ids:
|
||||||
|
workorder.blocked_by_workorder_ids = blocked_by_workorder_ids[0]
|
||||||
productions._reset_work_order_sequence()
|
productions._reset_work_order_sequence()
|
||||||
if self.production_id.product_id.categ_id.type == '成品':
|
if self.production_id.product_id.categ_id.type == '成品':
|
||||||
productions._reset_subcontract_pick_purchase()
|
productions._reset_subcontract_pick_purchase()
|
||||||
@@ -109,5 +110,6 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
|
|||||||
workorders = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted(
|
workorders = item.workorder_ids.filtered(lambda wo: wo.state not in ('cancel')).sorted(
|
||||||
key=lambda a: a.sequence)
|
key=lambda a: a.sequence)
|
||||||
if workorders[0].state in ['pending']:
|
if workorders[0].state in ['pending']:
|
||||||
if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程':
|
if workorders[
|
||||||
|
0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程':
|
||||||
workorders[0].state = 'waiting'
|
workorders[0].state = 'waiting'
|
||||||
|
|||||||
@@ -65,4 +65,4 @@ class ProductionTechnologyWizard(models.TransientModel):
|
|||||||
key=lambda a: a.sequence)
|
key=lambda a: a.sequence)
|
||||||
if workorder[0].state in ['pending']:
|
if workorder[0].state in ['pending']:
|
||||||
if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程':
|
if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程':
|
||||||
workorders[0].state = 'waiting'
|
workorder[0].state = 'waiting'
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ from datetime import datetime
|
|||||||
import requests
|
import requests
|
||||||
from odoo import http
|
from odoo import http
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
# from OCC.Extend.DataExchange import read_step_file
|
from OCC.Extend.DataExchange import read_step_file
|
||||||
# from OCC.Extend.DataExchange import write_stl_file
|
from OCC.Extend.DataExchange import write_stl_file
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
from odoo.modules import get_resource_path
|
from odoo.modules import get_resource_path
|
||||||
from odoo.exceptions import ValidationError, UserError
|
from odoo.exceptions import ValidationError, UserError
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import requests
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
# from OCC.Core.GProp import GProp_GProps
|
# from OCC.Core.GProp import GProp_GProps
|
||||||
# from OCC.Extend.DataExchange import read_step_file
|
from OCC.Extend.DataExchange import read_step_file
|
||||||
# from OCC.Extend.DataExchange import write_stl_file
|
from OCC.Extend.DataExchange import write_stl_file
|
||||||
from odoo.addons.sf_base.commons.common import Common
|
from odoo.addons.sf_base.commons.common import Common
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
from odoo.modules import get_resource_path
|
from odoo.modules import get_resource_path
|
||||||
|
|||||||
@@ -250,35 +250,36 @@ class RePurchaseOrder(models.Model):
|
|||||||
server_product_process = []
|
server_product_process = []
|
||||||
production_process = product_id_to_production_names.get(
|
production_process = product_id_to_production_names.get(
|
||||||
production.product_id.id)
|
production.product_id.id)
|
||||||
|
purchase_order = self.env['purchase.order'].search(
|
||||||
|
[('state', '=', 'draft'), ('origin', '=', production.name),
|
||||||
|
('purchase_type', '=', 'consignment')], order='name asc')
|
||||||
for pp in consecutive_process_parameters:
|
for pp in consecutive_process_parameters:
|
||||||
server_template = self.env['product.template'].search(
|
server_template = self.env['product.template'].search(
|
||||||
[('server_product_process_parameters_id', '=', pp.surface_technics_parameters_id.id),
|
[('server_product_process_parameters_id', '=', pp.surface_technics_parameters_id.id),
|
||||||
('detailed_type', '=', 'service')])
|
('detailed_type', '=', 'service')])
|
||||||
purchase_order_line = self.env['purchase.order.line'].search(
|
if not purchase_order:
|
||||||
[('product_id', '=', server_template.product_variant_id.id),
|
|
||||||
('product_qty', '=', len(production_process))], limit=1, order='id desc')
|
|
||||||
if not purchase_order_line:
|
|
||||||
server_product_process.append((0, 0, {
|
server_product_process.append((0, 0, {
|
||||||
'product_id': server_template.product_variant_id.id,
|
'product_id': server_template.product_variant_id.id,
|
||||||
'product_qty': len(production_process),
|
'product_qty': 1,
|
||||||
'product_uom': server_template.uom_id.id
|
'product_uom': server_template.uom_id.id
|
||||||
}))
|
}))
|
||||||
else:
|
for purchase in purchase_order:
|
||||||
if production.name in production_process:
|
for po in purchase.order_line:
|
||||||
purchase_order = self.env['purchase.order'].search(
|
if server_template.server_product_process_parameters_id == pp.surface_technics_parameters_id:
|
||||||
[('state', '=', 'draft'), ('origin', '=', ','.join(production_process)),
|
purchase_order_line = self.env['purchase.order.line'].search(
|
||||||
('purchase_type', '=', 'consignment')])
|
[('product_id', '=', server_template.product_variant_id.id),
|
||||||
if not purchase_order:
|
('product_qty', '=', 1.0), ('id', '=', po.id)], limit=1,
|
||||||
server_product_process.append((0, 0, {
|
order='id desc')
|
||||||
'product_id': server_template.product_variant_id.id,
|
if not purchase_order_line and purchase not in purchase_order:
|
||||||
'product_qty': len(production_process),
|
server_product_process.append((0, 0, {
|
||||||
'product_uom': server_template.uom_id.id
|
'product_id': server_template.product_variant_id.id,
|
||||||
}))
|
'product_qty': 1,
|
||||||
|
'product_uom': server_template.uom_id.id
|
||||||
|
}))
|
||||||
if server_product_process:
|
if server_product_process:
|
||||||
self.env['purchase.order'].sudo().create({
|
self.env['purchase.order'].sudo().create({
|
||||||
'partner_id': server_template.seller_ids[0].partner_id.id,
|
'partner_id': server_template.seller_ids[0].partner_id.id,
|
||||||
'origin': ','.join(production_process),
|
'origin': production.name,
|
||||||
'state': 'draft',
|
'state': 'draft',
|
||||||
'purchase_type': 'consignment',
|
'purchase_type': 'consignment',
|
||||||
'order_line': server_product_process})
|
'order_line': server_product_process})
|
||||||
|
|||||||
Reference in New Issue
Block a user