diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index c29abbf4..68e45759 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -7,7 +7,7 @@ from odoo.exceptions import ValidationError, UserError import requests import json from re import findall as regex_findall -from datetime import datetime +from datetime import datetime, timedelta from re import split as regex_split from odoo import SUPERUSER_ID, _, api, fields, models from odoo.tools import float_compare @@ -154,6 +154,7 @@ class StockRule(models.Model): '''创建制造订单''' productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( productions_values) + self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) ''' @@ -188,6 +189,30 @@ class StockRule(models.Model): 'mail.message_origin_link', values={'self': production, 'origin': origin_production}, subtype_id=self.env.ref('mail.mt_note').id) + ''' + 创建生产计划 + ''' + # 工单耗时 + workorder_duration = 0 + for workorder in production.workorder_ids: + workorder_duration += workorder.duration_expected + + + sale_order = self.env['sale.order'].sudo().search([('name', '=', production.origin)]) + if sale_order: + bb = sale_order.deadline_of_delivery + productions = self.env['sf.production.plan'].with_user(SUPERUSER_ID).sudo().with_company(company_id).\ + create({ + 'name': production.name, + 'production_id': production.id, + 'date_planned_start': production.date_planned_start, + 'origin': production.origin, + 'product_qty': production.product_qty, + 'product_id': production.product_id.id, + 'state': 'draft', + }) + + return True