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

@@ -24,12 +24,33 @@
'views/production_line_view.xml',
'views/tray_view.xml',
'views/model_type_view.xml',
# 'views/kanban_change.xml'
],
'assets': {
'web.assets_qweb': [
],
'web.assets_backend': [
'sf_manufacturing/static/src/xml/kanban_change.xml',
'sf_manufacturing/static/src/js/kanban_change.js',
'sf_manufacturing/static/src/scss/kanban_change.scss'
]
},
'demo': [
],
'qweb': [
],
'assets': {
'web.assets_backend': [
'sf_manufacturing/static/src/js/kanban_change.js',
'sf_manufacturing/static/src/scss/kanban_change.scss',
'sf_manufacturing/static/src/xml/kanban_change.xml',
],
},
'license': 'LGPL-3',
'installable': True,
'application': False,

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("注册夹具到云端失败,请联系管理员!")

View File

@@ -0,0 +1,78 @@
/** @odoo-module */
import { KanbanController } from "@web/views/kanban/kanban_controller";
import { kanbanView } from "@web/views/kanban/kanban_view";
import { registry } from "@web/core/registry";
// the controller usually contains the Layout and the renderer.
class CustomKanbanController extends KanbanController {
// Your logic here, override or insert new methods...
// if you override setup(), don't forget to call super.setup()
async setup() {
super.setup();
console.log('99999999111');
this.workOrders = await this.getAllWorkOrders();
console.log('lines', this.workOrders);
}
buttonClick(ev) {
const button = ev.currentTarget;
const id = button.getAttribute('data-id');
console.log('true_id', id);
const context = {production_line_show: 'shengchanxian1'}
this.env.services.rpc('/web/dataset/call_kw', {
model: 'mrp.workcenter',
method: 'search_read',
args: [[], ['id']],
kwargs: {}
}).then((records) => {
console.log(records)
const ids = records.map(record => record.id);
const context = {production_line_show: id};
this.env.services.rpc('/web/dataset/call_kw', {
model: 'mrp.workcenter',
method: 'write',
args: [ids, context],
kwargs: {}
}).then((response) => {
console.log('response', response);
setTimeout(function () {
location.reload();
},2000)
});
});
}
async getAllWorkOrders() {
const response = await this.env.services.rpc('/web/dataset/call_kw',{
model: 'sf.production.line',
method: 'search_read',
args: [],
kwargs: {},
});
// const response1 = await this.env.services.rpc('/web/dataset/call_kw',{
// model: 'mrp.workcenter',
// method: 'search_read',
// args: [],
// kwargs: {},
// });
console.log('response', response);
// console.log('response1', response1);
// 你可以在这里处理响应,例如将其存储在控制器的状态中
return response;
}
}
CustomKanbanController.template = "sf_manufacturing.CustomKanbanView1";
export const customKanbanView = {
...kanbanView, // contains the default Renderer/Controller/Model
Controller: CustomKanbanController,
};
// Register it to the views registry
registry.category("views").add("custom_kanban1", customKanbanView);

View File

