Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/刀具物料与夹具物料的反注册

# Conflicts:
#	sf_mrs_connect/models/res_config_setting.py
This commit is contained in:
jinling.yang
2023-08-08 17:18:06 +08:00
22 changed files with 797 additions and 251 deletions

View File

@@ -6,6 +6,9 @@ from odoo.addons.resource.models.resource import Intervals
class ResWorkcenter(models.Model):
_inherit = "mrp.workcenter"
# 生产线显示
production_line_show = fields.Char(string='生产线')
equipment_id = fields.Many2one('maintenance.equipment', string='设备')
machine_tool_id = fields.Many2one('sf.machine_tool', string='机床')
production_line_id = fields.Many2one('sf.production.line', string='生产线')

View File

@@ -154,6 +154,12 @@ class ResProductMo(models.Model):
fixture_screw_size = fields.Integer(string="螺牙大小(mm)", size=6)
# 注册状态
register_state = fields.Selection([('未注册', '未注册'), ('已注册', '已注册'),('注册失败','注册失败')], string='注册状态', default='未注册')
industry_code = fields.Char('行业编码', readonly=True)
@api.onchange('brand_id')
def _onchange_brand_id(self):
if self.brand_id:
self.manufacturer_model_number = self.brand_id.manufacturer_model_number
def _json_apply_machine_tool_type_item_code(self, item):
code_arr = []

View File

