解决冲突

This commit is contained in:
胡尧
2024-12-27 13:56:41 +08:00
61 changed files with 1479 additions and 289 deletions

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
from . import controllers
from . import models
from . import wizards

View File

@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
{
'name': "机企猫 采购审批流程",
'summary': """
Short (1 phrase/line) summary of the module's purpose, used as
subtitle on modules listing or apps.openerp.com""",
'description': """
Long description of module's purpose
""",
'author': "My Company",
'website': "https://www.yourcompany.com",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/16.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['purchase', 'base_tier_validation', 'documents'],
# always loaded
'data': [
'security/ir.model.access.csv',
'data/documents_data.xml',
'wizards/upload_file_wizard_view.xml',
'views/views.xml',
],
# only loaded in demonstration mode
'demo': [
'demo/demo.xml',
],
}

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import controllers

View File

@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# from odoo import http
# class JikimoPurchaseTierValidation(http.Controller):
# @http.route('/jikimo_purchase_tier_validation/jikimo_purchase_tier_validation', auth='public')
# def index(self, **kw):
# return "Hello, world"
# @http.route('/jikimo_purchase_tier_validation/jikimo_purchase_tier_validation/objects', auth='public')
# def list(self, **kw):
# return http.request.render('jikimo_purchase_tier_validation.listing', {
# 'root': '/jikimo_purchase_tier_validation/jikimo_purchase_tier_validation',
# 'objects': http.request.env['jikimo_purchase_tier_validation.jikimo_purchase_tier_validation'].search([]),
# })
# @http.route('/jikimo_purchase_tier_validation/jikimo_purchase_tier_validation/objects/<model("jikimo_purchase_tier_validation.jikimo_purchase_tier_validation"):obj>', auth='public')
# def object(self, obj, **kw):
# return http.request.render('jikimo_purchase_tier_validation.object', {
# 'object': obj
# })

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- 创建采购合同文件夹 -->
<record id="documents_purchase_contracts_folder" model="documents.folder">
<field name="name">采购合同</field>
<field name="description">存放采购合同相关文件</field>
<field name="sequence">10</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,30 @@
<odoo>
<data>
<!--
<record id="object0" model="jikimo_purchase_tier_validation.jikimo_purchase_tier_validation">
<field name="name">Object 0</field>
<field name="value">0</field>
</record>
<record id="object1" model="jikimo_purchase_tier_validation.jikimo_purchase_tier_validation">
<field name="name">Object 1</field>
<field name="value">10</field>
</record>
<record id="object2" model="jikimo_purchase_tier_validation.jikimo_purchase_tier_validation">
<field name="name">Object 2</field>
<field name="value">20</field>
</record>
<record id="object3" model="jikimo_purchase_tier_validation.jikimo_purchase_tier_validation">
<field name="name">Object 3</field>
<field name="value">30</field>
</record>
<record id="object4" model="jikimo_purchase_tier_validation.jikimo_purchase_tier_validation">
<field name="name">Object 4</field>
<field name="value">40</field>
</record>
-->
</data>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models

View File

@@ -0,0 +1,154 @@
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
import logging
_logger = logging.getLogger(__name__)
class jikimo_purchase_tier_validation(models.Model):
_name = 'purchase.order'
_inherit = ['purchase.order', 'tier.validation']
_tier_validation_buttons_xpath = "/form/header/button[@id='draft_confirm'][1]"
contract_document_id = fields.Many2one('documents.document', string='合同文件')
contract_file = fields.Binary(related='contract_document_id.datas', string='合同文件内容')
contract_file_name = fields.Char(related='contract_document_id.attachment_id.name', string='文件名')
# 是否已上传合同文件
is_upload_contract_file = fields.Boolean(string='是否已上传合同文件', default=False)
def button_confirm(self):
for record in self:
if record.need_validation and record.validation_status != 'validated':
raise ValidationError(_('请先完成审批!'))
return super().button_confirm()
# def button_confirm(self):
# self = self.with_context(skip_validation=True)
# return super().button_confirm()
#
# def _check_state_conditions(self, vals):
# self.ensure_one()
# if self._context.get('skip_validation'):
# return False
# return (
# self._check_state_from_condition()
# and vals.get(self._state_field) in self._state_to
# )
def request_validation(self):
for record in self:
error_messages = []
# 检查必填字段
required_fields = {
'partner_ref': '合同名称',
'contract_number': '合同编号'
}
missing_fields = [
name for field, name in required_fields.items()
if not record[field]
]
if missing_fields:
error_messages.append('1、如下字段要求必须填写%s' % ''.join(missing_fields))
# 检查合同文件
if not record.contract_document_id:
error_messages.append('2、必须点击上传合同文件')
# 如果有任何错误,一次性显示所有错误信息
if error_messages:
raise ValidationError('\n'.join(error_messages))
return super(jikimo_purchase_tier_validation, self).request_validation()
# 上传合同文件
def upload_contract_file(self):
print('upload_contract_file===========================')
# self.ensure_one()
# return {
# 'name': _('上传合同文件'),
# 'type': 'ir.actions.act_window',
# 'res_model': 'ir.attachment',
# 'view_mode': 'form',
# 'view_type': 'form',
# 'target': 'new',
# 'context': {
# 'default_res_model': self._name,
# 'default_res_id': self.id,
# 'default_type': 'binary',
# 'default_mimetype': 'application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,image/jpeg,image/png',
# }
# }
self.ensure_one()
action = {
'type': 'ir.actions.act_window',
'name': _('上传合同文件'),
'res_model': 'ir.attachment.wizard', # 我们需要创建一个新的向导模型
'view_mode': 'form',
'target': 'new',
'context': {
'default_res_model': self._name,
'default_res_id': self.id,
}
}
return action
# 删除合同文件
def delete_contract_file(self):
self.ensure_one()
if self.contract_document_id:
try:
document = self.contract_document_id
# 清空关联
self.write({
'contract_document_id': False,
'contract_file': False,
'contract_file_name': False
})
# 删除文档
if document:
document.with_context(no_attachment=True).sudo().unlink()
self.is_upload_contract_file = False
# 返回视图动作来刷新当前表单
return {
'type': 'ir.actions.act_window',
'res_model': 'purchase.order',
'res_id': self.id,
'view_mode': 'form',
'view_type': 'form',
'target': 'current',
'flags': {'mode': 'readonly'},
}
except Exception as e:
_logger.error('删除合同文件时出错: %s', str(e))
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('错误'),
'message': _('删除文件时出现错误'),
'type': 'danger',
'sticky': True,
}
}
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('提示'),
'message': _('没有需要删除的合同文件'),
'type': 'warning',
'sticky': False,
}
}

View File

@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_ir_attachment_wizard,ir.attachment.wizard,model_ir_attachment_wizard,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_ir_attachment_wizard ir.attachment.wizard model_ir_attachment_wizard base.group_user 1 1 1 1

View File

@@ -0,0 +1,24 @@
<odoo>
<data>
<!--
<template id="listing">
<ul>
<li t-foreach="objects" t-as="object">
<a t-attf-href="#{ root }/objects/#{ object.id }">
<t t-esc="object.display_name"/>
</a>
</li>
</ul>
</template>
<template id="object">
<h1><t t-esc="object.display_name"/></h1>
<dl>
<t t-foreach="object._fields" t-as="field">
<dt><t t-esc="field"/></dt>
<dd><t t-esc="object[field]"/></dd>
</t>
</dl>
</template>
-->
</data>
</odoo>

View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<record model="ir.ui.view" id="tier_validation_view_purchase_order_form_inherit">
<field name="name">tier_validation_view_purchase_order_form_inherit</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//header/button[@name='button_cancel']" position="replace">
</xpath>
<xpath expr="//header/button[last()]" position="after">
<button name="button_cancel" states="draft,to approve,sent,purchase" string="取消" type="object" data-hotkey="x" />
</xpath>
<xpath expr="//header/button[@name='action_rfq_send'][1]" position="before">
<field name="validation_status" invisible="1"/>
<field name="is_upload_contract_file" invisible="1"/>
<button name="upload_contract_file" string="上传合同" type="object" class="oe_highlight" attrs="{'invisible': ['|', ('validation_status', '!=', 'no'), ('is_upload_contract_file', '=', True)]}"/>
<button name="delete_contract_file" string="删除合同" type="object" class="oe_highlight" attrs="{'invisible': ['|', ('validation_status', '!=', 'no'), ('is_upload_contract_file', '=', False)]}"/>
</xpath>
<xpath expr="//notebook/page[1]" position="before">
<page string="合同" name="contract_documents"
attrs="{'invisible': [('contract_document_id', '=', False)]}"
autofocus="autofocus">
<group>
<group>
<field name="contract_document_id" invisible="1"/>
<field name="contract_file_name" invisible="1"/>
<field name="contract_file"
widget="adaptive_viewer"
filename="contract_file_name"/>
</group>
</group>
</page>
</xpath>
</field>
</record>
<!-- actions opening views on models -->
<!--
<record model="ir.actions.act_window" id="jikimo_purchase_tier_validation.action_window">
<field name="name">jikimo_purchase_tier_validation window</field>
<field name="res_model">jikimo_purchase_tier_validation.jikimo_purchase_tier_validation</field>
<field name="view_mode">tree,form</field>
</record>
-->
<!-- server action to the one above -->
<!--
<record model="ir.actions.server" id="jikimo_purchase_tier_validation.action_server">
<field name="name">jikimo_purchase_tier_validation server</field>
<field name="model_id" ref="model_jikimo_purchase_tier_validation_jikimo_purchase_tier_validation"/>
<field name="state">code</field>
<field name="code">
action = {
"type": "ir.actions.act_window",
"view_mode": "tree,form",
"res_model": model._name,
}
</field>
</record>
-->
<!-- Top menu item -->
<!--
<menuitem name="jikimo_purchase_tier_validation" id="jikimo_purchase_tier_validation.menu_root"/>
-->
<!-- menu categories -->
<!--
<menuitem name="Menu 1" id="jikimo_purchase_tier_validation.menu_1" parent="jikimo_purchase_tier_validation.menu_root"/>
<menuitem name="Menu 2" id="jikimo_purchase_tier_validation.menu_2" parent="jikimo_purchase_tier_validation.menu_root"/>
-->
<!-- actions -->
<!--
<menuitem name="List" id="jikimo_purchase_tier_validation.menu_1_list" parent="jikimo_purchase_tier_validation.menu_1"
action="jikimo_purchase_tier_validation.action_window"/>
<menuitem name="Server to list" id="jikimo_purchase_tier_validation" parent="jikimo_purchase_tier_validation.menu_2"
action="jikimo_purchase_tier_validation.action_server"/>
-->
</data>
</odoo>

View File

@@ -0,0 +1 @@
from . import upload_file_wizard

View File

@@ -0,0 +1,114 @@
from odoo import models, fields, api, _
class IrAttachmentWizard(models.TransientModel):
_name = 'ir.attachment.wizard'
_description = '文件上传向导'
attachment = fields.Binary(string='选择文件', required=True)
filename = fields.Char(string='文件名')
res_model = fields.Char()
res_id = fields.Integer()
# def action_upload_file(self):
# self.ensure_one()
# # 首先创建 ir.attachment
# attachment = self.env['ir.attachment'].create({
# 'name': self.filename,
# 'type': 'binary',
# 'datas': self.attachment,
# 'res_model': self.res_model,
# 'res_id': self.res_id,
# })
#
# # 获取默认的文档文件夹
# workspace = self.env['documents.folder'].search([('name', '=', '采购合同')], limit=1)
#
# # 创建 documents.document 记录
# document = self.env['documents.document'].create({
# 'name': self.filename,
# 'attachment_id': attachment.id,
# 'folder_id': workspace.id,
# 'res_model': self.res_model,
# 'res_id': self.res_id,
# })
#
# return {
# 'type': 'ir.actions.client',
# 'tag': 'display_notification',
# 'params': {
# 'title': _('成功'),
# 'message': _('文件上传成功'),
# 'type': 'success',
# }
# }
def action_upload_file(self):
self.ensure_one()
# 获取当前用户的 partner_id
current_partner = self.env.user.partner_id
# 首先创建 ir.attachment
attachment = self.env['ir.attachment'].create({
'name': self.filename,
'type': 'binary',
'datas': self.attachment,
'res_model': self.res_model,
'res_id': self.res_id,
})
# 获取默认的文档文件夹
workspace = self.env['documents.folder'].search([('name', '=', '采购合同')], limit=1)
# 创建 documents.document 记录
document = self.env['documents.document'].create({
'name': self.filename,
'attachment_id': attachment.id,
'folder_id': workspace.id,
'res_model': self.res_model,
'res_id': self.res_id,
'partner_id': current_partner.id,
})
# 更新采购订单的合同文档字段
purchase_order = self.env['purchase.order'].browse(self.res_id)
purchase_order.write({
'contract_document_id': document.id,
'is_upload_contract_file': True
})
# 显示成功消息并关闭向导
message = {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('成功'),
'message': _('文件上传成功'),
'type': 'success',
'sticky': False, # 自动消失
'next': {
'type': 'ir.actions.act_window_close'
}
}
}
return message
# def action_upload_file(self):
# self.ensure_one()
# attachment = self.env['ir.attachment'].create({
# 'name': self.filename,
# 'type': 'binary',
# 'datas': self.attachment,
# 'res_model': self.res_model,
# 'res_id': self.res_id,
# })
# return {
# 'type': 'ir.actions.client',
# 'tag': 'display_notification',
# 'params': {
# 'title': _('成功'),
# 'message': _('文件上传成功'),
# 'type': 'success',
# }
# }

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_upload_file_wizard_form" model="ir.ui.view">
<field name="name">ir.attachment.wizard.form</field>
<field name="model">ir.attachment.wizard</field>
<field name="arch" type="xml">
<form string="上传文件">
<group>
<field name="attachment" widget="binary" filename="filename" options="{'accepted_file_extensions': '.pdf,.doc,.docx,.jpg,.jpeg,.png'}"/>
<field name="filename" invisible="1"/>
<field name="res_model" invisible="1"/>
<field name="res_id" invisible="1"/>
</group>
<footer>
<button name="action_upload_file" string="确认上传" type="object" class="btn-primary"/>
<button string="取消" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
</odoo>

