销售和排程添加消息推送

This commit is contained in:
jinling.yang
2024-09-20 15:42:07 +08:00
parent f6e371f223
commit cc8906980c
16 changed files with 168 additions and 135 deletions

View File

@@ -11,10 +11,9 @@
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
'depends': ['base', 'sf_plan', 'sf_sale'],
'depends': ['base', 'jikimo_message_notify'],
'data': [
'security/ir.model.access.csv',
'views/sf_message_template_view.xml',
'data/bussiness_node.xml'
],
'test': [
],

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<odoo>
<data noupdate="1">
<record id="bussiness_pending_order" model="jikimo.message.bussiness.node">
<field name="name">待接单</field>
<field name="model">sale.order</field>
</record>
<record id="bussiness_to_be_confirm" model="jikimo.message.bussiness.node">
<field name="name">确认接单</field>
<field name="model">sale.order</field>
</record>
</data>
</odoo>

View File

@@ -3,4 +3,4 @@ from odoo import models, fields, api, _
class SFMessageCamProgram(models.Model):
_name = 'sf.cam.work.order.program.knife.plan'
_inherit = ['sf.cam.work.order.program.knife.plan', 'sf.message.template']
_inherit = ['sf.cam.work.order.program.knife.plan', 'jikimo.message.dispatch']

View File

@@ -3,4 +3,4 @@ from odoo import models, fields, api, _
class SFMessagefunctionalToolAssembly(models.Model):
_name = 'sf.functional.tool.assembly'
_inherit = ['sf.functional.tool.assembly', 'sf.message.template']
_inherit = ['sf.functional.tool.assembly', 'jikimo.message.dispatch']

View File

@@ -1,6 +1,25 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
class SFMessagePlan(models.Model):
_name = 'sf.production.plan'
_inherit = ['sf.production.plan', 'sf.message.template']
_inherit = ['sf.production.plan', 'jikimo.message.dispatch']
# def create(self, vals_list):
# res = super(SFMessagePlan, self).create(vals_list)
# if res:
# try:
# res.add_queue('待排程')
# except Exception as e:
# logging.info('add_queue error:%s' % e)
# return res
#
# def _get_message(self):
# res = super(SFMessagePlan, self)._get_message()
# if res:
# try:
# res.add_queue('待排程')
# except Exception as e:
# logging.info('_get_message error:%s' % e)
# return res

View File

@@ -3,4 +3,4 @@ from odoo import models, fields, api, _
class SFMessagePurchase(models.Model):
_name = 'purchase.order'
_inherit = ['purchase.order', 'sf.message.template']
_inherit = ['purchase.order', 'jikimo.message.dispatch']

View File

@@ -1,11 +1,43 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
class SFMessageSale(models.Model):
_name = 'sale.order'
_inherit = ['sale.order', 'sf.message.template']
_inherit = ['sale.order', 'jikimo.message.dispatch']
# def create(self):
# res = super(SFMessageSale, self).create()
# if res is True:
def create(self, vals_list):
res = super(SFMessageSale, self).create(vals_list)
if res:
try:
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()
if res is True:
try:
self.add_queue('确认接单')
except Exception as e:
logging.info('add_queue error:%s' % e)
return res
# 继承并重写jikimo.message.dispatch的_get_message()
def _get_message(self, message_queue_ids):
if message_queue_ids.message_template_id.bussiness_node_id.name == '确认接单':
# sale_order = self.env['sale.order'].search([('id', '=', message_queue_ids.model.res_id)])
sale_order_line = self.env['sale.order.line'].search([('order_id', '=', int(message_queue_ids.res_id))])
if len(sale_order_line) == 1:
product = sale_order_line[0].product_id.name
elif len(sale_order_line) > 1:
product = '%s...' % sale_order_line[0].product_id.name
res = super(SFMessageSale, self)._get_message(message_queue_ids)
if res:
try:
res.add_queue('待排程')
except Exception as e:
logging.info('_get_message error:%s' % e)
return res

View File

@@ -3,4 +3,4 @@ from odoo import models, fields, api, _
class SFMessageStockPicking(models.Model):
_name = 'stock.picking'
_inherit = ['stock.picking', 'sf.message.template']
_inherit = ['stock.picking', 'jikimo.message.dispatch']

View File

