优化报废

This commit is contained in:
jinling.yang
2024-08-20 14:30:42 +08:00
parent 3c8dac799d
commit e259fd0c05
2 changed files with 56 additions and 91 deletions

View File

@@ -6,6 +6,8 @@ import os
import re
import requests
from itertools import groupby
from datetime import datetime
from collections import defaultdict, namedtuple
from odoo import api, fields, models, SUPERUSER_ID, _
from odoo.exceptions import UserError, ValidationError
from odoo.addons.sf_base.commons.common import Common
@@ -123,6 +125,7 @@ class MrpProduction(models.Model):
manual_quotation = fields.Boolean('人工编程', default=False, readonly=True)
is_scrap = fields.Boolean('是否报废', default=False)
is_remanufacture = fields.Boolean('是否重新制造', default=False)
@api.depends(
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', 'tool_state',
@@ -934,7 +937,8 @@ class MrpProduction(models.Model):
logging.info('get_new_program error:%s' % e)
raise UserError("从云平台获取最新程序失败,请联系管理员")
def recreateManufacturing(self, item, procurement, rule):
def recreateManufacturing(self, item):
"""
重新生成制造订单
"""
@@ -942,56 +946,65 @@ class MrpProduction(models.Model):
procurement_requests = []
sale_order = self.env['sale.order'].sudo().search([('name', '=', self.origin)])
values = self.env['mrp.production'].create_production1_values(self)
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(
self.company_id).create(
values)
# productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(
# self.company_id).create(
# values)
# 查询出库移动记录
out_picking = self.env['stock.picking'].search(
[('logistics_way', '!=', False), ('origin', '=', sale_order.name), ('name', 'ilike', 'WH/OUT/')])
for move in out_picking.move_ids:
values = move._prepare_procurement_values()
origin = move._prepare_procurement_origin()
procurement_requests.append(self.env['procurement.group'].Procurement(
move.product_id, move.product_uom_qty, move.product_uom,
move.location_id, move.rule_id and move.rule_id.name or "/",
origin, move.company_id, values))
[('origin', '=', sale_order.name), ('name', 'ilike', 'WH/OUT/')])
move = out_picking.move_ids.filtered(lambda pd: pd.product_id == self.product_id)
move_values = {'product_description_variants': '',
'date_planned': datetime.now(),
'date_deadline': datetime.now(),
# 'move_dest_ids': self.env['stock.move'].search([('id', '=', move.id)]),
'move_dest_ids': move,
'group_id': False,
'route_ids': [],
'warehouse_id': self.warehouse_id,
'priority': 0,
'orderpoint_id': False,
'product_packaging_id': False}
rule = self.env['stock.rule'].search(
[('action', '=', 'pull'), ('procure_method', '=', 'mts_else_mto'), (
'location_dest_id', '=', self.env['stock.location'].search([('parent_path', '=', '2/5/')]).id),
('location_src_id', '=', self.env['stock.location'].search(
[('barcode', '=', 'CP')]).id)])
origin = move._prepare_procurement_origin()
procurement_requests.append(self.env['procurement.group'].Procurement(
move.product_id, 1.0, move.product_uom,
self.env['stock.location'].search([('barcode', '=', 'CP')]),
rule and rule.name or "/",
origin, move.company_id, move_values))
self.env['procurement.group'].run(procurement_requests,
raise_user_error=not self.env.context.get('from_orderpoint'))
for procurement, rule in procurements:
if not rule.location_src_id:
msg = _('No source location defined on stock rule: %s!') % (rule.name,)
raise ProcurementException([(procurement, msg)])
if rule.procure_method == 'mts_else_mto':
mtso_products_by_locations[rule.location_src_id].append(procurement.product_id.id)
# out_picking.move_ids._action_confirm()
# self.env['stock.move'].search([('')])
# for
move_values = rule._get_stock_move_values(*procurement)
move_values['procure_method'] = 'make_to_order'
moves_values_by_company[procurement.company_id.id].append(move_values)
# moves_values = [{'name': ,''}]
for company_id, moves_values in moves_values_by_company.items():
logging.info(moves_values)
moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
moves_values)
logging.info(moves)
# Since action_confirm launch following procurement_group we should activate it.
moves._action_confirm()
# moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(moves_values)
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
(
p.move_dest_ids.procure_method != 'make_to_order' and
not p.move_raw_ids and not p.workorder_ids)).action_confirm()
productions.programming_no = self.programming_no
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
# productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
# (
# p.move_dest_ids.procure_method != 'make_to_order' and
# not p.move_raw_ids and not p.workorder_ids)).action_confirm()
productions = self.env['mrp.production'].sudo().search(
[('origin', '=', self.origin)], order='id desc', limit=1)
move = self.env['stock.move'].search([('origin', '=', productions.name)], order='id desc')
for mo in move:
print(mo.id)
if mo.name in ['/', '']:
if mo.name == '/':
domain = [('barcode', '=', 'WH-PC'), ('sequence_code', '=', 'PC')]
elif mo.name == '':
domain = [('barcode', '=', 'WH-INTERNAL'), ('sequence_code', '=', 'INT')]
picking_type = self.env['stock.picking.type'].search(domain)
mo.picking_type_id = picking_type.id
mo._assign_picking()
mo.reference = mo.picking_id.name
productions.write({'programming_no': self.programming_no, 'is_remanufacture': True})
productions.procurement_group_id.mrp_production_ids.move_dest_ids.write(
{'group_id': self.env['procurement.group'].search([('name', '=', sale_order.name)])})
scarp_process_parameter_workorder = self.env['mrp.workorder'].search(
[('surface_technics_parameters_id', '!=', False), ('production_id', '=', self.id),
('is_subcontract', '=', True)])
if scarp_process_parameter_workorder:
production_programming = self.env['mrp.production'].search(
[('programming_no', '=', self.production_id.programming_no)], order='name asc')
[('programming_no', '=', self.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 purchase_item in purchase_orders.order_line:
@@ -1054,7 +1067,6 @@ class MrpProduction(models.Model):
production_item)
else:
productions.programming_state = '编程中'
for production in productions:
origin_production = production.move_dest_ids and production.move_dest_ids[
0].raw_material_production_id or False