@@ -0,0 +1,22 @@
.choosekanban {
display: flex;
justify-content: flex-start;
align-items: center;
margin-left: 16px !important;
}
.choosekanban > button {
padding: 0 2vw !important;
height: 2vw !important;
border: none !important;
border-right: 1px solid #ccc !important;
background-color: #EEEEEE;
color: #989799;
font-weight: bold;
}
.o_content > .d-flex {
display: block !important;
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-name="sf_manufacturing.CustomKanbanView1" t-inherit="web.KanbanView" owl="1">
<xpath expr="//t[@t-component='props.Renderer']" position="before">
<div class="choosekanban">
<!-- <t t-foreach="env['mrp.workcenter'].get_dynamic_data()" t-as="i" t-key="i"> -->
<t t-foreach="workOrders" t-as="i" t-key="i.id">
<button t-on-click="buttonClick" t-att-data-id="i.name">
<t t-esc="i.name"></t>
</button>
</t>
</div>
</xpath>
</t>
</templates>

View File

@@ -94,6 +94,7 @@
<xpath expr="//field[@name='alternative_workcenter_ids']" position="after">
<field name="production_line_id"/>
<field name="equipment_id"/>
<field name="production_line_show" invisible="1"/>
</xpath>
<xpath expr="//field[@name='resource_calendar_id']" position="after">
<field name="is_process_outsourcing"/>
@@ -101,15 +102,194 @@
</field>
</record>
<record id="mrp_workcenter_view_kanban_inherit_maintenance" model="ir.ui.view">
<field name="name">mrp.workcenter.view.kanban.inherit.maintenance</field>
<!-- <record id="mrp_workcenter_view_kanban_inherit_maintenance" model="ir.ui.view"> -->
<!-- <field name="name">mrp.workcenter.view.kanban.inherit.maintenance</field> -->
<!-- <field name="model">mrp.workcenter</field> -->
<!-- <field name="inherit_id" ref="mrp.mrp_workcenter_kanban"/> -->
<!-- <field name="arch" type="xml"> -->
<!-- <xpath expr="//div[@name='plan_order']" position="after"> -->
<!-- <div> -->
<!-- <a name="%(maintenance.hr_equipment_request_action)d" type="action">Maintenance</a> -->
<!-- </div> -->
<!-- </xpath> -->
<!-- </field> -->
<!-- </record> -->
<!-- 继承原有的看板视图 -->
<record id="mrp_workcenter_kanban_inherit1" model="ir.ui.view">
<field name="name">mrp.workcenter.kanban.inherit</field>
<field name="model">mrp.workcenter</field>
<field name="inherit_id" ref="mrp.mrp_workcenter_kanban"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='plan_order']" position="after">
<div>
<a name="%(maintenance.hr_equipment_request_action)d" type="action">Maintenance</a>
</div>
<xpath expr="//kanban" position="replace">
<kanban class="oe_background_grey o_kanban_dashboard o_workcenter_kanban" create="0" sample="1"
js_class="custom_kanban1">
<field name="name"/>
<field name="color"/>
<field name="workorder_count"/>
<field name="working_state"/>
<field name="oee_target"/>
<field name="production_line_show"/>
<field name="production_line_id"/>
<templates>
<t t-name="kanban-box"
t-if="record.production_line_id.value == record.production_line_show.raw_value">
<!-- <div t-on-click="console.log(record.production_line_id,'11111111111')"></div>-->
<!-- <div t-on-click="console.log(record.production_line_show,'22222222222')"></div>-->
<div t-attf-class="#{!selection_mode ? kanban_color(record.color.raw_value) : ''}">
<div t-attf-class="o_kanban_card_header o_kanban_record_top">
<div class="o_kanban_record_headings o_kanban_card_header_title">
<span class="o_primary ml8" style="display: inline-block">
<field name="name"/>
</span>
</div>
<div class="o_kanban_manage_button_section">
<a class="o_kanban_manage_toggle_button" href="#">
<i class="fa fa-ellipsis-v" role="img" aria-label="Manage" title="Manage"/>
</a>
</div>
</div>
<div class="container o_kanban_card_content">
<div class="row mb16">
<div class="col-6 o_kanban_primary_left">
<div class="btn-group" name="o_wo">
<t t-if="record.workorder_count.raw_value &gt; 0">
<button class="btn btn-primary" name="action_work_order"
type="object"
context="{'search_default_ready': 1, 'search_default_progress': 1}">
<span>WORK ORDERS</span>
</button>
</t>
<t t-if="record.workorder_count.raw_value &lt;= 0">
<button class="btn btn-warning"
name="%(mrp.act_product_mrp_production_workcenter)d"
type="action">
<span>PLAN ORDERS</span>
</button>
</t>
</div>
</div>
<div class="col-6 o_kanban_primary_right">
<div class="row" t-if="record.workorder_ready_count.raw_value &gt; 0">
<div class="col-8">
<a name="action_work_order" type="object"
context="{'search_default_ready': 1}">
To Launch
</a>
</div>
<div class="col-4 text-end">
<field name="workorder_ready_count"/>
</div>
</div>
<div class="row" t-if="record.workorder_progress_count.raw_value &gt; 0">
<div class="col-8">
<a name="action_work_order" type="object"
context="{'search_default_progress': 1}">
In Progress
</a>
</div>
<div class="col-4 text-end">
<field name="workorder_progress_count"/>
</div>
</div>
<div class="row" t-if="record.workorder_late_count.raw_value &gt; 0">
<div class="col-8">
<a name="action_work_order" type="object"
context="{'search_default_late': 1}">
Late
</a>
</div>
<div class="col-4 text-end">
<field name="workorder_late_count"/>
</div>
</div>
<div class="row" t-if="record.oee.raw_value &gt; 0">
<div class="col-6">
<a name="%(mrp.mrp_workcenter_productivity_report_oee)d"
type="action">
OEE
</a>
</div>
<div class="col-6 text-end">
<span t-att-class="record.oee_target.raw_value and (record.oee.raw_value &lt; record.oee_target.raw_value) and 'text-danger' or (record.oee.raw_value &gt; record.oee_target.raw_value) and 'text-success' or 'text-warning'">
<strong>
<field name="oee" widget="integer"/>%
</strong>
</span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 o_kanban_primary_left"
style="position:absolute; bottom:10px;" name="wc_stages">
<a name="%(mrp.act_mrp_block_workcenter)d" type="action"
class="o_status float-end"
title="No workorder currently in progress. Click to mark work center as blocked."
aria-label="No workorder currently in progress. Click to mark work center as blocked."
attrs="{'invisible': [('working_state','in',('blocked','done'))]}"/>
<a name="unblock" type="object" class=" o_status o_status_red float-end"
title="Workcenter blocked, click to unblock."
aria-label="Workcenter blocked, click to unblock."
attrs="{'invisible': [('working_state','in',('normal','done'))]}"/>
<a name="%(mrp.act_mrp_block_workcenter)d" type="action"
class="o_status o_status_green float-end"
title="Work orders in progress. Click to block work center."
aria-label="Work orders in progress. Click to block work center."
attrs="{'invisible': [('working_state','in',('normal','blocked'))]}"/>
</div>
</div>
</div>
<div class="container o_kanban_card_manage_pane dropdown-menu" role="menu">
<div class="row">
<div class="col-6 o_kanban_card_manage_section o_kanban_manage_view">
<div role="menuitem" class="o_kanban_card_manage_title">
<span>Actions</span>
</div>
<div role="menuitem" name="plan_order">
<a name="action_work_order" type="object">Plan Orders</a>
</div>
<div>
<a name="%(maintenance.hr_equipment_request_action)d" type="action">
Maintenance
</a>
</div>
</div>
<div class="col-6 o_kanban_card_manage_section o_kanban_manage_new">
<div role="menuitem" class="o_kanban_card_manage_title">
<span>Reporting</span>
</div>
<div role="menuitem">
<a name="%(mrp.mrp_workcenter_productivity_report_oee)d" type="action">
OEE
</a>
</div>
<div role="menuitem">
<a name="%(mrp.mrp_workorder_workcenter_report)d" type="action"
context="{'search_default_thisyear':True}">
Performance
</a>
</div>
<div role="menuitem">
<a name="action_work_order" type="object"
context="{'search_default_waiting': 1}">Waiting Availability
</a>
</div>
</div>
</div>
<div t-if="widget.editable" class="o_kanban_card_manage_settings row">
<div role="menuitem" aria-haspopup="true" class="col-8">
<ul role="menu" class="oe_kanban_colorpicker" data-field="color"/>
</div>
<div role="menuitem" class="text-end">
<a type="edit">Settings</a>
</div>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</xpath>
</field>
</record>
@@ -141,5 +321,22 @@
</field>
</record>
<!--&lt;!&ndash; 测试searchpanel &ndash;&gt;-->
<!-- <record id="view_location_search_sf11111_inherit" model="ir.ui.view">-->
<!-- <field name="name">mrp.workcenter.inherit</field>-->
<!-- <field name="model">mrp.workcenter</field>-->
<!-- <field name="inherit_id" ref="mrp.view_mrp_workcenter_search"/>-->
<!-- <field name="arch" type="xml">-->
<!-- <xpath expr="//search[1]" position="inside">-->
<!-- <searchpanel class="account_root">-->
<!--&lt;!&ndash; <field name="location_type" icon="fa-filter"/> &ndash;&gt;-->
<!-- <field name="production_line_id" select="multi"/>-->
<!-- </searchpanel>-->
<!-- </xpath>-->
<!-- </field>-->
<!-- </record>-->
=======
>>>>>>> develop
</odoo>