@@ -4,31 +4,9 @@ from abc import ABC, abstractmethod
class SfMessageTemplate(models.Model):
_name = "sf.message.template"
_description = u'消息模板'
_inherit = "jikimo.message.template"
name = fields.Char(string=u"名称", required=True)
description = fields.Char(string=u"描述")
content = fields.Html(string=u"内容", render_engine='qweb', translate=True, prefetch=True, sanitize=False)
msgtype = fields.Selection(
[('text', u'文字'), ('markdown', u'Markdown')], u'消息类型',
required=True, default='markdown')
notification_department_id = fields.Many2one('hr.department', u'通知部门', required=True)
notification_employee_ids = fields.Many2many('hr.employee', string=u'员工',
domain="[('department_id', '=',notification_department_id)]",
required=True)
is_send_time = fields.Boolean(string=u"定时发送", default=False)
send_time_1 = fields.Integer('发送时间点1')
send_time_2 = fields.Integer('发送时间点2')
active = fields.Boolean(string=u"是否有效", default=True)
@api.onchange('notification_department_id')
def _clear_employee_ids(self):
if self.notification_department_id:
self.notification_employee_ids = False
@abstractmethod
def dispatch(self, args):
"""
强迫继承该类必走该抽象方法'
"""
def _get_message_model(self):
res = super(SfMessageTemplate, self)._get_message_model()
res.append("sale.order")
return res

View File

@@ -3,4 +3,4 @@ from odoo import models, fields, api, _
class SFMessageWork(models.Model):
_name = 'mrp.workorder'
_inherit = ['mrp.workorder', 'sf.message.template']
_inherit = ['mrp.workorder', 'jikimo.message.dispatch']

View File

@@ -1,9 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_sf_message_template_group_sale_salemanager,sf_message_template,model_sf_message_template,sf_base.group_sale_salemanager,1,1,1,0
access_sf_message_template_group_purchase,sf_message_template,model_sf_message_template,sf_base.group_purchase,1,1,1,0
access_sf_message_template_group_sf_stock_user,sf_message_template,model_sf_message_template,sf_base.group_sf_stock_user,1,1,1,0
access_sf_message_template_group_sf_order_user,sf_message_template,model_sf_message_template,sf_base.group_sf_order_user,1,1,1,0
access_sf_message_template_group_sf_tool_user,sf_message_template,model_sf_message_template,sf_base.group_sf_tool_user,1,1,1,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2
access_sf_message_template_group_purchase sf_message_template model_sf_message_template sf_base.group_purchase 1 1 1 0
access_sf_message_template_group_sf_stock_user sf_message_template model_sf_message_template sf_base.group_sf_stock_user 1 1 1 0
access_sf_message_template_group_sf_order_user sf_message_template model_sf_message_template sf_base.group_sf_order_user 1 1 1 0
access_sf_message_template_group_sf_tool_user sf_message_template model_sf_message_template sf_base.group_sf_tool_user 1 1 1 0
3
4
5

View File

@@ -7,7 +7,7 @@
<record id="sf_message_template_view_form" model="ir.ui.view">
<field name="name">sf.message.template.view.form</field>
<field name="model">sf.message.template</field>
<field name="model">message.template</field>
<field name="arch" type="xml">
<form string="消息模板">
<sheet>
@@ -18,14 +18,12 @@
</h1>
</div>
<group>
<!-- <field name="type"/>-->
<!-- <field name="type"/>-->
<field name="notify_model_id"/>
<field name="content" widget="html" class="oe-bordered-editor"
options="{'style-inline': true, 'codeview': true, 'dynamic_placeholder': true}"/>
<field name="description"/>
<field name="msgtype"/>
<field name="is_send_time"/>
<field name="send_time_1" attrs="{'invisible': [('is_send_time', '=', False)]}"/>
<field name="send_time_2" attrs="{'invisible': [('is_send_time', '=', False)]}"/>
<field name="notification_department_id"/>
<field name="notification_employee_ids" widget="many2many_tags"/>
</group>
@@ -36,16 +34,13 @@
<record id="sf_message_template_view_tree" model="ir.ui.view">
<field name="name">sf.message.template.view.tree</field>
<field name="model">sf.message.template</field>
<field name="model">message.template</field>
<field name="arch" type="xml">
<tree string="消息模板">
<field name="name"/>
<!-- <field name="type"/>-->
<!-- <field name="type"/>-->
<field name="content"/>
<field name="msgtype"/>
<field name="is_send_time"/>
<field name="send_time_1" attrs="{'invisible': [('is_send_time', '=', False)]}"/>
<field name="send_time_2" attrs="{'invisible': [('is_send_time', '=', False)]}"/>
<field name="notification_department_id"/>
<field name="notification_employee_ids" widget="many2many_tags"/>
<field name="description"/>
@@ -55,7 +50,7 @@
<record id="sf_message_template_search_view" model="ir.ui.view">
<field name="name">sf.message.template.search.view</field>
<field name="model">sf.message.template</field>
<field name="model">message.template</field>
<field name="arch" type="xml">
<search>
<field name="name" string="模糊搜索"
@@ -69,7 +64,7 @@
<!--定义单证类型视图动作-->
<record id="sf_message_template_action" model="ir.actions.act_window">
<field name="name">消息模板</field>
<field name="res_model">sf.message.template</field>
<field name="res_model">message.template</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="sf_message_template_view_tree"/>
</record>