sf的销售订单生成制造订单的方法,该方法内,需让制造订单和工单的数据入数据库,以便生成表面外协工艺相关的外协出入库单及关联的库存(stock.move)记录的代码可转移至生成工单的该行代码production.workorder_ids = workorders_values前后左右
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from odoo import api, fields, models, SUPERUSER_ID, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from collections import defaultdict, namedtuple
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from odoo.exceptions import UserError
|
||||
@@ -36,10 +37,42 @@ class StatusChange(models.Model):
|
||||
logging.info('函数已经执行=============4')
|
||||
|
||||
self.with_context(context)._action_confirm()
|
||||
# self.env.cr.commit()
|
||||
self.env.cr.commit()
|
||||
print(self.mrp_production_ids)
|
||||
process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', 58)])
|
||||
# 判断外协工序是否连续有多个外协工序为同一个供应商(产品为表面工艺服务的供应商),
|
||||
# 如果有的话,则将连续的多个外协工序(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()
|
||||
@@ -152,17 +185,20 @@ class FinishStatusChange(models.Model):
|
||||
|
||||
if self.user_has_groups('stock.group_reception_report') \
|
||||
and self.picking_type_id.auto_show_reception_report:
|
||||
lines = self.move_ids.filtered(lambda m: m.product_id.type == 'product' and m.state != 'cancel' and m.quantity_done and not m.move_dest_ids)
|
||||
lines = self.move_ids.filtered(lambda
|
||||
m: m.product_id.type == 'product' and m.state != 'cancel' and m.quantity_done and not m.move_dest_ids)
|
||||
if lines:
|
||||
# don't show reception report if all already assigned/nothing to assign
|
||||
wh_location_ids = self.env['stock.location']._search([('id', 'child_of', self.picking_type_id.warehouse_id.view_location_id.id), ('usage', '!=', 'supplier')])
|
||||
wh_location_ids = self.env['stock.location']._search(
|
||||
[('id', 'child_of', self.picking_type_id.warehouse_id.view_location_id.id),
|
||||
('usage', '!=', 'supplier')])
|
||||
if self.env['stock.move'].search([
|
||||
('state', 'in', ['confirmed', 'partially_available', 'waiting', 'assigned']),
|
||||
('product_qty', '>', 0),
|
||||
('location_id', 'in', wh_location_ids),
|
||||
('move_orig_ids', '=', False),
|
||||
('picking_id', 'not in', self.ids),
|
||||
('product_id', 'in', lines.product_id.ids)], limit=1):
|
||||
('state', 'in', ['confirmed', 'partially_available', 'waiting', 'assigned']),
|
||||
('product_qty', '>', 0),
|
||||
('location_id', 'in', wh_location_ids),
|
||||
('move_orig_ids', '=', False),
|
||||
('picking_id', 'not in', self.ids),
|
||||
('product_id', 'in', lines.product_id.ids)], limit=1):
|
||||
action = self.action_view_reception_report()
|
||||
action['context'] = {'default_picking_ids': self.ids}
|
||||
return action
|
||||
|
||||
Reference in New Issue
Block a user