View File

@@ -7,6 +7,7 @@ from datetime import datetime
import random
from odoo import api, models, fields, _
from odoo.api import depends
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT, float_round
from odoo.osv.expression import OR
@@ -122,7 +123,13 @@ class QualityPoint(models.Model):
class QualityCheck(models.Model):
_inherit = "quality.check"
part_name = fields.Char('零件名称', compute='_compute_part_name_number', readonly=True)
part_number = fields.Char('零件图号', compute='_compute_part_name_number', readonly=True)
@depends('product_id')
def _compute_part_name_number(self):
for record in self:
record.part_number = record.product_id.part_number
record.part_name = record.product_id.part_name
failure_message = fields.Html(related='point_id.failure_message', readonly=True)
measure = fields.Float('Measure', default=0.0, digits='Quality Tests', tracking=True)
measure_success = fields.Selection([

View File

@@ -389,6 +389,8 @@
<field name="name" decoration-bf="1"/>
<field name="measure_on" optional="show"/>
<field name='product_id' optional="show"/>
<field name="part_name" optional="hide"/>
<field name='part_number' optional="show"/>
<field name="lot_id" invisible="context.get('show_lots_text')"/>
<field name="lot_name" invisible="not context.get('show_lots_text')"/>
<field name="picking_id" optional="hide" string="Transfer"/>

View File

@@ -36,6 +36,8 @@ class StatusChange(models.Model):
# 使用super()来调用原始方法(在本例中为'sale.order'模型的'action_confirm'方法)
try:
res = super(StatusChange, self).action_confirm()
# 修改销售订单状态为【加工中】
self.write({'state': 'processing'})
logging.info('原生方法返回结果:%s' % res)
# 原有方法执行后进行额外的操作如调用外部API
process_start_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

View File

@@ -9,9 +9,9 @@ class StockRuleInherit(models.Model):
@api.model
def _run_buy(self, procurements):
# 判断补货组的采购类型
procurements_group = {'standard': [], 'consignment': []}
procurements_group = {'standard': [], 'outsourcing': []}
for procurement, rule in procurements:
is_consignment = False
is_outsourcing = False
product = procurement.product_id
# 获取主 BOM
bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)], limit=1)
@@ -24,17 +24,17 @@ class StockRuleInherit(models.Model):
for route in raw_material.route_ids:
# print('route.name:', route.name)
if route.name == '按订单补给外包商':
is_consignment = True
is_outsourcing = True
if is_consignment:
procurements_group['consignment'].append((procurement, rule))
if is_outsourcing:
procurements_group['outsourcing'].append((procurement, rule))
else:
procurements_group['standard'].append((procurement, rule))
for key, value in procurements_group.items():
super(StockRuleInherit, self)._run_buy(value)
if key == 'consignment':
if key == 'outsourcing':
for procurement, rule in value:
supplier = procurement.values.get('supplier')
if supplier:
@@ -49,7 +49,7 @@ class StockRuleInherit(models.Model):
], limit=1)
logging.info("po=: %s", po)
if po:
po.write({'purchase_type': 'consignment'})
po.write({'purchase_type': 'outsourcing'})
# # 首先调用父类的 _run_buy 方法,以保留原有逻辑
# super(StockRuleInherit, self)._run_buy(procurements)
@@ -83,5 +83,5 @@ class StockRuleInherit(models.Model):
# ], limit=1)
# logging.info("po=: %s", po)
# if po:
# po.write({'purchase_type': 'consignment'})
# po.write({'purchase_type': 'outsourcing'})
# break

View File

@@ -40,6 +40,7 @@
'views/res_config_settings_views.xml',
'views/sale_order_views.xml',
'views/mrp_workorder_batch_replan.xml',
'views/purchase_order_view.xml',
],
'assets': {

View File

@@ -363,24 +363,18 @@ class MrpProduction(models.Model):
# if production.state == 'pending_cam':
# if all(wo_state in 'done' for wo_state in production.workorder_ids.mapped('state')):
# production.state = 'done'
if any(
(
wo.test_results == '返工' and wo.state == 'done' and production.programming_state in [
'已编程']) or (
wo.state == 'rework' and production.programming_state == '编程中') or (
wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中',
'已编程'])
for wo in
production.workorder_ids):
if any((wo.test_results == '返工' and wo.state == 'done' and production.programming_state in ['已编程'])
or (wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中', '已编程'])
for wo in production.workorder_ids):
production.state = 'rework'
if any(wo.test_results == '报废' and wo.state == 'done' for wo in production.workorder_ids):
production.state = 'scrap'
if any(dr.test_results == '报废' and dr.handle_result == '已处理' for dr in
production.detection_result_ids):
production.state = 'cancel'
# 如果制造订单的功能刀具为【无效刀】则制造订单状态改为返工
if production.tool_state == '2':
production.state = 'rework'
if production.workorder_ids and all(wo_state in ('done', 'rework', 'cancel') for wo_state in production.workorder_ids.mapped('state')):
if production.state not in ['scrap', 'rework', 'cancel']:
production.state = 'done'
# 退回调整
def technology_back_adjust(self):
@@ -769,7 +763,8 @@ class MrpProduction(models.Model):
}]
if production.product_id.categ_id.type in ['成品', '坯料']:
# # 根据工序设计生成工单
for route in production.technology_design_ids:
technology_design_ids = sorted(production.technology_design_ids, key=lambda x: x.sequence)
for route in technology_design_ids:
workorder_has = self.env['mrp.workorder'].search(
[('technology_design_id', '=', route.id), ('production_id', '=', production.id)])
if not workorder_has:
@@ -963,10 +958,11 @@ class MrpProduction(models.Model):
work_ids = workorder_ids.filtered(lambda item: item.sequence == 0)
# 对工单进行逐个插入
for work_id in work_ids:
for order_id in rec.workorder_ids.filtered(lambda item: item.sequence > 0):
if work_id.name == order_id.name and work_id.processing_panel == order_id.processing_panel:
work_id.sequence = order_id.sequence + 1
break
order_rework_ids = rec.workorder_ids.filtered(
lambda item: (item.sequence > 0 and work_id.name == item.name
and work_id.processing_panel == item.processing_panel))
order_rework_ids = sorted(order_rework_ids, key=lambda item: item.sequence, reverse=True)
work_id.sequence = order_rework_ids[0].sequence + 1
# 对该工单之后的工单工序进行加一
work_order_ids = rec.workorder_ids.filtered(
lambda item: item.sequence >= work_id.sequence and item.id != work_id.id)

View File

@@ -138,7 +138,8 @@ class ResMrpWorkOrder(models.Model):
is_subcontract = fields.Boolean(string='是否外协')
surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数")
picking_ids = fields.Many2many('stock.picking', string='外协出入库单', compute='_compute_surface_technics_picking_ids')
picking_ids = fields.Many2many('stock.picking', string='外协出入库单',
compute='_compute_surface_technics_picking_ids')
purchase_id = fields.Many2many('purchase.order', string='外协采购单')
surface_technics_picking_count = fields.Integer("外协出入库", compute='_compute_surface_technics_picking_ids')
@@ -327,7 +328,7 @@ class ResMrpWorkOrder(models.Model):
'view_mode': 'form',
}
return result
def _get_surface_technics_purchase_ids(self):
domain = [('origin', '=', self.production_id.name), ('purchase_type', '=', 'consignment')]
purchase_orders = self.env['purchase.order'].search(domain)
@@ -1429,6 +1430,8 @@ class ResMrpWorkOrder(models.Model):
rfid_code = workorder.rfid_code
workorder.write({'rfid_code_old': rfid_code,
'rfid_code': False})
self.env['stock.lot'].sudo().search([('rfid', '=', rfid_code)]).write(
{'tool_material_status': '可用'})
if workorder.rfid_code:
raise ValidationError(f'{workorder.name}】工单解绑失败,请重新点击完成按钮!!!')
# workorder.rfid_code_old = rfid_code
@@ -1567,7 +1570,7 @@ class ResMrpWorkOrder(models.Model):
'default_confirm_button': '确认解除',
# 'default_feeder_station_start_id': feeder_station_start_id,
}}
move_subcontract_workorder_ids = fields.One2many('stock.move', 'subcontract_workorder_id', string='组件')
@@ -1778,6 +1781,7 @@ class SfWorkOrderBarcodes(models.Model):
if workorder_rfid:
for item in workorder_rfid:
item.write({'rfid_code': barcode})
lot.sudo().write({'tool_material_status': '在用'})
logging.info("Rfid[%s]绑定成功!!!" % barcode)
else:
raise UserError('该Rfid【%s】绑定的是【%s】, 不是托盘!!!' % (barcode, lot.product_id.name))

View File

@@ -774,11 +774,10 @@ class ResProductMo(models.Model):
# bfm下单
manual_quotation = fields.Boolean('人工编程', default=False, readonly=True)
part_number = fields.Char(string='零件图号', readonly=True)
machining_drawings = fields.Binary('2D加工图纸', readonly=True)
quality_standard = fields.Binary('质检标准', readonly=True)
part_name = fields.Char(string='零件名称', readonly=True)
part_number = fields.Char(string='零件图号', readonly=True)
@api.constrains('tool_length')
def _check_tool_length_size(self):
if self.tool_length > 1000000:
@@ -892,7 +891,7 @@ class ResProductMo(models.Model):
'machining_drawings': '' if not item['machining_drawings'] else base64.b64decode(
item['machining_drawings']),
'quality_standard': '' if not item['quality_standard'] else base64.b64decode(item['quality_standard']),
'part_name': item['part_name'],
'part_name': item.get('part_name') or '',
}
tax_id = self.env['account.tax'].sudo().search(
[('type_tax_use', '=', 'sale'), ('amount', '=', item.get('tax')), ('price_include', '=', 'True')])

View File

@@ -10,7 +10,6 @@ from odoo.tools import OrderedSet
# _get_surface_technics_purchase_ids
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
def button_confirm(self):
super().button_confirm()
workorders = self.env['mrp.workorder'].search([('purchase_id', '=', self.id)])
@@ -29,3 +28,16 @@ class PurchaseOrder(models.Model):
if not mo.move_line_ids:
self.env['stock.move.line'].create(mo.get_move_line(workorder.production_id, workorder))
return True
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True)
related_product = fields.Many2one('product.product',compute='_compute_related_product', string='关联产品',help='经此产品工艺加工成的成品')
@api.depends('order_id.origin')
def _compute_related_product(self):
for record in self:
if record.product_id.detailed_type:
production_id = self.env['mrp.production'].search([('name', '=', record.order_id.origin)])
record.related_product = production_id.product_id if production_id else False
else:
record.related_product = False

View File

