Files
jikimo_sf/sf_stock/models/stock_picking.py
2024-08-27 17:24:04 +08:00

40 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
import json
import requests
from odoo import models, fields, api
from odoo.exceptions import UserError
import logging
_logger = logging.getLogger(__name__)
class StockPicking(models.Model):
_inherit = 'stock.picking'
# 重写验证下发发货到bfm
def button_validate(self):
info = super(StockPicking, self).button_validate()
if self.picking_type_id.code == 'outgoing':
self.send_to_bfm()
return info
def send_to_bfm(self):
# 下发发货到bfm
config = self.env['res.config.settings'].get_values()
json1 = {
'params': {
'name': self.origin,
'send_no': self.name,
'qty_done': self.move_line_ids.qty_done,
},
}
url1 = config['bfm_url_new'] + '/api/stock/deliver_goods'
r = requests.post(url1, json=json1, data=None)
if r.status_code == 200:
result = json.loads(r.json()['result'])
if result['code'] != 200:
raise UserError(result['message'] or '工厂发货下发bfm失败')
else:
raise UserError('工厂发货下发bfm失败')