diff --git a/jikimo_demand_plan_queue/__init__.py b/jikimo_demand_plan_queue/__init__.py
new file mode 100644
index 00000000..a0fdc10f
--- /dev/null
+++ b/jikimo_demand_plan_queue/__init__.py
@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from . import models
diff --git a/jikimo_demand_plan_queue/__manifest__.py b/jikimo_demand_plan_queue/__manifest__.py
new file mode 100644
index 00000000..83f5e07d
--- /dev/null
+++ b/jikimo_demand_plan_queue/__manifest__.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+{
+ 'name': '机企猫 需求计划排程队列',
+ 'version': '1.0',
+ 'summary': """ 使用队列进行排程 """,
+ 'author': 'fox',
+ 'website': '',
+ 'category': '',
+ 'depends': ['queue_job_batch', 'sf_demand_plan'],
+ 'data': [
+
+ ],
+
+ 'application': True,
+ 'installable': True,
+ 'auto_install': False,
+ 'license': 'LGPL-3',
+}
diff --git a/jikimo_demand_plan_queue/models/__init__.py b/jikimo_demand_plan_queue/models/__init__.py
new file mode 100644
index 00000000..54314ee3
--- /dev/null
+++ b/jikimo_demand_plan_queue/models/__init__.py
@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from . import production_demand_plan
diff --git a/jikimo_demand_plan_queue/models/production_demand_plan.py b/jikimo_demand_plan_queue/models/production_demand_plan.py
new file mode 100644
index 00000000..fd51e055
--- /dev/null
+++ b/jikimo_demand_plan_queue/models/production_demand_plan.py
@@ -0,0 +1,20 @@
+from odoo import models, fields
+
+
+class ProductionDemandPlan(models.Model):
+ _inherit = 'sf.production.demand.plan'
+
+
+ def _do_production_schedule(self, pro_plan_list):
+ """使用队列进行排程"""
+ batch_size = 10
+ current_time = fields.Datetime.now().strftime('%Y%m%d%H%M%S')
+ index = 1
+ for i in range(0, len(pro_plan_list), batch_size):
+ batch = self.env['queue.job.batch'].get_new_batch('plan-%s-%s' % (current_time, index))
+ pro_plans = pro_plan_list[i:i+batch_size]
+ pro_plans.with_context(
+ job_batch=batch
+ ).with_delay().do_production_schedule()
+ index += 1
+ batch.enqueue()
\ No newline at end of file
diff --git a/jikimo_frontend/static/src/scss/custom_style.scss b/jikimo_frontend/static/src/scss/custom_style.scss
index c668d82e..6ffb824d 100644
--- a/jikimo_frontend/static/src/scss/custom_style.scss
+++ b/jikimo_frontend/static/src/scss/custom_style.scss
@@ -521,11 +521,6 @@ div:has(.o_required_modifier) > label::before {
}
}
-// 设置表格横向滚动
-.o_list_renderer.o_renderer {
- max-width: 100%;
- overflow-x: auto;
-}
// 设置表单页面label文本不换行
.o_form_view .o_group .o_wrap_label .o_form_label {
diff --git a/jikimo_purchase_request/models/__init__.py b/jikimo_purchase_request/models/__init__.py
index 4d5c92da..f1ba1696 100644
--- a/jikimo_purchase_request/models/__init__.py
+++ b/jikimo_purchase_request/models/__init__.py
@@ -6,3 +6,4 @@ from . import mrp_production
from . import purchase_order
from . import stock_rule
from . import stock_picking
+from . import product_product
diff --git a/jikimo_purchase_request/models/mrp_production.py b/jikimo_purchase_request/models/mrp_production.py
index 6973d51f..d7cd4b81 100644
--- a/jikimo_purchase_request/models/mrp_production.py
+++ b/jikimo_purchase_request/models/mrp_production.py
@@ -12,9 +12,7 @@ class MrpProduction(models.Model):
if item.product_id.is_customer_provided:
item.pr_mp_count = 0
else:
- # 由于采购申请合并了所有销售订单行的采购,所以不区分产品
- mrp_names = self.env['mrp.production'].search([('origin', '=', item.origin)]).mapped('name')
- pr_ids = self.env['purchase.request'].sudo().search([('origin', 'in', mrp_names)])
+ pr_ids = item._get_purchase_request()
item.pr_mp_count = len(pr_ids)
# pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', item.name), ('is_subcontract', '!=', 'True')])
@@ -25,8 +23,7 @@ class MrpProduction(models.Model):
self.ensure_one()
# 由于采购申请合并了所有销售订单行的采购,所以不区分产品
- mrp_names = self.env['mrp.production'].search([('origin', '=', self.origin)]).mapped('name')
- pr_ids = self.env['purchase.request'].sudo().search([('origin', 'in', mrp_names)])
+ pr_ids = self._get_purchase_request()
action = {
'res_model': 'purchase.request',
@@ -44,3 +41,12 @@ class MrpProduction(models.Model):
'view_mode': 'tree,form',
})
return action
+
+ def _get_purchase_request(self):
+ """获取跟制造订单相关的采购申请单(根据采购申请单行项目的产品匹配)"""
+ mrp_names = self.env['mrp.production'].search([('origin', '=', self.origin)]).mapped('name')
+ pr_ids = self.env['purchase.request'].sudo().search([('origin', 'in', mrp_names)])
+ product_list = self.product_id._get_product_include_bom()
+ pr_line_ids = pr_ids.line_ids.filtered(lambda l: l.product_id in product_list)
+ return pr_line_ids.mapped('request_id')
+
\ No newline at end of file
diff --git a/jikimo_purchase_request/models/product_product.py b/jikimo_purchase_request/models/product_product.py
new file mode 100644
index 00000000..c59fcdb8
--- /dev/null
+++ b/jikimo_purchase_request/models/product_product.py
@@ -0,0 +1,17 @@
+from odoo import models
+
+
+class ProductProduct(models.Model):
+ _inherit = 'product.product'
+
+
+ def _get_product_include_bom(self):
+ """获取产品列表(包括所有bom)"""
+ self.ensure_one()
+ product_list = [self]
+ bom_ids = self.bom_ids
+ while (bom_ids):
+ bom_product_ids = bom_ids.bom_line_ids.mapped('product_id')
+ product_list.append(bom_product_ids)
+ bom_ids = bom_product_ids.bom_ids
+ return product_list
\ No newline at end of file
diff --git a/jikimo_purchase_request/models/stock_picking.py b/jikimo_purchase_request/models/stock_picking.py
index abac1b1b..97b294f3 100644
--- a/jikimo_purchase_request/models/stock_picking.py
+++ b/jikimo_purchase_request/models/stock_picking.py
@@ -42,6 +42,6 @@ class StockPicking(models.Model):
purchase_request_lines = self.move_ids.move_orig_ids.purchase_line_id.purchase_request_lines
if purchase_request_lines:
purchase_request_lines.move_dest_ids = [
- (4, x.id) for x in backorder_ids.move_ids if x.product_id.id == purchase_request_lines.product_id.id
+ (4, x.id) for x in backorder_ids.move_ids if x.product_id.id in purchase_request_lines.mapped('product_id.id')
]
return res
\ No newline at end of file
diff --git a/sf_demand_plan/__manifest__.py b/sf_demand_plan/__manifest__.py
index 932685e0..e65fdca7 100644
--- a/sf_demand_plan/__manifest__.py
+++ b/sf_demand_plan/__manifest__.py
@@ -10,7 +10,7 @@
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
- 'depends': ['sf_plan', 'jikimo_printing'],
+ 'depends': ['sf_plan','jikimo_printing'],
'data': [
'security/ir.model.access.csv',
'views/demand_plan.xml',
@@ -23,6 +23,7 @@
],
'web.assets_backend': [
'sf_demand_plan/static/src/scss/style.css',
+ 'sf_demand_plan/static/src/js/print_demand.js',
]
},
'license': 'LGPL-3',
diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py
index ef11adcc..12214bff 100644
--- a/sf_demand_plan/models/sf_production_demand_plan.py
+++ b/sf_demand_plan/models/sf_production_demand_plan.py
@@ -39,11 +39,7 @@ class SfProductionDemandPlan(models.Model):
company_id = fields.Many2one(
related='sale_order_id.company_id',
store=True, index=True, precompute=True)
- partner_id = fields.Many2one(
- comodel_name='res.partner',
- related='sale_order_line_id.order_partner_id',
- string="客户",
- store=True, index=True)
+ customer_name = fields.Char('客户', related='sale_order_id.customer_name')
order_remark = fields.Text(related='sale_order_id.remark',
string="订单备注", store=True)
glb_url = fields.Char(related='sale_order_line_id.glb_url', string='glb文件地址')
@@ -64,7 +60,7 @@ class SfProductionDemandPlan(models.Model):
product_uom_qty = fields.Float(
string="需求数量",
related='sale_order_line_id.product_uom_qty', store=True)
- deadline_of_delivery = fields.Date('客户交期', related='sale_order_id.deadline_of_delivery', store=True)
+ deadline_of_delivery = fields.Date('客户交期', related='sale_order_line_id.delivery_end_date', store=True)
inventory_quantity_auto_apply = fields.Float(
string="成品库存",
compute='_compute_inventory_quantity_auto_apply'
@@ -73,7 +69,10 @@ class SfProductionDemandPlan(models.Model):
"交货数量", related='sale_order_line_id.qty_delivered')
qty_to_deliver = fields.Float(
"待交货数量", related='sale_order_line_id.qty_to_deliver')
- model_long = fields.Char('尺寸', compute='_compute_model_long')
+ model_long = fields.Char('尺寸(mm)', compute='_compute_model_long')
+ blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类',
+ related='product_id.blank_type')
+ embryo_long = fields.Char('坯料尺寸(mm)', compute='_compute_embryo_long')
materials_id = fields.Char('材料', compute='_compute_materials_id', store=True)
model_machining_precision = fields.Selection(selection=_get_machining_precision, string='精度',
related='product_id.model_machining_precision')
@@ -197,6 +196,14 @@ class SfProductionDemandPlan(models.Model):
else:
line.model_long = None
+ @api.depends('product_id.model_long', 'product_id.model_width', 'product_id.model_height')
+ def _compute_embryo_long(self):
+ for line in self:
+ if line.product_id:
+ line.embryo_long = f"{round(line.product_id.model_long, 3)}*{round(line.product_id.model_width, 3)}*{round(line.product_id.model_height, 3)}"
+ else:
+ line.embryo_long = None
+
@api.depends('product_id.materials_id')
def _compute_materials_id(self):
for line in self:
@@ -272,18 +279,21 @@ class SfProductionDemandPlan(models.Model):
else:
record.actual_end_date = None
- @api.depends('sale_order_id.mrp_production_ids.move_raw_ids.forecast_availability',
- 'sale_order_id.mrp_production_ids.move_raw_ids.quantity_done')
+ @api.depends('sale_order_id.mrp_production_ids.move_raw_ids.reserved_availability')
def _compute_material_check(self):
for record in self:
if record.sale_order_id and record.sale_order_id.mrp_production_ids:
manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered(
lambda mo: mo.product_id == record.product_id)
+
if manufacturing_orders and manufacturing_orders.move_raw_ids:
- total_forecast_availability = sum(manufacturing_orders.mapped('move_raw_ids.forecast_availability'))
- total_quantity_done = sum(manufacturing_orders.mapped('move_raw_ids.quantity_done'))
- total_sum = total_forecast_availability + total_quantity_done
- if float_compare(total_sum, record.product_uom_qty,
+ # 获取完成的制造订单
+ done_manufacturing = manufacturing_orders.filtered(lambda mo: mo.state == 'done')
+ product_qty = sum(done_manufacturing.mapped('product_qty'))
+ # 需求数量-完成数量
+ product_uom_qty = record.product_uom_qty - product_qty
+ total_reserved_availability = sum(manufacturing_orders.mapped('move_raw_ids.reserved_availability'))
+ if float_compare(total_reserved_availability, product_uom_qty,
precision_rounding=record.product_id.uom_id.rounding) >= 0:
record.material_check = '1' # 已齐套
else:
@@ -308,13 +318,17 @@ class SfProductionDemandPlan(models.Model):
[('name', '=', '1#CNC自动生产线')], limit=1)
if sf_production_line:
now = datetime.now()
- time_part = (now + timedelta(minutes=3)).time()
+ time_part = (now + timedelta(hours=2)).time()
date_part = fields.Date.from_string(self.planned_start_date)
date_planned_start = datetime.combine(date_part, time_part)
pro_plan_list.production_line_id = sf_production_line.id
pro_plan_list.date_planned_start = date_planned_start
- for pro_plan in pro_plan_list:
- pro_plan.do_production_schedule()
+ self._do_production_schedule(pro_plan_list)
+
+ def _do_production_schedule(self, pro_plan_list):
+ for pro_plan in pro_plan_list:
+ pro_plan.do_production_schedule()
+
def button_action_print(self):
return {
@@ -503,7 +517,10 @@ class SfProductionDemandPlan(models.Model):
action = self.env["ir.actions.actions"]._for_xml_id("stock.action_picking_tree_all")
picking_ids = None
if self.supply_method in ('automation', 'manual'):
- picking_ids = self.sale_order_id.mrp_production_ids.mapped('picking_ids').filtered(
+ mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered(
+ lambda p: p.product_id.id == self.product_id.id
+ )
+ picking_ids = mrp_production_ids.mapped('picking_ids').filtered(
lambda p: p.state == 'assigned')
elif self.supply_method in ('purchase', 'outsourcing'):
picking_ids = self.sale_order_id.picking_ids.filtered(
diff --git a/sf_demand_plan/static/src/js/print_demand.js b/sf_demand_plan/static/src/js/print_demand.js
new file mode 100644
index 00000000..a05638a7
--- /dev/null
+++ b/sf_demand_plan/static/src/js/print_demand.js
@@ -0,0 +1,256 @@
+odoo.define('sf_demand.print_demand', function (require) {
+ "use strict";
+
+ var ListController = require('web.ListController');
+ var ListRenderer = require('web.ListRenderer');
+ var ListView = require('web.ListView');
+ var viewRegistry = require('web.view_registry');
+ var { url } = require("@web/core/utils/urls")
+
+ var CustomListRenderer = ListRenderer.extend({
+ _render: function () {
+ var self = this;
+ this.getParent()?.$buttons.hide();
+
+ return this._super.apply(this, arguments).then(function () {
+ if(!self.state.data || !self.state.data.length) return
+ // 添加图片预览容器到页面左侧
+ if (!$('.table-image-preview-container').length) {
+ self.$el.parent().addClass('custom-table-image-container')
+ self.$el.before(
+ `
+
![]()
+
+
`
+ );
+
+ }
+
+ if(!$('.denmand_set').length) {
+
+ const checked = self.getParent().radioCheck || 'all'
+
+ self.$el.prepend(`
+
+ `)
+ setTimeout(() => {
+ $(`input[name=set][value=${checked}]`).prop('checked', true)
+ $('.denmand_set').trigger('click')
+ }, 100);
+ self.$el.prepend(`
+
+
+
+
+ `);
+ }
+ });
+ },
+ start: function() {
+ setTimeout(() => {
+ this.$el.find('.o_data_row').eq(0).trigger('click')
+ this.getParent().$el?.find('.o_cp_top_right,.o_cp_bottom').hide()
+ }, 500);
+ return this._super();
+ },
+ events: _.extend({}, ListRenderer.prototype.events, {
+ 'click .o_data_row': '_onCustomRowClick',
+ 'click .o_print_custom': '_onPrintClick',
+ 'click .o_cancel_custom': '_onCancelClick',
+ 'click .denmand_set': '_onDenmandChange',
+ }),
+ _onCancelClick() {
+ this.getParent()?.getParent()?.dialogs.closeAll()
+ },
+ _onCustomRowClick: async function (ev) {
+ var self = this;
+ var $row = $(ev.currentTarget);
+ var index = $row.index();
+ var data = this.state.data[index];
+ if(data.fileData?.fileUrl) {
+
+ } else {
+ data.fileData = { }
+ if(data.res_id) {
+ // 正确获取 ORM 服务的方式
+ // var orm = this.getParent().getParent().env.services
+ const key = data.data.type == 1 ? 'machining_drawings' : 'cnc_worksheet'
+ const attachment = await this._rpc({
+ model: 'ir.binary',
+ method: 'attachment_info',
+ args: [
+ data.model,
+ data.res_id,
+ key
+ ],
+ })
+
+ if (attachment) {
+ Object.assign(data.fileData, attachment)
+ this._getTypeInfo(attachment.mimetype, data.fileData)
+ }
+ const fileUrl = this.getFileUrl(data.fileData.attachment_type, data, key)
+ data.fileData.fileUrl = fileUrl
+ }
+ }
+ $('.table-image-preview-container').hide()
+ if(data.fileData.attachment_type == 'iframe') {
+
+ $('iframe.table-image-preview-container').attr('src', decodeURIComponent(data.fileData.fileUrl) ).show()
+ } else {
+ $('img.table-image-preview-container').attr('src', data.fileData.fileUrl).show()
+ }
+ },
+ getSelectedIds: function() {
+ return this.state.data.filter(_ => !_.hide).map(_ => {
+ return _.data.id
+ })
+ },
+ _onPrintClick(e) {
+ var print_ids = this.getSelectedIds();
+ this._rpc({
+ model: 'sf.demand.plan.print.wizard',
+ method: 'demand_plan_print',
+ args: [ print_ids ] ,
+ // context: this.state.getContext()
+ }).then((e) => {
+
+ this.getParent()?.getParent()?.env.services?.notification.notify( {
+ type: 'info',
+ message: e.message,
+ })
+ // self.do_notify("成功", "打印任务已发送到打印机");
+ }).catch(function(error) {
+ console.error("打印错误:", error);
+ // self.do_warn("打印失败", error.data.message || "未知错误");
+ }).finally(e => {
+ this.getParent().reload()
+ })
+
+ },
+ _onDenmandChange(e) {
+ const isChecked = $(e.currentTarget).find('input:checked').val()
+ this.getParent().radioCheck = isChecked
+ this.$el.find('tbody').find('.o_data_row').show()
+
+ this.state.data.forEach(_ => {
+ _.hide = false
+ })
+ const self = this
+ if(!isChecked || isChecked == 'all') return
+ this.$el.find('tbody').children('.o_data_row').each(function() {
+ if($(this).find('td[name=type]').text() != isChecked) {
+ const i = $(this).index()
+
+ self.state.data[i].hide = true
+ $(this).hide()
+ }
+ })
+ },
+ getFileUrl(attachment_type, data, key) {
+ let fileUrl
+ switch (attachment_type) {
+ case 'image':
+ const timer = +new Date()
+ fileUrl = url("/web/image", {
+ model: data.model,
+ id: data.res_id,
+ field: key,
+ unique: '',
+ timer
+ });
+
+ break;
+ case 'iframe':
+
+ const iframe_file_url = encodeURIComponent(
+ url("/web/content", {
+ model: data.model,
+ id: data.res_id,
+ field: key,
+ })
+ );
+ fileUrl = `${this.state.attachment_base}?file=${iframe_file_url}`;
+ case 'unknown':
+ fileUrl = encodeURIComponent(
+ url("/web/content", {
+ model: data.model,
+ id: data.res_id,
+ field: key,
+ })
+ );
+ }
+
+ return fileUrl
+ },
+ _getTypeInfo(type, data) {
+ switch (type) {
+ case 'application/pdf':
+ data.attachment_base = `/web/static/lib/pdfjs/web/viewer.html`;
+ data.attachment_type = 'iframe'
+ break;
+ case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
+ data.attachment_base = `/jikimo_attachment_viewer/static/lib/docxjs/viewer.html`;
+ data.attachment_type = 'iframe'
+ break;
+ case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
+ data.attachment_base = `/jikimo_attachment_viewer/static/lib/exceljs/viewer.html`;
+ data.attachment_type = 'iframe'
+ break;
+ case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
+ data.attachment_base = '';
+ data.attachment_type = 'unknown'
+ break;
+ case 'image/png':
+ case 'image/jpeg':
+ case 'image/jpg':
+ data.attachment_base = ''
+ data.attachment_type = 'image'
+ break;
+ default:
+ data.attachment_base = ''
+ data.attachment_type = 'unknown'
+ break;
+ }
+ }
+ });
+
+ var CustomListController = ListController.extend({
+ // 可以保留或移除,根据是否需要处理自定义事件
+ // 处理打印操作
+ // rpc.query({
+ // model: 'sf.demand.plan.print.wizard',
+ // method: 'demand_plan_print',
+ // args: [recordIds]
+ // }).then(function(result) {
+ // self.do_notify("成功", "打印任务已发送到打印机");
+ // // 刷新视图显示最新状态
+ // self.reload();
+ // }).catch(function(error) {
+ // self.do_warn("打印失败", error.data.message || "发生未知错误");
+ // });
+ });
+
+ var PrintDemand = ListView.extend({
+ config: _.extend({}, ListView.prototype.config, {
+ Renderer: CustomListRenderer,
+ Controller: CustomListController,
+ }),
+ });
+
+ viewRegistry.add('print_demand', PrintDemand);
+
+ return PrintDemand;
+});
\ No newline at end of file
diff --git a/sf_demand_plan/static/src/scss/style.css b/sf_demand_plan/static/src/scss/style.css
index f5b687fb..9662a10a 100644
--- a/sf_demand_plan/static/src/scss/style.css
+++ b/sf_demand_plan/static/src/scss/style.css
@@ -9,3 +9,76 @@
.demand_plan_tree .o_list_table_ungrouped {
min-width: 1900px;
}
+
+
+.o_selected_row {
+ background-color: #e6f7ff !important;
+ font-weight: bold;
+}
+
+.custom-table-image-container {
+ display: flex;
+ height: calc(95vh - 254px);
+ gap: 20px;
+ position: relative;
+ th.o_list_record_selector, td.o_list_record_selector{
+ display: none;
+ }
+ .custom-preview-container, .print_demand {
+ flex: 1;
+
+ max-width: 49%;
+ tbody {
+ tr:not(.o_data_row) {
+ display: none;
+ }
+ }
+ tfoot {
+ display: none;
+ }
+ }
+ .print_demand {
+ .table-responsive {
+ width: 100%;
+ overflow-x: auto!important;
+ }
+ }
+ .custom-preview-container {
+ background-color: #dadce0;
+ padding: 20px;
+ img {
+ max-width: 100%;
+ max-height: 100%;
+ }
+ iframe {
+ width: 100%;
+ height: 100%;
+ }
+ }
+ .o_print_custom, .o_cancel_custom {
+ position: absolute;
+ bottom: 20px;
+ right: 20px;
+ }
+ .o_print_custom {
+ right: 66px;
+ }
+}
+
+.denmand_set {
+ display: flex;
+ align-items: center;
+ height: 50px;
+ > span {
+ font-weight: bold;
+ }
+ input {
+ margin-left: 30px;
+ }
+ label {
+ margin-left: 5px;
+ }
+ input,label {
+ cursor: pointer;
+ }
+}
\ No newline at end of file
diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml
index f78e5cf6..24a2707e 100644
--- a/sf_demand_plan/views/demand_plan.xml
+++ b/sf_demand_plan/views/demand_plan.xml
@@ -3,7 +3,7 @@
sf.production.demand.plan.tree
sf.production.demand.plan
-
-
+
@@ -28,6 +28,8 @@
+
+
@@ -80,7 +82,7 @@
-
+
@@ -89,7 +91,7 @@
-
+
sf.demand.plan.print.wizard.tree
sf.demand.plan.print.wizard
-
+
-
-
+
+
diff --git a/sf_dlm/models/product_template.py b/sf_dlm/models/product_template.py
index f9825c88..b7d54518 100644
--- a/sf_dlm/models/product_template.py
+++ b/sf_dlm/models/product_template.py
@@ -10,6 +10,7 @@ class ResProductTemplate(models.Model):
model_name = fields.Char('模型名称')
categ_type = fields.Selection(
[("成品", "成品"), ("胚料", "胚料"), ("原材料", "原材料")], string='产品的类别', related='categ_id.type', store=True)
+ blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类')
model_long = fields.Float('模型长[mm]', digits=(16, 3))
model_width = fields.Float('模型宽[mm]', digits=(16, 3))
model_height = fields.Float('模型高[mm]', digits=(16, 3))
@@ -72,14 +73,20 @@ class ResProductTemplate(models.Model):
copy_product_id.product_tmpl_id.active = True
model_type = self.env['sf.model.type'].search([], limit=1)
attachment = self.attachment_create(item['model_name'], item['model_data'])
+ # 判断参数中是否包含 坯料尺寸(长、宽、高)
+ blank_bool = any(value is not None and value != 0 for value in (
+ item.get('blank_length'), item.get('blank_width'), item.get('blank_height'))) if all(
+ key in item for key in ('blank_length', 'blank_width', 'blank_height')) else False
vals = {
'name': '%s-%s-%s' % ('P', order_id.name, i),
- 'model_long': item['model_long'] + model_type.embryo_tolerance,
- 'model_width': item['model_width'] + model_type.embryo_tolerance,
- 'model_height': item['model_height'] + model_type.embryo_tolerance,
- 'model_volume': (item['model_long'] + model_type.embryo_tolerance) * (
- item['model_width'] + model_type.embryo_tolerance) * (
- item['model_height'] + model_type.embryo_tolerance),
+ 'blank_type': item.get('blank_type'),
+ 'model_long': item.get('blank_length') if blank_bool else item['model_long'] + model_type.embryo_tolerance,
+ 'model_width': item.get('blank_width') if blank_bool else item['model_width'] + model_type.embryo_tolerance,
+ 'model_height': item.get('blank_height') if blank_bool else item['model_height'] + model_type.embryo_tolerance,
+ 'model_volume': ((item['model_long'] + model_type.embryo_tolerance) *
+ (item['model_width'] + model_type.embryo_tolerance) *
+ (item['model_height'] + model_type.embryo_tolerance)) if not blank_bool else (
+ item.get('blank_length') * item.get('blank_width') * item.get('blank_height')),
'product_model_type_id': model_type.id,
'model_processing_panel': 'R',
'model_machining_precision': item['model_machining_precision'],
diff --git a/sf_dlm_management/views/product_template_management_view.xml b/sf_dlm_management/views/product_template_management_view.xml
index 672251e4..bb9904a7 100644
--- a/sf_dlm_management/views/product_template_management_view.xml
+++ b/sf_dlm_management/views/product_template_management_view.xml
@@ -95,7 +95,7 @@
-
+
@@ -104,6 +104,7 @@
+
0 else 0), 3)
on_time_rate = 1 - delay_rate
- if plan_data:
- data = {
- 'plan_data_total_counts': plan_data_total_counts,
- 'plan_data_finish_counts': plan_data_finish_counts,
- 'plan_data_plan_counts': plan_data_total_counts,
- 'plan_data_fault_counts': plan_data_fault_counts,
- 'nopass_orders_counts': detection_data - len(pass_nums),
- 'finishe_rate': finishe_rate,
- 'plan_data_progress_deviation': plan_data_progress_deviation,
- 'plan_data_rework_counts': plan_data_rework_counts,
- 'on_time_rate': on_time_rate,
- # 'detection_data': detection_data,
- 'detection_data': plan_data_finish_counts,
- 'pass_rate': (plan_data_finish_counts - plan_data_fault_counts) / plan_data_finish_counts,
- 'plan_data_overtime_counts': plan_data_overtime_counts,
- 'overtime_rate': plan_data_overtime_counts / plan_data_finish_counts
- if plan_data_finish_counts > 0 else 0,
- }
- res['data'][line] = data
+ # if plan_data:
+ data = {
+ 'plan_data_total_counts': plan_data_total_counts,
+ 'plan_data_finish_counts': plan_data_finish_counts,
+ 'plan_data_plan_counts': plan_data_total_counts,
+ 'plan_data_fault_counts': plan_data_fault_counts,
+ 'nopass_orders_counts': detection_data - len(pass_nums),
+ 'finishe_rate': finishe_rate,
+ 'plan_data_progress_deviation': plan_data_progress_deviation,
+ 'plan_data_rework_counts': plan_data_rework_counts,
+ 'on_time_rate': on_time_rate,
+ # 'detection_data': detection_data,
+ 'detection_data': plan_data_finish_counts,
+ 'pass_rate': (plan_data_finish_counts - plan_data_fault_counts) / plan_data_finish_counts,
+ 'plan_data_overtime_counts': plan_data_overtime_counts,
+ 'overtime_rate': plan_data_overtime_counts / plan_data_finish_counts
+ if plan_data_finish_counts > 0 else 0,
+ }
+ res['data'][line] = data
return json.dumps(res) # 注意使用 json.dumps 而不是直接用 json.JSONEncoder().encode()
@@ -608,16 +633,34 @@ class Sf_Dashboard_Connect(http.Controller):
date_list.append(current_date)
current_date += timedelta(days=1)
return date_list
+
- for line in line_list:
- date_field_name = 'date_finished' # 替换为你模型中的实际字段名
- order_counts = []
+ if time_unit == 'hour':
+
+ for line in line_list:
+ date_field_name = 'date_finished' # 替换为你模型中的实际字段名
+ order_counts = []
- if time_unit == 'hour':
+ if line == '业绩总览':
+ work_order_domain = [('routing_type', 'in', ['人工线下加工', 'CNC加工'])]
+ elif line == '人工线下加工中心':
+ work_order_domain = [('routing_type', '=', '人工线下加工')]
+ else:
+ work_order_domain = [
+ ('production_line_id.name', '=', line),
+ ('routing_type', '=', 'CNC加工')
+ ]
time_intervals = get_time_intervals(begin_time, end_time, time_unit)
print('============================= %s' % time_intervals)
time_count_dict = {}
+ plan_count_dict = {}
+
+ orders = request.env['mrp.workorder'].sudo().search(work_order_domain + [
+ ('state', 'in', ['done']),
+ (date_field_name, '>=', begin_time.strftime('%Y-%m-%d %H:%M:%S')),
+ (date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S'))
+ ])
for time_interval in time_intervals:
start_time, end_time = time_interval
@@ -629,66 +672,113 @@ class Sf_Dashboard_Connect(http.Controller):
# (date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')) # 包括结束时间
# ])
- orders = request.env['mrp.workorder'].sudo().search([
- ('routing_type', '=', 'CNC加工'), # 将第一个条件合并进来
- ('production_line_id.name', '=', line),
- ('state', 'in', ['done']),
- (date_field_name, '>=', start_time.strftime('%Y-%m-%d %H:%M:%S')),
- (date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S'))
- ])
+ interval_orders = orders.filtered(
+ lambda o: o[date_field_name] >= start_time
+ and o[date_field_name] <= end_time
+ )
# 使用小时和分钟作为键,确保每个小时的数据有独立的键
key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
- time_count_dict[key] = len(orders)
+ # time_count_dict[key] = len(orders)
+ time_count_dict[key] = sum(interval_orders.mapped('qty_produced'))
+
+ # 计划量,目前只能从mail.message中筛选出
+ plan_order_messages = request.env['mail.message'].sudo().search([
+ ('model', '=', 'mrp.workorder'),
+ ('create_date', '>=', begin_time.strftime('%Y-%m-%d %H:%M:%S')),
+ ('create_date', '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')),
+ ('tracking_value_ids.field_desc', '=', '状态'),
+ ('tracking_value_ids.new_value_char', '=', '就绪')
+ ])
+
+ for time_interval in time_intervals:
+ start_time, end_time = time_interval
+
+ # orders = plan_obj.search([
+ # ('production_line_id.name', '=', line),
+ # ('state', 'in', ['done']),
+ # (date_field_name, '>=', start_time.strftime('%Y-%m-%d %H:%M:%S')),
+ # (date_field_name, '<=', end_time.strftime('%Y-%m-%d %H:%M:%S')) # 包括结束时间
+ # ])
+
+ interval_plan_orders = plan_order_messages.filtered(
+ lambda o: o.create_date >= start_time
+ and o.create_date <= end_time
+ )
+
+ interval_orders = request.env['mrp.workorder'].sudo().browse(interval_plan_orders.mapped('res_id'))
+ if line == '业绩总览':
+ interval_orders = interval_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工'])
+ elif line == '人工线下加工中心':
+ interval_orders = interval_orders.filtered(lambda o: o.routing_type == '人工线下加工')
+ else:
+ interval_orders = interval_orders.filtered(lambda o: o.routing_type == 'CNC加工' and o.production_line_id.name == line)
+
+ # 使用小时和分钟作为键,确保每个小时的数据有独立的键
+ key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
+ # time_count_dict[key] = len(orders)
+ plan_count_dict[key] = sum(interval_orders.mapped('qty_production'))
+
# order_counts.append()
res['data'][line] = {
'finish_order_nums': time_count_dict,
- 'plan_order_nums': 28
+ 'plan_order_nums': plan_count_dict
}
- return json.dumps(res)
+ else:
- date_list = get_date_list(begin_time, end_time)
+ for line in line_list:
+ date_field_name = 'date_finished' # 替换为你模型中的实际字段名
+ order_counts = []
- for date in date_list:
- next_day = date + timedelta(days=1)
- orders = request.env['mrp.workorder'].sudo().search(
- [('production_id.production_line_id.name', '=', line), ('state', 'in', ['done']),
- ('routing_type', '=', 'CNC加工'),
- (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
- (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
- ])
+ if line == '业绩总览':
+ work_order_domain = [('routing_type', 'in', ['人工线下加工', 'CNC加工'])]
+ elif line == '人工线下加工中心':
+ work_order_domain = [('routing_type', '=', '人工线下加工')]
+ else:
+ work_order_domain = [
+ ('production_line_id.name', '=', line),
+ ('routing_type', '=', 'CNC加工')
+ ]
- rework_orders = request.env['mrp.workorder'].sudo().search(
- [('production_id.production_line_id.name', '=', line), ('state', 'in', ['rework']),
- ('routing_type', '=', 'CNC加工'),
- (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
- (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
- ])
- not_passed_orders = request.env['mrp.workorder'].sudo().search(
- [('production_id.production_line_id.name', '=', line), ('state', 'in', ['scrap', 'cancel']),
- ('routing_type', '=', 'CNC加工'),
- (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
- (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
- ])
- order_counts.append({
- 'date': date.strftime('%Y-%m-%d'),
- 'order_count': len(orders),
- 'rework_orders': len(rework_orders),
- 'not_passed_orders': len(not_passed_orders)
- })
- # 外面包一层,没什么是包一层不能解决的,包一层就能区分了,类似于包一层div
- # 外面包一层的好处是,可以把多个数据结构打包在一起,方便前端处理
+ date_list = get_date_list(begin_time, end_time)
- # date_list_dict = {line: order_counts}
+ for date in date_list:
+ next_day = date + timedelta(days=1)
+ orders = request.env['mrp.workorder'].sudo().search(work_order_domain + [
+ ('state', 'in', ['done']),
+ (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
+ (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
+ ])
- res['data'][line] = order_counts
+ rework_orders = request.env['mrp.workorder'].sudo().search(work_order_domain + [
+ ('state', 'in', ['rework']),
+ (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
+ (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
+ ])
+ not_passed_orders = request.env['mrp.workorder'].sudo().search(work_order_domain + [
+ ('state', 'in', ['scrap', 'cancel']),
+ (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
+ (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
+ ])
+ order_counts.append({
+ 'date': date.strftime('%Y-%m-%d'),
+ 'order_count': sum(orders.mapped('qty_produced')),
+ 'rework_orders': sum(rework_orders.mapped('qty_produced')),
+ 'not_passed_orders': sum(not_passed_orders.mapped('qty_produced'))
+ })
+ # 外面包一层,没什么是包一层不能解决的,包一层就能区分了,类似于包一层div
+ # 外面包一层的好处是,可以把多个数据结构打包在一起,方便前端处理
+
+ # date_list_dict = {line: order_counts}
+
+ res['data'][line] = order_counts
return json.dumps(res)
# 实时产量
@http.route('/api/RealTimeProduct', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
def RealTimeProduct(self, **kw):
"""
- 获取实时产量
+ 获取实时产量(作废)
:param kw:
:return:
"""
@@ -711,6 +801,21 @@ class Sf_Dashboard_Connect(http.Controller):
# 当班计划量
for line in line_list:
+
+ if line == '业绩总览':
+ work_order_domain = [('routing_type', 'in', ['人工线下加工', 'CNC加工'])]
+ plan_domain = []
+ elif line == '人工线下加工中心':
+ work_order_domain = [('routing_type', '=', '人工线下加工')]
+ plan_domain = [('production_type', '=', '人工线下加工')]
+ else:
+ work_order_domain = [
+ ('production_line_id.name', '=', line),
+ ('routing_type', '=', 'CNC加工')
+ ]
+ plan_domain = [('production_line_id.name', '=', line)]
+
+
plan_order_nums = plan_obj.search_count(
[('production_line_id.name', '=', line), ('state', 'not in', ['draft']),
('date_planned_start', '>=', begin_time),
@@ -752,10 +857,10 @@ class Sf_Dashboard_Connect(http.Controller):
:param kw:
:return:
"""
-
# res = {'status': 1, 'message': '成功', 'not_done_data': [], 'done_data': []}
res = {'status': 1, 'message': '成功', 'data': {}}
plan_obj = request.env['sf.production.plan'].sudo()
+ work_order_obj = request.env['mrp.workorder'].sudo()
line_list = ast.literal_eval(kw['line_list'])
begin_time_str = kw['begin_time'].strip('"')
end_time_str = kw['end_time'].strip('"')
@@ -765,28 +870,39 @@ class Sf_Dashboard_Connect(http.Controller):
not_done_data = []
done_data = []
final_data = {}
+ not_done_index = 1
+ done_index = 1
for line in line_list:
+
+ if line == '业绩总览':
+ work_order_domain = [('routing_type', 'in', ['人工线下加工', 'CNC加工'])]
+ elif line == '人工线下加工中心':
+ work_order_domain = [('routing_type', '=', '人工线下加工')]
+ else:
+ work_order_domain = [
+ ('production_line_id.name', '=', line),
+ ('routing_type', '=', 'CNC加工')
+ ]
# 未完成订单
# not_done_orders = plan_obj.search(
# [('production_line_id.name', '=', line), ('state', 'not in', ['finished']),
# ('production_id.state', 'not in', ['cancel', 'done']), ('active', '=', True)
# ])
- not_done_orders = request.env['mrp.workorder'].sudo().search(
- [('production_line_id.name', '=', line), ('state', 'in', ['ready', 'progress']),
- ('routing_type', '=', 'CNC加工')
- ])
+ not_done_orders = work_order_obj.search(work_order_domain +
+ [('state', 'in', ['ready', 'progress'])], order='id asc'
+ )
# 完成订单
# 获取当前时间,并计算24小时前的时间
current_time = datetime.now()
time_24_hours_ago = current_time - timedelta(hours=24)
- finish_orders = plan_obj.search([
- ('production_line_id.name', '=', line), ('state', 'in', ['finished']),
- ('production_id.state', 'not in', ['cancel']), ('active', '=', True),
- ('actual_end_time', '>=', time_24_hours_ago)
- ])
+ finish_orders = work_order_obj.search(work_order_domain + [
+ ('state', 'in', ['finished']),
+ ('production_id.state', 'not in', ['cancel']),
+ ('date_finished', '>=', time_24_hours_ago)
+ ], order='id asc')
# print(finish_orders)
# 获取所有未完成订单的ID列表
@@ -795,14 +911,14 @@ class Sf_Dashboard_Connect(http.Controller):
finish_order_ids = [order.id for order in finish_orders]
# 对ID进行排序
- sorted_order_ids = sorted(order_ids)
+ # sorted_order_ids = sorted(order_ids)
- finish_sorted_order_ids = sorted(finish_order_ids)
+ # finish_sorted_order_ids = sorted(finish_order_ids)
# 创建ID与序号的对应关系
- id_to_sequence = {order_id: index + 1 for index, order_id in enumerate(sorted_order_ids)}
+ # id_to_sequence = {order_id: index + 1 for index, order_id in enumerate(sorted_order_ids)}
- finish_id_to_sequence = {order_id: index + 1 for index, order_id in enumerate(finish_sorted_order_ids)}
+ # finish_id_to_sequence = {order_id: index + 1 for index, order_id in enumerate(finish_sorted_order_ids)}
# # 输出结果或进一步处理
# for order_id, sequence in id_to_sequence.items():
@@ -833,16 +949,17 @@ class Sf_Dashboard_Connect(http.Controller):
}
line_dict = {
- 'sequence': id_to_sequence[order.id],
+ 'sequence': not_done_index,
'workorder_name': order.production_id.name,
'blank_name': blank_name,
'material': material,
'dimensions': dimensions,
- 'order_qty': 1,
+ 'order_qty': order.qty_production,
'state': state_dict[order.state],
}
not_done_data.append(line_dict)
+ not_done_index += 1
for finish_order in finish_orders:
if not finish_order.actual_end_time:
@@ -861,17 +978,18 @@ class Sf_Dashboard_Connect(http.Controller):
material = material_match.group(1) if material_match else 'No match found'
line_dict = {
- 'sequence': finish_id_to_sequence[finish_order.id],
+ 'sequence': done_index,
'workorder_name': finish_order.name,
'blank_name': blank_name,
'material': material,
'dimensions': dimensions,
- 'order_qty': finish_order.product_qty,
+ 'order_qty': order.qty_produced,
'finish_time': finish_order.actual_end_time.strftime(
'%Y-%m-%d %H:%M:%S') if finish_order.actual_end_time else ' '
}
done_data.append(line_dict)
+ done_index += 1
# 开始包一层
res['data'][line] = {'not_done_data': not_done_data, 'done_data': done_data}
diff --git a/sf_manufacturing/controllers/main.py b/sf_manufacturing/controllers/main.py
index 1e5f4a57..6172dc11 100644
--- a/sf_manufacturing/controllers/main.py
+++ b/sf_manufacturing/controllers/main.py
@@ -45,9 +45,8 @@ class JikimoSaleRoutePicking(Sf_Bf_Connect):
product.product_tmpl_id.is_customer_provided = True if item['embryo_redundancy_id'] else False
order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item)
i += 1
- if kw.get('contract_file_name') and kw.get('contract_file') and kw.get('contract_code'):
- order_id.create_sale_documents(kw.get('contract_file_name'), kw.get('contract_file'))
- order_id.write({'contract_code': kw.get('contract_code'), 'contract_date': kw.get('contract_date')})
+ # BFM 内部下单 新增合同等内容补充
+ order_id.write_sale_documents(kw)
res['factory_order_no'] = order_id.name
order_id.confirm_to_supply_method()
except Exception as e:
diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py
index 22effb7e..4062814e 100644
--- a/sf_manufacturing/models/product_template.py
+++ b/sf_manufacturing/models/product_template.py
@@ -26,6 +26,7 @@ class ResProductMo(models.Model):
model_file = fields.Binary('模型文件')
categ_type = fields.Selection(string='产品的类别', related='categ_id.type', store=True)
model_name = fields.Char('模型名称')
+ blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类')
model_long = fields.Float('模型长(mm)', digits=(16, 3))
model_width = fields.Float('模型宽(mm)', digits=(16, 3))
model_height = fields.Float('模型高(mm)', digits=(16, 3))
@@ -893,14 +894,20 @@ class ResProductMo(models.Model):
if not embryo_redundancy_id:
raise UserError('请先配置模型类型内的坯料冗余')
product_name = self.generate_product_name(order_id, item, i)
+ # 判断参数中是否包含 坯料尺寸(长、宽、高)
+ blank_bool = any(value is not None and value != 0 for value in (
+ item.get('blank_length'), item.get('blank_width'), item.get('blank_height'))) if all(
+ key in item for key in ('blank_length', 'blank_width', 'blank_height')) else False
vals = {
'name': product_name,
- 'model_long': self.format_float(item['model_long'] + embryo_redundancy_id.long),
- 'model_width': self.format_float(item['model_width'] + embryo_redundancy_id.width),
- 'model_height': self.format_float(item['model_height'] + embryo_redundancy_id.height),
- 'model_volume': self.format_float((item['model_long'] + embryo_redundancy_id.long) * (
- item['model_width'] + embryo_redundancy_id.width) * (
- item['model_height'] + embryo_redundancy_id.height)),
+ 'blank_type': item.get('blank_type'),
+ 'model_long': item.get('blank_length') if blank_bool else self.format_float(item['model_long'] + embryo_redundancy_id.long),
+ 'model_width': item.get('blank_width') if blank_bool else self.format_float(item['model_width'] + embryo_redundancy_id.width),
+ 'model_height': item.get('blank_height') if blank_bool else self.format_float(item['model_height'] + embryo_redundancy_id.height),
+ 'model_volume': self.format_float(((item['model_long'] + embryo_redundancy_id.long) *
+ (item['model_width'] + embryo_redundancy_id.width) *
+ (item['model_height'] + embryo_redundancy_id.height))) if not blank_bool else (
+ item.get('blank_length') * item.get('blank_width') * item.get('blank_height')),
'product_model_type_id': model_type.id,
'model_processing_panel': item['processing_panel_detail'],
'model_machining_precision': item['model_machining_precision'],
diff --git a/sf_manufacturing/models/sale_order.py b/sf_manufacturing/models/sale_order.py
index 0bb660ac..34c61950 100644
--- a/sf_manufacturing/models/sale_order.py
+++ b/sf_manufacturing/models/sale_order.py
@@ -193,6 +193,19 @@ class SaleOrder(models.Model):
'target': 'new',
'res_id': wizard.id,
}
+
+ def write_sale_documents(self, kw):
+ """BFM 内部下单 内容补充 """
+ val = {}
+ if kw.get('contract_file_name') and kw.get('contract_file'):
+ document_id = self.create_sale_documents(kw.get('contract_file_name'), kw.get('contract_file'))
+ val.update({'contract_document_id': document_id.id})
+ if kw.get('contract_code') or kw.get('contract_date'):
+ val.update({'contract_code': kw.get('contract_code'), 'contract_date': kw.get('contract_date')})
+ if kw.get('customer_name'):
+ val.update({'customer_name': kw.get('customer_name')})
+ self.write(val)
+
def create_sale_documents(self, contract_file_name, contract_file):
# 创建ir.attachment记录
attachment = self.env['ir.attachment'].sudo().create({
@@ -214,9 +227,7 @@ class SaleOrder(models.Model):
'res_id': self.id,
})
- self.write({
- 'contract_document_id': document.id
- })
+ return document
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
diff --git a/sf_quality/data/insepection_report_template.xml b/sf_quality/data/insepection_report_template.xml
index 14a42065..001a9a84 100644
--- a/sf_quality/data/insepection_report_template.xml
+++ b/sf_quality/data/insepection_report_template.xml
@@ -92,7 +92,7 @@
-
+
| 产品名称: |
@@ -113,7 +113,7 @@
|
-
+
检验结果
-

+
@@ -182,7 +182,7 @@
-
+
操作员:
@@ -200,11 +200,11 @@
-->
-
-
-
-
+
+
+
+
@@ -275,7 +275,7 @@
-
+
@@ -329,9 +329,11 @@
-->
-
-
-
+
+
+
+
+
diff --git a/sf_quality/views/quality_check_view.xml b/sf_quality/views/quality_check_view.xml
index 953de51e..3798ad95 100644
--- a/sf_quality/views/quality_check_view.xml
+++ b/sf_quality/views/quality_check_view.xml
@@ -66,7 +66,7 @@
不合格
- {'invisible': ['|',('quality_state', '!=', 'pass'),('work_state','in', ('done', 'rework'))]}
+ {'invisible': ['|','|',('quality_state', '!=', 'pass'),('work_state','in', ('done', 'rework')),'&',('quality_state', '=', 'pass'), ('test_type', '=', 'factory_inspection')]}
不合格
diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py
index 90e1bd21..c879093e 100644
--- a/sf_sale/models/sale_order.py
+++ b/sf_sale/models/sale_order.py
@@ -63,6 +63,7 @@ class ReSaleOrder(models.Model):
model_display_version = fields.Char('模型展示版本', default="v1")
+ customer_name = fields.Char('终端客户')
contract_code = fields.Char('合同编号')
contract_date = fields.Date('合同日期')
contract_document_id = fields.Many2one('documents.document', string='合同文件')
@@ -157,7 +158,7 @@ class ReSaleOrder(models.Model):
'is_incoming_material': True if item.get('embryo_redundancy_id') else False,
'manual_quotation': item.get('manual_quotation'),
'model_id': item['model_id'],
- 'delivery_end_date': item['delivery_end_date'],
+ 'delivery_end_date': item['delivery_end_date']
}
return self.env['sale.order.line'].with_context(skip_procurement=True).create(vals)
@@ -291,8 +292,7 @@ class ResaleOrderLine(models.Model):
manual_quotation = fields.Boolean('人工编程', default=False)
model_url = fields.Char('模型文件地址')
model_id = fields.Char('模型ID')
-
- delivery_end_date = fields.Date('交货截止日期')
+ delivery_end_date = fields.Date('客户交期')
@api.depends('embryo_redundancy_id')
def _compute_is_incoming_material(self):
diff --git a/sf_sale/views/sale_order_view.xml b/sf_sale/views/sale_order_view.xml
index 05460a61..3b115620 100644
--- a/sf_sale/views/sale_order_view.xml
+++ b/sf_sale/views/sale_order_view.xml
@@ -90,6 +90,9 @@
+
+
+
{'readonly': [('state', 'in', ['cancel','sale'])]}
@@ -138,7 +141,7 @@
hide
-
+
diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py
index ff8f4e6f..219e0f80 100644
--- a/sf_tool_management/models/base.py
+++ b/sf_tool_management/models/base.py
@@ -818,6 +818,7 @@ class FunctionalToolAssembly(models.Model):
def _get_old_tool_material_lot(self, material_ids):
""" 根据先进先出原则选择物料批次 """
+ material_ids = material_ids.filtered(lambda m: m.tracking != 'none')
location_id = self.env['stock.location'].search([('name', '=', '刀具房')])
stock_quant = self.env['stock.quant'].sudo().search(
[('location_id', '=', location_id.id), ('product_id', 'in', material_ids.ids), ('quantity', '>', '0')],
diff --git a/sf_warehouse/migrations/1.2/post-migrate.py b/sf_warehouse/migrations/1.2/post-migrate.py
index b681f796..3c2165e1 100644
--- a/sf_warehouse/migrations/1.2/post-migrate.py
+++ b/sf_warehouse/migrations/1.2/post-migrate.py
@@ -7,8 +7,14 @@ def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})
sf_shelf_model = env["sf.shelf"]
sf_shelf_location_model = env["sf.shelf.location"]
+
+ preproduction_shelf_ids = sf_shelf_location_model.get_preproduction_shelf_ids()
+
shelves = sf_shelf_model.search([])
for shelf in shelves:
+ if shelf.id not in preproduction_shelf_ids:
+ continue
+
shelf_barcode = shelf.barcode or ""
if not shelf_barcode:
continue
diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py
index 33373600..2cb35264 100644
--- a/sf_warehouse/models/model.py
+++ b/sf_warehouse/models/model.py
@@ -13,6 +13,7 @@ from odoo import api, fields, models, _
from odoo.osv import expression
from odoo.exceptions import UserError, ValidationError
+_logger = logging.getLogger(__name__)
class SfLocation(models.Model):
_inherit = 'stock.location'
@@ -459,7 +460,40 @@ class ShelfLocation(models.Model):
product_sn_ids = fields.One2many('sf.shelf.location.lot', 'shelf_location_id', string='产品批次号')
# 产品数量
product_num = fields.Integer('总数量', compute='_compute_number', store=True)
-
+ tool_rfid = fields.Char('Rfid', compute='_compute_tool', store=True)
+ tool_name_id = fields.Many2one('sf.functional.cutting.tool.entity', string='功能刀具名称', compute='_compute_tool', store=True)
+ display_rfid = fields.Char('RFID', compute='_compute_display_rfid', store=True)
+ @api.depends('product_sn_id')
+ def _compute_display_rfid(self):
+ """计算显示 RFID"""
+ for record in self:
+ try:
+ record.display_rfid = record.product_sn_id.rfid if record.product_sn_id else ''
+ except Exception as e:
+ record.display_rfid = ''
+
+ @api.depends('product_id')
+ def _compute_tool(self):
+ """计算工具 RFID"""
+ for record in self:
+ try:
+ if record.product_id:
+ if record.product_id.categ_id.name == '功能刀具':
+ # 搜索关联的功能刀具实体
+ tool_id = self.env['sf.functional.cutting.tool.entity'].search(
+ [('barcode_id', '=', record.product_sn_id.id)], limit=1
+ )
+ if tool_id:
+ record.tool_rfid = tool_id.rfid
+ record.tool_name_id = tool_id.id
+ continue
+ # 默认值
+ record.tool_rfid = ''
+ record.tool_name_id = False
+ except Exception as e:
+ record.tool_rfid = ''
+ record.tool_name_id = False
+ _logger.error(f"计算 tool_rfid 时出错: {e}")
@api.depends('product_num')
def _compute_product_num(self):
for record in self:
@@ -563,8 +597,27 @@ class ShelfLocation(models.Model):
else:
_layer_capacity = _layer_capacity
_layer = _layer+1
+ _layer_capacity = f"{_layer_capacity:02d}"
record.kanban_show_layer_info=f"{_layer}-{_layer_capacity}"
record.kanban_show_center_control_code=f"{_cc_code}"
+ @api.model
+ def get_preproduction_shelf_ids(self):
+ """
+ 获取预生产区域的货架ID列表
+ Returns:
+ list: 货架ID列表
+ """
+ query = """
+ SELECT DISTINCT b.shelf_id
+ FROM stock_location a
+ LEFT JOIN sf_shelf_location b ON a.id = b.location_id
+ WHERE a.barcode LIKE 'WH-PREPRODUCTION'
+ """
+ self.env.cr.execute(query)
+ result = self.env.cr.fetchall()
+ # 将结果转换为ID列表
+ shelf_ids = [record[0] for record in result if record[0]]
+ return shelf_ids
class SfShelfLocationLot(models.Model):
_name = 'sf.shelf.location.lot'
@@ -581,6 +634,7 @@ class SfShelfLocationLot(models.Model):
for item in self:
if item.qty_num > item.qty:
raise ValidationError('变更数量不能比库存数量大!!!')
+
class SfStockMoveLine(models.Model):
diff --git a/sf_warehouse/static/src/css/kanban_location_custom.scss b/sf_warehouse/static/src/css/kanban_location_custom.scss
index 3bb002e5..67ff9654 100644
--- a/sf_warehouse/static/src/css/kanban_location_custom.scss
+++ b/sf_warehouse/static/src/css/kanban_location_custom.scss
@@ -1,128 +1,198 @@
-// 定义一个 mixin 来处理重复的样式
-@mixin kanban-common-styles($record-count-each-row,
- $record-gap: 16px,
- $color-guide-width: 70px) {
+// 定义看板公共样式的Mixin
+@mixin kanban-common-styles($record-count-each-row, $record-gap: 16px) {
$record-gap-total-width: $record-gap * ($record-count-each-row - 1);
-
+
display: flex !important;
flex-wrap: wrap !important;
overflow-x: hidden !important;
overflow-y: auto !important;
- padding: 0px !important;
+ padding: 0 !important;
gap: $record-gap !important;
width: 100% !important;
height: 100% !important;
-
- // 设置卡片样式
+
+ // === 卡片基础样式(完全保留)===
.o_kanban_record {
- flex: 0 0 calc((100% - #{$record-gap-total-width}) / #{$record-count-each-row}) !important;
- height: calc((100% - #{$record-gap * 6}) / 6) !important; // 平均分配高度
- margin: 0 !important;
- padding: 0px !important;
- background-color: white !important;
- border: 1px solid #dee2e6 !important;
- border-radius: 4px !important;
- box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) !important;
- min-width: calc((100% - #{$record-gap-total-width}) / #{$record-count-each-row}) !important;
- max-width: calc((100% - #{$record-gap-total-width}) / #{$record-count-each-row}) !important;
-
+ flex: 0 0 calc((100% - #{$record-gap-total-width}) / #{$record-count-each-row}) !important;
+ height: calc((100% - #{$record-gap * 6}) / 6) !important;
+ margin: 0 !important;
+ padding: 0 !important;
+ background-color: white !important;
+ border: 1px solid #dee2e6 !important;
+ border-radius: 4px !important;
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) !important;
+ min-width: calc((100% - #{$record-gap-total-width}) / #{$record-count-each-row}) !important;
+ max-width: calc((100% - #{$record-gap-total-width}) / #{$record-count-each-row}) !important;
+ position: relative;
+ transition: all 0.25s ease !important;
+ overflow: visible !important; // 允许悬停条溢出卡片边界
+
+ // === 状态标签(保留原设计)===
+ .status-label {
+ position: absolute;
+ top: 8px;
+ right: 8px;
+ padding: 3px 8px;
+ background: rgba(255, 255, 255, 0.9);
+ border: 1px solid #e0e0e0;
+ border-radius: 3px;
+ font-size: 11px;
+ color: #424242;
+ z-index: 2;
+ }
+
+ // === 优化:悬停信息条(核心改动)===
+ .status-hover-bar {
+ position: absolute;
+ bottom: calc(100% + 8px); // 默认显示在卡片上方
+ left: 0;
+ z-index: 1000;
+ min-width: max-content; // 宽度自适应内容
+ max-width: 300px; // 防止过宽
+ padding: 10px 12px;
+ background: rgba(255, 255, 255, 0.95);
+ border: 1px solid #e0e0e0;
+ border-radius: 4px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
+ font-size: 12px;
+ color: #424242;
+ white-space: nowrap; // 强制单行显示
+ opacity: 0;
+ pointer-events: none; // 避免阻挡卡片交互
+ transition: opacity 0.2s ease, transform 0.2s ease;
+ transform: translateY(10px);
+
+ // 三角形指示器
+ &::after {
+ content: '';
+ position: absolute;
+ top: 100%;
+ left: 15px;
+ border: 6px solid transparent;
+ border-top-color: rgba(0, 0, 0, 0.85);
+ }
+
+ div {
+ margin-bottom: 4px;
+ line-height: 1.4;
+ }
+ }
+
+ // === 悬停触发逻辑 ===
+ &:hover {
+ transform: translateY(-4px) !important;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
+ z-index: 10;
+
+ .status-hover-bar {
+ background: rgba(50, 50, 50, 0.9);
+ color: #fff !important;
+ font-size: 12px;
+ opacity: 0.9;
+ transform: translateY(0);
+ pointer-events: auto; // 悬停时允许交互
+ }
+ }
+
+ // === 边界保护(智能定位)===
+ // 左侧卡片:左对齐
+ &:nth-child(#{$record-count-each-row}n+1) .status-hover-bar {
+ left: 0;
+ right: auto;
+ &::after { left: 15px; }
+ }
+
+ // 右侧卡片:右对齐
+ &:nth-child(#{$record-count-each-row}n) .status-hover-bar {
+ left: auto;
+ right: 0;
+ &::after {
+ left: auto;
+ right: 15px;
+ }
+ }
+ &:nth-child(#{$record-count-each-row}n + #{$record-count-each-row - 1}) .status-hover-bar {
+ left: auto;
+ right: 0;
+ &::after {
+ left: auto;
+ right: 15px;
+ }
+ }
+ // 顶部卡片:悬停条显示在下方
+ &:nth-child(-n+#{$record-count-each-row}) .status-hover-bar {
+ bottom: auto;
+ top: calc(100% + 8px);
+ &::after {
+ top: auto;
+ bottom: 100%;
+ border-top-color: transparent;
+ border-bottom-color: rgba(255, 255, 255, 0.95);
+ }
+ }
+
+ // === 禁用状态样式(保留原效果)===
+ &.kanban_color_3 {
+ opacity: 0.6;
&:hover {
- transform: translateY(-1px) !important;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15) !important;
- }
-
- .o_kanban_record_bottom {
- margin: 0;
- }
-
- .oe_kanban_card.kanban_color_3,
- .oe_kanban_card.kanban_color_1,
- .oe_kanban_card.kanban_color_2 {
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- width: 100%;
- height: 100%;
-
- .sf_kanban_custom_location_info_style {
- display: flex !important;
- justify-content: center !important;
- align-items: center !important;
- width: 100%;
- font-size: 14px;
- color: #000000;
- }
-
- .sf_kanban_no {
- display: flex !important;
- justify-content: center !important;
- align-items: center !important;
- font-size: 18px;
- color: #000000;
- }
+ opacity: 0.85;
+ .status-hover-bar {
+ background:rgba(0, 0, 0, 0.85);
+ color: white !important;
+ border: 1px solid rgba(255, 255, 255, 0.15) !important;
+ }
}
+ }
}
-}
-
-// 使用 mixin 为不同的列数生成样式
-.o_kanban_view {
- .sf_kanban_location_style {
- // 设置卡片样式
- .o_kanban_record {
-
- &:hover {
- transform: translateY(-1px) !important;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15) !important;
- }
-
- .o_kanban_record_bottom {
- margin: 0;
- }
-
- .oe_kanban_card.kanban_color_3,
- .oe_kanban_card.kanban_color_1,
- .oe_kanban_card.kanban_color_2 {
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- width: 100%;
- height: 100%;
-
- .sf_kanban_custom_location_info_style {
- display: flex !important;
- justify-content: center !important;
- align-items: center !important;
- width: 100%;
- font-size: 14px;
- color: #000000;
- }
-
- .sf_kanban_no {
- display: flex !important;
- justify-content: center !important;
- align-items: center !important;
- font-size: 18px;
- color: #000000;
- }
- }
+ }
+
+ // === 看板视图样式(完全保留)===
+ .o_kanban_view {
+ // 卡片内部结构(不修改)
+ .o_kanban_record {
+ .o_kanban_record_bottom {
+ margin: 0;
+ }
+ .oe_kanban_card.kanban_color_3,
+ .oe_kanban_card.kanban_color_1,
+ .oe_kanban_card.kanban_color_2 {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 100%;
+ .sf_kanban_custom_location_info_style {
+ display: flex !important;
+ justify-content: center !important;
+ align-items: center !important;
+ width: 100%;
+ font-size: 15px;
+ color: #000000;
+ padding:0px;
}
+
+ .sf_kanban_no {
+ display: flex !important;
+ justify-content: center !important;
+ align-items: center !important;
+ font-size: 18px;
+ color: #000000;
+ }
+ }
}
-
+
+ // 不同列数的看板样式
.sf_kanban_location_style12 {
- @include kanban-common-styles(12);
+ @include kanban-common-styles(12);
}
-
.sf_kanban_location_style19 {
- @include kanban-common-styles(19);
+ @include kanban-common-styles(19);
}
-
.sf_kanban_location_style4 {
- @include kanban-common-styles(4);
+ @include kanban-common-styles(4);
}
-
.sf_kanban_location_style3 {
- @include kanban-common-styles(3);
+ @include kanban-common-styles(3);
}
-}
\ No newline at end of file
+ }
\ No newline at end of file
diff --git a/sf_warehouse/static/src/js/custom_kanban_controller.js b/sf_warehouse/static/src/js/custom_kanban_controller.js
index ab3a57d6..2d591505 100644
--- a/sf_warehouse/static/src/js/custom_kanban_controller.js
+++ b/sf_warehouse/static/src/js/custom_kanban_controller.js
@@ -28,8 +28,18 @@ class CustomKanbanController extends KanbanController {
isBaseStyle: true
});
let self = this;
- // 获取货架分层数据
+
onWillStart(async () => {
+ try {
+ this.preproductionShelfIds = await this.orm.call(
+ 'sf.shelf.location',
+ 'get_preproduction_shelf_ids',
+ []
+ );
+ } catch (error) {
+ this.preproductionShelfIds = [];
+ }
+
this.searchModel.on('update', self, self._onUpdate);
await this.loadShelfLayersData();
});
@@ -50,7 +60,11 @@ class CustomKanbanController extends KanbanController {
let domain = this.searchModel.domain;
if (domain.length > 0) {
let shelfDomain = domain.find(item => item[0] === 'shelf_id');
- this.onShelfChange(shelfDomain[2]);
+ if (shelfDomain && shelfDomain[2] && this.preproductionShelfIds && this.preproductionShelfIds.includes(shelfDomain[2])) {
+ this.onShelfChange(shelfDomain[2]);
+ } else {
+ this.setKanbanStyle('sf_kanban_location_style');
+ }
} else {
this.setKanbanStyle('sf_kanban_location_style');
}
@@ -63,8 +77,7 @@ class CustomKanbanController extends KanbanController {
let shelfDomain = domain.find(item => item[0] === 'shelf_id');
if (shelfDomain) {
let shelfId = shelfDomain[2];
- // 如果货架ID存在,则设置相应的样式
- if (shelfId) {
+ if (shelfId && this.preproductionShelfIds.includes(shelfId)) {
this.onShelfChange(shelfId);
return;
}
@@ -75,7 +88,6 @@ class CustomKanbanController extends KanbanController {
this.setKanbanStyle('sf_kanban_location_style');
} catch (error) {
}
-
}
// 加载所有货架的层数数据
@@ -107,10 +119,18 @@ class CustomKanbanController extends KanbanController {
// 添加新类
if (isHave) kanbanViewEl.classList.add(style);
}
- const ghostCards = document.querySelectorAll('.o_kanban_ghost');
- ghostCards.forEach(card => {
- card.remove();
- });
+
+ // 获取当前的搜索域
+ let domain = this.searchModel.domain;
+ let shelfDomain = domain.find(item => item[0] === 'shelf_id');
+
+ // 只有当shelf_id在preproductionShelfIds中时才删除幽灵看板
+ if (shelfDomain && this.preproductionShelfIds && this.preproductionShelfIds.includes(shelfDomain[2])) {
+ const ghostCards = document.querySelectorAll('.o_kanban_ghost');
+ ghostCards.forEach(card => {
+ card.remove();
+ });
+ }
}
updatePagerLimit(limit) {
diff --git a/sf_warehouse/views/shelf_location.xml b/sf_warehouse/views/shelf_location.xml
index c39f61c6..82548935 100644
--- a/sf_warehouse/views/shelf_location.xml
+++ b/sf_warehouse/views/shelf_location.xml
@@ -193,53 +193,78 @@
-
- shelf.location.kanban
- sf.shelf.location
-
-
-
-
-
-
+
+ shelf.location.kanban
+ sf.shelf.location
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+ 产品:
+
+
+ 标签ID:
+
+
+
+ 功能刀具名称:
+
+
状态:
+
+
+
+
+
+
+
+
shelf.location.search