@@ -152,7 +152,7 @@ class SaleOrder(models.Model):
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True)
# 供货方式
supply_method = fields.Selection([
('automation', "自动化产线加工"),

View File

@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from collections import Counter
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError
@@ -6,7 +8,7 @@ from odoo.exceptions import ValidationError
class sf_technology_design(models.Model):
_name = 'sf.technology.design'
_description = "工艺设计"
group_uniq_id = fields.Integer('同一制造订单唯一id',default=0)
sequence = fields.Integer('序号')
route_id = fields.Many2one('mrp.routing.workcenter', '工序')
process_parameters_id = fields.Many2one('sf.production.process.parameter', string='表面工艺参数')
@@ -17,6 +19,11 @@ class sf_technology_design(models.Model):
is_auto = fields.Boolean('是否自动生成', default=False)
active = fields.Boolean('有效', default=True)
# @api.depends('production_id')
# def _compute_group_uniq_id(self):
# for record in self:
def json_technology_design_str(self, k, route, i, process_parameter):
workorders_values_str = [0, '', {
'route_id': route.id if route.routing_type in ['表面工艺'] else route.route_workcenter_id.id,
@@ -28,6 +35,9 @@ class sf_technology_design(models.Model):
'is_auto': True}]
return workorders_values_str
def write(self, vals):
print('qwfojkqwfkio')
return super(sf_technology_design, self).write(vals)
def unlink_technology_design(self):
self.active = False
@@ -37,4 +47,64 @@ class sf_technology_design(models.Model):
for vals in vals_list:
if not vals.get('route_id'):
raise ValidationError(_("工序不能为空"))
return super(sf_technology_design, self).create(vals_list)
result = super(sf_technology_design, self).create(vals_list)
for res in result:
record = self.search([('production_id', '=', res.production_id.id), ('active', 'in', [True, False])], order='group_uniq_id desc', limit=1)
res.group_uniq_id=record.group_uniq_id + 1
return result
def get_duplicates_with_inactive(self,technology_designs):
# 统计每个 'sequence' 出现的次数
sequence_count = Counter(technology_design.sequence for technology_design in technology_designs)
# 筛选出 'sequence' 重复且 'active' 为 False 的元素
result = [
technology_design for technology_design in technology_designs
if sequence_count[technology_design.sequence] > 1 and technology_design.active is False
]
return result
# def rearrange_numbering(self,self_technology_designs):
# inactive_designs = self.get_duplicates_with_inactive(self_technology_designs)
# if inactive_designs:
# max_design = max(self_technology_designs, key=lambda x: x.sequence)
# max_sequence = max_design.sequence if max_design else 0
# for designs in inactive_designs:
# max_sequence += 1
# designs.sequence = max_sequence
# self_technology_designs.sorted(key=lambda techology_design:techology_design.sequence)
# return self_technology_designs
def get_technology_design(self):
return {
'sequence':self.sequence,
'route_id': self.route_id.id,
'process_parameters_id': self.process_parameters_id.id,
'panel': self.panel,
'routing_tag': self.routing_tag,
'time_cycle_manual': self.time_cycle_manual,
'is_auto': self.is_auto,
'active': self.active,
'group_uniq_id':self.group_uniq_id,
}
def sync_technology_designs(self,production_technology_designs, self_technology_designs):
production_id = production_technology_designs[0].production_id.id
self_technology_design_dict = {item.group_uniq_id:item for item in self_technology_designs}
production_technology_designs_dict = {item.group_uniq_id:item for item in production_technology_designs}
for technology_design in production_technology_designs:
if not self_technology_design_dict.get(technology_design.group_uniq_id):
technology_design.write({'production_id': False})
else:
technology_design.write(self_technology_design_dict.get(technology_design.group_uniq_id).get_technology_design())
for technology_design in self_technology_designs:
if not production_technology_designs_dict.get(technology_design.group_uniq_id):
technology_design = technology_design.get_technology_design()
technology_design.update({'production_id': production_id})
technology_design.pop('group_uniq_id')
self.env['sf.technology.design'].create(technology_design)
def unified_procedure_multiple_work_orders(self,self_technology_designs,production_item):
technology_designs = self.env['sf.technology.design'].sudo().search(
[('production_id', '=', production_item.id), ('active', 'in', [True, False])])
self.sync_technology_designs(self_technology_designs=self_technology_designs,production_technology_designs=technology_designs)

View File

@@ -672,8 +672,8 @@ class StockPicking(models.Model):
'partner_id': self.partner_id.id,
})
move_dest_id = False
# 如果当前工单是是制造订单的最后一个工单
if workorder == item.workorder_ids[-1]:
# 如果当前工单是是制造订单的最后一个工艺外协工
if workorder == next((workorder for workorder in reversed(item.workorder_ids) if workorder.is_subcontract), None):
move_dest_id = item.move_raw_ids[0].id
else:
# 从sorted_workorders中找到上一工单的move

View File

@@ -18,9 +18,12 @@
<xpath expr="//field[@name='date_deadline']" position="replace"/>
<xpath expr="//field[@name='name']" position="after">
<field name="product_id" readonly="1" optional="show"/>
<field name="part_name" readonly="1" optional="hide"/>
<field name="part_number" readonly="1" optional="show"/>
</xpath>
<xpath expr="//field[@name='product_id']" position="after">
<field name="product_qty" sum="Total Qty" string="数量" readonly="1" optional="show"/>
<field name="deadline_of_delivery" optional="show"/>
</xpath>
<xpath expr="//field[@name='product_qty']" position="after">
<field name="product_uom_id" string="计量单位" options="{'no_open':True,'no_create':True}"
@@ -128,11 +131,6 @@
<field name="deadline_of_delivery" readonly="1"/>
<field name="tool_state_remark2" invisible="1"/>
</xpath>
<xpath expr="//header//button[@name='action_cancel']" position="replace">
<button name="action_cancel" type="object" string="取消" data-hotkey="z"
attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'cancel')), ('confirm_cancel', '=', True)]}"
groups="sf_base.group_sf_mrp_user"/>
</xpath>
<xpath expr="(//header//button[@name='button_mark_done'])[1]" position="replace">
<button name="button_mark_done"
attrs="{'invisible': ['|', '|', ('state', 'in', ('draft', 'cancel', 'done', 'to_close')), ('qty_producing', '=', 0), ('move_raw_ids', '!=', [])]}"
@@ -257,13 +255,6 @@
type="object" groups="sf_base.group_sf_mrp_user"/>
</xpath>
<xpath expr="//header//button[@name='action_cancel']" position="replace">
<button name="action_cancel" type="object" string="Cancel" data-hotkey="z"
attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'cancel')), ('confirm_cancel', '=', False)]}"
confirm="Some product moves have already been confirmed, this manufacturing order can't be completely cancelled. Are you still sure you want to process ?"
groups="sf_base.group_sf_mrp_user"/>
</xpath>
<xpath expr="//header//button[@name='button_unbuild']" position="replace">
<button name="button_unbuild" type="object" string="拆单"
attrs="{'invisible': [('state', '!=', 'done')]}" data-hotkey="shift+v"
@@ -307,12 +298,14 @@
type="object" groups="sf_base.group_sf_mrp_user"/>
</xpath>
<xpath expr="//header//button[@name='action_cancel']" position="replace">
<xpath expr="//header//button[@name='action_cancel'][2]" position="replace">
<button name="action_cancel" type="object" string="取消" data-hotkey="z"
attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'cancel')), ('confirm_cancel', '=', False)]}"
attrs="{'invisible': ['|', '|', ('id', '=', False), ('state', 'in', ('done', 'rework', 'cancel')), ('confirm_cancel', '=', False)]}"
confirm="Some product moves have already been confirmed, this manufacturing order can't be completely cancelled. Are you still sure you want to process ?"
groups="sf_base.group_sf_mrp_user"/>
</xpath>
<xpath expr="//header//button[@name='action_cancel'][1]" position="replace"></xpath>
<xpath expr="//header//button[@name='button_unbuild']" position="replace">
<button name="button_unbuild" type="object" string="拆单"
attrs="{'invisible': [('state', '!=', 'done')]}" data-hotkey="shift+v"
@@ -441,9 +434,7 @@
<xpath expr="//tree//button[@name='button_start']" position="replace">
<field name="routing_type" invisible="True"/>
<button name="button_start" type="object" string="开始" class="btn-success" confirm="是否确认开始?"
attrs="{'invisible': ['|', '|', '|','|', ('production_state','in', ('draft', 'done', 'cancel')),
('working_state', '=', 'blocked'), ('state', 'in', ('done','rework', 'cancel')), ('is_user_working', '!=',
False), ('routing_type', '=', 'CNC加工')]}"
attrs="{'invisible': [('state', '!=', 'ready')]}"
groups="sf_base.group_sf_mrp_user"/>
</xpath>
<xpath expr="//tree//button[@name='button_pending']" position="replace">

View File

@@ -29,6 +29,8 @@
</field>
<field name="product_id" position="after">
<field name="equipment_id" optional="hide"/>
<field name="part_name" optional="hide"/>
<field name="part_number" optional="show"/>
</field>
<xpath expr="//field[@name='qty_remaining']" position="after">
<field name="manual_quotation" optional="show"/>
@@ -53,10 +55,7 @@
<!-- 'cancel')), ('working_state', '=', 'blocked'), ('state', 'in', ('done', 'cancel')),-->
<!-- ('is_user_working', '!=', False),("user_permissions","=",False),("name","=","CNC加工")]}-->
<!-- </attribute>-->
<attribute name="attrs">{'invisible': ['|', '|', '|','|','|', ('production_state','in', ('draft',
'done',
'cancel')), ('working_state', '=', 'blocked'), ('state', 'in', ('done','rework', 'cancel')),
('is_user_working', '!=', False),("user_permissions","=",False),("name","in",("CNC加工","解除装夹"))]}
<attribute name="attrs">{'invisible': [('state', '!=', 'ready')]}
</attribute>
</xpath>
<xpath expr="//button[@name='%(mrp.act_mrp_block_workcenter_wo)d']" position="attributes">
@@ -174,9 +173,7 @@
<!-- <button name="button_start" type="object" string="开始" class="btn-success" confirm="是否确认开始"-->
<!-- attrs="{'invisible': ['|', '|', '|', ('production_state','in', ('draft', 'done', 'cancel')), ('working_state', '=', 'blocked'), ('state', 'in', ('done', 'cancel','to be detected')), ('is_user_working', '!=', False)]}"/>-->
<button name="button_start" type="object" string="开始" class="btn-success" confirm="是否确认开始"
attrs="{'invisible': ['|', '|', '|', '|', '|', ('routing_type', '=', '装夹预调'), ('routing_type', '=', '解除装夹'), ('production_state','in', ('draft', 'done', 'cancel')), ('working_state', '=', 'blocked'), ('state', 'in', ('done','rework', 'cancel','to be detected')), ('is_user_working', '!=', False)]}"/>
<button name="button_start" type="object" string="开始" class="btn-success"
attrs="{'invisible': ['|', '|', '|', '|', ('routing_type', '!=', '装夹预调'), ('production_state','in', ('draft', 'done', 'cancel')), ('working_state', '=', 'blocked'), ('state', 'in', ('done','rework', 'cancel','to be detected')), ('is_user_working', '!=', False)]}"/>
attrs="{'invisible': [('state', '!=', 'ready')]}"/>
<button name="button_pending" type="object" string="暂停" class="btn-warning"
attrs="{'invisible': ['|', '|', ('production_state', 'in', ('draft', 'done', 'cancel')), ('working_state', '=', 'blocked'), ('is_user_working', '=', False)]}"/>
<button name="button_finish" type="object" string="完成" class="btn-success" confirm="是否确认完工"

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<record model="ir.ui.view" id="view_purchase_order_line_form_inherit_sf1">
<field name="name">purchase.order.form.inherit.sf</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='name']" position="after">
<field name="related_product" optional="show"/>
<field name="part_number" optional="show"/>
</xpath>
</field>
</record>
</data>
</odoo>

View File

@@ -18,6 +18,10 @@
<xpath expr="//page/field[@name='order_line']/tree/field[@name='remark']" position="before">
<field name="supply_method" attrs="{'invisible': [('state', '=', 'draft')], 'required': [('state', '=', 'supply method')]}" />
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='model_glb_file']" position="before">
<field name="part_number" optional="show"/>
</xpath>
<xpath expr="//header/button[@name='action_cancel']" position="attributes">
<attribute name="attrs">{'invisible': [('state', '!=', 'draft')]}</attribute>
</xpath>

View File

