50 lines
2.4 KiB
Python
50 lines
2.4 KiB
Python
import re
|
|
from odoo import models, fields, api, _
|
|
|
|
|
|
class SFMessageStockPicking(models.Model):
|
|
_name = 'stock.picking'
|
|
_description = "库存调拨"
|
|
_inherit = ['stock.picking', 'jikimo.message.dispatch']
|
|
|
|
def button_validate(self):
|
|
res = super(SFMessageStockPicking, self).button_validate()
|
|
if self.location_id.name == 'Vendors' and self.location_dest_id.name == '进货':
|
|
self.add_queue('调拨入库')
|
|
return res
|
|
|
|
@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('坯料发料提醒')
|
|
|
|
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'].search([('id', '=', int(message_queue_id.res_id))])
|
|
mrp_production_info = self.env['mrp.production'].search(
|
|
[('name', '=', stock_picking_line.origin)])
|
|
mrp_production_list = self.env['mrp.production'].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 = message_queue_id.message_template_id.get_url(int(message_queue_id.res_id))
|
|
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)
|
|
return contents
|
|
else:
|
|
res = super(SFMessageStockPicking, self)._get_message(message_queue_id)
|
|
return res
|