sf的销售订单生成制造订单的方法,该方法内,需让制造订单和工单的数据入数据库,以便生成表面外协工艺相关的外协出入库单及关联的库存(stock.move)记录的代码可转移至生成工单的该行代码production.workorder_ids = workorders_values前后左右
This commit is contained in:
@@ -65,6 +65,7 @@ class MrsProductionProcess(models.Model):
|
||||
category_id = fields.Many2one('sf.production.process.category')
|
||||
# workcenter_ids = fields.Many2many('mrp.workcenter', 'rel_workcenter_process', required=True)
|
||||
|
||||
|
||||
class MrsProcessingTechnology(models.Model):
|
||||
_name = 'sf.processing.technology'
|
||||
_description = '加工工艺'
|
||||
@@ -128,8 +129,9 @@ class MrsProductionProcessParameter(models.Model):
|
||||
def name_get(self):
|
||||
result = []
|
||||
for parameter in self:
|
||||
name = parameter.process_id.name + '-' + parameter.name
|
||||
result.append((parameter.id, name))
|
||||
if parameter.process_id:
|
||||
name = parameter.process_id.name + '-' + parameter.name
|
||||
result.append((parameter.id, name))
|
||||
return result
|
||||
|
||||
# 获取表面工艺的获取方式
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -171,23 +171,22 @@ class MrpProduction(models.Model):
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str('', production, route))
|
||||
production.workorder_ids = workorders_values
|
||||
process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', 58)])
|
||||
if process_parameter_workorder:
|
||||
|
||||
# for st in process_parameter_workorder:
|
||||
aa = self.env['mrp.workorder'].get_no_data(production.id)
|
||||
if aa:
|
||||
consecutive_workorders = []
|
||||
sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id)
|
||||
m =0
|
||||
sorted_workorders = sorted(aa, 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
|
||||
process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production.id)])
|
||||
for workorder in production.workorder_ids:
|
||||
workorder.duration_expected = workorder._get_duration_expected()
|
||||
# 判断外协工序是否连续有多个外协工序为同一个供应商(产品为表面工艺服务的供应商),
|
||||
# 如果有的话,则将连续的多个外协工序(ID),绑定同一张外协出入库单,单独的供应商工序则生成单独的外协出入库单
|
||||
# 如果没有连续的外协工序为同一个供应商,则根据规则生成多张外协出入库单,并绑定不同的工序ID
|
||||
|
||||
|
||||
# 在之前的销售单上重新生成制造订单
|
||||
def create_production1_values(self, production):
|
||||
|
||||
@@ -93,10 +93,14 @@ class ResMrpWorkOrder(models.Model):
|
||||
glb_file = fields.Binary("glb模型文件")
|
||||
is_subcontract = fields.Boolean(string='是否外协')
|
||||
surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数")
|
||||
stock_picking_in_ids = fields.One2many('stock.picking', 'workorder_in_id',string='库存外协入库单')
|
||||
stock_picking_out_ids = fields.One2many('stock.picking', 'workorder_out_id', string='库存外协出库单')
|
||||
picking_id = fields.Many2one('stock.picking', string='外协出入库单')
|
||||
supplier_id = fields.Integer('供应商Id')
|
||||
|
||||
def get_no_data(self, production_id):
|
||||
process_parameter_workorder = self.search(
|
||||
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', production_id)])
|
||||
return process_parameter_workorder
|
||||
|
||||
# 计算配料中心点和与x轴倾斜度方法
|
||||
def getcenter(self):
|
||||
try:
|
||||
|
||||
@@ -3,7 +3,7 @@ from collections import defaultdict, namedtuple
|
||||
from odoo.addons.stock.models.stock_rule import ProcurementException
|
||||
from re import findall as regex_findall
|
||||
from re import split as regex_split
|
||||
from odoo import SUPERUSER_ID, _, api, fields,models
|
||||
from odoo import SUPERUSER_ID, _, api, fields, models
|
||||
from odoo.tools import float_compare
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
@@ -12,6 +12,13 @@ from odoo.exceptions import UserError
|
||||
class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
|
||||
# @api.model
|
||||
# def _run_pull(self, procurements):
|
||||
# res = super(StockRule, self)._run_pull(procurements)
|
||||
# # process_parameter_workorder = self.env['mrp.workorder'].search(
|
||||
# # [('surface_technics_parameters_id', '!=', False), ('production_id', '=', self.production_id)])
|
||||
# stock_move = self.env['stock.move'].search([('raw_material_production_id', '=', self.id)])
|
||||
|
||||
@api.model
|
||||
def _run_pull(self, procurements):
|
||||
moves_values_by_company = defaultdict(list)
|
||||
@@ -183,6 +190,54 @@ class StockRule(models.Model):
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
return True
|
||||
|
||||
def create_outcontract_stock_move(self, sorted_workorders, item):
|
||||
outcontract_stock_move = self.env['stock.move'].search(
|
||||
[('workorder_id', '=', sorted_workorders.id), ('production_id', '=', item.id)])
|
||||
if not outcontract_stock_move:
|
||||
location_id = self.env.ref(
|
||||
'sf_manufacturing.stock_location_locations_virtual_outcontract').id,
|
||||
location_dest_id = self.env['stock.location'].search(
|
||||
[('barcode', '=', 'WH-PREPRODUCTION')]).id,
|
||||
outcontract_picking_in = self.env['stock.rule'].create_outcontract_picking(item,
|
||||
location_id,
|
||||
location_dest_id)
|
||||
outcontract_picking_in.write({'workorder_id': outcontract_picking_in.id})
|
||||
outcontract_picking_out = self.env['stock.rule'].create_outcontract_picking(item,
|
||||
location_dest_id,
|
||||
location_id)
|
||||
outcontract_picking_out.write({'workorder_id': outcontract_picking_out.id})
|
||||
|
||||
# 生成外协出入库单
|
||||
def create_outcontract_picking(self, item, location_src_id, location_dest_id):
|
||||
moves_values_by_company = defaultdict(list)
|
||||
list2 = []
|
||||
Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
|
||||
'product_uom', 'location_id', 'location_dest_id', 'name', 'origin',
|
||||
'company_id',
|
||||
'values'])
|
||||
s = Procurement(product_id=item.bom_id.product_id, product_qty=1.0, product_uom=item.product_uom,
|
||||
location_id=location_src_id,
|
||||
location_dest_id=location_dest_id,
|
||||
name=item.name,
|
||||
origin=item.origin,
|
||||
company_id=item.company_id,
|
||||
values=item.values,
|
||||
)
|
||||
item1 = list(item)
|
||||
item1[0] = s
|
||||
list2.append(tuple(item1))
|
||||
for procurement in list2:
|
||||
move_values = self.env['stock.rule']._get_stock_move_values(*procurement)
|
||||
moves_values_by_company[procurement.company_id.id].append(move_values)
|
||||
for company_id, moves_values in moves_values_by_company.items():
|
||||
moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
|
||||
moves_values)
|
||||
new_picking = True
|
||||
picking = self.env['stock.picking'].create(moves._get_new_picking_values())
|
||||
moves.write({'picking_id': picking.id})
|
||||
moves._assign_picking_post_process(new=new_picking)
|
||||
return picking
|
||||
|
||||
|
||||
class ProductionLot(models.Model):
|
||||
_inherit = 'stock.lot'
|
||||
@@ -233,8 +288,7 @@ class ProductionLot(models.Model):
|
||||
class ResStockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
workorder_in_id = fields.Many2one('mrp.workorder')
|
||||
workorder_out_id = fields.Many2one('mrp.workorder')
|
||||
workorder_id = fields.One2many('mrp.workorder', 'picking_id')
|
||||
|
||||
|
||||
class ResPurchaseOrder(models.Model):
|
||||
|
||||
Reference in New Issue
Block a user