@@ -10,7 +10,7 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
production_id = fields.Many2one('mrp.production', string='制造订单号')
origin = fields.Char(string='源单据')
is_technology_re_adjust = fields.Boolean(default=False)
is_technology_re_adjust = fields.Boolean(default=True)
def confirm(self):
if self.is_technology_re_adjust is True:
@@ -24,38 +24,39 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
for production_item in productions:
# 该制造订单的其他同一销售订单的制造订单的工艺设计处理
if production_item != self.production_id:
for td_other in production_item.technology_design_ids:
if td_other.is_auto is False:
td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id)
if not td_del or td_del.active is False:
td_other.write({'active': False})
for td_main in technology_designs:
route_other = production_item.technology_design_ids.filtered(
lambda td: td.route_id.id == td_main.route_id.id)
if not route_other and td_main.active is True:
production_item.write({'technology_design_ids': [(0, 0, {
'route_id': td_main.route_id.id,
'process_parameters_id': False if td_main.process_parameters_id is False else
self.env[
'sf.production.process.parameter'].search(
[('id', '=', td_main.process_parameters_id.id)]).id,
'sequence': td_main.sequence,
'is_auto': td_main.is_auto})]})
else:
for ro in route_other:
domain = [('production_id', '=', self.production_id.id),
('active', 'in', [True, False]),
('route_id', '=', ro.route_id.id)]
if ro.route_id.routing_type == '表面工艺':
domain += [('process_parameters_id', '=', ro.process_parameters_id.id)]
elif ro.route_id.routing_tag == 'special' and ro.is_auto is False:
# display_name = ro.route_id.display_name
domain += [('id', '=', ro.id)]
elif ro.panel is not False:
domain += [('panel', '=', ro.panel)]
td_upd = self.env['sf.technology.design'].sudo().search(domain)
if td_upd:
ro.write({'sequence': td_upd.sequence, 'active': td_upd.active})
self.env['sf.technology.design'].sudo().unified_procedure_multiple_work_orders(technology_designs, production_item)
# for td_other in production_item.technology_design_ids:
# # if td_other.is_auto is False:
# # td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id)
# # if not td_del or td_del.active is False:
# # td_other.write({'active': False})
# for td_main in technology_designs:
# route_other = production_item.technology_design_ids.filtered(
# lambda td: td.route_id.id == td_main.route_id.id)
# if not route_other and td_main.active is True:
# production_item.write({'technology_design_ids': [(0, 0, {
# 'route_id': td_main.route_id.id,
# 'process_parameters_id': False if td_main.process_parameters_id is False else
# self.env[
# 'sf.production.process.parameter'].search(
# [('id', '=', td_main.process_parameters_id.id)]).id,
# 'sequence': td_main.sequence,
# 'is_auto': td_main.is_auto})]})
# else:
# for ro in route_other:
# domain = [('production_id', '=', self.production_id.id),
# ('active', 'in', [True, False]),
# ('route_id', '=', ro.route_id.id)]
# if ro.route_id.routing_type == '表面工艺':
# domain += [('process_parameters_id', '=', ro.process_parameters_id.id)]
# elif ro.route_id.routing_tag == 'special' and ro.is_auto is False:
# # display_name = ro.route_id.display_name
# domain += [('id', '=', ro.id)]
# elif ro.panel is not False:
# domain += [('panel', '=', ro.panel)]
# td_upd = self.env['sf.technology.design'].sudo().search(domain)
# if td_upd:
# ro.write({'sequence': td_upd.sequence, 'active': td_upd.active})
special_design = self.env['sf.technology.design'].sudo().search(
[('routing_tag', '=', 'special'), ('production_id', '=', production_item.id),
('is_auto', '=', False), ('active', 'in', [True, False])])
@@ -124,3 +125,4 @@ class ProductionTechnologyReAdjustWizard(models.TransientModel):
if workorders[
0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程':
workorders[0].state = 'waiting'

View File

@@ -11,7 +11,7 @@ class ProductionTechnologyWizard(models.TransientModel):
production_id = fields.Many2one('mrp.production', string='制造订单号')
origin = fields.Char(string='源单据')
is_technology_confirm = fields.Boolean(default=False)
is_technology_confirm = fields.Boolean(default=True)
def confirm(self):
if self.is_technology_confirm is True and self.production_id.product_id.categ_id.type in ['成品', '坯料']:
@@ -19,40 +19,44 @@ class ProductionTechnologyWizard(models.TransientModel):
('product_id', '=', self.production_id.product_id.id)]
else:
domain = [('id', '=', self.production_id.id)]
technology_designs = self.production_id.technology_design_ids
technology_designs = self.env['sf.technology.design'].sudo().search(
[('production_id', '=', self.production_id.id), ('active', 'in', [True, False])])
# technology_designs = self.production_id.technology_design_ids
productions = self.env['mrp.production'].search(domain)
for production in productions:
if production != self.production_id:
for td_other in production.technology_design_ids:
if td_other.is_auto is False:
td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id)
if not td_del or td_del.active is False:
td_other.write({'active': False})
for td_main in technology_designs:
route_other = production.technology_design_ids.filtered(
lambda td: td.route_id.id == td_main.route_id.id)
if not route_other and td_main.active is True:
production.write({'technology_design_ids': [(0, 0, {
'route_id': td_main.route_id.id,
'process_parameters_id': False if td_main.process_parameters_id is False else self.env[
'sf.production.process.parameter'].search(
[('id', '=', td_main.process_parameters_id.id)]).id,
'sequence': td_main.sequence})]})
else:
for ro in route_other:
domain = [('production_id', '=', self.production_id.id),
('active', 'in', [True, False]),
('route_id', '=', ro.route_id.id)]
if ro.route_id.routing_type == '表面工艺':
domain += [('process_parameters_id', '=', ro.process_parameters_id.id)]
elif ro.route_id.routing_tag == 'special' and ro.is_auto is False:
# display_name = ro.route_id.display_name
domain += [('id', '=', ro.id)]
elif ro.panel is not False:
domain += [('panel', '=', ro.panel)]
td_upd = self.env['sf.technology.design'].sudo().search(domain)
if td_upd:
ro.write({'sequence': td_upd.sequence, 'active': td_upd.active})
self.env['sf.technology.design'].sudo().unified_procedure_multiple_work_orders(technology_designs,
production)
# for td_other in production.technology_design_ids:
# if td_other.is_auto is False:
# td_del = technology_designs.filtered(lambda tdo: tdo.route_id.id == td_other.route_id.id)
# if not td_del or td_del.active is False:
# td_other.write({'active': False})
# for td_main in technology_designs:
# route_other = production.technology_design_ids.filtered(
# lambda td: td.route_id.id == td_main.route_id.id)
# if not route_other and td_main.active is True:
# production.write({'technology_design_ids': [(0, 0, {
# 'route_id': td_main.route_id.id,
# 'process_parameters_id': False if td_main.process_parameters_id is False else self.env[
# 'sf.production.process.parameter'].search(
# [('id', '=', td_main.process_parameters_id.id)]).id,
# 'sequence': td_main.sequence})]})
# else:
# for ro in route_other:
# domain = [('production_id', '=', self.production_id.id),
# ('active', 'in', [True, False]),
# ('route_id', '=', ro.route_id.id)]
# if ro.route_id.routing_type == '表面工艺':
# domain += [('process_parameters_id', '=', ro.process_parameters_id.id)]
# elif ro.route_id.routing_tag == 'special' and ro.is_auto is False:
# # display_name = ro.route_id.display_name
# domain += [('id', '=', ro.id)]
# elif ro.panel is not False:
# domain += [('panel', '=', ro.panel)]
# td_upd = self.env['sf.technology.design'].sudo().search(domain)
# if td_upd:
# ro.write({'sequence': td_upd.sequence, 'active': td_upd.active})
special_design = self.env['sf.technology.design'].sudo().search(
[('routing_tag', '=', 'special'), ('production_id', '=', production.id),
('is_auto', '=', False), ('active', 'in', [True, False])])
@@ -116,3 +120,4 @@ class ProductionTechnologyWizard(models.TransientModel):
if workorder[0].state in ['pending']:
if workorder[0].production_id.product_id.categ_id.type == '成品' and item.programming_state != '已编程':
workorder[0].state = 'waiting'
return productions

View File

@@ -287,6 +287,8 @@ class ReworkWizard(models.TransientModel):
self.production_id.update_programming_state()
self.production_id.write(
{'programming_state': '编程中', 'work_state': '编程中', 'state': 'progress'})
# ================= 返工完成,制造订单状态置为加工中 ==============
self.production_id.write({'state': 'progress', 'is_rework': False})
@api.onchange('production_id')
def onchange_processing_panel_id(self):

View File

@@ -11,13 +11,15 @@
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
'depends': ['sale', 'purchase', 'sf_plan', 'jikimo_message_notify', 'stock', 'sf_quality', 'mrp'],
'depends': ['sale', 'purchase', 'sf_plan', 'jikimo_message_notify', 'stock', 'sf_quality', 'mrp',
'sf_manufacturing','product'],
'data': [
'data/bussiness_node.xml',
'data/cron_data.xml',
'data/template_data.xml',
'security/ir.model.access.csv',
'views/mrp_workorder_views.xml',
'views/purchase_order_view.xml',
],
'test': [
],

View File

