消息提醒
This commit is contained in:
@@ -140,5 +140,15 @@
|
|||||||
<field name="name">工序外协发料通知</field>
|
<field name="name">工序外协发料通知</field>
|
||||||
<field name="model">mrp.production</field>
|
<field name="model">mrp.production</field>
|
||||||
</record>
|
</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>
|
</data>
|
||||||
</odoo>
|
</odoo>
|
||||||
@@ -362,5 +362,32 @@
|
|||||||
单号:产品[{{name}}]({{url}})发料单
|
单号:产品[{{name}}]({{url}})发料单
|
||||||
事项:请确认{{num}}个工序外协发料单并发料处理。</field>
|
事项:请确认{{num}}个工序外协发料单并发料处理。</field>
|
||||||
</record>
|
</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>
|
</data>
|
||||||
</odoo>
|
</odoo>
|
||||||
@@ -24,6 +24,19 @@ class SFMessagePurchase(models.Model):
|
|||||||
[('id', '=', int(message_queue_id.res_id))])
|
[('id', '=', int(message_queue_id.res_id))])
|
||||||
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', purchase_order_line.origin)])
|
mrp_production = self.env['mrp.production'].sudo().search([('name', '=', purchase_order_line.origin)])
|
||||||
process_outsourcing.add(mrp_production.product_id.id)
|
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')]
|
||||||
|
else:
|
||||||
|
domain = [('delivery_warning', '=', 'overdue')]
|
||||||
|
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')
|
||||||
|
action_id = self.env.ref("purchase.purchase_form_action").id
|
||||||
|
url_with_id = f"{url}/web#view_type=list&action={action_id}"
|
||||||
|
content = content.replace('{{url}}', url_with_id).replace('{{num}}', str(purchase_order_num))
|
||||||
|
contents.append(content)
|
||||||
if process_outsourcing:
|
if process_outsourcing:
|
||||||
content_info = content
|
content_info = content
|
||||||
for products_id in process_outsourcing:
|
for products_id in process_outsourcing:
|
||||||
@@ -58,3 +71,27 @@ class SFMessagePurchase(models.Model):
|
|||||||
# 拼接URL
|
# 拼接URL
|
||||||
full_url = url + "/web#" + query_string
|
full_url = url + "/web#" + query_string
|
||||||
return full_url
|
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
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'wizard/sale_order_wizard_views.xml',
|
'wizard/sale_order_wizard_views.xml',
|
||||||
'wizard/purchase_order_wizard_views.xml',
|
'wizard/purchase_order_wizard_views.xml',
|
||||||
|
'data/cron_data.xml',
|
||||||
'views/sale_team.xml',
|
'views/sale_team.xml',
|
||||||
'views/sale_order_view.xml',
|
'views/sale_order_view.xml',
|
||||||
'views/res_partner_view.xml',
|
'views/res_partner_view.xml',
|
||||||
|
|||||||
16
sf_sale/data/cron_data.xml
Normal file
16
sf_sale/data/cron_data.xml
Normal 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>
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import base64
|
import base64
|
||||||
|
import logging
|
||||||
from odoo import Command
|
from odoo import Command
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.exceptions import UserError, ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
READONLY_FIELD_STATES = {
|
READONLY_FIELD_STATES = {
|
||||||
state: [('readonly', True)]
|
state: [('readonly', True)]
|
||||||
@@ -218,6 +220,10 @@ class RePurchaseOrder(models.Model):
|
|||||||
purchase_type = fields.Selection([('standard', '标准采购'), ('consignment', '委外加工')], string='采购类型',
|
purchase_type = fields.Selection([('standard', '标准采购'), ('consignment', '委外加工')], string='采购类型',
|
||||||
default='standard')
|
default='standard')
|
||||||
|
|
||||||
|
delivery_warning = fields.Selection([('normal', '正常'), ('warning', '预警'), ('overdue', '已逾期')],
|
||||||
|
string='交期状态',
|
||||||
|
tracking=True)
|
||||||
|
|
||||||
@api.depends('partner_id')
|
@api.depends('partner_id')
|
||||||
def _compute_user_id(self):
|
def _compute_user_id(self):
|
||||||
if not self.user_id:
|
if not self.user_id:
|
||||||
@@ -299,6 +305,27 @@ class RePurchaseOrder(models.Model):
|
|||||||
|
|
||||||
return result
|
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.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 ResPartnerToSale(models.Model):
|
class ResPartnerToSale(models.Model):
|
||||||
_inherit = 'res.partner'
|
_inherit = 'res.partner'
|
||||||
|
|||||||
Reference in New Issue
Block a user