@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import base64
from collections import defaultdict, namedtuple
from odoo.addons.stock.models.stock_rule import ProcurementException
from odoo.addons.sf_base.commons.common import Common
@@ -280,57 +281,14 @@ class StockPicking(models.Model):
if picking_out.state != 'done':
raise UserError(
_('该入库单对应的单号为%s的出库单还未完成,不能进行验证操作!' % picking_out.name))
# 采购单验证(夹具和刀具)
if self.product_id.categ_type in ['刀具', '夹具']:
self._register_fixture()
res = super().button_validate()
return res
# 将采购到的夹具注册到Cloud
def _register_fixture(self):
create_url = '/api/fixture/create'
config = self.env['res.config.settings'].get_values()
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
strurl = config['sf_url'] + create_url
for item in self:
val = {
'token': config['token'],
'name': item.name,
'brand_code': self.env['sf.machine.brand'].search([('id', '=', item.product_id.brand_id.id)]).code,
'manufacturer_model_number': item.product_id.manufacturer_model_number,
'fixture_material_code': self.env['sf.fixture.material'].search(
[('id', '=', item.product_id.fixture_material_id.id)]).code,
'fixture_multi_mounting_type_code': self.env['sf.multi_mounting.type'].search(
[('id', '=', item.product_id.fixture_multi_mounting_type_id.id)]).code,
'fixture_materials_type_code': self.env['sf.materials.model'].search(
[('id', '=', item.product_id.materials_type_id.id)]).materials_no,
'fixture_clamping_way': item.product_id.fixture_clamping_way,
'fixture_port_type': item.product_id.fixture_port_type,
'fixture_length': item.product_id.tool_length,
'fixture_width': item.product_id.tool_width,
'fixture_height': item.product_id.tool_height,
'fixture_weight': item.product_id.tool_weight,
'fixture_clamp_workpiece_length_max': item.product_id.fixture_clamp_workpiece_length_max,
'fixture_clamp_workpiece_width_max': item.product_id.fixture_clamp_workpiece_width_max,
'fixture_clamp_workpiece_height_max': item.product_id.fixture_clamp_workpiece_height_max,
'fixture_clamp_workpiece_diameter_max': item.product_id.fixture_clamp_workpiece_diameter_max,
'fixture_maximum_carrying_weight': item.product_id.fixture_maximum_carrying_weight,
'fixture_maximum_clamping_force': item.product_id.fixture_maximum_clamping_force,
'fixture_driving_way': item.product_id.fixture_driving_way,
'fixture_apply_machine_tool_type_codes': self.env[
'product.template']._json_apply_machine_tool_type_item_code(item),
'fixture_through_hole_size': item.product_id.fixture_through_hole_size,
'fixture_screw_size': item.product_id.fixture_screw_size,
}
try:
ret = requests.post(strurl, json={}, data=val, headers=headers)
ret = ret.json()
if ret['status'] == 200:
item.product_id.write({'register_state': '已注册'})
else:
item.product_id.write({'register_state': '注册失败'})
except Exception as e:
raise UserError("注册夹具到云端失败,请联系管理员!")
res = super().button_validate()
# 采购单验证(夹具和刀具)
for item in self.move_ids_without_package:
if item.product_id.categ_type in ['刀具', '夹具']:
if item.quantity_done > 0:
item._register_fixture()
return res
# 创建 外协出库入单
def create_outcontract_picking(self, sorted_workorders_arr, item):
@@ -388,3 +346,58 @@ class ReStockMove(models.Model):
'location_dest_id': self.mapped('location_dest_id').id,
'state': 'confirmed',
}
# 将采购到的夹具注册到Cloud
def _register_fixture(self):
create_url = '/api/fixture/create'
config = self.env['res.config.settings'].get_values()
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
strurl = config['sf_url'] + create_url
for item in self:
val = {
'token': config['token'],
'name': item.product_id.name,
'brand_code': self.env['sf.machine.brand'].search([('id', '=', item.product_id.brand_id.id)]).code,
'manufacturer_model_number': item.product_id.manufacturer_model_number,
'fixture_material_code': self.env['sf.fixture.material'].search(
[('id', '=', item.product_id.fixture_material_id.id)]).code,
'fixture_multi_mounting_type_code': self.env['sf.multi_mounting.type'].search(
[('id', '=', item.product_id.fixture_multi_mounting_type_id.id)]).code,
'fixture_materials_type_code': self.env['sf.materials.model'].search(
[('id', '=', item.product_id.materials_type_id.id)]).materials_no,
'fixture_clamping_way': item.product_id.fixture_clamping_way,
'fixture_port_type': item.product_id.fixture_port_type,
'fixture_length': item.product_id.tool_length,
'fixture_width': item.product_id.tool_width,
'fixture_height': item.product_id.tool_height,
'fixture_weight': item.product_id.tool_weight,
'fixture_amount': int(item.quantity_done),
'fixture_model_file': '' if not item.product_id.fixture_model_file else base64.b64encode(
item.product_id.fixture_model_file).decode(
'utf-8'),
'fixture_clamp_workpiece_length_max': item.product_id.fixture_clamp_workpiece_length_max,
'fixture_clamp_workpiece_width_max': item.product_id.fixture_clamp_workpiece_width_max,
'fixture_clamp_workpiece_height_max': item.product_id.fixture_clamp_workpiece_height_max,
'fixture_clamp_workpiece_diameter_max': item.product_id.fixture_clamp_workpiece_diameter_max,
'fixture_maximum_carrying_weight': item.product_id.fixture_maximum_carrying_weight,
'fixture_maximum_clamping_force': item.product_id.fixture_maximum_clamping_force,
'fixture_driving_way': '' if not item.product_id.fixture_driving_way else item.product_id.fixture_driving_way,
'fixture_apply_machine_tool_type_codes': self.env[
'product.template']._json_apply_machine_tool_type_item_code(item),
'fixture_through_hole_size': item.product_id.fixture_through_hole_size,
'fixture_screw_size': item.product_id.fixture_screw_size,
}
try:
if item.product_id.industry_code:
val['industry_code'] = item.product_id.industry_code
ret = requests.post(strurl, json={}, data=val, headers=headers)
ret = ret.json()
if ret['status'] == 200:
if not item.product_id.industry_code:
item.product_id.write({'register_state': '已注册', 'industry_code': ret['industry_code']})
else:
item.product_id.write({'register_state': '已注册'})
else:
item.product_id.write({'register_state': '注册失败'})
except Exception as e:
raise UserError("注册夹具到云端失败,请联系管理员!")