@@ -4,10 +4,12 @@ import logging
from odoo import http
from odoo.http import request
from odoo.addons.sf_mrs_connect.controllers.controllers import Sf_Mrs_Connect
from odoo.addons.sf_bf_connect.controllers.controllers import Sf_Bf_Connect
from odoo.addons.sf_base.commons.common import Common
_logger = logging.getLogger(__name__)
class MessageSfMrsConnect(Sf_Mrs_Connect):
@http.route('/api/cnc_processing/create', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
@@ -39,7 +41,8 @@ class MessageSfMrsConnect(Sf_Mrs_Connect):
_logger.info('无效用刀异常消息推送接口:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/api/maintenance_logs/notify', type='json', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
@http.route('/api/maintenance_logs/notify', type='json', auth='public', methods=['GET', 'POST'], csrf=False,
cors="*")
def maintenance_logs_notify(self, **kw):
res = {'code': 200, 'message': '设备故障日志信息推送成功'}
datas = request.httprequest.data
@@ -51,10 +54,26 @@ class MessageSfMrsConnect(Sf_Mrs_Connect):
try:
if not isinstance(log_id, list):
log_id = [log_id]
maintenance_logs = request.env['sf.maintenance.logs'].sudo().search([('id', 'in', [int(id) for id in log_id])])
maintenance_logs = request.env['sf.maintenance.logs'].sudo().search(
[('id', 'in', [int(id) for id in log_id])])
if maintenance_logs:
maintenance_logs.add_queue('设备故障')
except Exception as e:
res = {'code': 400, 'message': '设备故障信息推送失败', 'error': str(e)}
return json.JSONEncoder().encode(res)
class MessageSfBfConnect(Sf_Bf_Connect):
@http.route('/api/bfm_process_order/list', type='http', auth='sf_token', methods=['GET', 'POST'], csrf=False,
cors="*")
def get_bfm_process_order_list(self, **kw):
res = super(MessageSfBfConnect, self).get_bfm_process_order_list(**kw)
response_data = json.loads(res.data.decode('utf-8'))
if response_data['status'] == 1:
try:
_logger.info('已进入待接单消息推送:%s' % response_data)
sale_order = request.env['sale.order'].sudo().search([('name', '=', response_data['factory_order_no'])])
sale_order.add_queue('待接单')
except Exception as e:
logging.info('add_queue error:%s' % e)
return res

View File

@@ -22,6 +22,15 @@
<field name="model">sale.order</field>
</record>
<record id="bussiness_supply_method" model="jikimo.message.bussiness.node">
<field name="name">待确认供货方式</field>
<field name="model">sale.order</field>
</record>
<record id="bussiness_technology_to_confirmed" model="jikimo.message.bussiness.node">
<field name="name">待确认加工路线</field>
<field name="model">mrp.production</field>
</record>
<record id="transfer_inventory" model="jikimo.message.bussiness.node">
<field name="name">调拨入库</field>
@@ -47,7 +56,7 @@
<!--工单-->
<record id="bussiness_mrp_workorder_remind" model="jikimo.message.bussiness.node">
<field name="name">工单已下发通知</field>
<field name="model">mrp.workorder</field>
<field name="model">product.product</field>
</record>
<!--发货调拨-->
<record id="production_completed_warehouse_reminder" model="jikimo.message.bussiness.node">
@@ -106,5 +115,40 @@
<field name="name">设备故障</field>
<field name="model">sf.maintenance.logs</field>
</record>
<record id="bussiness_state_draft" model="jikimo.message.bussiness.node">
<field name="name">待排程</field>
<field name="model">mrp.production</field>
</record>
<record id="bussiness_outsourcing" model="jikimo.message.bussiness.node">
<field name="name">委外加工采购单提醒</field>
<field name="model">purchase.order</field>
</record>
<record id="bussiness_purchase" model="jikimo.message.bussiness.node">
<field name="name">外购订单采购单提醒</field>
<field name="model">purchase.order</field>
</record>
<record id="bussiness_process_outsourcing" model="jikimo.message.bussiness.node">
<field name="name">工序外协采购单通知</field>
<field name="model">purchase.order</field>
</record>
<record id="bussiness_outsourced_outbound" model="jikimo.message.bussiness.node">
<field name="name">工序外协发料通知</field>
<field name="model">mrp.production</field>
</record>
<record id="bussiness_purchase_order_warning" model="jikimo.message.bussiness.node">
<field name="name">采购订单预警提醒</field>
<field name="model">purchase.order</field>
</record>
<record id="bussiness_purchase_order_overdue" model="jikimo.message.bussiness.node">
<field name="name">采购单已逾期提醒</field>
<field name="model">purchase.order</field>
</record>
</data>
</odoo>

View File

@@ -10,7 +10,7 @@
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 待接单提醒:
单号:销售订单[{{name}}]({{url}})
单号:询价单[{{name}}]({{url}})
事项:请确认是否接单。
</field>
</record>
@@ -72,14 +72,14 @@
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 坯料发料提醒:
单号:产品[{{product_id}}]({{request_url}})
事项:共{{number}}个生产发料单待确认处理</field>
单号:发料单[{{name}}]({{request_url}})
事项:请确认坯料发料单并处理</field>
</record>
<record id="template_mrp_workorder_remind" model="jikimo.message.template">
<field name="name">工单已下发通知</field>
<field name="model_id" ref="mrp_workorder.model_mrp_workorder"/>
<field name="model">mrp.workorder</field>
<field name="model_id" ref="product.model_product_product"/>
<field name="model">product.product</field>
<field name="bussiness_node_id" ref="bussiness_mrp_workorder_remind"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
@@ -275,5 +275,119 @@
机台号:[{{maintenance_equipment_id.name}}]({{url}})
事项:{{create_date}}故障报警</field>
</record>
<record id="template_supply_method" model="jikimo.message.template">
<field name="name">待确认供货方式</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="model">sale.order</field>
<field name="bussiness_node_id" ref="bussiness_supply_method"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 待确认供货方式提醒:
单号:销售订单[{{name}}]({{url}})
事项:请确认供货方式。
</field>
</record>
<record id="template_technology_to_confirmed" model="jikimo.message.template">
<field name="name">待确认加工路线</field>
<field name="model_id" ref="mrp.model_mrp_production"/>
<field name="model">mrp.production</field>
<field name="bussiness_node_id" ref="bussiness_technology_to_confirmed"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 待确认加工路线提醒:
单号:产品[{{name}}]({{url}})
事项:有{{production_num}}个制造订单需要确认加工路线。
</field>
</record>
<record id="template_state_draft" model="jikimo.message.template">
<field name="name">待排程</field>
<field name="model_id" ref="mrp.model_mrp_production"/>
<field name="model">mrp.production</field>
<field name="bussiness_node_id" ref="bussiness_state_draft"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 待排程提醒:
单号:产品[{{name}}]({{url}})
事项:有{{production_num}}个制造订单待排程。
</field>
</record>
<record id="template_outsourcing_remind" model="jikimo.message.template">
<field name="name">委外加工采购单提醒</field>
<field name="model_id" ref="purchase.model_purchase_order"/>
<field name="model">purchase.order</field>
<field name="bussiness_node_id" ref="bussiness_outsourcing"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 委外加工采购通知:
单号:委外加工采购单[{{name}}]({{request_url}})
事项:请确认委外采购单并处理。</field>
</record>
<record id="template_purchase_remind" model="jikimo.message.template">
<field name="name">外购订单采购单提醒</field>
<field name="model_id" ref="purchase.model_purchase_order"/>
<field name="model">purchase.order</field>
<field name="bussiness_node_id" ref="bussiness_purchase"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 外购订单采购通知:
单号:外购采购单[{{name}}]({{request_url}})
事项:请确认外购采购单并处理。</field>
</record>
<record id="template_process_outsourcing_remind" model="jikimo.message.template">
<field name="name">工序外协采购单通知</field>
<field name="model_id" ref="purchase.model_purchase_order"/>
<field name="model">purchase.order</field>
<field name="bussiness_node_id" ref="bussiness_process_outsourcing"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 工序外协采购单通知:
单号:工序外协采购,产品[{{name}}]({{url}})
事项:请确认{{num}}个工序外协采购单并处理。</field>
</record>
<record id="template_outsourced_outbound_remind" model="jikimo.message.template">
<field name="name">工序外协发料通知</field>
<field name="model_id" ref="mrp.model_mrp_production"/>
<field name="model">mrp.production</field>
<field name="bussiness_node_id" ref="bussiness_outsourced_outbound"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 工序外协发料提醒:
单号:产品[{{name}}]({{url}})发料单
事项:请确认{{num}}个工序外协发料单并发料处理。</field>
</record>
<record id="template_purchase_order_warning" model="jikimo.message.template">
<field name="name">采购订单预警提醒</field>
<field name="model_id" ref="purchase.model_purchase_order"/>
<field name="model">purchase.order</field>
<field name="bussiness_node_id" ref="bussiness_purchase_order_warning"/>
<field name="msgtype">markdown</field>
<field name="send_type">timing</field>
<field name="urgency">normal</field>
<field name="content">### 采购订单预警提醒
事项:[共有{{num}}个采购订单有逾期风险]({{url}})
</field>
</record>
<record id="template_purchase_order_overdue" model="jikimo.message.template">
<field name="name">采购单已逾期提醒</field>
<field name="model_id" ref="purchase.model_purchase_order"/>
<field name="model">purchase.order</field>
<field name="bussiness_node_id" ref="bussiness_purchase_order_overdue"/>
<field name="msgtype">markdown</field>
<field name="send_type">timing</field>
<field name="urgency">normal</field>
<field name="content">### 采购单已逾期提醒
事项:[共有{{num}}个采购订单已逾期]({{url}})
</field>
</record>
</data>
</odoo>

View File

@@ -10,3 +10,6 @@ from . import sf_message_functional_tool_dismantle
from . import sf_message_mrp_production
from . import sf_message_quality_cnc_test
from . import sf_message_maintenance_logs
from . import sf_message_mrp_production_wizard
from . import sf_message_mrp_production_adjust_wizard
from . import sf_message_product

View File

@@ -14,19 +14,24 @@ class SFMessageMrpProduction(models.Model):
'workorder_ids.state', 'product_qty', 'qty_producing')
def _compute_state(self):
super(SFMessageMrpProduction, self)._compute_state()
for record in self:
if record.state in ['scrap', 'done']:
# 查询制造订单下的所有未完成的生产订单
mrp_production = record.env['mrp.production'].search(
[('origin', '=', record.origin), ('state', 'not in', ['scrap', 'done'])])
if not mrp_production:
mrp_production_queue = self.env["jikimo.message.queue"].search([('res_id', '=', record.id)])
if not mrp_production_queue:
record.add_queue('生产完工入库提醒')
try:
for record in self:
if record.state in ['scrap', 'done']:
# 查询制造订单下的所有未完成的生产订单
mrp_production = record.env['mrp.production'].search(
[('origin', '=', record.origin), ('state', 'not in', ['scrap', 'done'])])
if not mrp_production:
mrp_production_queue = self.env["jikimo.message.queue"].search([('res_id', '=', record.id)])
if not mrp_production_queue:
record.add_queue('生产完工入库提醒')
except Exception as e:
logging.info('add_queue生产完工入库提醒 error:%s' % e)
# 获取发送消息内容
def _get_message(self, message_queue_ids):
contents = []
unique_products = set()
technology_to_confirmed = set()
for message_queue_id in message_queue_ids:
if message_queue_id.message_template_id.name == '生产完工入库提醒':
content = message_queue_id.message_template_id.content
@@ -40,15 +45,65 @@ class SFMessageMrpProduction(models.Model):
content = content.replace('{{name}}', stock_picking_sfp.name).replace(
'{{sale_order_name}}', mrp_production.origin).replace('{{request_url}}', url)
contents.append(content)
if message_queue_id.message_template_id.name == '待确认加工路线':
content = message_queue_id.message_template_id.content
mrp_production = self.env['mrp.production'].sudo().search([('id', '=', int(message_queue_id.res_id))])
technology_to_confirmed.add(mrp_production.product_id.id)
if message_queue_id.message_template_id.name == '待排程':
content = message_queue_id.message_template_id.content
mrp_production = self.env['mrp.production'].sudo().search([('id', '=', int(message_queue_id.res_id))])
unique_products.add(mrp_production.product_id.id)
if message_queue_id.message_template_id.name == '工序外协发料通知':
content = message_queue_id.message_template_id.content
mrp_production = self.env['mrp.production'].sudo().search([('id', '=', int(message_queue_id.res_id))])
mrp_production_list = self.env['mrp.production'].sudo().search(
[('product_id', '=', mrp_production.product_id.id)])
mrp_production_names = mrp_production_list.mapped('name')
stock_picking_num = self.env['stock.picking'].sudo().search_count(
[('origin', 'in', mrp_production_names), ('state', '=', 'assigned')])
if stock_picking_num >= 1:
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
action_id = self.env.ref('stock.action_picking_tree_ready').id
url_with_id = f"{url}/web#view_type=list&action={action_id}"
content = content.replace('{{name}}', mrp_production.product_id.name).replace('{{url}}',
url_with_id).replace(
'{{num}}', str(stock_picking_num))
contents.append(content)
if unique_products:
action_id = self.env.ref('sf_plan.sf_production_plan_action1').id
unique_products_contents = self.get_production_info(content, unique_products, 'confirmed',
action_id)
contents.extend(unique_products_contents)
if technology_to_confirmed:
action_id = self.env.ref('mrp.mrp_production_action').id
technology_to_confirmed_contents = self.get_production_info(content, technology_to_confirmed,
'technology_to_confirmed',
action_id)
contents.extend(technology_to_confirmed_contents)
logging.info('生产完工入库提醒: %s' % contents)
return contents, message_queue_ids
def get_production_info(self, content, product_ids, state, action_id):
contents = []
for products_id in product_ids:
product_name = self.env['product.product'].sudo().search([('id', '=', products_id)]).name
production_num = self.env['mrp.production'].sudo().search_count(
[('product_id', '=', products_id), ('state', '=', state)])
if production_num >= 1:
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
url_with_id = f"{url}/web#view_type=list&action={action_id}"
new_content = (content.replace('{{name}}', product_name)
.replace('{{url}}', url_with_id)
.replace('{{production_num}}', str(production_num)))
contents.append(new_content)
return contents
def request_url(self, id):
url = self.env['ir.config_parameter'].get_param('web.base.url')
action_id = self.env.ref('stock.action_picking_tree_all').id
menu_id = self.env['ir.model.data'].search([('name', '=', 'module_theme_treehouse')]).id
# 查询参数
params = {'id': id, 'menu_id': menu_id, 'action': action_id, 'model': 'mrp.production',
params = {'id': id, 'menu_id': menu_id, 'action': action_id, 'model': 'mrp.production',
'view_type': 'form'}
# 拼接查询参数
query_string = urlencode(params)

View File

@@ -0,0 +1,17 @@
import logging
from odoo import models, fields, api, _
class SFMessageMrpProductionAdjustWizard(models.TransientModel):
_name = 'sf.production.technology.re_adjust.wizard'
_description = "制造订单工艺调整"
_inherit = ['sf.production.technology.re_adjust.wizard', 'jikimo.message.dispatch']
def confirm(self):
super(SFMessageMrpProductionAdjustWizard, self).confirm()
try:
for production_info in self.production_id:
if production_info.state == 'technology_to_confirmed':
production_info.add_queue('待确认加工路线')
except Exception as e:
logging.info('add_queue待确认加工路线 error:%s' % e)

View File

@@ -0,0 +1,23 @@
import logging
from odoo import models, fields, api, _
class SFMessageMrpProductionWizard(models.TransientModel):
_name = 'sf.production.technology.wizard'
_description = "制造订单工艺确认向导"
_inherit = ['sf.production.technology.wizard', 'jikimo.message.dispatch']
def confirm(self):
productions = super(SFMessageMrpProductionWizard, self).confirm()
try:
for production_info in self.production_id:
if production_info.state == 'confirmed' and production_info.product_id.categ_id.type == '成品':
production_info.add_queue('待排程')
for production_id in productions:
workorder_ids = production_id.workorder_ids.filtered(
lambda p: p.routing_type == '表面工艺' and p.state != 'cancel')
for workorder_id in workorder_ids:
purchase_orders_id = workorder_id._get_surface_technics_purchase_ids()
purchase_orders_id.add_queue('工序外协采购单通知')
except Exception as e:
logging.info('add_queue待排程 error:%s' % e)

View File

@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
from urllib.parse import urlencode
class SFMessagePlan(models.Model):
_name = 'product.product'
_inherit = ['product.product', 'jikimo.message.dispatch']
def _get_message(self, message_queue_ids):
contents = []
for message_queue_id in message_queue_ids:
if message_queue_id.message_template_id.name == '工单已下发通知':
content = message_queue_id.message_template_id.content
product_product = self.env['product.product'].sudo().search([('id', '=', int(message_queue_id.res_id))])
mrp_production_list = self.env['mrp.production'].sudo().search(
[('product_id', '=', product_product.id)])
production_num = 0
for mrp_production_info in mrp_production_list:
routing_type = '人工线下加工' if mrp_production_info.production_type == '人工线下加工' else '装夹预调'
mrp_production_ready = mrp_production_info.workorder_ids.filtered(
lambda w: w.routing_type == routing_type and w.state == 'ready')
if mrp_production_ready:
production_num += 1
if production_num >= 1:
url = self.get_request_url()
content = content.replace('{{product_id}}', product_product.name).replace(
'{{number}}', str(production_num)).replace(
'{{request_url}}', url)
contents.append(content)
return contents
def get_request_url(self):
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
action_id = self.env.ref('sf_message.mrp_workorder_issued_action').id
menu_id = self.env.ref('mrp.menu_mrp_root').id
active_id = self.env['mrp.workcenter'].sudo().search([('name', '=', '工件装夹中心')]).id
# 查询参数
params = {'menu_id': menu_id, 'action': action_id, 'model': 'mrp.workorder',
'view_type': 'list', 'active_id': active_id}
# 拼接查询参数
query_string = urlencode(params)
# 拼接URL
full_url = url + "/web#" + query_string
return full_url

View File

@@ -8,20 +8,62 @@ class SFMessagePurchase(models.Model):
def _get_message(self, message_queue_ids):
contents = []
process_outsourcing = set()
for message_queue_id in message_queue_ids:
if message_queue_id.message_template_id.name == '坯料采购提醒':
if message_queue_id.message_template_id.name in (
'坯料采购提醒', '委外加工采购单提醒', '外购订单采购单提醒'):
content = message_queue_id.message_template_id.content
url = self.request_url(int(message_queue_id.res_id))
purchase_order_line = self.env['purchase.order'].search([('id', '=', int(message_queue_id.res_id))])
content = content.replace('{{name}}', purchase_order_line.name).replace(
'{{request_url}}', url)
contents.append(content)
if message_queue_id.message_template_id.name == '工序外协采购单通知':
content = message_queue_id.message_template_id.content
purchase_order_line = self.env['purchase.order'].sudo().search(
[('id', '=', int(message_queue_id.res_id))])
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', purchase_order_line.origin)])
process_outsourcing.add(mrp_production.product_id.id)
if message_queue_id.message_template_id.name in ('采购订单预警提醒', '采购单已逾期提醒'):
content = message_queue_id.message_template_id.content
if message_queue_id.message_template_id.name == '采购订单预警提醒':
domain = [('delivery_warning', '=', 'warning')]
action_id = self.env.ref("sf_message.purchase_form_warning_action").id
else:
domain = [('delivery_warning', '=', 'overdue')]
action_id = self.env.ref("sf_message.purchase_form_overdue_action").id
purchase_order_num = self.env['purchase.order'].sudo().search_count(domain)
if purchase_order_num >= 1:
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
menu_id = self.env.ref('purchase.menu_purchase_form_action').id
url_with_id = f"{url}/web#view_type=list&action={action_id}&menu_id={menu_id}"
content = content.replace('{{url}}', url_with_id).replace('{{num}}', str(purchase_order_num))
contents.append(content)
if process_outsourcing:
content_info = content
for products_id in process_outsourcing:
production_num = 0
product_name = self.env['product.product'].sudo().search([('id', '=', products_id)]).name
production_list = self.env['mrp.production'].sudo().search(
[('product_id', '=', products_id), ('state', '=', 'confirmed')])
for production_info in production_list:
workorder_ids = len(production_info.workorder_ids.filtered(
lambda p: p.routing_type == '表面工艺' and p.state != 'cancel'))
production_num += workorder_ids
if production_num >= 1:
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
action_id = self.env.ref('purchase.purchase_form_action').id
url_with_id = f"{url}/web#view_type=list&action={action_id}"
new_content = (content_info.replace('{{name}}', product_name)
.replace('{{url}}', url_with_id)
.replace('{{num}}', str(production_num)))
contents.append(new_content)
return contents, message_queue_ids
def request_url(self, id):
url = self.env['ir.config_parameter'].get_param('web.base.url')
action_id = self.env.ref('purchase.purchase_form_action').id
menu_id = self.env['ir.model.data'].search([('name', '=', 'module_website_payment')]).id
menu_id = self.env.ref('purchase.menu_purchase_form_action').id
# 查询参数
params = {'id': id, 'menu_id': menu_id, 'action': action_id,
'model': 'purchase.order',
@@ -31,3 +73,27 @@ class SFMessagePurchase(models.Model):
# 拼接URL
full_url = url + "/web#" + query_string
return full_url
def _overdue_or_warning_func(self):
last_overdue_order, last_warning_order = super(SFMessagePurchase, self)._overdue_or_warning_func()
if last_overdue_order:
business_node_id = self.env.ref('sf_message.template_purchase_order_overdue').id
purchase_order_has = self._get_message_queue(business_node_id)
if not purchase_order_has:
last_overdue_order.add_queue("采购单已逾期提醒")
if last_warning_order:
business_node_id = self.env.ref('sf_message.template_purchase_order_warning').id
purchase_order_has = self._get_message_queue(business_node_id)
if not purchase_order_has:
last_warning_order.add_queue("采购订单预警提醒")
def _get_message_queue(self, business_node_id):
message_template = self.env["jikimo.message.template"].sudo().search([
("model", "=", self._name),
("bussiness_node_id", "=", business_node_id)
], limit=1)
purchase_order_has = self.env['jikimo.message.queue'].sudo().search([
('message_status', '=', 'pending'),
('message_template_id', '=', message_template.id)
])
return purchase_order_has

View File

@@ -8,17 +8,6 @@ class SFMessageSale(models.Model):
_name = 'sale.order'
_inherit = ['sale.order', 'jikimo.message.dispatch']
@api.model_create_multi
def create(self, vals_list):
res = super(SFMessageSale, self).create(vals_list)
if res:
try:
logging.info('add_queue res:%s' % res)
res.add_queue('待接单')
except Exception as e:
logging.info('add_queue error:%s' % e)
return res
# 确认接单
def action_confirm(self):
res = super(SFMessageSale, self).action_confirm()
@@ -29,19 +18,34 @@ class SFMessageSale(models.Model):
purchase_order_id = []
if picking_ids:
for picking_id in picking_ids:
picking_id.add_queue('待确认加工路线')
purchase_order_ids = (
picking_id.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id |
picking_id.procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id).ids
purchase_order_id.extend(purchase_order_ids)
if purchase_order_id:
purchase_order_list = self.env['purchase.order'].sudo().search([('id', 'in', purchase_order_id)])
purchase_order_list = self.env['purchase.order'].sudo().search(
[('id', 'in', purchase_order_id)])
for purchase_order_info in purchase_order_list:
purchase_order_info.add_queue('坯料采购提醒')
purchase_order_ids = self.order_line.purchase_line_ids.order_id | self.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id | self.procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id
for purchase_order_id in purchase_order_ids:
if purchase_order_id.purchase_type == 'outsourcing':
purchase_order_id.add_queue('委外加工采购单提醒')
if purchase_order_id.purchase_type == 'standard':
purchase_order_id.add_queue('外购订单采购单提醒')
except Exception as e:
logging.info('add_queue error:%s' % e)
logging.info('action_confirm res:%s' % res)
return res
def confirm_to_supply_method(self):
super(SFMessageSale, self).confirm_to_supply_method()
try:
self.add_queue('待确认供货方式')
except Exception as e:
logging.info('add_queue待确认供货方式 error:%s' % e)
# 继承并重写jikimo.message.dispatch的_get_message()
def _get_message(self, message_queue_ids):
contents = []
@@ -53,9 +57,11 @@ class SFMessageSale(models.Model):
time_range = timedelta(minutes=2)
i = 0
for item in message_queue_ids:
if item.message_template_id.bussiness_node_id.name == '待接单':
if item.message_template_id.bussiness_node_id.name in ('待接单', '待确认供货方式'):
content, _ = super(SFMessageSale, self)._get_message(item)
action_id = self.env.ref('sale.action_quotations_with_onboarding').id
action_id = self.env.ref('sale.action_quotations_with_onboarding').id \
if item.message_template_id.bussiness_node_id.name == '待接单' \
else self.env.ref('sale.action_orders').id
url_with_id = f"{url}/web#id={item.res_id}&view_type=form&action={action_id}"
content = content[0].replace('{{url}}', url_with_id)
contents.append(content)

View File

@@ -12,26 +12,44 @@ class SFMessageStockPicking(models.Model):
@api.model_create_multi
def create(self, vals):
result = super(SFMessageStockPicking, self).create(vals)
for obj in result:
if obj.location_id.name == '进货' and obj.location_dest_id.name == '刀具房':
obj.add_queue('调拨入库')
try:
for obj in result:
if obj.location_id.name == '进货' and obj.location_dest_id.name == '刀具房':
obj.add_queue('调拨入库')
except Exception as e:
logging.info('add_queue调拨入库 error:%s' % e)
return result
@api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id')
def _compute_state(self):
super(SFMessageStockPicking, self)._compute_state()
for record in self:
if record.state == 'assigned' and record.check_in == 'PC':
record.add_queue('坯料发料提醒')
try:
for record in self:
if (record.state == 'assigned' and record.picking_type_id.sequence_code == 'PC'
and record.product_id.categ_id.type == '坯料'):
record.add_queue('坯料发料提醒')
if record.picking_type_id.sequence_code == 'SFP' and record.state == 'done':
stock_picking_sfp = record.env['stock.picking'].search(
[('origin', '=', record.origin), ('state', '!=', 'done'),
('picking_type_id.sequence_code', '=', 'SFP')])
if not stock_picking_sfp:
stock_picking_send = self.env["jikimo.message.queue"].sudo().search([('res_id', '=', record.id)])
if not stock_picking_send:
record.add_queue('订单发货提醒')
if record.picking_type_id.sequence_code == 'SFP' and record.state == 'done':
stock_picking_sfp = record.env['stock.picking'].search(
[('origin', '=', record.origin), ('state', '!=', 'done'),
('picking_type_id.sequence_code', '=', 'SFP')])
if not stock_picking_sfp:
stock_picking_send = self.env["jikimo.message.queue"].sudo().search(
[('res_id', '=', record.id)])
if not stock_picking_send:
record.add_queue('订单发货提醒')
if record.picking_type_id.sequence_code == 'OCOUT' and record.state == 'assigned':
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', record.origin)])
production_list = self.env['mrp.production'].sudo().search(
[('product_id', '=', mrp_production.product_id.id)])
manufacturing_order_names = production_list.mapped('name')
stock_picking_list = self.env['stock.picking'].sudo().search(
[('origin', 'in', manufacturing_order_names), ('picking_type_id.sequence_code', '=', 'OCOUT')])
all_ready_or_done = all(picking.state in ['assigned', 'done'] for picking in stock_picking_list)
if all_ready_or_done:
mrp_production.add_queue('工序外协发料通知')
except Exception as e:
logging.info('add_queue_compute_state error:%s' % e)
def deal_stock_picking_sfp(self, message_queue_id): # 处理订单发货提醒
content = None
@@ -49,27 +67,18 @@ class SFMessageStockPicking(models.Model):
def _get_message(self, message_queue_ids):
contents = []
product_id = []
for message_queue_id in message_queue_ids:
i = 0
if message_queue_id.message_template_id.name == '坯料发料提醒':
content = message_queue_id.message_template_id.content
stock_picking_line = self.env['stock.picking'].sudo().search([('id', '=', int(message_queue_id.res_id))])
mrp_production_info = self.env['mrp.production'].sudo().search(
[('name', '=', stock_picking_line.origin)])
mrp_production_list = self.env['mrp.production'].sudo().search(
[('product_id', '=', mrp_production_info.product_id.id)])
for mrp_production_line in mrp_production_list:
picking_ids = mrp_production_line.picking_ids
for picking_id in picking_ids:
if picking_id.state == 'assigned' and picking_id.check_in == 'PC':
i += 1
if i > 0 and mrp_production_info.product_id.id not in product_id:
url = self.request_url()
content = content.replace('{{product_id}}', mrp_production_info.product_id.name).replace(
'{{number}}', str(i)).replace('{{request_url}}', url)
product_id.append(mrp_production_info.product_id.id)
contents.append(content)
stock_picking_line = self.env['stock.picking'].sudo().search(
[('id', '=', int(message_queue_id.res_id))])
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
action_id = self.env.ref('stock.action_picking_tree_ready').id
menu_id = self.env.ref('stock.menu_stock_root').id
url_with_id = f"{url}/web#view_type=form&action={action_id}&menu_id={menu_id}&id={stock_picking_line.id}"
content = content.replace('{{name}}', stock_picking_line.name).replace(
'{{request_url}}', url_with_id)
contents.append(content)
elif message_queue_id.message_template_id.name == '订单发货提醒':
content = self.deal_stock_picking_sfp(message_queue_id)
if content:
@@ -86,19 +95,6 @@ class SFMessageStockPicking(models.Model):
else:
return super(SFMessageStockPicking, self).get_special_url(id, tmplate_name, special_name, model_id)
def request_url(self):
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
action_id = self.env.ref('stock.stock_picking_type_action').id
menu_id = self.env['ir.model.data'].sudo().search([('name', '=', 'module_theme_treehouse')]).id
# 查询参数
params = {'menu_id': menu_id, 'action': action_id, 'model': 'stock.picking',
'view_type': 'kanban'}
# 拼接查询参数
query_string = urlencode(params)
# 拼接URL
full_url = url + "/web#" + query_string
return full_url
def request_url1(self, id):
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
action_id = self.env.ref('stock.action_picking_tree_all').id

View File

@@ -16,4 +16,6 @@ class SfMessageTemplate(models.Model):
res.append('mrp.workorder')
res.append('sf.maintenance.logs')
res.append('quality.cnc.test')
res.append('mrp.production')
res.append('product.product')
return res

View File

@@ -12,19 +12,30 @@ class SFMessageWork(models.Model):
_name = 'mrp.workorder'
_inherit = ['mrp.workorder', 'jikimo.message.dispatch']
@api.depends('production_availability', 'blocked_by_workorder_ids.state', 'production_id.tool_state')
@api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state',
'production_id.tool_state', 'production_id.schedule_state', 'sequence',
'production_id.programming_state')
def _compute_state(self):
super(SFMessageWork, self)._compute_state()
for workorder in self:
if workorder.state == 'ready' and workorder.routing_type == '装夹预调':
min_sequence_wk = None
work_ids = workorder.production_id.workorder_ids.filtered(lambda w: w.routing_type == '装夹预调')
if work_ids:
min_sequence_wk = work_ids.sorted(key=lambda w: w.sequence)[0]
if (
workorder.state == 'ready' and workorder.routing_type == '装夹预调' and workorder.id == min_sequence_wk.id) or (
workorder.state == 'ready' and workorder.routing_type == '人工线下加工'):
message_template = self.env["jikimo.message.template"].sudo().search(
[("name", "=", '工单已下发通知')], limit=1)
jikimo_message_queue = self.env['jikimo.message.queue'].sudo().search(
[('res_id', '=', workorder.id), ("message_status", "=", "pending")])
[('res_id', '=', workorder.production_id.product_id.id),
("message_status", "in", ("pending", "sent")),
('message_template_id', '=', message_template.id)])
if not jikimo_message_queue:
workorder.add_queue('工单已下发通知')
workorder.production_id.product_id.add_queue('工单已下发通知')
def _get_message(self, message_queue_ids):
contents = []
product_id = []
bussiness_node = None
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
current_time_strf = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
@@ -37,20 +48,7 @@ class SFMessageWork(models.Model):
}
i = 0
for message_queue_id in message_queue_ids:
if message_queue_id.message_template_id.name == '工单已下发通知':
content = message_queue_id.message_template_id.content
mrp_workorder_line = self.env['mrp.workorder'].sudo().search([('id', '=', int(message_queue_id.res_id))])
mrp_workorder_list = self.env['mrp.workorder'].sudo().search(
[('product_id', '=', mrp_workorder_line.product_id.id), ('state', '=', 'ready'),
('routing_type', '=', '装夹预调')])
if len(mrp_workorder_list) > 0 and mrp_workorder_line.product_id.id not in product_id:
url = self.request_url()
content = content.replace('{{product_id}}', mrp_workorder_line.product_id.name).replace(
'{{number}}', str(len(mrp_workorder_list))).replace(
'{{request_url}}', url)
product_id.append(mrp_workorder_line.product_id.id)
contents.append(content)
elif message_queue_id.message_template_id.name in template_names['预警'] + template_names['已逾期']:
if message_queue_id.message_template_id.name in template_names['预警'] + template_names['已逾期']:
item = message_queue_id.message_template_id
bussiness_node = item.bussiness_node_id.name
for reminder_time in item.reminder_time_ids:
@@ -95,20 +93,6 @@ class SFMessageWork(models.Model):
contents.append(content)
return contents, message_queue_ids
def request_url(self):
url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
action_id = self.env.ref('sf_message.mrp_workorder_issued_action').id
menu_id = self.env['ir.model.data'].sudo().search([('name', '=', 'module_stock_dropshipping')]).id
active_id = self.env['mrp.workcenter'].sudo().search([('name', '=', '工件装夹中心')]).id
# 查询参数
params = {'menu_id': menu_id, 'action': action_id, 'model': 'mrp.workorder',
'view_type': 'list', 'active_id': active_id}
# 拼接查询参数
query_string = urlencode(params)
# 拼接URL
full_url = url + "/web#" + query_string
return full_url
def _overdue_or_warning_func(self):
workorders = self.env['mrp.workorder'].search(
[("state", "in", ["ready", "progress", "to be detected"]), ('schedule_state', '=', '已排')])

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="purchase_form_warning_action" model="ir.actions.act_window">
<field name="name">采购订单</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order</field>
<field name="view_mode">tree,kanban,form,pivot,graph,calendar,activity</field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('purchase.purchase_order_view_tree')}),
(0, 0, {'view_mode': 'kanban', 'view_id': ref('purchase.purchase_order_view_kanban_without_dashboard')}),
]"/>
<field name="domain">[('state','in',('purchase', 'done'))]</field>
<field name="search_view_id" ref="purchase.purchase_order_view_search"/>
<field name="context">{'search_default_filter_order_warning':1}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
还没有采购订单, 我们先创建一个!
</p>
<p>
当您下单到您的供应商,确定您的询价它会变成采购订单.
</p>
</field>
</record>
<record id="purchase_form_overdue_action" model="ir.actions.act_window">
<field name="name">采购订单</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order</field>
<field name="view_mode">tree,kanban,form,pivot,graph,calendar,activity</field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('purchase.purchase_order_view_tree')}),
(0, 0, {'view_mode': 'kanban', 'view_id': ref('purchase.purchase_order_view_kanban_without_dashboard')}),
]"/>
<field name="domain">[('state','in',('purchase', 'done'))]</field>
<field name="search_view_id" ref="purchase.purchase_order_view_search"/>
<field name="context">{'search_default_filter_order_overdue':1}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
还没有采购订单, 我们先创建一个!
</p>
<p>
当您下单到您的供应商,确定您的询价它会变成采购订单.
</p>
</field>
</record>
</odoo>

