夹具物料注册

This commit is contained in:
jinling.yang
2023-08-07 17:29:17 +08:00
parent aa7e39c28a
commit b3f2065edd
4 changed files with 105 additions and 91 deletions

View File

@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
from collections import defaultdict, namedtuple
from odoo.addons.stock.models.stock_rule import ProcurementException
from odoo.addons.sf_base.commons.common import Common
from odoo.exceptions import ValidationError, UserError
import requests
import json
from re import findall as regex_findall
from datetime import datetime
from re import split as regex_split
@@ -278,9 +282,56 @@ class StockPicking(models.Model):
_('该入库单对应的单号为%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("注册夹具到云端失败,请联系管理员!")
# 创建 外协出库入单
def create_outcontract_picking(self, sorted_workorders_arr, item):
m = 0