修复报废

This commit is contained in:
jinling.yang
2024-08-16 17:28:21 +08:00
parent e2d7576a5e
commit 3c8dac799d
5 changed files with 85 additions and 32 deletions

View File

@@ -934,17 +934,50 @@ class MrpProduction(models.Model):
logging.info('get_new_program error:%s' % e)
raise UserError("从云平台获取最新程序失败,请联系管理员")
def recreateManufacturing(self, item):
def recreateManufacturing(self, item, procurement, rule):
"""
重新生成制造订单
"""
if self.is_scrap is True:
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)
# moves_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))
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())