View File

@@ -13,7 +13,8 @@ class sf_production_plan(models.Model):
_description = 'sf_production_plan'
_inherit = ['mail.thread']
# _order = 'state desc, write_date desc'
part_name = fields.Char('零件名称', related='product_id.part_name', readonly=True)
part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True)
state = fields.Selection([
('draft', '待排程'),
('done', '已排程'),

View File

@@ -17,6 +17,8 @@
decoration-danger="state == 'finished'"/>
<field name="name"/>
<field name="origin"/>
<field name="part_number" optional="show"/>
<field name="part_name" optional="hide"/>
<field name="order_deadline" widget="date"/>
<field name="product_qty"/>
<field name="production_line_id"/>

View File

@@ -16,7 +16,7 @@ class SfQualityCncTest(models.Model):
equipment_id = fields.Many2one(related='workorder_id.equipment_id', string='加工设备')
production_line_id = fields.Many2one(related='workorder_id.production_line_id',
string='生产线')
part_number = fields.Char(related='workorder_id.part_number', string='成品零件图号')
part_number = fields.Char(related='workorder_id.part_number', string='零件图号')
detection_report = fields.Binary(related='workorder_id.detection_report', readonly=True, string='检测报告')
state = fields.Selection([
('waiting', '待判定'),

View File

@@ -18,7 +18,8 @@
<field name="production_id"/>
<field name="processing_panel"/>
<field name="product_id"/>
<field name="part_number"/>
<field name="part_number" optional="show"/>
<field name="part_name" optional="hide"/>
<field name="number"/>
<field name="state" widget="badge"
decoration-success="state == 'done'"

View File

@@ -16,6 +16,7 @@
'security/ir.model.access.csv',
'wizard/sale_order_wizard_views.xml',
'wizard/purchase_order_wizard_views.xml',
'data/cron_data.xml',
'views/sale_team.xml',
'views/sale_order_view.xml',
'views/res_partner_view.xml',

View File

@@ -0,0 +1,16 @@
<odoo>
<data noupdate="1">
<record model="ir.cron" id="ir_cron_purchase_order_overdue_warning">
<field name="name">检查采购单是否已逾期预警和逾期</field>
<field name="model_id" ref="model_purchase_order"/>
<field name="state">code</field>
<field name="code">model._overdue_or_warning_func()</field>
<field name="interval_number">10</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="user_id" ref="base.user_root"/>
<field name="active" eval="True"/>
</record>
</data>
</odoo>

View File

@@ -170,9 +170,9 @@ class ReSaleOrder(models.Model):
def _compute_purchase_order_count(self):
for order in self:
order.purchase_order_count = len(order._get_purchase_orders().filtered(
lambda po: po.purchase_type not in ['consignment']))
lambda po: po.purchase_type not in ['outsourcing']))
order.consignment_purchase_order_count = len(order._get_purchase_orders().filtered(
lambda po: po.purchase_type in ['consignment']))
lambda po: po.purchase_type in ['outsourcing']))
def action_view_purchase_orders(self):
"""
@@ -180,7 +180,7 @@ class ReSaleOrder(models.Model):
"""
self.ensure_one()
purchase_order_ids = self._get_purchase_orders().filtered(
lambda po: po.purchase_type not in ['consignment']).ids
lambda po: po.purchase_type not in ['outsourcing']).ids
action = {
'res_model': 'purchase.order',
'type': 'ir.actions.act_window',
@@ -203,21 +203,21 @@ class ReSaleOrder(models.Model):
委外加工
"""
self.ensure_one()
consignment_purchase_order_ids = self._get_purchase_orders().filtered(
lambda po: po.purchase_type in ['consignment']).ids
outsourcing_purchase_order_ids = self._get_purchase_orders().filtered(
lambda po: po.purchase_type in ['outsourcing']).ids
action = {
'res_model': 'purchase.order',
'type': 'ir.actions.act_window',
}
if len(consignment_purchase_order_ids) == 1:
if len(outsourcing_purchase_order_ids) == 1:
action.update({
'view_mode': 'form',
'res_id': consignment_purchase_order_ids[0],
'res_id': outsourcing_purchase_order_ids[0],
})
else:
action.update({
'name': _("%s生成委外加工订单", self.name),
'domain': [('id', 'in', consignment_purchase_order_ids)],
'domain': [('id', 'in', outsourcing_purchase_order_ids)],
'view_mode': 'tree,form',
})
return action
@@ -225,7 +225,8 @@ class ReSaleOrder(models.Model):
class ResaleOrderLine(models.Model):
_inherit = 'sale.order.line'
# part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True)
part_name = fields.Char('零件名称', related='product_id.part_name', readonly=True)
model_glb_file = fields.Binary('模型的glb文件', compute='_compute_model_glb_file', store=True)
# product_template_id = fields.Many2one(
# string="产品",
@@ -281,13 +282,34 @@ class RePurchaseOrder(models.Model):
store=True)
purchase_type = fields.Selection(
[('standard', '标准采购'), ('consignment', '委外加'), ('outsourcing', '序外协'), ('outside', '外购订单')],
string='采购类型', default='standard')
[('standard', '标准采购'), ('consignment', '序外协'), ('outsourcing', '委外加'), ('outside', '外购订单')],
string='采购类型', default='standard', store=True, compute='_compute_purchase_type')
origin_sale_id = fields.Many2one('sale.order', string='销售订单号', compute='_compute_origin_sale_id')
# 合同编号
contract_number = fields.Char(string='合同编号', size=20)
# 合同概况
contract_summary = fields.Text(string='合同概况')
@api.depends('origin')
def _compute_purchase_type(self):
for purchase in self:
order_id = self.env['sale.order'].sudo().search([('name', '=', purchase.origin)])
if order_id:
product_list = [line.product_id.id for line in purchase.order_line]
for order_line in order_id.order_line:
if order_line.supply_method == 'purchase':
if order_line.product_id.id in product_list:
purchase.purchase_type = 'outside'
break
elif order_line.supply_method == 'outsourcing':
if order_line.product_id.id in product_list:
purchase.purchase_type = 'outsourcing'
break
@api.depends('order_line.move_dest_ids.group_id.mrp_production_ids',
'order_line.move_ids.move_dest_ids.group_id.mrp_production_ids')
'order_line.move_ids.move_dest_ids.group_id.mrp_production_ids', 'origin')
def _compute_origin_sale_id(self):
for purchase in self:
productions_ids = purchase._get_mrp_productions()
@@ -295,8 +317,16 @@ class RePurchaseOrder(models.Model):
if productions_ids[0].sale_order_id:
purchase.origin_sale_id = productions_ids[0].sale_order_id.id
continue
order_id = self.env['sale.order'].sudo().search([('name', '=', purchase.origin)])
if order_id:
purchase.origin_sale_id = order_id.id
continue
purchase.origin_sale_id = False
delivery_warning = fields.Selection([('normal', '正常'), ('warning', '预警'), ('overdue', '已逾期')],
string='交期状态', default='normal',
tracking=True)
@api.depends('partner_id')
def _compute_user_id(self):
if not self.user_id:
@@ -379,12 +409,33 @@ class RePurchaseOrder(models.Model):
return result
# # 采购订单逾期预警和已逾期
def _overdue_or_warning_func(self):
purchase_order = self.sudo().search(
[('state', 'in', ['purchase']), ('date_planned', '!=', False),
('receipt_status', 'in', ('partial', 'pending'))])
last_overdue_order = None
last_warning_order = None
for item in purchase_order:
current_time = datetime.datetime.now()
if item.date_planned <= current_time: # 已逾期
item.delivery_warning = 'overdue'
last_overdue_order = item
elif (item.date_planned - current_time).total_seconds() < 48 * 3600: # 预警
item.delivery_warning = 'warning'
last_warning_order = item
purchase_order_done = self.sudo().search([('state', 'in', ['purchase']), ('receipt_status', '=', 'full')])
purchase_order_overdue = purchase_order_done.filtered(lambda x: x.delivery_warning in ['overdue', 'warning'])
if purchase_order_overdue:
purchase_order_overdue.write({'delivery_warning': 'normal'})
return last_overdue_order, last_warning_order
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
part_name = fields.Char('零件名称', related='product_id.part_name', readonly=True)
# part_number = fields.Char('零件图号',related='product_id.part_number', readonly=True)
class ResPartnerToSale(models.Model):
_inherit = 'res.partner'

View File

@@ -16,10 +16,11 @@
<button name="button_confirm" type="object" states="draft" context="{'validate_analytic': True}"
string="Confirm Order" id="draft_confirm"/>
<button name="action_view_picking"
string="接收产品" class="oe_highlight" type="object"
attrs="{'invisible': ['|', '|' , ('is_shipped', '=', True), ('state','not in', ('purchase','done')), ('incoming_picking_count', '=', 0)]}"
data-hotkey="y" groups="stock.group_stock_user"/>
<button name="button_cancel" states="draft,to approve,sent,purchase" string="取消" type="object" data-hotkey="x" />
string="接收产品" class="oe_highlight" type="object"
attrs="{'invisible': ['|', '|' , ('is_shipped', '=', True), ('state','not in', ('purchase','done')), ('incoming_picking_count', '=', 0)]}"
data-hotkey="y" groups="stock.group_stock_user"/>
<button name="button_cancel" states="draft,to approve,sent,purchase" string="取消" type="object"
data-hotkey="x"/>
</xpath>
<xpath expr="//header/button[@name='button_cancel'][2]" position="attributes">
<attribute name="invisible">1</attribute>
@@ -35,13 +36,13 @@
<field name="partner_id" widget="res_partner_many2one" context="{'is_supplier': True }"/>
</field>
<field name="currency_id" position="after">
<field name="remark" attrs="{'readonly': [('state', 'in', ['purchase'])]}"/>
<field name="remark" attrs="{'readonly': [('state', 'in', ['purchase'])]}" string="订单备注"/>
</field>
<xpath expr="//form/header/button[@name='button_confirm'][2]" position="replace">
<button name="button_confirm" type="object" context="{'validate_analytic': True}"
string="确认订单" id="draft_confirm"
groups="sf_base.group_purchase,sf_base.group_purchase_director"
attrs="{'invisible': [('state', 'in', ['purchase'])]}"
attrs="{'invisible': [('state', 'in', ['purchase', 'cancel'])]}"
/>
</xpath>
<xpath expr="//form/header/button[@name='action_rfq_send'][1]" position="replace">
@@ -134,10 +135,18 @@
<attribute name="optional">hide</attribute>
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='name']" position="after">
<field name="part_name" string="零件名称" optional="show"/>
<field name="part_name" optional="show"/>
<!-- <field name="part_number" optional="show"/>-->
</xpath>
<xpath expr="//field[@name='date_order']" position="attributes">
<attribute name="string">报价截止日期</attribute>
<attribute name="string">签约日期</attribute>
</xpath>
<field name="payment_term_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<xpath expr="//field[@name='date_order']" position="after">
<field name="payment_term_id" attrs="{'readonly': ['|', ('invoice_status','=', 'invoiced'), ('state', '=', 'done')]}" options="{'no_create': True}"/>
<field name="contract_summary"/>
</xpath>
<field name="partner_ref" position="attributes">
<attribute name="attrs">{'readonly': [('state', 'in', ['purchase'])]}
@@ -168,14 +177,50 @@
</attribute>
</field>
<!-- 添加采购类型字段 -->
<field name="partner_ref" position="after">
<!-- 添加采购类型字段 -->
<field name="partner_id" position="after">
<field name="purchase_type" string="采购类型" readonly="1"/>
<field name="picking_type_id" string="作业类型" domain="[('code','=','incoming'), '|', ('warehouse_id', '=', False), ('warehouse_id.company_id', '=', company_id)]" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
<label for="date_planned" string="最近交货日期"/>
<div name="date_planned_div" class="o_row">
<field name="date_planned" attrs="{'readonly': [('state', 'not in', ('draft', 'sent', 'to approve', 'purchase'))]}"/>
<field name="mail_reminder_confirmed" invisible="1"/>
<span class="text-muted" attrs="{'invisible': [('mail_reminder_confirmed', '=', False)]}">(confirmed by vendor)</span>
</div>
<field name="effective_date" attrs="{'invisible': [('effective_date', '=', False)]}" string="到货时间"/>
</field>
<!-- 添加销售订单号字段-->
<field name="effective_date" position="after">
<field name="origin_sale_id" readonly="1" attrs="{'invisible': [('origin_sale_id', '=', False)]}"/>
<field name="partner_ref" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<xpath expr="//sheet/group/group[2]/field[1]" position="before">
<field name="partner_ref" string="合同名称"/>
<field name="contract_number"/>
</xpath>
<!-- 添加销售订单号字段-->
<xpath expr="//sheet/group/group[2]/div[@name='date_approve']" position="after">
<!-- <field name="origin_sale_id" readonly="1" attrs="{'invisible': [('origin_sale_id', '=', False)]}" string="参考销售订单"/> -->
<field name="origin_sale_id" readonly="1" string="参考销售订单"/>
</xpath>
<xpath expr="//sheet/group/group[2]/field[@name='effective_date']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<!-- 隐藏 label -->
<xpath expr="//label[@for='receipt_reminder_email']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<!-- 隐藏整个 reminder div -->
<xpath expr="//div[@name='reminder']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<!-- 使用更精确的路径定位原始元素 -->
<xpath expr="//sheet/group/group[2]/label[@for='date_planned']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//sheet/group/group[2]/div[@name='date_planned_div']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</field>
</record>
@@ -194,11 +239,13 @@
<attribute name="optional">hide</attribute>
</xpath>
<xpath expr="//field[@name='date_order']" position="attributes">
<attribute name="string">报价截止日期</attribute>
<attribute name="string">签约日期</attribute>
<attribute name="widget">''</attribute>
</xpath>
<xpath expr="//field[@name='date_planned']" position="replace">
</xpath>
<xpath expr="//field[@name='date_order']" position="after">
<field name="date_planned"/>
<field name="date_planned" string="最近交货日期"/>
</xpath>
<xpath expr="//field[@name='name']" position="after">
<field name="purchase_type"/>
@@ -222,6 +269,8 @@
<attribute name="attrs">{'readonly': [('state', 'in', ['purchase'])]}
</attribute>
</field>
<xpath expr="//field[@name='picking_type_id'][1]" position="replace">
</xpath>
</field>
</record>
@@ -232,6 +281,8 @@
<field name="arch" type="xml">
<tree position="attributes">
<attribute name="default_order">date_approve asc</attribute>
<attribute name="decoration-warning">delivery_warning == 'warning'</attribute>
<attribute name="decoration-danger">delivery_warning == 'overdue'</attribute>
</tree>
<xpath expr="//field[@name='activity_ids']" position="attributes">
<attribute name="optional">hide</attribute>
@@ -242,10 +293,12 @@
<attribute name="string">采购员</attribute>
</xpath>
<xpath expr="//field[@name='user_id']" position="after">
<field name="date_planned" string="预计到货日期" optional="show"/>
<field name="delivery_warning" optional="show"/>
<field name="date_planned" string="最近交货日期" optional="show" widget="date"/>
</xpath>
<xpath expr="//field[@name='name']" position="after">
<field name="purchase_type"/>
<field name="delivery_warning" invisible="1"/>
</xpath>
<xpath expr="//field[@name='name']" position="attributes">
<attribute name="class">purchase_order_list_name</attribute>
@@ -253,6 +306,21 @@
</field>
</record>
<record id="view_purchase_order_view_search_inherit_sf" model="ir.ui.view">
<field name="name">purchase.order.search.inherit.sf</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_view_search"/>
<field name="arch" type="xml">
<xpath expr="//filter[@name='order_date']" position="after">
<separator/>
<filter string="正常" name="filter_order_normal"
domain="['|', ('delivery_warning', '=', 'normal'), ('delivery_warning', '=', False)]"/>
<filter string="预警" name="filter_order_warning" domain="[('delivery_warning', '=', 'warning')]"/>
<filter string="逾期" name="filter_order_overdue" domain="[('delivery_warning', '=', 'overdue')]"/>
</xpath>
</field>
</record>
<record id="purchase_order_search_inherit_sf" model="ir.ui.view">
<field name="name">purchase.order.list.select.inherit.sf</field>
<field name="model">purchase.order</field>
@@ -261,12 +329,12 @@
<xpath expr="//field[@name='name']" position="replace">
<field name="name" string="单据编码" filter_domain="[('name', 'ilike', self)]"/>
</xpath>
<!-- <xpath expr="//search" position="inside">-->
<!-- <searchpanel>-->
<!-- <field name="purchase_type" icon="fa-filter"/>-->
<!-- <field name="state" icon="fa-filter"/>-->
<!-- </searchpanel>-->
<!-- </xpath>-->
<!-- <xpath expr="//search" position="inside">-->
<!-- <searchpanel>-->
<!-- <field name="purchase_type" icon="fa-filter"/>-->
<!-- <field name="state" icon="fa-filter"/>-->
<!-- </searchpanel>-->
<!-- </xpath>-->
</field>
</record>
@@ -278,7 +346,7 @@
<xpath expr="//search" position="inside">
<searchpanel>
<field name="purchase_type" icon="fa-filter" enable_counters="1"/>
<field name="state" icon="fa-filter" enable_counters="1"/>
<field name="delivery_warning" icon="fa-filter" enable_counters="1"/>
</searchpanel>
</xpath>
</field>

View File

@@ -103,6 +103,7 @@
<xpath expr="//field[@name='order_line']/tree/field[@name='name']" position="before">
<field name="model_glb_file" widget="Viewer3D" optional="show"
string="模型文件" attrs="{'readonly': [('state', 'in', ['draft'])]}"/>
<field name="part_name" optional="hide"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree/field[@name='price_subtotal']" position="after">
<field name="remark"/>
@@ -169,8 +170,14 @@
<field name="manual_quotation" />
<field name="is_incoming_material"/>
</xpath>
<xpath expr="//sheet//group//group[@name='order_details']//div[@class='o_td_label'][2]//label[@for='date_order']" position="attributes">
<attribute name="string">下单日期</attribute>
<xpath expr="//div[@class='o_td_label'][2]" position="replace"></xpath>
<xpath expr="//field[@name='date_order'][1]" position="replace"></xpath>
<xpath expr="//field[@name='date_order']" position="replace"></xpath>
<xpath expr="//div[@class='o_td_label'][1]" position="replace">
<div class="o_td_label" attrs="{'invisible': [('state', 'in', ['done', 'cancel'])]}">
<label for="date_order" string="下单日期"/>
</div>
<field name="date_order" attrs="{'invisible': [('state', 'in', ['done', 'cancel'])], 'required': True}" nolabel="1"/>
</xpath>
</field>

View File

@@ -45,7 +45,8 @@ class FunctionalCuttingToolEntity(models.Model):
string='状态', store=True, default='正常')
current_location_id = fields.Many2one('stock.location', string='当前位置', compute='_compute_current_location_id',
store=True)
current_shelf_location_id = fields.Many2one('sf.shelf.location', string='当前货位', readonly=True)
current_shelf_location_id = fields.Many2one('sf.shelf.location', string='当前货位',
compute='_compute_current_location_id', store=True)
current_location = fields.Selection(
[('组装后', '组装后'), ('刀具房', '刀具房'), ('线边刀库', '线边刀库'), ('机内刀库', '机内刀库')],
string='位置', compute='_compute_current_location_id', store=True)
@@ -85,6 +86,10 @@ class FunctionalCuttingToolEntity(models.Model):
if quant_id.inventory_quantity_auto_apply > 0:
record.current_location_id = quant_id.location_id
if quant_id.location_id.name == '制造前':
shelf_location_id = self.env['sf.shelf.location'].sudo().search([
('product_sn_id', '=', record.barcode_id.id)])
if shelf_location_id:
record.current_shelf_location_id = shelf_location_id.id
if not record.current_shelf_location_id:
record.current_location = '机内刀库'
else:

View File

@@ -126,7 +126,7 @@ class StockLot(models.Model):
tool_material_search_id = fields.Many2one('sf.tool.material.search', string='刀具物料搜索')
fixture_material_search_id = fields.Many2one('sf.fixture.material.search', string='夹具物料搜索')
tool_material_status = fields.Selection(
[('未入库', '未入库'), ('可用', '可用'), ('在用', '在用'), ('报废', '报废')], string='状态',
[('未入库', '未入库'), ('可用', '可用'), ('在用', '空闲'), ('报废', '报废')], string='状态',
compute='_compute_tool_material_status', store=True)
@api.depends('quant_ids')

View File

@@ -198,8 +198,8 @@ class MrpProduction(models.Model):
logging.info('cnc用刀校验到无效刀自动调用重新编程方法update_programming_state()')
self[0].update_programming_state()
self[0].write({'is_rework': False})
# 修改制造订单 编程状态变为“编程中” 制造订单状态为‘返工’
self.write({'programming_state': '编程中', 'work_state': '编程中', 'state': 'rework'})
# 修改制造订单 编程状态变为“编程中”
self.write({'programming_state': '编程中', 'work_state': '编程中'})
self[0].workorder_ids.filtered(
lambda a: a.name == '装夹预调' and a.state not in ['rework', 'done', 'cancel'])._compute_state()
if missing_tool_1:

View File

@@ -888,12 +888,11 @@ class SfStockMoveLine(models.Model):
def _check_destination_location_id(self):
for item in self:
if item:
i = 0
barcode = item.destination_location_id.barcode
for line in item.picking_id.move_line_ids_without_package:
if barcode and barcode == line.destination_location_id.barcode:
i += 1
if i > 1:
if line.destination_location_id:
if (barcode and barcode == line.destination_location_id.barcode
and item.product_id != line.product_id):
raise ValidationError(
'%s】货位已经被占用,请重新选择!!!' % item.destination_location_id.barcode)