新增采购入库时实时注册夹具产品到cloud
This commit is contained in:
@@ -1,8 +1,4 @@
|
|||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
from odoo.addons.sf_base.commons.common import Common
|
|
||||||
from odoo.exceptions import ValidationError
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
class FixtureMaterial(models.Model):
|
class FixtureMaterial(models.Model):
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
|
from odoo.addons.sf_base.commons.common import Common
|
||||||
|
from odoo.exceptions import ValidationError,UserError
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class ResProductMo(models.Model):
|
class ResProductMo(models.Model):
|
||||||
@@ -152,6 +156,12 @@ class ResProductMo(models.Model):
|
|||||||
fixture_through_hole_size = fields.Integer(string="过孔大小[mm]", size=6)
|
fixture_through_hole_size = fields.Integer(string="过孔大小[mm]", size=6)
|
||||||
fixture_screw_size = fields.Integer(string="螺牙大小[mm]", size=6)
|
fixture_screw_size = fields.Integer(string="螺牙大小[mm]", size=6)
|
||||||
|
|
||||||
|
def _json_apply_machine_tool_type_item_code(self, item):
|
||||||
|
code_arr = []
|
||||||
|
for i in item.fixture_apply_machine_tool_type_ids:
|
||||||
|
code_arr.append(i.code)
|
||||||
|
return code_arr
|
||||||
|
|
||||||
def _get_ids(self, param):
|
def _get_ids(self, param):
|
||||||
type_ids = []
|
type_ids = []
|
||||||
if not param:
|
if not param:
|
||||||
@@ -350,6 +360,42 @@ class ResProductMo(models.Model):
|
|||||||
item.cutting_tool_standard_speed = False
|
item.cutting_tool_standard_speed = False
|
||||||
item.image_1920 = False
|
item.image_1920 = False
|
||||||
|
|
||||||
|
# 将采购到的夹具注册到Cloud
|
||||||
|
def _register_fixture(self):
|
||||||
|
config = self.env['res.config.settings'].get_values()
|
||||||
|
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||||
|
strurl = config['sf_url'] + self.crea_url
|
||||||
|
for item in self:
|
||||||
|
val = {
|
||||||
|
'factory_token': config['token'],
|
||||||
|
'name': item.name,
|
||||||
|
'brand_id': item.brand_id.code,
|
||||||
|
'materials_type_id': item.materials_type_id.code,
|
||||||
|
'fixture_material_code': item.fixture_material_id.code,
|
||||||
|
'fixture_multi_mounting_type_id': item.fixture_multi_mounting_type_id.code,
|
||||||
|
'fixture_clamping_way': item.fixture_clamping_way,
|
||||||
|
'fixture_port_type': item.fixture_port_type,
|
||||||
|
'fixture_clamp_workpiece_length_max': item.fixture_clamp_workpiece_length_max,
|
||||||
|
'fixture_clamp_workpiece_width_max': item.fixture_clamp_workpiece_width_max,
|
||||||
|
'fixture_clamp_workpiece_height_max': item.fixture_clamp_workpiece_height_max.id,
|
||||||
|
'fixture_clamp_workpiece_diameter_max': item.fixture_clamp_workpiece_diameter_max,
|
||||||
|
'fixture_maximum_carrying_weight': item.fixture_maximum_carrying_weight,
|
||||||
|
'fixture_maximum_clamping_force': item.fixture_maximum_clamping_force,
|
||||||
|
'fixture_driving_way': item.fixture_driving_way,
|
||||||
|
'fixture_apply_machine_tool_type_ids': self._json_apply_machine_tool_type_item_code(item),
|
||||||
|
'fixture_through_hole_size': item.fixture_through_hole_size,
|
||||||
|
'fixture_screw_size': item.fixture_screw_size,
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
ret = requests.post(strurl, json={}, data=val, headers=headers)
|
||||||
|
ret = ret.json()
|
||||||
|
if ret['status'] == 200:
|
||||||
|
raise UserError(ret['message'])
|
||||||
|
else:
|
||||||
|
raise UserError(ret['message'])
|
||||||
|
except Exception as e:
|
||||||
|
raise UserError("注册夹具到云端失败,请联系管理员!")
|
||||||
|
|
||||||
|
|
||||||
class ResMrpBomMo(models.Model):
|
class ResMrpBomMo(models.Model):
|
||||||
_inherit = 'mrp.bom'
|
_inherit = 'mrp.bom'
|
||||||
|
|||||||
@@ -276,7 +276,8 @@ class StockPicking(models.Model):
|
|||||||
if picking_out.state != 'done':
|
if picking_out.state != 'done':
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_('该入库单对应的单号为%s的出库单还未完成,不能进行验证操作!' % picking_out.name))
|
_('该入库单对应的单号为%s的出库单还未完成,不能进行验证操作!' % picking_out.name))
|
||||||
|
# 采购单验证(夹具和刀具)
|
||||||
|
if self.product_id.categ_type in ['刀具', '夹具']:
|
||||||
res = super().button_validate()
|
res = super().button_validate()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|||||||
@@ -61,12 +61,12 @@ class ResConfigSettings(models.TransientModel):
|
|||||||
_logger.info("同步夹具物料")
|
_logger.info("同步夹具物料")
|
||||||
self.env['sf.multi_mounting.type'].sync_all_multi_mounting_type()
|
self.env['sf.multi_mounting.type'].sync_all_multi_mounting_type()
|
||||||
_logger.info("同步联装类型")
|
_logger.info("同步联装类型")
|
||||||
self.env['sf.fixture.model'].sync_all_fixture_model()
|
# self.env['sf.fixture.model'].sync_all_fixture_model()
|
||||||
_logger.info("同步夹具型号")
|
# _logger.info("同步夹具型号")
|
||||||
self.env['sf.functional.fixture.type'].sync_all_functional_fixture_type()
|
self.env['sf.functional.fixture.type'].sync_all_functional_fixture_type()
|
||||||
_logger.info("同步功能夹具类型")
|
_logger.info("同步功能夹具类型")
|
||||||
self.env['sf.functional.fixture'].sync_all_functional_fixture()
|
# self.env['sf.functional.fixture'].sync_all_functional_fixture()
|
||||||
_logger.info("同步功能夹具")
|
# _logger.info("同步功能夹具")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.info("捕获错误信息:%s" % e)
|
_logger.info("捕获错误信息:%s" % e)
|
||||||
raise ValidationError("数据错误导致同步失败,请联系管理员")
|
raise ValidationError("数据错误导致同步失败,请联系管理员")
|
||||||
|
|||||||
Reference in New Issue
Block a user