工单开始需要完成上一步
This commit is contained in:
@@ -8,7 +8,8 @@ from io import BytesIO
|
|||||||
from odoo import api, fields, models, SUPERUSER_ID, _
|
from odoo import api, fields, models, SUPERUSER_ID, _
|
||||||
from pystrich.code128 import Code128Encoder
|
from pystrich.code128 import Code128Encoder
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -83,6 +84,56 @@ class MrpWorkOrder(models.Model):
|
|||||||
_description = '工单'
|
_description = '工单'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def button_start(self):
|
||||||
|
if self.state == 'waiting':
|
||||||
|
self.ensure_one()
|
||||||
|
if any(not time.date_end for time in self.time_ids.filtered(lambda t: t.user_id.id == self.env.user.id)):
|
||||||
|
return True
|
||||||
|
# As button_start is automatically called in the new view
|
||||||
|
if self.state in ('done', 'cancel'):
|
||||||
|
return True
|
||||||
|
|
||||||
|
if self.product_tracking == 'serial':
|
||||||
|
self.qty_producing = 1.0
|
||||||
|
else:
|
||||||
|
self.qty_producing = self.qty_remaining
|
||||||
|
|
||||||
|
self.env['mrp.workcenter.productivity'].create(
|
||||||
|
self._prepare_timeline_vals(self.duration, datetime.now())
|
||||||
|
)
|
||||||
|
if self.production_id.state != 'progress':
|
||||||
|
self.production_id.write({
|
||||||
|
'date_start': datetime.now(),
|
||||||
|
})
|
||||||
|
if self.state == 'progress':
|
||||||
|
return True
|
||||||
|
start_date = datetime.now()
|
||||||
|
vals = {
|
||||||
|
'state': 'progress',
|
||||||
|
'date_start': start_date,
|
||||||
|
}
|
||||||
|
if not self.leave_id:
|
||||||
|
leave = self.env['resource.calendar.leaves'].create({
|
||||||
|
'name': self.display_name,
|
||||||
|
'calendar_id': self.workcenter_id.resource_calendar_id.id,
|
||||||
|
'date_from': start_date,
|
||||||
|
'date_to': start_date + relativedelta(minutes=self.duration_expected),
|
||||||
|
'resource_id': self.workcenter_id.resource_id.id,
|
||||||
|
'time_type': 'other'
|
||||||
|
})
|
||||||
|
vals['leave_id'] = leave.id
|
||||||
|
return self.write(vals)
|
||||||
|
else:
|
||||||
|
if self.date_planned_start > start_date:
|
||||||
|
vals['date_planned_start'] = start_date
|
||||||
|
if self.date_planned_finished and self.date_planned_finished < start_date:
|
||||||
|
vals['date_planned_finished'] = start_date
|
||||||
|
return self.write(vals)
|
||||||
|
else:raise ValidationError(_('请先完成上一步工单'))
|
||||||
# def get_tray_info(self):
|
# def get_tray_info(self):
|
||||||
# @api.onchange('X_axis', 'Y_axis', 'Z_axis')
|
# @api.onchange('X_axis', 'Y_axis', 'Z_axis')
|
||||||
# def get_center_point(self):
|
# def get_center_point(self):
|
||||||
@@ -196,56 +247,66 @@ class MrpWorkOrder(models.Model):
|
|||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def recreateManufacturing(self):
|
def recreateManufacturingOrWorkerOrder(self):
|
||||||
"""
|
"""
|
||||||
重新生成制造订单
|
重新生成制造订单或者重新生成工单
|
||||||
"""
|
"""
|
||||||
values = self.env['mrp.production'].create_production1_values(self.production_id)
|
if self.test_results == '报废':
|
||||||
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(
|
values = self.env['mrp.production'].create_production1_values(self.production_id)
|
||||||
self.production_id.company_id).create(
|
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(
|
||||||
values)
|
self.production_id.company_id).create(
|
||||||
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
values)
|
||||||
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
||||||
productions._create_workorder()
|
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 \
|
productions._create_workorder()
|
||||||
(
|
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()
|
(
|
||||||
|
p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm()
|
||||||
|
|
||||||
for production in productions:
|
for production in productions:
|
||||||
origin_production = production.move_dest_ids and production.move_dest_ids[
|
origin_production = production.move_dest_ids and production.move_dest_ids[
|
||||||
0].raw_material_production_id or False
|
0].raw_material_production_id or False
|
||||||
orderpoint = production.orderpoint_id
|
orderpoint = production.orderpoint_id
|
||||||
if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
|
if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
|
||||||
production.message_post(
|
production.message_post(
|
||||||
body=_('This production order has been created from Replenishment Report.'),
|
body=_('This production order has been created from Replenishment Report.'),
|
||||||
message_type='comment',
|
message_type='comment',
|
||||||
subtype_xmlid='mail.mt_note')
|
subtype_xmlid='mail.mt_note')
|
||||||
elif orderpoint:
|
elif orderpoint:
|
||||||
production.message_post_with_view(
|
production.message_post_with_view(
|
||||||
'mail.message_origin_link',
|
'mail.message_origin_link',
|
||||||
values={'self': production, 'origin': orderpoint},
|
values={'self': production, 'origin': orderpoint},
|
||||||
subtype_id=self.env.ref('mail.mt_note').id)
|
subtype_id=self.env.ref('mail.mt_note').id)
|
||||||
elif origin_production:
|
elif origin_production:
|
||||||
production.message_post_with_view(
|
production.message_post_with_view(
|
||||||
'mail.message_origin_link',
|
'mail.message_origin_link',
|
||||||
values={'self': production, 'origin': origin_production},
|
values={'self': production, 'origin': origin_production},
|
||||||
subtype_id=self.env.ref('mail.mt_note').id)
|
subtype_id=self.env.ref('mail.mt_note').id)
|
||||||
|
if self.test_results == '返工':
|
||||||
# print(productions)
|
productions = self.production_id
|
||||||
return ""
|
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
||||||
|
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||||
def recreateWorkerOrder(self):
|
productions._create_workorder2(self.processing_panel)
|
||||||
"""
|
else:
|
||||||
返工重新生成工单
|
return True
|
||||||
"""
|
|
||||||
productions = self.production_id
|
|
||||||
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
|
||||||
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
|
||||||
productions._create_workorder2(self.processing_panel)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def fetchCNC(self):
|
def fetchCNC(self):
|
||||||
return ""
|
return ""
|
||||||
|
def json_workorder_str1(self, k, production, route):
|
||||||
|
workorders_values_str = [0, '', {
|
||||||
|
'product_uom_id': production.product_uom_id.id,
|
||||||
|
'qty_producing': 0,
|
||||||
|
'operation_id': False,
|
||||||
|
'name': route.route_workcenter_id.name,
|
||||||
|
'processing_panel': k,
|
||||||
|
'routing_type': route.routing_type,
|
||||||
|
'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids),
|
||||||
|
'date_planned_start': False,
|
||||||
|
'date_planned_finished': False,
|
||||||
|
'duration_expected': 60,
|
||||||
|
'duration': 0
|
||||||
|
}]
|
||||||
|
return workorders_values_str
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@@ -283,19 +344,8 @@ class MrpProduction(models.Model):
|
|||||||
for rec in self:
|
for rec in self:
|
||||||
current_sequence = 1
|
current_sequence = 1
|
||||||
for work in rec.workorder_ids:
|
for work in rec.workorder_ids:
|
||||||
if work.processing_panel == '':
|
work.sequence = current_sequence
|
||||||
work.sequence = current_sequence
|
current_sequence += 1
|
||||||
current_sequence += 1
|
|
||||||
for work in rec.workorder_ids:
|
|
||||||
if work.processing_panel == k:
|
|
||||||
work.sequence = current_sequence
|
|
||||||
current_sequence += 1
|
|
||||||
for work in rec.workorder_ids:
|
|
||||||
if work.processing_panel != k and work.processing_panel != "":
|
|
||||||
work.sequence = current_sequence
|
|
||||||
current_sequence += 1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _create_workorder1(self, k):
|
def _create_workorder1(self, k):
|
||||||
@@ -342,11 +392,11 @@ class MrpProduction(models.Model):
|
|||||||
|
|
||||||
if route.routing_type == '后置三元质量检测':
|
if route.routing_type == '后置三元质量检测':
|
||||||
workorders_values.append(
|
workorders_values.append(
|
||||||
self.env['mrp.workorder'].json_workorder_str(k, production, route)
|
self.env['mrp.workorder'].json_workorder_str1(k, production, route)
|
||||||
)
|
)
|
||||||
if route.routing_type == 'CNC加工':
|
if route.routing_type == 'CNC加工':
|
||||||
workorders_values.append(
|
workorders_values.append(
|
||||||
self.env['mrp.workorder'].json_workorder_str(k, production, route))
|
self.env['mrp.workorder'].json_workorder_str1(k, production, route))
|
||||||
|
|
||||||
production.workorder_ids = workorders_values
|
production.workorder_ids = workorders_values
|
||||||
for workorder in production.workorder_ids:
|
for workorder in production.workorder_ids:
|
||||||
@@ -358,8 +408,4 @@ class MrpProduction(models.Model):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
class Attachment(models.Model):
|
|
||||||
_inherit = 'ir.attachment'
|
|
||||||
|
|
||||||
cnc_model = fields.Binary('cnc文件', attachment=False)
|
|
||||||
model_name = fields.Char('模型名称')
|
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
<field name="model">mrp.workorder</field>
|
<field name="model">mrp.workorder</field>
|
||||||
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
|
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
|
<!-- <field name="production_id" position="after">-->
|
||||||
|
<!-- <field name="tray_code" readonly="1" attrs='{"invisible": [("tray_code","=",False)]}'/>-->
|
||||||
|
<!-- </field>-->
|
||||||
|
|
||||||
<xpath expr="//page[last()]" position="after">
|
<xpath expr="//page[last()]" position="after">
|
||||||
<page string="获取CNC加工程序" attrs='{"invisible": [("routing_type","!=","获取CNC加工程序")]}'>
|
<page string="获取CNC加工程序" attrs='{"invisible": [("routing_type","!=","获取CNC加工程序")]}'>
|
||||||
<div class="col-12 col-lg-6 o_setting_box">
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
@@ -229,18 +233,15 @@
|
|||||||
<xpath expr="//page[last()]" position="after">
|
<xpath expr="//page[last()]" position="after">
|
||||||
<page string="后置三元检测" attrs='{"invisible": [("routing_type","!=","后置三元质量检测")]}'>
|
<page string="后置三元检测" attrs='{"invisible": [("routing_type","!=","后置三元质量检测")]}'>
|
||||||
<group>
|
<group>
|
||||||
<field name="test_results" widget="radio"/>
|
<field name="test_results" widget="selection"/>
|
||||||
<div class="col-12 col-lg-6 o_setting_box">
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
<button type="object" class="oe_highlight" name="recreateWorkerOrder" string="重新生成工单"
|
<button type="object" class="oe_highlight" name="recreateManufacturingOrWorkerOrder" string="检测确认"
|
||||||
attrs='{"invisible": [("test_results","!=","返工")]}'
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="col-12 col-lg-6 o_setting_box">
|
|
||||||
<button type="object" class="oe_highlight" name="recreateManufacturing" string="重新生成制造订单"
|
|
||||||
attrs='{"invisible": [("test_results","!=","报废")]}'
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user