编写sf生产完工入库提醒,订单发货提醒代码

This commit is contained in:
hujiaying
2024-10-10 15:52:14 +08:00
parent a1b9f2dd3b
commit 49cbeee261
6 changed files with 118 additions and 3 deletions

View File

@@ -11,7 +11,7 @@
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
'depends': ['sale', 'purchase', 'sf_plan', 'jikimo_message_notify', 'stock'],
'depends': ['sale', 'purchase', 'sf_plan', 'jikimo_message_notify', 'stock', 'mrp'],
'data': [
'data/bussiness_node.xml',
# 'data/cron_data.xml',

View File

@@ -48,6 +48,15 @@
<field name="name">工单已下发通知</field>
<field name="model">mrp.workorder</field>
</record>
<!--发货调拨-->
<record id="production_completed_warehouse_reminder" model="jikimo.message.bussiness.node">
<field name="name">生产完工入库提醒</field>
<field name="model">mrp.production</field>
</record>
<record id="order_delivery_reminder" model="jikimo.message.bussiness.node">
<field name="name">订单发货提醒</field>
<field name="model">stock.picking</field>
</record>
<!-- <record id="bussiness_mrp_workorder_pre_overdue_warning" model="jikimo.message.bussiness.node">-->
<!-- <field name="name">装夹预调工单逾期预警</field>-->
<!-- <field name="model">mrp.workorder</field>-->

View File

@@ -106,5 +106,31 @@
单号:组装任务单[{{name}}]({{request_url}})
事项:{{use_tool_time}}前完成组装</field>
</record>
<record id="template_production_completed_remind" model="jikimo.message.template">
<field name="menu_id" ref="mrp.menu_mrp_root"/>
<field name="action_id" ref="mrp.mrp_production_action"/>
<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="production_completed_warehouse_reminder"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 生产完工入库提醒:
单号:生产入库单[{{name}}]({{request_url}})
事项:销售订单{{sale_order_name}}已全部产出,请入库处理</field>
</record>
<record id="template_order_delivery_remind" model="jikimo.message.template">
<field name="menu_id" ref="stock.menu_stock_root"/>
<field name="action_id" ref="stock.action_picking_tree_ready"/>
<field name="name">订单发货提醒</field>
<field name="model_id" ref="stock.model_stock_picking"/>
<field name="model">stock.picking</field>
<field name="bussiness_node_id" ref="order_delivery_reminder"/>
<field name="msgtype">markdown</field>
<field name="urgency">normal</field>
<field name="content">### 订单发货提醒:
单号:发料出库单[{{name}}]({{request_url}})
事项:销售订单{{sale_order_name}}已全部产出并出库,请及时发货</field>
</record>
</data>
</odoo>

View File

@@ -7,3 +7,4 @@ from . import sf_message_functional_tool_assembly
from . import sf_message_purchase
from . import sf_message_workorder
from . import sf_message_functional_tool_dismantle
from . import sf_message_mrp_production

View File

@@ -0,0 +1,55 @@
import re
from odoo import models, fields, api, _
from urllib.parse import urlencode
class SFMessageMrpProduction(models.Model):
_name = 'mrp.production'
_description = "制造订单"
_inherit = ['mrp.production', 'jikimo.message.dispatch']
@api.depends(
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state',
'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('生产完工入库提醒')
# 获取发送消息内容
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
mrp_production = self.env['mrp.production'].search([('id', '=', int(message_queue_id.res_id))])
if mrp_production and len(mrp_production) > 0:
stock_picking_sfp = self.env['stock.picking'].search(
[('origin', '=', mrp_production.origin), ('picking_type_id.sequence_code', '=', 'SFP'),
('state', '=', 'assigned')], limit=1)
if stock_picking_sfp:
url = self.request_url()
content = content.replace('{{name}}', stock_picking_sfp.name).replace(
'{{sale_order_name}}', mrp_production.origin).replace('{{request_url}}', url)
contents.append(content)
return contents
def request_url(self):
url = self.env['ir.config_parameter'].get_param('web.base.url')
action_id = self.env.ref('mrp.mrp_production_action').id
menu_id = self.env['ir.model.data'].search([('name', '=', 'module_theme_treehouse')]).id
# 查询参数
params = {'menu_id': menu_id, 'action': action_id, 'model': 'mrp.production',
'view_type': 'kanban'}
# 拼接查询参数
query_string = urlencode(params)
# 拼接URL
full_url = url + "/web#" + query_string
return full_url

View File

@@ -23,6 +23,31 @@ class SFMessageStockPicking(models.Model):
if record.state == 'assigned' and record.check_in == 'PC':
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"].search([('res_id', '=', record.id)])
if not stock_picking_send:
record.add_queue('订单发货提醒')
def deal_stock_picking_sfp(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
stock_picking = self.env['stock.picking'].search([('id', '=', int(message_queue_id.res_id))])
stock_picking_out = self.env['stock.picking'].search(
[('origin', '=', stock_picking.origin), ('state', '=', 'assigned'),
('picking_type_id.sequence_code', '=', 'OUT')])
if stock_picking_out and len(stock_picking_out) > 0:
url = self.request_url()
content = content.replace('{{name}}', stock_picking_out.name).replace(
'{{sale_order_name}}', stock_picking_out.origin).replace('{{request_url}}', url)
contents.append(content)
return contents
def _get_message(self, message_queue_ids):
contents = []
product_id = []
@@ -48,8 +73,7 @@ class SFMessageStockPicking(models.Model):
contents.append(content)
return contents
else:
res = super(SFMessageStockPicking, self)._get_message(message_queue_id)
return res
return self.deal_stock_picking_sfp(message_queue_ids)
def request_url(self):
url = self.env['ir.config_parameter'].get_param('web.base.url')