优化表面工艺
This commit is contained in:
@@ -25,7 +25,7 @@ class StatusChange(models.Model):
|
||||
if not server_product:
|
||||
server_product_none.append(item.name)
|
||||
if server_product_none:
|
||||
raise UserError(_("请先至产品中创建表面工艺参数为%s的服务产品", ", ".join(server_product_none)))
|
||||
raise UserError(_("请先至【产品】中创建【表面工艺参数】为%s的服务产品", ", ".join(server_product_none)))
|
||||
|
||||
# 使用super()来调用原始方法(在本例中为'sale.order'模型的'action_confirm'方法)
|
||||
res = super(StatusChange, self).action_confirm()
|
||||
|
||||
@@ -131,7 +131,9 @@ class ResMrpWorkOrder(models.Model):
|
||||
is_subcontract = fields.Boolean(string='是否外协')
|
||||
surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数")
|
||||
picking_ids = fields.Many2many('stock.picking', string='外协出入库单')
|
||||
# purchase_id = fields.Many2one('purchase.order', string='外协采购单')
|
||||
surface_technics_picking_count = fields.Integer("外协出入库", compute='_compute_surface_technics_picking_ids')
|
||||
surface_technics_purchase_count = fields.Integer("外协采购", compute='_compute_surface_technics_purchase_ids')
|
||||
|
||||
@api.depends('name', 'production_id.name')
|
||||
def _compute_surface_technics_picking_ids(self):
|
||||
@@ -153,6 +155,43 @@ class ResMrpWorkOrder(models.Model):
|
||||
action['context'] = dict(self._context, default_origin=self.name)
|
||||
return action
|
||||
|
||||
@api.depends('state', 'production_id.name')
|
||||
def _compute_surface_technics_purchase_ids(self):
|
||||
for order in self:
|
||||
if order.routing_type == '表面工艺':
|
||||
production_programming = self.env['mrp.production'].search(
|
||||
[('programming_no', '=', order.production_id.programming_no)], order='name asc')
|
||||
production_list = [production.name for production in production_programming]
|
||||
purchase = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))])
|
||||
for line in purchase.order_line:
|
||||
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id and line.product_qty == len(
|
||||
production_programming):
|
||||
# server_product = self.env['product.template'].search(
|
||||
# [('server_product_process_parameters_id', '=', pp.id),
|
||||
# ('detailed_type', '=', 'service')])
|
||||
# purchase_order_line = self.env['purchase.order.line'].search(
|
||||
# [('product_id', '=', server_product.id), ('product_qty', '=', len(production_programming))])
|
||||
# if purchase_order_line:
|
||||
order.surface_technics_purchase_count = len(purchase)
|
||||
else:
|
||||
order.surface_technics_purchase_count = 0
|
||||
|
||||
def action_view_surface_technics_purchase(self):
|
||||
self.ensure_one()
|
||||
production_programming = self.env['mrp.production'].search(
|
||||
[('programming_no', '=', self.production_id.programming_no)], order='name asc')
|
||||
production_list = [production.name for production in production_programming]
|
||||
purchase_orders = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))])
|
||||
result = {
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "purchase.order",
|
||||
"res_id": purchase_orders.id,
|
||||
# "domain": [['id', 'in', self.purchase_id]],
|
||||
"name": _("Purchase Orders"),
|
||||
'view_mode': 'form',
|
||||
}
|
||||
return result
|
||||
|
||||
supplier_id = fields.Many2one('res.partner', string='外协供应商')
|
||||
equipment_id = fields.Many2one('maintenance.equipment', string='加工设备', tracking=True)
|
||||
# 保存名称
|
||||
@@ -887,8 +926,19 @@ class ResMrpWorkOrder(models.Model):
|
||||
if unclamp_workorder:
|
||||
if workorder.is_subcontract is False:
|
||||
workorder.state = 'ready'
|
||||
# else:
|
||||
|
||||
else:
|
||||
production_programming = self.env['mrp.production'].search(
|
||||
[('programming_no', '=', self.production_id.programming_no)], order='name asc')
|
||||
production_list = [production.name for production in production_programming]
|
||||
purchase_orders = self.env['purchase.order'].search(
|
||||
[('origin', '=', ','.join(production_list))])
|
||||
for line in purchase_orders.order_line:
|
||||
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id and line.product_qty == len(
|
||||
production_programming):
|
||||
if purchase_orders.state == 'purchase':
|
||||
workorder.state = 'ready'
|
||||
else:
|
||||
workorder.state = 'waiting'
|
||||
|
||||
# else:
|
||||
# if workorder.state not in ['cancel', 'rework']:
|
||||
@@ -941,7 +991,6 @@ class ResMrpWorkOrder(models.Model):
|
||||
workorder.state = 'waiting'
|
||||
continue
|
||||
|
||||
|
||||
# elif workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'cancel', 'progress',
|
||||
# 'rework']:
|
||||
# per_work = self.env['mrp.workorder'].search(
|
||||
|
||||
@@ -124,6 +124,10 @@ class ResProductMo(models.Model):
|
||||
name = '%s%s' % (item.cutting_tool_model_id.name, item.specification_id.name)
|
||||
item.name = name
|
||||
|
||||
def _get_process_parameters_product(self, production_process):
|
||||
return self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', production_process.id)]).seller_ids[0]
|
||||
|
||||
@api.onchange('cutting_tool_model_id')
|
||||
def _onchange_cutting_tool_model_id(self):
|
||||
for item in self:
|
||||
|
||||
@@ -274,13 +274,17 @@ class StockRule(models.Model):
|
||||
if production_item.product_id.id in product_id_to_production_names:
|
||||
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 sorted_process_parameters[i].supplier_id.id == sorted_process_parameters[
|
||||
i + 1].supplier_id.id and sorted_process_parameters[i].gain_way == '外协':
|
||||
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])
|
||||
@@ -289,15 +293,15 @@ class StockRule(models.Model):
|
||||
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_workorders:
|
||||
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[i],
|
||||
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,
|
||||
@@ -316,36 +320,6 @@ class StockRule(models.Model):
|
||||
else:
|
||||
self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i], production_item,
|
||||
product_id_to_production_names)
|
||||
# for pp in production_item.product_id.model_process_parameters_ids:
|
||||
# if pp.gain_way == '外协':
|
||||
# server_product = self.env['product.template'].search(
|
||||
# [('server_product_process_parameters_id', '=', pp.id),
|
||||
# ('detailed_type', '=', 'service')])
|
||||
# purchase_order_line = self.env['purchase.order.line'].search(
|
||||
# [('product_id', '=', server_product.id)])
|
||||
# if not purchase_order_line:
|
||||
# is_exist = False
|
||||
# else:
|
||||
# for item in purchase_order_line:
|
||||
# purchase_order = self.env['purchase.order'].search(
|
||||
# [('state', '=', 'draft'), ('origin', 'ilike', production_item.name),
|
||||
# ('id', '=', item.order_id)])
|
||||
# if not purchase_order:
|
||||
# is_exist = False
|
||||
# if is_exist is False:
|
||||
# production_process = product_id_to_production_names.get(
|
||||
# production_item.product_id.id)
|
||||
# self.env['purchase.order'].sudo().create({
|
||||
# 'partner_id': server_product.seller_ids.partner_id.id,
|
||||
# 'origin': ','.join(production_process),
|
||||
# 'state': 'draft',
|
||||
# 'order_line': [(0, 0, {
|
||||
# 'product_id': server_product.product_variant_id.id,
|
||||
# 'product_qty': len(production_process),
|
||||
# 'product_uom': server_product.uom_id.id
|
||||
# })]
|
||||
# })
|
||||
|
||||
# # 同一个产品多个制造订单对应一个编程单和模型库
|
||||
# # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递
|
||||
if not production_item.programming_no:
|
||||
|
||||
@@ -123,6 +123,18 @@
|
||||
attrs="{'invisible': [('surface_technics_picking_count', '=', 0)]}">
|
||||
<field name="surface_technics_picking_count" widget="statinfo" string="工艺外协"/>
|
||||
</button>
|
||||
<button type="object" name="action_view_surface_technics_purchase" class="oe_stat_button"
|
||||
icon="fa-credit-card"
|
||||
groups="base.group_user,sf_base.group_sf_order_user"
|
||||
attrs="{'invisible': [('surface_technics_purchase_count', '=', 0),('routing_type', '!=', '表面工艺')]}">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value">
|
||||
<field name="surface_technics_purchase_count"/>
|
||||
</span>
|
||||
<span class="o_stat_text">采购</span>
|
||||
</div>
|
||||
<!-- <field name="surface_technics_purchase_count" widget="statinfo" string="采购"/>-->
|
||||
</button>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='state']" position="before">
|
||||
<field name='tool_state' invisible="1"/>
|
||||
|
||||
@@ -211,36 +211,46 @@ class RePurchaseOrder(models.Model):
|
||||
if not line.taxes_id:
|
||||
raise UserError('请对【产品】中的【税】进行选择')
|
||||
|
||||
def get_purchase_order(self, production, product_id_to_production_names):
|
||||
for pp in production.product_id.model_process_parameters_ids:
|
||||
def get_purchase_order(self, consecutive_process_parameters, production, product_id_to_production_names):
|
||||
is_exist = True
|
||||
server_product_process = []
|
||||
production_process = product_id_to_production_names.get(
|
||||
production.product_id.id)
|
||||
for pp in consecutive_process_parameters:
|
||||
if pp.gain_way == '外协':
|
||||
server_product = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', pp.id),
|
||||
('detailed_type', '=', 'service')])
|
||||
purchase_order_line = self.env['purchase.order.line'].search(
|
||||
[('product_id', '=', server_product.id)])
|
||||
[('product_id', '=', server_product.id), ('product_qty', '=', len(production_process))])
|
||||
if not purchase_order_line:
|
||||
is_exist = False
|
||||
server_product_process.append((0, 0, {
|
||||
'product_id': server_product.product_variant_id.id,
|
||||
'product_qty': len(production_process),
|
||||
'product_uom': server_product.uom_id.id
|
||||
}))
|
||||
else:
|
||||
for item in purchase_order_line:
|
||||
purchase_order = self.env['purchase.order'].search(
|
||||
[('state', '=', 'draft'), ('origin', 'ilike', production.name),
|
||||
('id', '=', item.order_id)])
|
||||
('id', '=', item.order_id.id)])
|
||||
if not purchase_order:
|
||||
is_exist = False
|
||||
if is_exist is False:
|
||||
production_process = product_id_to_production_names.get(
|
||||
production.product_id.id)
|
||||
self.env['purchase.order'].sudo().create({
|
||||
'partner_id': server_product.seller_ids.partner_id.id,
|
||||
'origin': ','.join(production_process),
|
||||
'state': 'draft',
|
||||
'order_line': [(0, 0, {
|
||||
'product_id': server_product.product_variant_id.id,
|
||||
'product_qty': len(production_process),
|
||||
'product_uom': server_product.uom_id.id
|
||||
})]
|
||||
})
|
||||
server_product_process.append((0, 0, {
|
||||
'product_id': server_product.product_variant_id.id,
|
||||
'product_qty': len(production_process),
|
||||
'product_uom': server_product.uom_id.id
|
||||
}))
|
||||
if is_exist is False:
|
||||
purchase_order = self.env['purchase.order'].search(
|
||||
[('state', '=', 'draft'), ('origin', '=', ','.join(production_process))])
|
||||
if not purchase_order:
|
||||
self.env['purchase.order'].sudo().create({
|
||||
'partner_id': server_product.seller_ids.partner_id.id,
|
||||
'origin': ','.join(production_process),
|
||||
'state': 'draft',
|
||||
'order_line': server_product_process})
|
||||
|
||||
@api.onchange('order_line')
|
||||
def _onchange_order_line(self):
|
||||
|
||||
Reference in New Issue
Block a user