Compare commits
192 Commits
master
...
feature/72
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bba9e8e8a8 | ||
|
|
e4c3435840 | ||
|
|
2a7048dafd | ||
|
|
2bb215f9df | ||
|
|
a2be3a0dbf | ||
|
|
1f4ceab377 | ||
|
|
94d727e8e0 | ||
|
|
42d9f894dd | ||
|
|
9416d1c1a0 | ||
|
|
7dd44ca12c | ||
|
|
5a98b20988 | ||
|
|
2738085a1e | ||
|
|
61c1fdbd05 | ||
|
|
7eea5a0ff2 | ||
|
|
714c68c0c1 | ||
|
|
f3e7ba7f68 | ||
|
|
df589b43e7 | ||
|
|
8bdc65c626 | ||
|
|
0c3407572f | ||
|
|
e5404efb60 | ||
|
|
46f60028aa | ||
|
|
bfc071debd | ||
|
|
7fca59322e | ||
|
|
42694c1ac6 | ||
|
|
e88fc012ec | ||
|
|
ff7cd9c927 | ||
|
|
588b7d340f | ||
|
|
5902d61f13 | ||
|
|
8cfad007b9 | ||
|
|
5008210176 | ||
|
|
f487ab4cce | ||
|
|
0441f345ef | ||
|
|
3527105e83 | ||
|
|
88e4cfb541 | ||
|
|
5a175c078f | ||
|
|
20980bed9d | ||
|
|
9b94357439 | ||
|
|
5ae3c5dd47 | ||
|
|
60be14dda2 | ||
|
|
f0ff7c4a74 | ||
|
|
2b6e2fe31b | ||
|
|
f1390e47c9 | ||
|
|
c7cd0a6a69 | ||
|
|
fa5307a2ea | ||
|
|
07e4cdcaa0 | ||
|
|
ff5925eb06 | ||
|
|
2a7e07b4c0 | ||
|
|
4706bfe85e | ||
|
|
2f21c510bd | ||
|
|
7adaa7e79b | ||
|
|
166d10e7d9 | ||
|
|
36d6a3ed4c | ||
|
|
650ff9b3e2 | ||
|
|
559c6bfb1d | ||
|
|
e83d3f8a1c | ||
|
|
ac0966f3bf | ||
|
|
1f93ba3b42 | ||
|
|
4d2ab82645 | ||
|
|
7b4499184d | ||
|
|
d02babaf0a | ||
|
|
acb6fd42ca | ||
|
|
c2cb24c60b | ||
|
|
3be1c4c529 | ||
|
|
60e7415a27 | ||
|
|
22763903a4 | ||
|
|
4c6cf0ba5e | ||
|
|
02012b2c52 | ||
|
|
a2b2efed7d | ||
|
|
925c59e1fe | ||
|
|
f86e27b45e | ||
|
|
b704f99a29 | ||
|
|
1ac6314f5f | ||
|
|
8b3eef1256 | ||
|
|
22ccb095ee | ||
|
|
9db4ea745b | ||
|
|
60fd4d4a73 | ||
|
|
c6c4331c0b | ||
|
|
10c6f59f52 | ||
|
|
df4995fa24 | ||
|
|
6e877d0449 | ||
|
|
3822d78f35 | ||
|
|
b23e50daa6 | ||
|
|
4615f1576f | ||
|
|
0350f78710 | ||
|
|
20df1c0365 | ||
|
|
20069d5336 | ||
|
|
c8f1676de9 | ||
|
|
b267f2351d | ||
|
|
c31cc868a9 | ||
|
|
0e7d6fac4e | ||
|
|
334d406c35 | ||
|
|
70113cb3c5 | ||
|
|
048f07aba4 | ||
|
|
c03cda8250 | ||
|
|
272e424975 | ||
|
|
1fd9900e41 | ||
|
|
50a066c23a | ||
|
|
fe4659987f | ||
|
|
a68d6d4d06 | ||
|
|
c14e2c19bf | ||
|
|
c630074f4a | ||
|
|
4bea169327 | ||
|
|
e2ddac4fb0 | ||
|
|
e52ec3982f | ||
|
|
160bd117b7 | ||
|
|
a19cf5d894 | ||
|
|
885064fb12 | ||
|
|
8f7e785760 | ||
|
|
8123885c71 | ||
|
|
c2f346571d | ||
|
|
e3494ce8b7 | ||
|
|
413cf43ea0 | ||
|
|
deda36a0f9 | ||
|
|
d75cff0a5d | ||
|
|
8a953a1417 | ||
|
|
d046fd5298 | ||
|
|
28ade4ac72 | ||
|
|
9f00fddc09 | ||
|
|
372f95d812 | ||
|
|
f165bec662 | ||
|
|
4099756d15 | ||
|
|
133eac4a5c | ||
|
|
f41d3558d2 | ||
|
|
91bad533c3 | ||
|
|
f5ed94866b | ||
|
|
b70f280c6e | ||
|
|
9922402b3b | ||
|
|
152657e41b | ||
|
|
0a79a4e336 | ||
|
|
174af13a58 | ||
|
|
00922e3674 | ||
|
|
832b06be1f | ||
|
|
3b60db56de | ||
|
|
2a330a4bd8 | ||
|
|
579b7138e7 | ||
|
|
98f8430c45 | ||
|
|
912847ae33 | ||
|
|
33647fa3e0 | ||
|
|
d1f9f8cf8c | ||
|
|
7d1f7b11eb | ||
|
|
02b4f76326 | ||
|
|
72f737c370 | ||
|
|
a2a652eea4 | ||
|
|
2f26aee90a | ||
|
|
98c5b3b013 | ||
|
|
0d76d1a7d3 | ||
|
|
b177bd95ff | ||
|
|
a5bb686708 | ||
|
|
c1bafef1aa | ||
|
|
46125dc44b | ||
|
|
05c5c0ef81 | ||
|
|
d0d3215bf3 | ||
|
|
35e80266d7 | ||
|
|
92a0c15708 | ||
|
|
0013f9f8c9 | ||
|
|
149d8e287b | ||
|
|
3f65742add | ||
|
|
b56e3545a1 | ||
|
|
fd7080a332 | ||
|
|
85fb64ed55 | ||
|
|
9ad06b4361 | ||
|
|
f9c13341e6 | ||
|
|
d2a61c79d0 | ||
|
|
5f80b377e5 | ||
|
|
ab2e685004 | ||
|
|
dcc5eef006 | ||
|
|
7e8b2adb3d | ||
|
|
9aa870065b | ||
|
|
60c39929b2 | ||
|
|
9a5b8a2627 | ||
|
|
73696eb72c | ||
|
|
55babb8a35 | ||
|
|
6682dbfb7d | ||
|
|
e0b8e5fe07 | ||
|
|
800f2eb6a7 | ||
|
|
3cc633131e | ||
|
|
e3fb266890 | ||
|
|
844f7de1ab | ||
|
|
13d33488dc | ||
|
|
266601cf84 | ||
|
|
2e168a4ba7 | ||
|
|
68ba47ed70 | ||
|
|
5bb6fcd4f7 | ||
|
|
9a05bbd82c | ||
|
|
b33c992b25 | ||
|
|
5947b3dfe9 | ||
|
|
95e43b0fba | ||
|
|
e7afc76753 | ||
|
|
788183e239 | ||
|
|
f38f60a6a8 | ||
|
|
71a0f39ec9 | ||
|
|
92f591c3e7 |
2
jikimo_demand_plan_queue/__init__.py
Normal file
2
jikimo_demand_plan_queue/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import models
|
||||
18
jikimo_demand_plan_queue/__manifest__.py
Normal file
18
jikimo_demand_plan_queue/__manifest__.py
Normal file
@@ -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',
|
||||
}
|
||||
2
jikimo_demand_plan_queue/models/__init__.py
Normal file
2
jikimo_demand_plan_queue/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import production_demand_plan
|
||||
20
jikimo_demand_plan_queue/models/production_demand_plan.py
Normal file
20
jikimo_demand_plan_queue/models/production_demand_plan.py
Normal file
@@ -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()
|
||||
@@ -10,6 +10,7 @@
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'views/sale_order_view.xml',
|
||||
'views/purchase_order.xml',
|
||||
'views/mrp_production.xml',
|
||||
'views/purchase_request_view.xml',
|
||||
'wizard/purchase_request_line_make_purchase_order_view.xml',
|
||||
|
||||
@@ -16,6 +16,69 @@ class PurchaseOrder(models.Model):
|
||||
('rejected', '已驳回')
|
||||
], string='Status', readonly=True, index=True, copy=False, default='draft', tracking=True)
|
||||
|
||||
# 成品采购订单对应的坯料采购申请单和采购订单数量
|
||||
purchase_request_count = fields.Integer('子·采购申请数量', compute='_compute_purchase_request')
|
||||
purchase_order_count = fields.Integer('子·采购订单数量', compute='_compute_purchase_request')
|
||||
|
||||
@api.depends('state')
|
||||
def _compute_purchase_request(self):
|
||||
for record in self:
|
||||
purchase_request_ids, purchase_order_ids = record.get_purchase_request_order()
|
||||
record.purchase_request_count = len(purchase_request_ids)
|
||||
record.purchase_order_count = len(purchase_order_ids)
|
||||
|
||||
def action_view_preform_body_purchase_request(self):
|
||||
self.ensure_one()
|
||||
name_list = self._get_pinking_name()
|
||||
purchase_request_ids = self.env['purchase.request'].search([('origin', 'in', name_list)])
|
||||
|
||||
action = {
|
||||
'res_model': 'purchase.request',
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
if len(purchase_request_ids) == 1:
|
||||
action.update({
|
||||
'view_mode': 'form',
|
||||
'res_id': purchase_request_ids[0].id,
|
||||
})
|
||||
else:
|
||||
action.update({
|
||||
'name': _("子·采购申请"),
|
||||
'domain': [('id', 'in', purchase_request_ids.ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
|
||||
def action_view_preform_body_purchase_order(self):
|
||||
self.ensure_one()
|
||||
name_list = self._get_pinking_name()
|
||||
purchase_order_ids = self.env['purchase.order'].search([('origin', 'in', name_list)])
|
||||
|
||||
action = {
|
||||
'res_model': 'purchase.order',
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
if len(purchase_order_ids) == 1:
|
||||
action.update({
|
||||
'view_mode': 'form',
|
||||
'res_id': purchase_order_ids[0].id,
|
||||
})
|
||||
else:
|
||||
action.update({
|
||||
'name': _("子·采购订单"),
|
||||
'domain': [('id', 'in', purchase_order_ids.ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
|
||||
def get_purchase_request_order(self):
|
||||
name_list = self._get_pinking_name()
|
||||
purchase_request_ids = self.env['purchase.request'].search([('origin', 'in', name_list)])
|
||||
purchase_order_ids = self.env['purchase.order'].search([('origin', 'in', name_list)])
|
||||
return purchase_request_ids, purchase_order_ids
|
||||
|
||||
def _get_pinking_name(self):
|
||||
return [picking_id.name for picking_id in self.picking_ids if picking_id.name]
|
||||
|
||||
def button_confirm(self):
|
||||
res = super(PurchaseOrder, self).button_confirm()
|
||||
@@ -31,12 +94,20 @@ class PurchaseOrder(models.Model):
|
||||
|
||||
def button_cancel(self):
|
||||
"""
|
||||
将取消的采购订单关联的库存移动撤销
|
||||
1. 先将采购订单行与目标库存移动断开链接,避免采购单取消后,调拨单被调整为mts的问题
|
||||
2. 取消采购订单
|
||||
3. 将采购订单行与目标库存移动重新建立链接
|
||||
"""
|
||||
move_ids = self.order_line.move_dest_ids.filtered(lambda move: move.state != 'done' and not move.scrapped)
|
||||
created_purchase_request_line_ids = {}
|
||||
if self.order_line.move_dest_ids.created_purchase_request_line_id:
|
||||
move_ids = self.order_line.move_dest_ids.filtered(lambda move: move.state != 'done' and not move.scrapped)
|
||||
created_purchase_request_line_ids = {move.id: move.created_purchase_request_line_id for move in move_ids}
|
||||
self.order_line.write({'move_dest_ids': [(5, 0, 0)]})
|
||||
res =super(PurchaseOrder, self).button_cancel()
|
||||
if move_ids.mapped('created_purchase_request_line_id'):
|
||||
move_ids.write({'state': 'waiting', 'is_done': False})
|
||||
for move_id, created_purchase_request_line_id in created_purchase_request_line_ids.items():
|
||||
self.env['stock.move'].browse(move_id).created_purchase_request_line_id = created_purchase_request_line_id
|
||||
# if move_ids.mapped('created_purchase_request_line_id'):
|
||||
# move_ids.write({'state': 'waiting', 'is_done': False})
|
||||
return res
|
||||
|
||||
def write(self, vals):
|
||||
|
||||
@@ -16,6 +16,7 @@ class PurchaseRequest(models.Model):
|
||||
)
|
||||
|
||||
rule_new_add = fields.Boolean('采购请求为规则创建', default=False, compute='_compute_state', store=True)
|
||||
rule_purchase_to_request = fields.Boolean('采购单根据规则创建坯料采购申请', default=False)
|
||||
|
||||
@api.depends('state')
|
||||
def _compute_state(self):
|
||||
|
||||
@@ -44,7 +44,7 @@ class StatusChange(models.Model):
|
||||
else:
|
||||
action.update({
|
||||
'name': _("从 %s生成采购请求单", self.name),
|
||||
'domain': [('id', 'in', pr_ids)],
|
||||
'domain': [('id', 'in', pr_ids.ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
|
||||
@@ -41,7 +41,20 @@ class StockPicking(models.Model):
|
||||
if backorder_ids:
|
||||
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 in purchase_request_lines.mapped('product_id.id')
|
||||
purchase_request_lines.move_dest_ids = [
|
||||
(4, x.id) for x in backorder_ids.move_ids if
|
||||
x.product_id.id in purchase_request_lines.mapped('product_id.id') and \
|
||||
not x.created_purchase_request_line_id
|
||||
]
|
||||
return res
|
||||
return res
|
||||
|
||||
def _subcontracted_produce(self, subcontract_details):
|
||||
super()._subcontracted_produce(subcontract_details)
|
||||
|
||||
# 判断是否根据规则生成新的采购申请单据,如果生成则修改状态为 approved
|
||||
if self:
|
||||
pr_ids = self.env["purchase.request"].sudo().search(
|
||||
[('origin', 'like', self.name), ('rule_purchase_to_request', '=', True), ('state', '=', 'draft')])
|
||||
if pr_ids:
|
||||
pr_ids.write({'need_validation': False})
|
||||
pr_ids.write({"state": "approved", 'need_validation': True, 'rule_new_add': False})
|
||||
|
||||
@@ -26,7 +26,7 @@ class StockRule(models.Model):
|
||||
request_data = rule._prepare_purchase_request(
|
||||
procurement.origin, procurement.values
|
||||
)
|
||||
request_data.update({'rule_new_add': True})
|
||||
request_data = self._update_request_data(procurement, request_data)
|
||||
pr = purchase_request_model.create(request_data)
|
||||
cache[domain] = pr
|
||||
elif (
|
||||
@@ -44,6 +44,18 @@ class StockRule(models.Model):
|
||||
request_line_data.update({'origin': procurement.origin})
|
||||
purchase_request_line_model.create(request_line_data)
|
||||
|
||||
def _update_request_data(self, procurement, request_data):
|
||||
sp = self.env['stock.picking'].sudo().search([('name', '=', procurement.origin)])
|
||||
if len(sp) == 1:
|
||||
po = self.env['purchase.order'].sudo().search(
|
||||
[('name', '=', sp.origin), ('purchase_type', '=', 'outsourcing')])
|
||||
if po:
|
||||
request_data.update({'rule_purchase_to_request': True})
|
||||
else:
|
||||
request_data.update({'rule_new_add': True})
|
||||
return request_data
|
||||
|
||||
|
||||
def _run_buy(self, procurements):
|
||||
# 如果补货组相同,并且产品相同,则合并
|
||||
procurements_dict = defaultdict()
|
||||
|
||||
28
jikimo_purchase_request/views/purchase_order.xml
Normal file
28
jikimo_purchase_request/views/purchase_order.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="purchase_order_form_jikimo_purchase_request" model="ir.ui.view">
|
||||
<field name="name">purchase.order.inherited.form.jikimo.purchase.request</field>
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="inherit_id" ref="mrp_subcontracting_purchase.purchase_order_form_mrp_subcontracting_purchase"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[hasclass('oe_button_box')]/button[@name='action_view_subcontracting_resupply']" position="before">
|
||||
<button
|
||||
class="oe_stat_button" name="action_view_preform_body_purchase_order"
|
||||
type="object" icon="fa-truck" attrs="{'invisible': [('purchase_order_count', '=', 0)]}" groups="stock.group_stock_user">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value"><field name="purchase_order_count"/></span>
|
||||
<span class="o_stat_text">子·采购订单</span>
|
||||
</div>
|
||||
</button>
|
||||
<button
|
||||
class="oe_stat_button" name="action_view_preform_body_purchase_request"
|
||||
type="object" icon="fa-truck" attrs="{'invisible': [('purchase_request_count', '=', 0)]}" groups="stock.group_stock_user">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value"><field name="purchase_request_count"/></span>
|
||||
<span class="o_stat_text">子·采购申请</span>
|
||||
</div>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -67,6 +67,16 @@
|
||||
<field name="part_number"/>
|
||||
<field name="part_name" invisible="1"/>
|
||||
</xpath>
|
||||
<xpath expr="//tree" position="inside">
|
||||
<header>
|
||||
<button
|
||||
name="%(purchase_request.action_purchase_request_line_make_purchase_order)d"
|
||||
string="创建询价单"
|
||||
type="action"
|
||||
class="btn-primary"
|
||||
/>
|
||||
</header>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@ class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
|
||||
def _run_buy(self, procurements):
|
||||
res = super(StockRule, self)._run_buy(procurements)
|
||||
# 判断是否根据规则生成新的采购申请单据,如果生成则修改状态为 approved
|
||||
origins = list(set([procurement[0].origin for procurement in procurements]))
|
||||
res = super(StockRule, self)._run_buy(procurements)
|
||||
# origins = list(set([procurement[0].origin for procurement in procurements]))
|
||||
for origin in origins:
|
||||
pr_ids = self.env["purchase.request"].sudo().search(
|
||||
[('origin', 'like', origin), ('rule_new_add', '=', True), ('state', '=', 'draft')])
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
],
|
||||
'web.assets_backend': [
|
||||
'sf_base/static/src/scss/*.scss',
|
||||
'sf_base/static/src/js/*.js',
|
||||
],
|
||||
|
||||
},
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { barcodeGenericHandlers } from '@barcodes/barcode_handlers';
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
// 定义新的 clickOnButton 函数
|
||||
function customClickOnButton(selector) {
|
||||
console.log("This is the custom clickOnButton function!");
|
||||
|
||||
const buttons = document.body.querySelectorAll(selector);
|
||||
|
||||
let length = buttons.length;
|
||||
if (length > 0) {
|
||||
buttons[length - 1].click();
|
||||
} else {
|
||||
console.warn(`Button with selector ${selector} not found`);
|
||||
}
|
||||
}
|
||||
|
||||
patch(barcodeGenericHandlers, "start", {
|
||||
start(env, { ui, barcode, notification }) {
|
||||
// 使用新定义的 clickOnButton 函数
|
||||
const COMMANDS = {
|
||||
"O-CMD.EDIT": () => customClickOnButton(".o_form_button_edit"),
|
||||
"O-CMD.DISCARD": () => customClickOnButton(".o_form_button_cancel"),
|
||||
"O-CMD.SAVE": () => customClickOnButton(".o_form_button_save"),
|
||||
"O-CMD.PREV": () => customClickOnButton(".o_pager_previous"),
|
||||
"O-CMD.NEXT": () => customClickOnButton(".o_pager_next"),
|
||||
"O-CMD.PAGER-FIRST": () => updatePager("first"),
|
||||
"O-CMD.PAGER-LAST": () => updatePager("last"),
|
||||
"O-CMD.CONFIRM": () => customClickOnButton(".jikimo_button_confirm"),
|
||||
"O-CMD.FLUSHED": () => customClickOnButton(".jikimo_button_flushed"),
|
||||
};
|
||||
|
||||
barcode.bus.addEventListener("barcode_scanned", (ev) => {
|
||||
const barcode = ev.detail.barcode;
|
||||
if (barcode.startsWith("O-BTN.")) {
|
||||
let targets = [];
|
||||
try {
|
||||
targets = getVisibleElements(ui.activeElement, `[barcode_trigger=${barcode.slice(6)}]`);
|
||||
} catch (_e) {
|
||||
console.warn(`Barcode '${barcode}' is not valid`);
|
||||
}
|
||||
for (let elem of targets) {
|
||||
elem.click();
|
||||
}
|
||||
}
|
||||
if (barcode.startsWith("O-CMD.")) {
|
||||
const fn = COMMANDS[barcode];
|
||||
if (fn) {
|
||||
fn();
|
||||
} else {
|
||||
notification.add(env._t("Barcode: ") + `'${barcode}'`, {
|
||||
title: env._t("Unknown barcode command"),
|
||||
type: "danger"
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -1,42 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from '@web/core/registry';
|
||||
|
||||
import { formView } from '@web/views/form/form_view';
|
||||
import { FormController } from '@web/views/form/form_controller';
|
||||
|
||||
import { listView } from '@web/views/list/list_view';
|
||||
import { ListController } from '@web/views/list/list_controller'
|
||||
|
||||
import { onRendered, onMounted } from "@odoo/owl";
|
||||
|
||||
export class RemoveFocusFormController extends FormController {
|
||||
setup() {
|
||||
super.setup();
|
||||
|
||||
onMounted(() => {
|
||||
this.__owl__.bdom.el.querySelectorAll(':focus').forEach(element => element.blur());
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
registry.category('views').add('remove_focus_form_view', {
|
||||
...formView,
|
||||
Controller: RemoveFocusFormController,
|
||||
});
|
||||
|
||||
|
||||
export class RemoveFocusListController extends ListController {
|
||||
setup() {
|
||||
super.setup();
|
||||
|
||||
onMounted(() => {
|
||||
this.__owl__.bdom.el.querySelectorAll(':focus').forEach(element => element.blur());
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
registry.category('views').add('remove_focus_list_view', {
|
||||
...listView,
|
||||
Controller: RemoveFocusListController,
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': '机企猫智能工厂 需求计划',
|
||||
'version': '1.0',
|
||||
'version': '1.1',
|
||||
'summary': '智能工厂计划管理',
|
||||
'sequence': 1,
|
||||
'description': """
|
||||
@@ -10,11 +10,17 @@
|
||||
""",
|
||||
'category': 'sf',
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': ['sf_plan', 'jikimo_printing'],
|
||||
'depends': ['sf_plan','jikimo_printing'],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'data/stock_route_group.xml',
|
||||
'views/demand_plan_info.xml',
|
||||
'views/demand_plan.xml',
|
||||
'views/stock_route.xml',
|
||||
'views/sale_order_views.xml',
|
||||
'wizard/sf_demand_plan_print_wizard_view.xml',
|
||||
'wizard/sf_release_plan_wizard_views.xml',
|
||||
'views/menu_view.xml',
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
@@ -24,6 +30,7 @@
|
||||
'web.assets_backend': [
|
||||
'sf_demand_plan/static/src/scss/style.css',
|
||||
'sf_demand_plan/static/src/js/print_demand.js',
|
||||
'sf_demand_plan/static/src/js/custom_button.js',
|
||||
]
|
||||
},
|
||||
'license': 'LGPL-3',
|
||||
|
||||
21
sf_demand_plan/data/stock_route_group.xml
Normal file
21
sf_demand_plan/data/stock_route_group.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<data noupdate="0">
|
||||
<record id="stock_route_group_automation_sf" model="stock.route.group">
|
||||
<field name="name">自动化产线加工</field>
|
||||
<field name="code">automation</field>
|
||||
</record>
|
||||
<record id="stock_route_group_manual_sf" model="stock.route.group">
|
||||
<field name="name">人工线下加工</field>
|
||||
<field name="code">manual</field>
|
||||
</record>
|
||||
<record id="stock_route_group_purchase_sf" model="stock.route.group">
|
||||
<field name="name">外购</field>
|
||||
<field name="code">purchase</field>
|
||||
</record>
|
||||
<record id="stock_route_group_outsourcing_sf" model="stock.route.group">
|
||||
<field name="name">委外加工</field>
|
||||
<field name="code">outsourcing</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
25
sf_demand_plan/migrations/1.1/post-migrate.py
Normal file
25
sf_demand_plan/migrations/1.1/post-migrate.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# migrations/1.1.0/post-migrate.py
|
||||
import os
|
||||
import csv
|
||||
import logging
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
# 获取环境
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
|
||||
ProductionLine = env['sf.production.demand.plan']
|
||||
DemandPlan = env['sf.demand.plan']
|
||||
|
||||
lines = ProductionLine.search([('demand_plan_id', '=', False)])
|
||||
for line in lines:
|
||||
vals = {
|
||||
'sale_order_id': line.sale_order_id.id,
|
||||
'sale_order_line_id': line.sale_order_line_id.id,
|
||||
'line_ids': line.ids
|
||||
}
|
||||
new_plan = DemandPlan.create(vals)
|
||||
line.write({'demand_plan_id': new_plan.id})
|
||||
@@ -1,4 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import sf_demand_plan
|
||||
from . import sf_production_demand_plan
|
||||
from . import sale_order
|
||||
from . import stock_route
|
||||
from . import mrp_bom
|
||||
from . import mrp_production
|
||||
from . import stock_rule
|
||||
from . import purchase_request
|
||||
from . import purchase_order
|
||||
|
||||
29
sf_demand_plan/models/mrp_bom.py
Normal file
29
sf_demand_plan/models/mrp_bom.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class MrpBom(models.Model):
|
||||
_inherit = 'mrp.bom'
|
||||
|
||||
# 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品后再次进行创建bom
|
||||
def bom_create(self, product, bom_type, product_type, code=None):
|
||||
bom_id = self.env['mrp.bom'].create({
|
||||
'product_tmpl_id': product.product_tmpl_id.id,
|
||||
'type': bom_type,
|
||||
# 'subcontractor_id': '' or subcontract.partner_id.id,
|
||||
'product_qty': 1,
|
||||
'product_uom_id': 1,
|
||||
'code': code
|
||||
})
|
||||
if bom_type == 'subcontract' and product_type is not False:
|
||||
subcontract = self.get_supplier(product.materials_type_id)
|
||||
bom_id.subcontractor_id = subcontract.partner_id.id
|
||||
return bom_id
|
||||
|
||||
def name_get(self):
|
||||
"""重写name_get方法,只显示BOM编码"""
|
||||
result = []
|
||||
for record in self:
|
||||
# 只显示BOM编码,如果编码为空则显示产品名称
|
||||
display_name = record.code or record.product_tmpl_id.name or f'BOM-{record.id}'
|
||||
result.append((record.id, display_name))
|
||||
return result
|
||||
43
sf_demand_plan/models/mrp_production.py
Normal file
43
sf_demand_plan/models/mrp_production.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models, api
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
|
||||
demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
|
||||
string="需求计划明细", readonly=True)
|
||||
|
||||
@api.depends('demand_plan_line_id')
|
||||
def _compute_production_type(self):
|
||||
for production in self:
|
||||
if production.demand_plan_line_id.supply_method == 'automation':
|
||||
production.production_type = '自动化产线加工'
|
||||
elif production.demand_plan_line_id.supply_method == 'manual':
|
||||
production.production_type = '人工线下加工'
|
||||
else:
|
||||
production.production_type = None
|
||||
|
||||
def _get_purchase_request(self):
|
||||
"""获取跟制造订单相关的采购申请单(根据采购申请单行项目的产品匹配)"""
|
||||
pr_ids = self.env['purchase.request'].sudo().search(
|
||||
[('line_ids.demand_plan_line_id', 'in', self.demand_plan_line_id.ids)])
|
||||
return pr_ids
|
||||
|
||||
@api.depends('procurement_group_id', 'procurement_group_id.stock_move_ids.group_id')
|
||||
def _compute_picking_ids(self):
|
||||
for order in self:
|
||||
if order.product_id.product_tmpl_id.single_manufacturing == True and not order.is_remanufacture:
|
||||
first_order = self.env['mrp.production'].search(
|
||||
[('demand_plan_line_id', '=', order.demand_plan_line_id.id), ('product_id', '=', order.product_id.id)], limit=1, order='id asc')
|
||||
order.picking_ids = self.env['stock.picking'].search([
|
||||
('group_id', '=', first_order.procurement_group_id.id), ('group_id', '!=', False),
|
||||
])
|
||||
order.delivery_count = len(first_order.picking_ids)
|
||||
else:
|
||||
order.picking_ids = self.env['stock.picking'].search([
|
||||
('group_id', '=', order.procurement_group_id.id), ('group_id', '!=', False),
|
||||
])
|
||||
order.delivery_count = len(order.picking_ids)
|
||||
48
sf_demand_plan/models/purchase_order.py
Normal file
48
sf_demand_plan/models/purchase_order.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.tools import float_compare
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
_inherit = 'purchase.order'
|
||||
|
||||
def button_confirm(self):
|
||||
if self.order_line[0].demand_plan_line_id:
|
||||
self = self.with_context(
|
||||
demand_plan_line_id=self.order_line[0].demand_plan_line_id.id
|
||||
)
|
||||
res = super(PurchaseOrder, self).button_confirm()
|
||||
return res
|
||||
|
||||
@api.depends('origin')
|
||||
def _compute_purchase_type(self):
|
||||
for purchase in self:
|
||||
if purchase.order_line[0].product_id.categ_id.name == '坯料':
|
||||
if purchase.order_line[0].product_id.materials_type_id.gain_way == '外协':
|
||||
purchase.purchase_type = 'outsourcing'
|
||||
else:
|
||||
if purchase.order_line[0].demand_plan_line_id.supply_method == 'outsourcing':
|
||||
purchase.purchase_type = 'outsourcing'
|
||||
|
||||
elif purchase.order_line[0].demand_plan_line_id.supply_method == 'purchase':
|
||||
purchase.purchase_type = 'outside'
|
||||
|
||||
|
||||
class PurchaseOrderLine(models.Model):
|
||||
_inherit = 'purchase.order.line'
|
||||
|
||||
demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
|
||||
string="需求计划明细", readonly=True)
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
res = super(PurchaseOrderLine, self).create(vals)
|
||||
if not res.demand_plan_line_id and res.order_id.origin:
|
||||
origin = [origin.replace(' ', '') for origin in res.order_id.origin.split(',')]
|
||||
if self.env.context.get('demand_plan_line_id'):
|
||||
res.demand_plan_line_id = self.env.context.get('demand_plan_line_id')
|
||||
elif 'MO' in res.order_id.origin:
|
||||
# 原单据是制造订单
|
||||
mp_ids = self.env['mrp.production'].sudo().search([('name', 'in', origin)])
|
||||
if mp_ids:
|
||||
res.demand_plan_line_id = mp_ids[0].demand_plan_line_id.id
|
||||
return res
|
||||
35
sf_demand_plan/models/purchase_request.py
Normal file
35
sf_demand_plan/models/purchase_request.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class PurchaseRequestLine(models.Model):
|
||||
_inherit = 'purchase.request.line'
|
||||
_description = '采购申请明细'
|
||||
|
||||
supply_method = fields.Selection([
|
||||
('automation', "自动化产线加工"),
|
||||
('manual', "人工线下加工"),
|
||||
('purchase', "外购"),
|
||||
('outsourcing', "委外加工"),
|
||||
], string='供货方式', readonly=True)
|
||||
|
||||
demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
|
||||
string="需求计划明细", readonly=True)
|
||||
|
||||
@api.depends('demand_plan_line_id')
|
||||
def _compute_supply_method(self):
|
||||
for prl in self:
|
||||
if prl.demand_plan_line_id:
|
||||
prl.supply_method = prl.demand_plan_line_id.supply_method
|
||||
else:
|
||||
prl.supply_method = None
|
||||
|
||||
|
||||
class PurchaseRequestLineMakePurchaseOrder(models.TransientModel):
|
||||
_inherit = "purchase.request.line.make.purchase.order"
|
||||
|
||||
@api.model
|
||||
def _prepare_purchase_order_line(self, po, item):
|
||||
ret = super(PurchaseRequestLineMakePurchaseOrder, self)._prepare_purchase_order_line(po, item)
|
||||
ret['demand_plan_line_id'] = item.line_id.demand_plan_line_id.id
|
||||
return ret
|
||||
@@ -10,20 +10,65 @@ class ReSaleOrder(models.Model):
|
||||
string='与此销售订单相关联的制造订单',
|
||||
groups='mrp.group_mrp_user', store=True)
|
||||
|
||||
demand_plan_ids = fields.Many2many(comodel_name="sf.demand.plan",
|
||||
string="需求计划", readonly=True)
|
||||
|
||||
demand_plan_count = fields.Integer(
|
||||
string="需求计划生成计数",
|
||||
compute='_compute_demand_plan_count'
|
||||
)
|
||||
|
||||
@api.depends('demand_plan_ids.line_ids.status')
|
||||
def _compute_purchase_request_count(self):
|
||||
for so in self:
|
||||
pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', so.name)])
|
||||
if pr_ids:
|
||||
so.purchase_request_purchase_order_count = len(pr_ids)
|
||||
else:
|
||||
so.purchase_request_purchase_order_count = 0
|
||||
|
||||
@api.depends('demand_plan_ids.line_ids')
|
||||
def _compute_demand_plan_count(self):
|
||||
for line in self:
|
||||
demand_plan = self.env['sf.production.demand.plan'].sudo().search([('sale_order_id', '=', line.id)])
|
||||
line.demand_plan_count = len(demand_plan)
|
||||
|
||||
def sale_order_create_line(self, product, item):
|
||||
ret = super(ReSaleOrder, self).sale_order_create_line(product, item)
|
||||
vals = {
|
||||
'sale_order_id': ret.order_id.id,
|
||||
'sale_order_line_id': ret.id,
|
||||
}
|
||||
demand_plan_info = self.env['sf.demand.plan'].sudo().create(vals)
|
||||
vals.update({'demand_plan_id': demand_plan_info.id, 'plan_uom_qty': ret.product_uom_qty,
|
||||
'new_supply_method': 'custom_made', 'custom_made_type': 'manual'})
|
||||
demand_plan = self.env['sf.production.demand.plan'].sudo().create(vals)
|
||||
demand_plan_info.write({'line_ids': demand_plan.ids})
|
||||
if demand_plan.product_id.machining_drawings_name:
|
||||
filename_url = demand_plan.product_id.machining_drawings_name.rsplit('.', 1)[0]
|
||||
wizard_vals = {
|
||||
'demand_plan_id': demand_plan.id,
|
||||
'model_id': demand_plan.model_id,
|
||||
'filename_url': filename_url,
|
||||
'machining_drawings': product.machining_drawings,
|
||||
'type': '1',
|
||||
}
|
||||
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
||||
ret.order_id.demand_plan_ids = [(4, demand_plan_info.id)]
|
||||
return ret
|
||||
|
||||
def confirm_to_supply_method(self):
|
||||
self.state = 'sale'
|
||||
for line in self.order_line:
|
||||
if line.product_id.auto_machining:
|
||||
line.supply_method = 'automation'
|
||||
|
||||
def action_view_demand_plan(self):
|
||||
self.ensure_one()
|
||||
demand_plan_ids = self.env['sf.production.demand.plan'].sudo().search([('sale_order_id', '=', self.id)]).ids
|
||||
return {
|
||||
'res_model': 'sf.production.demand.plan',
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _("需求计划"),
|
||||
'domain': [('id', 'in', demand_plan_ids)],
|
||||
'view_mode': 'tree',
|
||||
}
|
||||
|
||||
265
sf_demand_plan/models/sf_demand_plan.py
Normal file
265
sf_demand_plan/models/sf_demand_plan.py
Normal file
@@ -0,0 +1,265 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.tools import float_compare
|
||||
from odoo.exceptions import ValidationError
|
||||
import re
|
||||
|
||||
|
||||
class SfDemandPlan(models.Model):
|
||||
_name = 'sf.demand.plan'
|
||||
_description = 'sf_demand_plan'
|
||||
|
||||
state = fields.Selection([
|
||||
('10', '待工艺设计'),
|
||||
('30', '部分下达'),
|
||||
('40', '已下达'),
|
||||
('50', '取消'),
|
||||
], string='状态', default='10', compute='_compute_state', store=True)
|
||||
|
||||
line_ids = fields.One2many(comodel_name='sf.production.demand.plan',
|
||||
inverse_name='demand_plan_id', string="需求计划", copy=True)
|
||||
|
||||
sale_order_id = fields.Many2one(comodel_name="sale.order",
|
||||
string="销售订单", readonly=True)
|
||||
sale_order_line_id = fields.Many2one(comodel_name="sale.order.line",
|
||||
string="销售订单明细", readonly=True)
|
||||
|
||||
product_id = fields.Many2one(
|
||||
comodel_name='product.product',
|
||||
related='sale_order_line_id.product_id',
|
||||
string='产品', store=True, index=True)
|
||||
|
||||
part_name = fields.Char('零件名称', related='product_id.part_name')
|
||||
part_number = fields.Char('零件图号', compute='_compute_part_number', store=True)
|
||||
materials_id = fields.Char('材料', compute='_compute_materials_id', store=True)
|
||||
|
||||
blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类',
|
||||
related='product_id.blank_type')
|
||||
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型',
|
||||
related='product_id.blank_precision')
|
||||
manual_quotation = fields.Boolean('人工编程', related='product_id.manual_quotation', default=False)
|
||||
embryo_long = fields.Char('坯料尺寸(mm)', compute='_compute_embryo_long', store=True)
|
||||
is_incoming_material = fields.Boolean('客供料', related='sale_order_line_id.is_incoming_material', store=True)
|
||||
pending_qty = fields.Float(
|
||||
string="待计划",
|
||||
compute='_compute_pending_qty', store=True)
|
||||
planned_qty = fields.Float(
|
||||
string="已计划",
|
||||
compute='_compute_planned_qty', store=True)
|
||||
model_id = fields.Char('模型ID', related='product_id.model_id')
|
||||
customer_name = fields.Char('客户', related='sale_order_id.customer_name')
|
||||
product_uom_qty = fields.Float(
|
||||
string="需求数量",
|
||||
related='sale_order_line_id.product_uom_qty', store=True)
|
||||
deadline_of_delivery = fields.Date('客户交期', related='sale_order_line_id.delivery_end_date', store=True)
|
||||
contract_date = fields.Date('合同日期', related='sale_order_id.contract_date')
|
||||
contract_code = fields.Char('合同号', related='sale_order_id.contract_code', store=True)
|
||||
|
||||
model_process_parameters_ids = fields.Many2many('sf.production.process.parameter',
|
||||
'demand_plan_process_parameter_rel',
|
||||
string='表面工艺',
|
||||
compute='_compute_model_process_parameters_ids'
|
||||
, store=True
|
||||
)
|
||||
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
|
||||
inventory_quantity_auto_apply = fields.Float(
|
||||
string="成品库存",
|
||||
compute='_compute_inventory_quantity_auto_apply'
|
||||
)
|
||||
|
||||
priority = fields.Selection([
|
||||
('1', '紧急'),
|
||||
('2', '高'),
|
||||
('3', '中'),
|
||||
('4', '低'),
|
||||
], string='优先级', default='3')
|
||||
|
||||
overdelivery_allowed = fields.Boolean('可超量发货', default=False)
|
||||
|
||||
hide_button_release_plan = fields.Boolean(
|
||||
string='显示下达计划按钮',
|
||||
compute='_compute_hide_button_release_plan',
|
||||
default=False
|
||||
)
|
||||
|
||||
readonly_custom_made_type = fields.Boolean(
|
||||
string='字段自制类型只读',
|
||||
compute='_compute_readonly_custom_made_type',
|
||||
default=False
|
||||
)
|
||||
demand_plan_number = fields.Char('需求计划号', compute='_compute_demand_plan_number', readonly=True, store=True)
|
||||
origin = fields.Char('来源', related='sale_order_id.name', readonly=True, store=True)
|
||||
|
||||
@api.depends('product_id.part_number', 'product_id.model_name')
|
||||
def _compute_part_number(self):
|
||||
for line in self:
|
||||
if line.product_id:
|
||||
if line.product_id.part_number:
|
||||
line.part_number = line.product_id.part_number
|
||||
else:
|
||||
if line.product_id.model_name:
|
||||
line.part_number = line.product_id.model_name.rsplit('.', 1)[0]
|
||||
else:
|
||||
line.part_number = None
|
||||
|
||||
@api.depends('product_id.materials_id')
|
||||
def _compute_materials_id(self):
|
||||
for line in self:
|
||||
if line.product_id:
|
||||
line.materials_id = f"{line.product_id.materials_id.name}/{line.product_id.materials_type_id.name}"
|
||||
else:
|
||||
line.materials_id = 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:
|
||||
if line.product_id.blank_type == '圆料':
|
||||
line.embryo_long = f"Ø{round(line.product_id.model_width, 3)}*{round(line.product_id.model_long, 3)}"
|
||||
else:
|
||||
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.model_process_parameters_ids')
|
||||
def _compute_model_process_parameters_ids(self):
|
||||
for line in self:
|
||||
if line.product_id and line.product_id.model_process_parameters_ids:
|
||||
line.model_process_parameters_ids = [(6, 0, line.product_id.model_process_parameters_ids.ids)]
|
||||
else:
|
||||
line.model_process_parameters_ids = [(5, 0, 0)]
|
||||
|
||||
def _compute_inventory_quantity_auto_apply(self):
|
||||
location_id = self.env['stock.location'].search([('name', '=', '成品存货区')], limit=1).id
|
||||
product_ids = self.mapped('product_id').ids
|
||||
if product_ids:
|
||||
quant_data = self.env['stock.quant'].read_group(
|
||||
domain=[
|
||||
('product_id', 'in', product_ids),
|
||||
('location_id', '=', location_id)
|
||||
],
|
||||
fields=['product_id', 'inventory_quantity_auto_apply'],
|
||||
groupby=['product_id']
|
||||
)
|
||||
quantity_map = {item['product_id'][0]: item['inventory_quantity_auto_apply'] for item in quant_data}
|
||||
else:
|
||||
quantity_map = {}
|
||||
for line in self:
|
||||
if line.product_id:
|
||||
line.inventory_quantity_auto_apply = quantity_map.get(line.product_id.id, 0.0)
|
||||
else:
|
||||
line.inventory_quantity_auto_apply = 0.0
|
||||
|
||||
@api.depends('product_uom_qty', 'line_ids.plan_uom_qty')
|
||||
def _compute_pending_qty(self):
|
||||
for line in self:
|
||||
sum_plan_uom_qty = sum(line.line_ids.mapped('plan_uom_qty'))
|
||||
pending_qty = line.product_uom_qty - sum_plan_uom_qty
|
||||
if float_compare(pending_qty, 0,
|
||||
precision_rounding=line.product_id.uom_id.rounding) == -1:
|
||||
line.pending_qty = 0
|
||||
else:
|
||||
line.pending_qty = pending_qty
|
||||
|
||||
@api.depends('line_ids.plan_uom_qty')
|
||||
def _compute_planned_qty(self):
|
||||
for line in self:
|
||||
line.planned_qty = sum(line.line_ids.mapped('plan_uom_qty'))
|
||||
|
||||
@api.depends('line_ids.status')
|
||||
def _compute_hide_button_release_plan(self):
|
||||
for line in self:
|
||||
line.hide_button_release_plan = bool(line.line_ids.filtered(
|
||||
lambda p: p.status == '30'))
|
||||
|
||||
@api.depends('line_ids.status', 'sale_order_id.state')
|
||||
def _compute_state(self):
|
||||
for line in self:
|
||||
status_line = line.line_ids.filtered(lambda p: p.status == '60')
|
||||
if not line.line_ids:
|
||||
line.state = '10'
|
||||
elif line.sale_order_id.state == 'cancel':
|
||||
line.state = '50'
|
||||
line.line_ids.status = '100'
|
||||
elif len(line.line_ids) == len(status_line):
|
||||
line.state = '40'
|
||||
elif bool(status_line):
|
||||
line.state = '30'
|
||||
else:
|
||||
line.state = '10'
|
||||
|
||||
@api.depends('line_ids.status')
|
||||
def _compute_readonly_custom_made_type(self):
|
||||
for line in self:
|
||||
production_demand_plan = line.line_ids.filtered(
|
||||
lambda p: p.status in ('50', '60') and p.new_supply_method == 'custom_made')
|
||||
line.readonly_custom_made_type = bool(production_demand_plan)
|
||||
|
||||
@api.constrains('line_ids')
|
||||
def check_line_ids(self):
|
||||
for item in self:
|
||||
if not item.line_ids:
|
||||
raise ValidationError('计划不能为空!')
|
||||
|
||||
def write(self, vals):
|
||||
res = super(SfDemandPlan, self).write(vals)
|
||||
if 'line_ids' in vals:
|
||||
for line in self.line_ids:
|
||||
if not line.sale_order_id:
|
||||
line.sale_order_id = self.sale_order_id
|
||||
if not line.sale_order_line_id:
|
||||
line.sale_order_line_id = self.sale_order_line_id
|
||||
return res
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
for plan in self:
|
||||
result.append((plan.id, plan.demand_plan_number))
|
||||
return result
|
||||
|
||||
def button_production_release_plan(self):
|
||||
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
|
||||
sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty'))
|
||||
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||
check_overdelivery_allowed = False
|
||||
for line in line_ids:
|
||||
if line.location_id.id == customer_location_id:
|
||||
if not self.overdelivery_allowed:
|
||||
if float_compare(sum_product_uom_qty, self.product_uom_qty,
|
||||
precision_rounding=line.product_id.uom_id.rounding) == 1:
|
||||
check_overdelivery_allowed = True
|
||||
if check_overdelivery_allowed:
|
||||
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
||||
elif float_compare(sum_product_uom_qty, self.product_uom_qty,
|
||||
precision_rounding=self.product_id.uom_id.rounding) == 1:
|
||||
return {
|
||||
'name': _('需求计划'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(self.env.ref(
|
||||
'sf_demand_plan.sf_release_plan_wizard_form').id,
|
||||
'form')],
|
||||
'res_model': 'sf.release.plan.wizard',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_demand_plan_line_id': line_ids.ids,
|
||||
'default_release_message': f"您正在下达计划量 {sum_product_uom_qty},需求数量为 {self.product_uom_qty},已超过需求数量,是否继续?",
|
||||
}}
|
||||
else:
|
||||
for demand_plan_line_id in line_ids:
|
||||
demand_plan_line_id.action_confirm()
|
||||
|
||||
# 需求要求取值格式是来源+来源明细行ID,但是来源明细行ID取得就是product_id.name得最后一位,所以这里也直接截取product_id.name
|
||||
@api.depends('product_id.name')
|
||||
def _compute_demand_plan_number(self):
|
||||
for line in self:
|
||||
product_name = line.product_id.name or ''
|
||||
plan_no = None
|
||||
if line.product_id:
|
||||
# 使用正则表达式匹配P-后面的所有字符
|
||||
match = re.search(r'P-(.*)', product_name)
|
||||
if match:
|
||||
plan_no = match.group(1)
|
||||
line.demand_plan_number = plan_no
|
||||
else:
|
||||
line.demand_plan_number = None
|
||||
File diff suppressed because it is too large
Load Diff
49
sf_demand_plan/models/stock_route.py
Normal file
49
sf_demand_plan/models/stock_route.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
|
||||
class SfStockRoute(models.Model):
|
||||
_inherit = 'stock.route'
|
||||
|
||||
demand_plan_selectable = fields.Boolean("需求计划行")
|
||||
stock_route_group_ids = fields.Many2many('stock.route.group', 'route_to_group', string='路线组')
|
||||
demand_plan_ids = fields.Many2many('sf.production.demand.plan', 'stock_route_demand_plan', 'route_id',
|
||||
'demand_plan_id', '需求计划', copy=False, compute='_compute_demand_plan_ids',
|
||||
store=True)
|
||||
|
||||
@api.depends('demand_plan_selectable', 'stock_route_group_ids')
|
||||
def _compute_demand_plan_ids(self):
|
||||
for sr in self:
|
||||
if sr.demand_plan_selectable:
|
||||
stock_route_group = [srg.code for srg in sr.stock_route_group_ids]
|
||||
demand_plan_ids = self.env['sf.production.demand.plan'].sudo().search(
|
||||
[('supply_method', 'in', stock_route_group)])
|
||||
if demand_plan_ids:
|
||||
sr.demand_plan_ids = demand_plan_ids.ids
|
||||
continue
|
||||
sr.demand_plan_ids = None
|
||||
|
||||
# def name_get(self):
|
||||
# res = super().name_get()
|
||||
# if self.env.context.get('demand_plan_search_stock_route_id'):
|
||||
# demand_plan_id = self.env['sf.production.demand.plan'].sudo().browse(
|
||||
# int(self.env.context.get('demand_plan_search_stock_route_id')))
|
||||
# if demand_plan_id and demand_plan_id.supply_method:
|
||||
# supply_method = self._set_supply_method(demand_plan_id.supply_method)
|
||||
# res = [(item[0], f'{item[1]}-{supply_method}') for item in res if len(item) == 2]
|
||||
# return res
|
||||
#
|
||||
# def _set_supply_method(self, supply_method):
|
||||
# return {
|
||||
# 'automation': "自动化产线加工",
|
||||
# 'manual': "人工线下加工",
|
||||
# 'purchase': "外购",
|
||||
# 'outsourcing': "委外加工"
|
||||
# }.get(supply_method)
|
||||
|
||||
|
||||
class SfStockRouteGroup(models.Model):
|
||||
_name = 'stock.route.group'
|
||||
_description = '路线组'
|
||||
|
||||
name = fields.Char('名称')
|
||||
code = fields.Char('编码')
|
||||
22
sf_demand_plan/models/stock_rule.py
Normal file
22
sf_demand_plan/models/stock_rule.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
|
||||
def _prepare_mo_vals(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values,
|
||||
bom):
|
||||
res = super()._prepare_mo_vals(product_id, product_qty, product_uom, location_id, name, origin, company_id,
|
||||
values, bom)
|
||||
if self.env.context.get('demand_plan_line_id'):
|
||||
res['demand_plan_line_id'] = self.env.context.get('demand_plan_line_id')
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _prepare_purchase_request_line(self, request_id, procurement):
|
||||
res = super()._prepare_purchase_request_line(request_id, procurement)
|
||||
if self.env.context.get('demand_plan_line_id'):
|
||||
res['demand_plan_line_id'] = self.env.context.get('demand_plan_line_id')
|
||||
return res
|
||||
@@ -1,6 +1,16 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_sf_production_demand_plan,sf.production.demand.plan,model_sf_production_demand_plan,base.group_user,1,0,0,0
|
||||
access_sf_production_demand_plan_for_dispatch,sf.production.demand.plan for dispatch,model_sf_production_demand_plan,sf_base.group_plan_dispatch,1,1,0,0
|
||||
access_sf_production_demand_plan_for_dispatch,sf.production.demand.plan for dispatch,model_sf_production_demand_plan,sf_base.group_plan_dispatch,1,1,1,1
|
||||
|
||||
access_sf_demand_plan_print_wizard,sf.demand.plan.print.wizard,model_sf_demand_plan_print_wizard,base.group_user,1,0,0,0
|
||||
access_sf_demand_plan_print_wizard_for_dispatch,sf.demand.plan.print.wizard for dispatch,model_sf_demand_plan_print_wizard,sf_base.group_plan_dispatch,1,1,0,0
|
||||
|
||||
|
||||
access_sf_demand_plan,sf.demand.plan,model_sf_demand_plan,base.group_user,1,0,0,0
|
||||
access_sf_demand_plan_for_dispatch,sf.demand.plan for dispatch,model_sf_demand_plan,sf_base.group_plan_dispatch,1,1,0,0
|
||||
|
||||
access_stock_route_group,stock.route.group,model_stock_route_group,base.group_user,1,0,0,0
|
||||
access_stock_route_group_dispatch,stock.route.group.dispatch,model_stock_route_group,sf_base.group_plan_dispatch,1,1,0,0
|
||||
|
||||
access_sf_release_plan_wizard,sf.release.plan.wizard,model_sf_release_plan_wizard,base.group_user,1,0,0,0
|
||||
access_sf_release_plan_wizard_for_dispatch,sf.release.plan.wizard for dispatch,model_sf_release_plan_wizard,sf_base.group_plan_dispatch,1,1,1,1
|
||||
|
59
sf_demand_plan/static/src/js/custom_button.js
Normal file
59
sf_demand_plan/static/src/js/custom_button.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { ListRenderer } from "@web/views/list/list_renderer";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { useEffect } from "@odoo/owl";
|
||||
|
||||
export class CustomDemandPlanListRenderer extends ListRenderer {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.orm = useService("orm");
|
||||
this.notification = useService("notification");
|
||||
console.log('setup', this.props);
|
||||
|
||||
// 监听selection属性的变化
|
||||
useEffect(() => {
|
||||
this.updateButtonState();
|
||||
}, () => [this.props.list.selection]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新按钮状态
|
||||
*/
|
||||
async updateButtonState() {
|
||||
const selectedRecords = this.props.list.selection;
|
||||
const isStatus30 = selectedRecords.some(record => record.data.status != "30");
|
||||
const button = $(this.__owl__.parent.bdom.parentEl).find('button[name="button_batch_release_plan"]');
|
||||
console.log('isStatus30', isStatus30, button);
|
||||
if (isStatus30) {
|
||||
// 禁用按钮
|
||||
button.attr('disabled', true);
|
||||
} else {
|
||||
button.attr('disabled', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 使用setTimeout延迟注册,避免在模块加载时立即执行
|
||||
setTimeout(() => {
|
||||
const registerCustomRenderer = () => {
|
||||
try {
|
||||
const listView = registry.category("views").get("list");
|
||||
if (listView) {
|
||||
registry.category("views").add("custom_demand_plan_list", {
|
||||
...listView,
|
||||
Renderer: CustomDemandPlanListRenderer,
|
||||
});
|
||||
console.log("Custom demand plan list renderer registered successfully");
|
||||
} else {
|
||||
console.warn("List view not found, retrying...");
|
||||
// 如果还没找到,再等一段时间
|
||||
setTimeout(registerCustomRenderer, 1000);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error registering custom renderer:", error);
|
||||
}
|
||||
};
|
||||
|
||||
registerCustomRenderer();
|
||||
}, 1000);
|
||||
@@ -83,7 +83,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
th[data-name=processing_time] + th::before{
|
||||
content: '待执行单据';
|
||||
line-height: 38px;
|
||||
}
|
||||
/*.demand_plan_tree th[data-name=planned_start_date] + th::before{*/
|
||||
/* content: '待执行单据';*/
|
||||
/* line-height: 38px;*/
|
||||
/*}*/
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
<field name="model">sf.production.demand.plan</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="需求计划" default_order="sequence desc,id desc" editable="bottom"
|
||||
class="demand_plan_tree freeze-columns-before-part_number">
|
||||
class="demand_plan_tree freeze-columns-before-part_number" create="false" delete="false"
|
||||
js_class="custom_demand_plan_list">
|
||||
<header>
|
||||
<button string="打印" name="button_action_print" type="object"
|
||||
class="btn-primary"/>
|
||||
<button string="下达计划" name="button_batch_release_plan" type="object"
|
||||
class="btn-primary"
|
||||
/>
|
||||
</header>
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="id" optional="hide"/>
|
||||
@@ -19,17 +23,24 @@
|
||||
<field name="model_id" optional="hide"/>
|
||||
<field name="part_name"/>
|
||||
<field name="part_number"/>
|
||||
<field name="manual_quotation" optional="hide"/>
|
||||
<field name="is_incoming_material"/>
|
||||
<field name="supply_method"/>
|
||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="readonly_custom_made_type" invisible="1"/>
|
||||
<field name="custom_made_type"
|
||||
attrs="{'readonly': ['|',('status', '!=', '30'),('readonly_custom_made_type', '=', True)],
|
||||
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
||||
<field name="product_uom_qty"/>
|
||||
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="deadline_of_delivery"/>
|
||||
<field name="inventory_quantity_auto_apply"/>
|
||||
<field name="qty_delivered"/>
|
||||
<field name="qty_to_deliver"/>
|
||||
<field name="inventory_quantity_auto_apply" optional="hide"/>
|
||||
<field name="qty_delivered" optional="hide"/>
|
||||
<field name="qty_to_deliver" optional="hide"/>
|
||||
<field name="model_long"/>
|
||||
<field name="blank_type" optional="hide"/>
|
||||
<field name="blank_precision"/>
|
||||
<field name="embryo_long"/>
|
||||
<field name="unit_number" optional="hide"/>
|
||||
<field name="materials_id"/>
|
||||
<field name="model_machining_precision"/>
|
||||
<field name="model_process_parameters_ids" widget="many2many_tags"/>
|
||||
@@ -38,31 +49,32 @@
|
||||
<field name="sale_order_id" optional="hide"/>
|
||||
<field name="sale_order_line_number" optional="hide"/>
|
||||
<field name="order_state"/>
|
||||
<field name="route_id" optional="hide"/>
|
||||
<field name="route_ids" widget="many2many_tags" optional="hide"
|
||||
context="{'demand_plan_search_stock_route_id': id}"/>
|
||||
<field name="contract_date"/>
|
||||
<field name="date_order"/>
|
||||
<field name="contract_code"/>
|
||||
<field name="plan_remark"/>
|
||||
<field name="plan_remark" attrs="{'readonly': [('status', 'in', ('60','100'))]}"/>
|
||||
<field name="priority" decoration-danger="priority == '1'"
|
||||
decoration-warning="priority == '2'"
|
||||
decoration-info="priority == '3'"
|
||||
decoration-success="priority == '4'"/>
|
||||
<field name="material_check" optional="hide"/>
|
||||
<field name="hide_action_open_mrp_production" invisible="1"/>
|
||||
<field name="hide_action_purchase_orders" invisible="1"/>
|
||||
<field name="hide_action_stock_picking" invisible="1"/>
|
||||
<field name="hide_action_view_programming" invisible="1"/>
|
||||
<button name="action_open_sale_order" type="object" string="供货方式待确认" class="btn-secondary"
|
||||
attrs="{'invisible': [('supply_method', '!=', False)]}"/>
|
||||
<button name="action_open_mrp_production" type="object" string="待工艺确认" class="btn-secondary"
|
||||
attrs="{'invisible': [('hide_action_open_mrp_production', '=', False)]}"/>
|
||||
<button name="action_view_purchase_request" type="object" string="采购申请" class="btn-secondary"
|
||||
attrs="{'invisible': [('hide_action_purchase_orders', '=', False)]}"/>
|
||||
<button name="action_view_stock_picking" type="object" string="调拨单" class="btn-secondary"
|
||||
attrs="{'invisible': [('hide_action_stock_picking', '=', False)]}"/>
|
||||
<button name="action_view_programming" type="object" string="编程单" class="btn-secondary"
|
||||
attrs="{'invisible': [('hide_action_view_programming', '=', False)]}"/>
|
||||
<field name="planned_start_date"/>
|
||||
<!-- <field name="hide_action_open_mrp_production" invisible="1"/>-->
|
||||
<!-- <field name="hide_action_purchase_orders" invisible="1"/>-->
|
||||
<!-- <field name="hide_action_stock_picking" invisible="1"/>-->
|
||||
<!-- <field name="hide_action_view_programming" invisible="1"/>-->
|
||||
<!-- <button name="action_open_sale_order" type="object" string="供货方式待确认" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('supply_method', '!=', False)]}"/>-->
|
||||
<!-- <button name="action_open_mrp_production" type="object" string="待工艺确认" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('hide_action_open_mrp_production', '=', False)]}"/>-->
|
||||
<!-- <button name="action_view_purchase_request" type="object" string="采购申请" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('hide_action_purchase_orders', '=', False)]}"/>-->
|
||||
<!-- <button name="action_view_stock_picking" type="object" string="调拨单" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('hide_action_stock_picking', '=', False)]}"/>-->
|
||||
<!-- <button name="action_view_programming" type="object" string="编程单" class="btn-secondary"-->
|
||||
<!-- attrs="{'invisible': [('hide_action_view_programming', '=', False)]}"/>-->
|
||||
<field name="planned_start_date" attrs="{'readonly': [('status', 'in', ('60','100'))]}"/>
|
||||
<field name="actual_start_date"/>
|
||||
<field name="actual_end_date"/>
|
||||
<field name="processing_time"/>
|
||||
@@ -71,8 +83,15 @@
|
||||
<field name="write_date" string="更新时间"/>
|
||||
<field name="write_uid" optional="hide" string="更新人"/>
|
||||
<field name="print_count"/>
|
||||
<button name="release_production_order" type="object" string="下达生产" class="btn-primary"
|
||||
attrs="{'invisible': ['|',('status', '!=', '50'), ('supply_method', 'not in', ['automation', 'manual'])]}"/>
|
||||
<field name="hide_release_production_order" invisible="1"/>
|
||||
<button string="下达计划" name="button_release_plan" type="object"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
|
||||
/>
|
||||
<button name="button_release_production" type="object" string="下发生产" class="btn-primary"
|
||||
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||
/>
|
||||
<button name="edit_button" type="object" string="拆分" class="btn-primary"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -119,17 +138,4 @@
|
||||
<field name="view_mode">tree</field>
|
||||
</record>
|
||||
|
||||
|
||||
<menuitem
|
||||
id="demand_plan_menu"
|
||||
name="需求计划"
|
||||
sequence="140"
|
||||
action="sf_production_demand_plan_action"
|
||||
parent="sf_plan.sf_production_plan_menu"
|
||||
/>
|
||||
|
||||
<!-- 调拨动作中屏蔽验证-->
|
||||
<record id="stock.action_validate_picking" model="ir.actions.server">
|
||||
<field name="binding_model_id" eval="False"/>
|
||||
</record>
|
||||
</odoo>
|
||||
123
sf_demand_plan/views/demand_plan_info.xml
Normal file
123
sf_demand_plan/views/demand_plan_info.xml
Normal file
@@ -0,0 +1,123 @@
|
||||
<odoo>
|
||||
<record id="view_sf_demand_plan_form" model="ir.ui.view">
|
||||
<field name="name">sf.demand.plan.form</field>
|
||||
<field name="model">sf.demand.plan</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header>
|
||||
<field name="state" widget="statusbar"/>
|
||||
<field name="hide_button_release_plan" invisible="1"/>
|
||||
<button string="下达计划" name="button_production_release_plan" type="object"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('hide_button_release_plan', '=', False)]}"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<field name="demand_plan_number"/>
|
||||
<field name="product_id"/>
|
||||
<field name="part_name"/>
|
||||
<field name="part_number"/>
|
||||
<field name="materials_id"/>
|
||||
<field name="blank_type"/>
|
||||
<field name="blank_precision"/>
|
||||
<field name="embryo_long"/>
|
||||
<field name="manual_quotation"/>
|
||||
<field name="is_incoming_material"/>
|
||||
<field name="pending_qty"/>
|
||||
<field name="planned_qty"/>
|
||||
<field name="model_id"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="customer_name"/>
|
||||
<field name="product_uom_qty"/>
|
||||
<field name="deadline_of_delivery"/>
|
||||
<field name="contract_date"/>
|
||||
<field name="contract_code"/>
|
||||
<field name="model_process_parameters_ids" widget="many2many_tags"/>
|
||||
<field name="model_machining_precision"/>
|
||||
<field name="inventory_quantity_auto_apply"/>
|
||||
<field name="priority" attrs="{'readonly': [('state', 'in', ('40','50'))]}"/>
|
||||
<field name="overdelivery_allowed"/>
|
||||
<field name="origin"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="计划">
|
||||
<field name="line_ids" attrs="{'invisible': [('state', 'in', ('40','50'))]}">
|
||||
<tree editable="bottom" create="false" delete="false">
|
||||
<field name="status"/>
|
||||
<field name="readonly_custom_made_type" invisible="1"/>
|
||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="custom_made_type"
|
||||
attrs="{
|
||||
'readonly': ['|', '|', ('new_supply_method', '!=', 'custom_made'), ('status', '!=', '30'), ('readonly_custom_made_type', '=', True)],
|
||||
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
||||
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
||||
<field name="location_id" optional="hide"/>
|
||||
<field name="bom_id" optional="hide"/>
|
||||
<field name="processing_time" optional="hide"/>
|
||||
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="blank_arrival_date"/>
|
||||
<field name="finished_product_arrival_date"/>
|
||||
<field name="planned_start_date"/>
|
||||
<field name="actual_start_date"/>
|
||||
<field name="actual_end_date"/>
|
||||
<field name="plan_remark"/>
|
||||
<field name="procurement_reason"/>
|
||||
<field name="write_date" string="更新时间"/>
|
||||
<field name="hide_release_production_order" invisible="1"/>
|
||||
<button string="下达计划" name="button_release_plan" type="object"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
|
||||
/>
|
||||
<button name="button_release_production" type="object" string="下发生产"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||
/>
|
||||
</tree>
|
||||
</field>
|
||||
<field name="line_ids" attrs="{'invisible': [('state', 'not in', ('40','50'))]}">
|
||||
<tree editable="bottom">
|
||||
<field name="status"/>
|
||||
<field name="readonly_custom_made_type" invisible="1"/>
|
||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="custom_made_type"
|
||||
attrs="{
|
||||
'readonly': ['|', '|', ('new_supply_method', '!=', 'custom_made'), ('status', '!=', '30'), ('readonly_custom_made_type', '=', True)],
|
||||
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
||||
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
||||
<field name="location_id" optional="hide"/>
|
||||
<field name="bom_id" optional="hide" readonly="1" options="{'no_create': True}"/>
|
||||
<field name="processing_time" optional="hide"/>
|
||||
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="blank_arrival_date"/>
|
||||
<field name="finished_product_arrival_date"/>
|
||||
<field name="planned_start_date"/>
|
||||
<field name="actual_start_date"/>
|
||||
<field name="actual_end_date"/>
|
||||
<field name="plan_remark"/>
|
||||
<field name="procurement_reason"/>
|
||||
<field name="write_date" string="更新时间"/>
|
||||
<field name="hide_release_production_order" invisible="1"/>
|
||||
<button string="下达计划" name="button_release_plan" type="object"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
|
||||
/>
|
||||
<button name="button_release_production" type="object" string="下发生产"
|
||||
class="btn-primary"
|
||||
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||
/>
|
||||
<button string="详情" name="button_plan_detail" type="object"
|
||||
class="btn-primary"
|
||||
/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
18
sf_demand_plan/views/menu_view.xml
Normal file
18
sf_demand_plan/views/menu_view.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<menuitem
|
||||
id="demand_plan_menu"
|
||||
name="需求计划"
|
||||
sequence="140"
|
||||
action="sf_demand_plan.sf_production_demand_plan_action"
|
||||
parent="sf_plan.sf_production_plan_menu"
|
||||
/>
|
||||
|
||||
<!-- 调拨动作中屏蔽验证-->
|
||||
<record id="stock.action_validate_picking" model="ir.actions.server">
|
||||
<field name="binding_model_id" eval="False"/>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
29
sf_demand_plan/views/sale_order_views.xml
Normal file
29
sf_demand_plan/views/sale_order_views.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="view_order_form_inherit_plan" model="ir.ui.view">
|
||||
<field name="name">view.sale.order.form.inherit.plan</field>
|
||||
<field name="inherit_id" ref="sf_manufacturing.view_order_form_inherit_supply_method"/>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//header/button[@name='action_confirm'][last()]" position="attributes">
|
||||
<attribute name="invisible">True</attribute>
|
||||
</xpath>
|
||||
|
||||
<xpath expr="//page/field[@name='order_line']/tree/field[@name='supply_method']" position="attributes">
|
||||
<attribute name="invisible">True</attribute>
|
||||
</xpath>
|
||||
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<button class="oe_stat_button" name="action_view_demand_plan" type="object" icon="fa-pencil-square-o"
|
||||
attrs="{'invisible': [('demand_plan_count', '=', 0)]}">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value">
|
||||
<field name="demand_plan_count"/>
|
||||
</span>
|
||||
<span class="o_stat_text">需求计划</span>
|
||||
</div>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
21
sf_demand_plan/views/stock_route.xml
Normal file
21
sf_demand_plan/views/stock_route.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="sf_stock_location_route_form_view" model="ir.ui.view">
|
||||
<field name="name">stock.route.form</field>
|
||||
<field name="model">stock.route</field>
|
||||
<field name="inherit_id" ref="stock.stock_location_route_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='packaging_selectable']" position="after">
|
||||
<field name="demand_plan_selectable"/>
|
||||
</xpath>
|
||||
<xpath expr="//group[@name='route_selector']" position="after">
|
||||
<group name="group_category" string="组类">
|
||||
<group>
|
||||
<field name="stock_route_group_ids" options="{'no_create': True}" widget="many2many_tags"/>
|
||||
<field name="demand_plan_ids" invisible="1" options="{'no_create': True}" widget="many2many_tags"/>
|
||||
</group>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -1 +1,2 @@
|
||||
from . import sf_demand_plan_print_wizard
|
||||
from . import sf_release_plan_wizard
|
||||
|
||||
@@ -9,11 +9,6 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
||||
_name = 'sf.demand.plan.print.wizard'
|
||||
_description = u'打印向导'
|
||||
|
||||
demand_plan_id = fields.Many2one('sf.production.demand.plan', string='需求计划ID')
|
||||
product_id = fields.Many2one(
|
||||
comodel_name='product.product',
|
||||
related='demand_plan_id.product_id',
|
||||
string='产品', store=True, index=True)
|
||||
model_id = fields.Char('模型ID')
|
||||
filename_url = fields.Char('文件名/URL')
|
||||
type = fields.Selection([
|
||||
@@ -25,7 +20,7 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
||||
('success', '成功'),
|
||||
('fail', '失败'),
|
||||
], string='状态', default='not_start')
|
||||
machining_drawings = fields.Binary('2D加工图纸', related='product_id.machining_drawings', store=True)
|
||||
machining_drawings = fields.Binary('2D加工图纸')
|
||||
|
||||
cnc_worksheet = fields.Binary('程序单')
|
||||
|
||||
@@ -42,16 +37,19 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
||||
if pdf_data:
|
||||
try:
|
||||
# 执行打印
|
||||
self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
|
||||
# self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
|
||||
record.status = 'success'
|
||||
t_part, c_part = record.demand_plan_id.print_count.split('C')
|
||||
t_num = int(t_part[1:])
|
||||
c_num = int(c_part)
|
||||
if record.type == '1':
|
||||
t_num += 1
|
||||
elif record.type == '2':
|
||||
c_num += 1
|
||||
record.demand_plan_id.print_count = f"T{t_num}C{c_num}"
|
||||
production_demand_plan_id = self.env['sf.production.demand.plan'].sudo().search(
|
||||
[('model_id', '=', record.model_id)])
|
||||
for production_demand_plan in production_demand_plan_id:
|
||||
t_part, c_part = production_demand_plan.print_count.split('C')
|
||||
t_num = int(t_part[1:])
|
||||
c_num = int(c_part)
|
||||
if record.type == '1':
|
||||
t_num += 1
|
||||
elif record.type == '2':
|
||||
c_num += 1
|
||||
production_demand_plan.print_count = f"T{t_num}C{c_num}"
|
||||
success_records.append({
|
||||
'filename_url': record.filename_url,
|
||||
})
|
||||
@@ -78,18 +76,14 @@ class MrpWorkorder(models.Model):
|
||||
demand_plan_print = self.env['sf.demand.plan.print.wizard'].sudo().search(
|
||||
[('model_id', '=', record.model_id), ('type', '=', '2')])
|
||||
if demand_plan_print:
|
||||
self.env['sf.demand.plan.print.wizard'].sudo().write(
|
||||
demand_plan_print.write(
|
||||
{'cnc_worksheet': record.cnc_worksheet, 'filename_url': record.cnc_worksheet_name})
|
||||
else:
|
||||
demand_plan = self.env['sf.production.demand.plan'].sudo().search(
|
||||
[('product_id', '=', record.product_id.id)])
|
||||
if demand_plan:
|
||||
wizard_vals = {
|
||||
'demand_plan_id': demand_plan.id,
|
||||
'model_id': demand_plan.model_id,
|
||||
'type': '2',
|
||||
'cnc_worksheet': record.cnc_worksheet,
|
||||
'filename_url': record.cnc_worksheet_name
|
||||
}
|
||||
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
||||
wizard_vals = {
|
||||
'model_id': record.model_id,
|
||||
'type': '2',
|
||||
'cnc_worksheet': record.cnc_worksheet,
|
||||
'filename_url': record.cnc_worksheet_name
|
||||
}
|
||||
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
||||
return res
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
<field name="name">sf.demand.plan.print.wizard.tree</field>
|
||||
<field name="model">sf.demand.plan.print.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="打印" class="print_demand" js_class="print_demand" >
|
||||
<tree string="打印" class="print_demand" js_class="print_demand">
|
||||
<field name="model_id"/>
|
||||
<field name="filename_url"/>
|
||||
<field name="type"/>
|
||||
<field name="machining_drawings" attrs="{'column_invisible': True }"/>
|
||||
<field name="cnc_worksheet" attrs="{'column_invisible': True }" />
|
||||
<field name="machining_drawings" attrs="{'column_invisible': True }"/>
|
||||
<field name="cnc_worksheet" attrs="{'column_invisible': True }"/>
|
||||
<field name="status"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
27
sf_demand_plan/wizard/sf_release_plan_wizard.py
Normal file
27
sf_demand_plan/wizard/sf_release_plan_wizard.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
from odoo import models, fields, api, _
|
||||
from werkzeug.exceptions import InternalServerError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SfReleasePlanWizard(models.TransientModel):
|
||||
_name = 'sf.release.plan.wizard'
|
||||
_description = u'下达计划向导'
|
||||
|
||||
demand_plan_line_id = fields.Many2many(comodel_name="sf.production.demand.plan",
|
||||
string="需求计划明细", readonly=True)
|
||||
|
||||
release_message = fields.Char(string='提示', readonly=True)
|
||||
|
||||
def confirm(self):
|
||||
if self.demand_plan_line_id:
|
||||
for demand_plan_line_id in self.demand_plan_line_id:
|
||||
try:
|
||||
demand_plan_line_id.action_confirm()
|
||||
except Exception as e:
|
||||
self.env.cr.rollback()
|
||||
demand_plan_line_id.write({'is_processing': False})
|
||||
self.env.cr.commit()
|
||||
raise InternalServerError('操作失败', e)
|
||||
22
sf_demand_plan/wizard/sf_release_plan_wizard_views.xml
Normal file
22
sf_demand_plan/wizard/sf_release_plan_wizard_views.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="sf_release_plan_wizard_form">
|
||||
<field name="name">sf.release.plan.wizard.form</field>
|
||||
<field name="model">sf.release.plan.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<div>
|
||||
<div style="white-space: pre-wrap;">
|
||||
<field name="release_message"/>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<button string="确认" name="confirm" type="object" class="oe_highlight"/>
|
||||
<button string="取消" class="btn btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -6,50 +6,50 @@ from odoo import models, fields, api, _
|
||||
class StockRuleInherit(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
|
||||
@api.model
|
||||
def _run_buy(self, procurements):
|
||||
# 判断补货组的采购类型
|
||||
procurements_group = {'standard': [], 'outsourcing': []}
|
||||
for procurement, rule in procurements:
|
||||
is_outsourcing = False
|
||||
product = procurement.product_id
|
||||
# 获取主 BOM
|
||||
bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)], limit=1)
|
||||
|
||||
if bom:
|
||||
# 遍历 BOM 中的组件(即坯料等)
|
||||
for line in bom.bom_line_ids:
|
||||
raw_material = line.product_id
|
||||
# 检查路线
|
||||
for route in raw_material.route_ids:
|
||||
# print('route.name:', route.name)
|
||||
if route.name == '按订单补给外包商':
|
||||
is_outsourcing = True
|
||||
|
||||
if is_outsourcing:
|
||||
procurements_group['outsourcing'].append((procurement, rule))
|
||||
else:
|
||||
procurements_group['standard'].append((procurement, rule))
|
||||
|
||||
for key, value in procurements_group.items():
|
||||
super(StockRuleInherit, self)._run_buy(value)
|
||||
|
||||
if key == 'outsourcing':
|
||||
for procurement, rule in value:
|
||||
supplier = procurement.values.get('supplier')
|
||||
if supplier:
|
||||
domain = rule._make_po_get_domain(procurement.company_id, procurement.values,
|
||||
supplier.partner_id)
|
||||
logging.info("domain=============: %s", domain)
|
||||
po = self.env['purchase.order'].sudo().search([
|
||||
('partner_id', '=', supplier.partner_id.id),
|
||||
('company_id', '=', procurement.company_id.id), # 保证公司一致
|
||||
('origin', 'like', procurement.origin), # 根据来源匹配
|
||||
('state', '=', 'draft') # 状态为草稿
|
||||
], limit=1)
|
||||
logging.info("po=: %s", po)
|
||||
if po:
|
||||
po.write({'purchase_type': 'outsourcing'})
|
||||
# @api.model
|
||||
# def _run_buy(self, procurements):
|
||||
# # 判断补货组的采购类型
|
||||
# procurements_group = {'standard': [], 'outsourcing': []}
|
||||
# for procurement, rule in procurements:
|
||||
# is_outsourcing = False
|
||||
# product = procurement.product_id
|
||||
# # 获取主 BOM
|
||||
# bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)], limit=1)
|
||||
#
|
||||
# if bom:
|
||||
# # 遍历 BOM 中的组件(即坯料等)
|
||||
# for line in bom.bom_line_ids:
|
||||
# raw_material = line.product_id
|
||||
# # 检查路线
|
||||
# for route in raw_material.route_ids:
|
||||
# # print('route.name:', route.name)
|
||||
# if route.name == '按订单补给外包商':
|
||||
# is_outsourcing = True
|
||||
#
|
||||
# if is_outsourcing:
|
||||
# procurements_group['outsourcing'].append((procurement, rule))
|
||||
# else:
|
||||
# procurements_group['standard'].append((procurement, rule))
|
||||
#
|
||||
# for key, value in procurements_group.items():
|
||||
# super(StockRuleInherit, self)._run_buy(value)
|
||||
#
|
||||
# if key == 'outsourcing':
|
||||
# for procurement, rule in value:
|
||||
# supplier = procurement.values.get('supplier')
|
||||
# if supplier:
|
||||
# domain = rule._make_po_get_domain(procurement.company_id, procurement.values,
|
||||
# supplier.partner_id)
|
||||
# logging.info("domain=============: %s", domain)
|
||||
# po = self.env['purchase.order'].sudo().search([
|
||||
# ('partner_id', '=', supplier.partner_id.id),
|
||||
# ('company_id', '=', procurement.company_id.id), # 保证公司一致
|
||||
# ('origin', 'like', procurement.origin), # 根据来源匹配
|
||||
# ('state', '=', 'draft') # 状态为草稿
|
||||
# ], limit=1)
|
||||
# logging.info("po=: %s", po)
|
||||
# if po:
|
||||
# po.write({'purchase_type': 'outsourcing'})
|
||||
|
||||
# # 首先调用父类的 _run_buy 方法,以保留原有逻辑
|
||||
# super(StockRuleInherit, self)._run_buy(procurements)
|
||||
|
||||
@@ -437,7 +437,7 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
('state', 'in', ['ready', 'progress', 'done'])
|
||||
])
|
||||
|
||||
plan_data_total_counts = sum(plan_data_total.mapped('qty_produced'))
|
||||
plan_data_total_counts = sum(plan_data_total.mapped('qty_production'))
|
||||
|
||||
# # 工单完成量
|
||||
# plan_data_finish_counts = plan_obj.search_count(
|
||||
@@ -601,8 +601,11 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
line_list = ast.literal_eval(kw['line_list'])
|
||||
begin_time_str = kw['begin_time'].strip('"')
|
||||
end_time_str = kw['end_time'].strip('"')
|
||||
begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
|
||||
end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
|
||||
# 将时间减去8小时(UTC+8转UTC)
|
||||
begin_time = (datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S') - timedelta(hours=8))
|
||||
end_time = (datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S') - timedelta(hours=8))
|
||||
# begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
|
||||
# end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
|
||||
# print('line_list: %s' % line_list)
|
||||
print('kw', kw)
|
||||
time_unit = kw.get('time_unit', 'day').strip('"') # 默认单位为天
|
||||
@@ -636,6 +639,15 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
|
||||
|
||||
if time_unit == 'hour':
|
||||
|
||||
# 计划量,目前只能从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 line in line_list:
|
||||
date_field_name = 'date_finished' # 替换为你模型中的实际字段名
|
||||
@@ -678,19 +690,10 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
)
|
||||
|
||||
# 使用小时和分钟作为键,确保每个小时的数据有独立的键
|
||||
key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
|
||||
key = (start_time + timedelta(hours=8)).strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
|
||||
# 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
|
||||
|
||||
@@ -704,9 +707,11 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
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'))
|
||||
interval_order_ids = set(interval_plan_orders.mapped('res_id'))
|
||||
|
||||
interval_orders = request.env['mrp.workorder'].sudo().browse(interval_order_ids)
|
||||
if line == '业绩总览':
|
||||
interval_orders = interval_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工'])
|
||||
elif line == '人工线下加工中心':
|
||||
@@ -715,9 +720,9 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
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') # 只取小时:分钟:秒作为键
|
||||
key = (start_time + timedelta(hours=8)).strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
|
||||
# time_count_dict[key] = len(orders)
|
||||
plan_count_dict[key] = sum(interval_orders.mapped('qty_produced'))
|
||||
plan_count_dict[key] = sum(interval_orders.mapped('qty_production'))
|
||||
|
||||
# order_counts.append()
|
||||
res['data'][line] = {
|
||||
@@ -859,21 +864,37 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
"""
|
||||
# res = {'status': 1, 'message': '成功', 'not_done_data': [], 'done_data': []}
|
||||
res = {'status': 1, 'message': '成功', 'data': {}}
|
||||
# 解决产品名称取到英文的问题
|
||||
request.update_context(lang='zh_CN')
|
||||
plan_obj = request.env['sf.production.plan'].sudo()
|
||||
work_order_obj = request.env['mrp.workorder'].sudo()
|
||||
# 获取mrp.workorder的state字段的selection内容
|
||||
state_dict = dict(request.env['mrp.workorder'].sudo()._fields['state'].selection)
|
||||
line_list = ast.literal_eval(kw['line_list'])
|
||||
begin_time_str = kw['begin_time'].strip('"')
|
||||
end_time_str = kw['end_time'].strip('"')
|
||||
begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
|
||||
end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
|
||||
# print('line_list: %s' % line_list)
|
||||
not_done_data = []
|
||||
done_data = []
|
||||
final_data = {}
|
||||
not_done_index = 1
|
||||
done_index = 1
|
||||
|
||||
# 获取当前时间,并计算24小时前的时间
|
||||
current_time = datetime.now()
|
||||
time_48_hours_ago = current_time - timedelta(hours=48)
|
||||
|
||||
# # 计划量,目前只能从mail.message中筛选出
|
||||
# plan_order_messages = request.env['mail.message'].sudo().search([
|
||||
# ('model', '=', 'mrp.workorder'),
|
||||
# ('create_date', '>=', time_48_hours_ago.strftime('%Y-%m-%d %H:%M:%S')),
|
||||
# ('tracking_value_ids.field_desc', '=', '状态'),
|
||||
# ('tracking_value_ids.new_value_char', 'in', ['就绪', '生产中'])
|
||||
# ])
|
||||
|
||||
for line in line_list:
|
||||
not_done_data = []
|
||||
done_data = []
|
||||
not_done_index = 1
|
||||
done_index = 1
|
||||
|
||||
if line == '业绩总览':
|
||||
work_order_domain = [('routing_type', 'in', ['人工线下加工', 'CNC加工'])]
|
||||
@@ -889,21 +910,24 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
# [('production_line_id.name', '=', line), ('state', 'not in', ['finished']),
|
||||
# ('production_id.state', 'not in', ['cancel', 'done']), ('active', '=', True)
|
||||
# ])
|
||||
not_done_orders = work_order_obj.search(work_order_domain +
|
||||
[('state', 'in', ['ready', 'progress'])], order='id asc'
|
||||
not_done_orders = work_order_obj.search(work_order_domain + [
|
||||
('state', 'in', ['ready', 'progress']),
|
||||
('date_planned_start', '>=', time_48_hours_ago),
|
||||
('date_planned_start', '<=', current_time)
|
||||
], order='id asc'
|
||||
)
|
||||
|
||||
# 完成订单
|
||||
# 获取当前时间,并计算24小时前的时间
|
||||
current_time = datetime.now()
|
||||
time_24_hours_ago = current_time - timedelta(hours=24)
|
||||
# current_time = datetime.now()
|
||||
# time_24_hours_ago = current_time - timedelta(hours=24)
|
||||
|
||||
finish_orders = work_order_obj.search(work_order_domain + [
|
||||
('state', 'in', ['finished']),
|
||||
('state', 'in', ['done']),
|
||||
('production_id.state', 'not in', ['cancel']),
|
||||
('date_finished', '>=', time_24_hours_ago)
|
||||
('date_finished', '>=', time_48_hours_ago)
|
||||
], order='id asc')
|
||||
# print(finish_orders)
|
||||
# logging.info('完成订单: %s' % finish_orders)
|
||||
|
||||
# 获取所有未完成订单的ID列表
|
||||
order_ids = [order.id for order in not_done_orders]
|
||||
@@ -939,14 +963,6 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
material_match = re.search(material_pattern, blank_name)
|
||||
material = material_match.group(1) if material_match else 'No match found'
|
||||
|
||||
state_dict = {
|
||||
'draft': '待排程',
|
||||
'done': '已排程',
|
||||
'processing': '生产中',
|
||||
'finished': '已完成',
|
||||
'ready': '待加工',
|
||||
'progress': '生产中',
|
||||
}
|
||||
|
||||
line_dict = {
|
||||
'sequence': not_done_index,
|
||||
@@ -962,8 +978,6 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
not_done_index += 1
|
||||
|
||||
for finish_order in finish_orders:
|
||||
if not finish_order.actual_end_time:
|
||||
continue
|
||||
blank_name = ''
|
||||
try:
|
||||
blank_name = finish_order.production_id.move_raw_ids[0].product_id.name
|
||||
@@ -979,13 +993,13 @@ class Sf_Dashboard_Connect(http.Controller):
|
||||
|
||||
line_dict = {
|
||||
'sequence': done_index,
|
||||
'workorder_name': finish_order.name,
|
||||
'workorder_name': finish_order.production_id.name,
|
||||
'blank_name': blank_name,
|
||||
'material': material,
|
||||
'dimensions': dimensions,
|
||||
'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 ' '
|
||||
'order_qty': finish_order.qty_produced,
|
||||
'finish_time': finish_order.date_finished.strftime(
|
||||
'%Y-%m-%d %H:%M:%S') if finish_order.date_finished else ' '
|
||||
|
||||
}
|
||||
done_data.append(line_dict)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
'category': 'sf',
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': ['sf_base', 'sf_maintenance', 'web_widget_model_viewer', 'sf_warehouse', 'jikimo_attachment_viewer',
|
||||
'jikimo_sale_multiple_supply_methods', 'product'],
|
||||
'jikimo_sale_multiple_supply_methods', 'product', 'jikimo_tree_header_buttons_always_visible'],
|
||||
'data': [
|
||||
'data/cron_data.xml',
|
||||
'data/stock_data.xml',
|
||||
|
||||
@@ -18,4 +18,5 @@ from . import quick_easy_order
|
||||
from . import purchase_order
|
||||
from . import quality_check
|
||||
from . import purchase_request_line
|
||||
from . import bom
|
||||
# from . import stock_warehouse_orderpoint
|
||||
16
sf_manufacturing/models/bom.py
Normal file
16
sf_manufacturing/models/bom.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from odoo import models
|
||||
from odoo.osv.expression import AND
|
||||
|
||||
|
||||
class MrpBom(models.Model):
|
||||
_inherit = 'mrp.bom'
|
||||
|
||||
def _bom_subcontract_find(self, product, picking_type=None, company_id=False, bom_type='subcontract', subcontractor=False):
|
||||
domain = self._bom_find_domain(product, picking_type=picking_type, company_id=company_id, bom_type=bom_type)
|
||||
if self.env.context.get('stock_picking') == 'outsourcing':
|
||||
return self.search(domain, order='sequence, product_id, id', limit=1)
|
||||
if subcontractor:
|
||||
domain = AND([domain, [('subcontractor_ids', 'parent_of', subcontractor.ids)]])
|
||||
return self.search(domain, order='sequence, product_id, id', limit=1)
|
||||
else:
|
||||
return self.env['mrp.bom']
|
||||
@@ -1709,6 +1709,7 @@ class MrpProduction(models.Model):
|
||||
vals['procurement_group_id'] = product_group_id[product_id.id]
|
||||
else:
|
||||
vals['procurement_group_id'] = is_custemer_group_id[key]
|
||||
|
||||
return super(MrpProduction, self).create(vals_list)
|
||||
|
||||
@api.depends('procurement_group_id.stock_move_ids.created_purchase_line_id.order_id',
|
||||
|
||||
@@ -35,7 +35,7 @@ class ResProductMo(models.Model):
|
||||
model_volume = fields.Float('模型体积(m³)')
|
||||
model_area = fields.Float('模型表面积(m²)')
|
||||
model_machining_precision = fields.Selection(selection=_get_machining_precision, string='加工精度')
|
||||
model_processing_panel = fields.Char('模型加工面板')
|
||||
model_processing_panel = fields.Char('模型加工面板', default='')
|
||||
model_remark = fields.Char('模型备注说明')
|
||||
length = fields.Float('长(mm)', digits=(16, 3))
|
||||
width = fields.Float('宽(mm)', digits=(16, 3))
|
||||
@@ -913,7 +913,7 @@ class ResProductMo(models.Model):
|
||||
(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_processing_panel': item['processing_panel_detail'] if item['processing_panel_detail'] else '',
|
||||
'model_machining_precision': item['model_machining_precision'],
|
||||
'model_code': item['barcode'],
|
||||
'length': item['model_long'],
|
||||
|
||||
@@ -21,6 +21,7 @@ from odoo.addons.sf_base.commons.common import Common
|
||||
from odoo.exceptions import UserError
|
||||
from io import BytesIO
|
||||
from odoo.exceptions import ValidationError
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
|
||||
class stockWarehouse(models.Model):
|
||||
@@ -95,35 +96,36 @@ class StockRule(models.Model):
|
||||
precision_rounding=proc[
|
||||
0].product_uom.rounding) > 0)
|
||||
list2 = []
|
||||
for item in procurements:
|
||||
num = int(item[0].product_qty)
|
||||
for procurement, rule in procurements:
|
||||
num = int(procurement.product_qty)
|
||||
|
||||
product = self.env['product.product'].search(
|
||||
[("id", '=', item[0].product_id.id)])
|
||||
product_tmpl = self.env['product.template'].search(
|
||||
["&", ("id", '=', product.product_tmpl_id.id), ('single_manufacturing', "!=", False)])
|
||||
if product_tmpl:
|
||||
warehouse_id = rule.warehouse_id
|
||||
if not warehouse_id:
|
||||
warehouse_id = rule.location_dest_id.warehouse_id
|
||||
manu_rule = rule.route_id.rule_ids.filtered(lambda r: r.action == 'manufacture' and r.warehouse_id == warehouse_id)
|
||||
|
||||
if procurement.product_id.product_tmpl_id.single_manufacturing and manu_rule:
|
||||
if num > 1:
|
||||
for no in range(1, num + 1):
|
||||
Procurement = namedtuple('Procurement', ['product_id', 'product_qty',
|
||||
'product_uom', 'location_id', 'name', 'origin',
|
||||
'company_id',
|
||||
'values'])
|
||||
s = Procurement(product_id=item[0].product_id, product_qty=1.0, product_uom=item[0].product_uom,
|
||||
location_id=item[0].location_id,
|
||||
name=item[0].name,
|
||||
origin=item[0].origin,
|
||||
company_id=item[0].company_id,
|
||||
values=item[0].values,
|
||||
s = Procurement(product_id=procurement.product_id, product_qty=1.0, product_uom=procurement.product_uom,
|
||||
location_id=procurement.location_id,
|
||||
name=procurement.name,
|
||||
origin=procurement.origin,
|
||||
company_id=procurement.company_id,
|
||||
values=procurement.values,
|
||||
)
|
||||
item1 = list(item)
|
||||
item1[0] = s
|
||||
# item1 = list(item)
|
||||
# item1[0] = s
|
||||
|
||||
list2.append(tuple(item1))
|
||||
list2.append((s, rule))
|
||||
else:
|
||||
list2.append(item)
|
||||
list2.append((procurement, rule))
|
||||
else:
|
||||
list2.append(item)
|
||||
list2.append((procurement, rule))
|
||||
|
||||
for procurement, rule in list2:
|
||||
procure_method = rule.procure_method
|
||||
@@ -183,18 +185,6 @@ class StockRule(models.Model):
|
||||
'''创建制造订单'''
|
||||
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
|
||||
productions_values)
|
||||
# 将这一批制造订单的采购组根据成品设置为不同的采购组
|
||||
# product_group_id = {}
|
||||
# for index, production in enumerate(productions):
|
||||
# if production.product_id.id not in product_group_id.keys():
|
||||
# product_group_id[production.product_id.id] = production.procurement_group_id.id
|
||||
# else:
|
||||
# productions_values[index].update({'name': production.name})
|
||||
# procurement_group_vals = production._prepare_procurement_group_vals(productions_values[index])
|
||||
# production.procurement_group_id = self.env["procurement.group"].create(procurement_group_vals).id
|
||||
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||
|
||||
'''
|
||||
创建工单
|
||||
@@ -227,7 +217,8 @@ class StockRule(models.Model):
|
||||
'''
|
||||
创建制造订单时生成序列号
|
||||
'''
|
||||
production.action_generate_serial()
|
||||
if production.product_id.tracking != "none":
|
||||
production.action_generate_serial()
|
||||
origin_production = production.move_dest_ids and production.move_dest_ids[
|
||||
0].raw_material_production_id or False
|
||||
orderpoint = production.orderpoint_id
|
||||
@@ -452,7 +443,7 @@ class ProductionLot(models.Model):
|
||||
@api.model
|
||||
def _get_next_serial(self, company, product):
|
||||
"""Return the next serial number to be attributed to the product."""
|
||||
if product.tracking == "serial":
|
||||
if product.tracking != "none":
|
||||
last_serial = self.env['stock.lot'].search(
|
||||
[('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'ilike', product.name)],
|
||||
limit=1, order='name desc')
|
||||
@@ -463,7 +454,9 @@ class ProductionLot(models.Model):
|
||||
return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name if (
|
||||
not move_line_id or
|
||||
(last_serial and last_serial.name > move_line_id.lot_name)) else move_line_id.lot_name, 2)[1]
|
||||
return "%s-%03d" % (product.name, 1)
|
||||
else:
|
||||
return "%s-%03d" % (product.name, 1)
|
||||
return False
|
||||
|
||||
qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')
|
||||
|
||||
@@ -738,6 +731,33 @@ class StockPicking(models.Model):
|
||||
production.workorder_ids.write({'back_button_display': False})
|
||||
return res
|
||||
|
||||
def _prepare_subcontract_mo_vals(self, subcontract_move, bom):
|
||||
subcontract_move.ensure_one()
|
||||
group = self.env['procurement.group'].sudo().search([('name', '=', self.name)])
|
||||
if not group:
|
||||
group = self.env['procurement.group'].create({
|
||||
'name': self.name,
|
||||
'partner_id': self.partner_id.id,
|
||||
})
|
||||
product = subcontract_move.product_id
|
||||
warehouse = self._get_warehouse(subcontract_move)
|
||||
vals = {
|
||||
'company_id': subcontract_move.company_id.id,
|
||||
'procurement_group_id': group.id,
|
||||
'subcontractor_id': subcontract_move.picking_id.partner_id.commercial_partner_id.id,
|
||||
'picking_ids': [subcontract_move.picking_id.id],
|
||||
'product_id': product.id,
|
||||
'product_uom_id': subcontract_move.product_uom.id,
|
||||
'bom_id': bom.id,
|
||||
'location_src_id': subcontract_move.picking_id.partner_id.with_company(subcontract_move.company_id).property_stock_subcontractor.id,
|
||||
'location_dest_id': subcontract_move.picking_id.partner_id.with_company(subcontract_move.company_id).property_stock_subcontractor.id,
|
||||
'product_qty': subcontract_move.product_uom_qty,
|
||||
'picking_type_id': warehouse.subcontracting_type_id.id,
|
||||
'date_planned_start': subcontract_move.date - relativedelta(days=product.produce_delay)
|
||||
}
|
||||
return vals
|
||||
|
||||
|
||||
# 创建 外协出库入单
|
||||
def create_outcontract_picking(self, workorders, item, sorted_workorders):
|
||||
production = workorders[0].production_id
|
||||
@@ -1216,6 +1236,20 @@ class ReStockMove(models.Model):
|
||||
res['lot_id'] = self.subcontract_workorder_id.production_id.move_raw_ids.move_line_ids[0].lot_id.id
|
||||
return res
|
||||
|
||||
def _get_subcontract_bom(self):
|
||||
self.ensure_one()
|
||||
purchase_type = getattr(self.picking_id.purchase_id, 'purchase_type', False)
|
||||
if purchase_type:
|
||||
self = self.with_context(stock_picking=purchase_type)
|
||||
bom = self.env['mrp.bom'].sudo()._bom_subcontract_find(
|
||||
self.product_id,
|
||||
picking_type=self.picking_type_id,
|
||||
company_id=self.company_id.id,
|
||||
bom_type='subcontract',
|
||||
subcontractor=self.picking_id.partner_id
|
||||
)
|
||||
return bom
|
||||
|
||||
|
||||
class ReStockQuant(models.Model):
|
||||
_inherit = 'stock.quant'
|
||||
|
||||
@@ -44,7 +44,8 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
|
||||
if productions:
|
||||
# 修改需求计划中的程序工时
|
||||
demand_plan = request.env['sf.production.demand.plan'].with_user(
|
||||
request.env.ref("base.user_admin")).search([('model_id', '=', ret['folder_name'])])
|
||||
request.env.ref("base.user_admin")).search(
|
||||
[('model_id', '=', ret['folder_name']), ('new_supply_method', '=', 'custom_made')])
|
||||
if demand_plan and ret['total_estimated_time']:
|
||||
demand_plan.write(
|
||||
{'processing_time': ret['total_estimated_time']})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from . import ftp_operate
|
||||
from . import res_config_setting
|
||||
from . import sync_common
|
||||
from . import order_price
|
||||
from . import order_price
|
||||
|
||||
2
sf_purchase_arrival_inform/__init__.py
Normal file
2
sf_purchase_arrival_inform/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import models
|
||||
from . import wizard
|
||||
33
sf_purchase_arrival_inform/__manifest__.py
Normal file
33
sf_purchase_arrival_inform/__manifest__.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': '机企猫智能工厂 采购到货通知',
|
||||
'version': '1.1',
|
||||
'summary': '智能工厂计划管理',
|
||||
'sequence': 1,
|
||||
'description': """
|
||||
在本模块,支持采购到货通知
|
||||
""",
|
||||
'category': 'sf',
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': ['jikimo_purchase_request', 'quality_control', 'sf_manufacturing'],
|
||||
'data': [
|
||||
'views/product_category.xml',
|
||||
'views/purchase_view.xml',
|
||||
'wizard/purchase_confirm_wizard_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
'assets': {
|
||||
'web.assets_qweb': [
|
||||
],
|
||||
'web.assets_backend': [
|
||||
|
||||
]
|
||||
},
|
||||
'license': 'LGPL-3',
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'auto_install': False,
|
||||
}
|
||||
5
sf_purchase_arrival_inform/models/__init__.py
Normal file
5
sf_purchase_arrival_inform/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from . import product_category
|
||||
from . import purchase_order
|
||||
from . import storage_list
|
||||
from . import quality_check
|
||||
|
||||
7
sf_purchase_arrival_inform/models/product_category.py
Normal file
7
sf_purchase_arrival_inform/models/product_category.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class SfProductCategory(models.Model):
|
||||
_inherit = 'product.category'
|
||||
arrival_inform = fields.Boolean('到货通知', default=False)
|
||||
|
||||
108
sf_purchase_arrival_inform/models/purchase_order.py
Normal file
108
sf_purchase_arrival_inform/models/purchase_order.py
Normal file
@@ -0,0 +1,108 @@
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class SfPurchaseOrder(models.Model):
|
||||
_inherit = 'purchase.order'
|
||||
|
||||
# 收料入库明细
|
||||
storage_list_ids = fields.One2many('storage.list', 'purchase_order_id', string='收料入库明细')
|
||||
|
||||
# 计算字段:总收料数量
|
||||
total_received_quantity = fields.Float(string='到货数量',compute='_compute_total_received_quantity',store=True)
|
||||
|
||||
purchase_order_line_id = fields.Many2one('purchase.order.line', string='采购订单行')
|
||||
|
||||
@api.depends('order_line.arrival_quantity','order_line.product_qty')
|
||||
def _compute_total_received_quantity(self):
|
||||
for order in self:
|
||||
total_arrival_quantity = sum(line.arrival_quantity for line in order.order_line)
|
||||
total_product_qty=sum(line.product_qty for line in order.order_line)
|
||||
order.total_received_quantity = f'{total_arrival_quantity}/{total_product_qty}'
|
||||
|
||||
def open_arrival_inform(self):
|
||||
self.ensure_one()
|
||||
# 方式一:把数据写入普通模型(如果要持久化关联关系等场景)
|
||||
# 先清空旧数据(如果需要),避免重复
|
||||
self.env["storage.list"].search([
|
||||
("purchase_order_id", "=", self.id)
|
||||
]).unlink()
|
||||
pickings = self.env['stock.picking'].search([
|
||||
('origin', '=', self.name),
|
||||
# ('picking_type_code', '=', 'incoming'),
|
||||
('state', '!=', 'cancel')
|
||||
])
|
||||
relate_vals_list = []
|
||||
for picking in pickings:
|
||||
for move_line in picking.move_ids_without_package:
|
||||
relate_vals = {
|
||||
"purchase_order_id": self.id,
|
||||
"product_id": move_line.product_id.id,
|
||||
"picking_id": picking.id,
|
||||
"ordered_quantity": move_line.product_uom_qty,
|
||||
# "current_arrival_quantity": move_line.product_uom_qty, # 默认到货数量等于需求数量
|
||||
"product_code": move_line.product_id.default_code,
|
||||
"product_remark": move_line.name,
|
||||
"part_number": move_line.part_number,
|
||||
"state": picking.state,
|
||||
}
|
||||
relate_vals_list.append(relate_vals)
|
||||
if relate_vals_list:
|
||||
self.env["storage.list"].create(relate_vals_list)
|
||||
action = {
|
||||
'name': _("选择到货通知"),
|
||||
'type':'ir.actions.act_window',
|
||||
'view_mode':'form',
|
||||
'views': [(self.env.ref('sf_purchase_arrival_inform.storage_list_wrapper_form').id, 'form')],
|
||||
'res_model':'purchase.order',
|
||||
'target':'new',
|
||||
'res_id': self.id,
|
||||
'context': {
|
||||
'dialog_size': 'large',
|
||||
},
|
||||
}
|
||||
return action
|
||||
|
||||
def confirm_arrival_inform(self):
|
||||
"""确认到货通知"""
|
||||
# 直接调用storage_list的批量确认方法
|
||||
if self.storage_list_ids:
|
||||
self.storage_list_ids.button_confirm()
|
||||
|
||||
# 关闭弹窗
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
#询价单确认时加二次确认逻辑
|
||||
def button_confirm(self):
|
||||
"""采购订单确认,弹出确认向导"""
|
||||
# 无订单行时直接确认
|
||||
if not self.order_line:
|
||||
return super().button_confirm()
|
||||
|
||||
# 直接创建向导记录并打开
|
||||
wizard = self.env['purchase.confirm.wizard'].create({
|
||||
'purchase_order_id': self.id
|
||||
})
|
||||
|
||||
return {
|
||||
'name': _('询价单订单确认'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'purchase.confirm.wizard',
|
||||
'res_id': wizard.id,
|
||||
'view_mode': 'form',
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
def _execute_original_confirm(self):
|
||||
"""执行原始的确认逻辑"""
|
||||
res = super().button_confirm()
|
||||
return res
|
||||
|
||||
class SfPurchaseOrderLine(models.Model):
|
||||
_inherit = 'purchase.order.line'
|
||||
|
||||
# 到货数量(实际存储字段)
|
||||
arrival_quantity = fields.Float(string='到货数量', default=0.0, help='累计到货数量')
|
||||
|
||||
|
||||
|
||||
61
sf_purchase_arrival_inform/models/quality_check.py
Normal file
61
sf_purchase_arrival_inform/models/quality_check.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from odoo import models, fields, api
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class QualityPoint(models.Model):
|
||||
_inherit = 'quality.point'
|
||||
|
||||
quality_status = fields.Selection([
|
||||
('waiting', '等待'),
|
||||
('none', '待处理')
|
||||
], string='默认质检状态',
|
||||
help='收料入库时质量检查单的默认状态。如果设置了此值,系统会在创建质检单时自动使用该状态。')
|
||||
|
||||
class QualityCheck(models.Model):
|
||||
_inherit = 'quality.check'
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
"""
|
||||
重写create方法,根据quality.point配置动态设置quality_state
|
||||
当picking_type为收料入库时,从质量控制点配置中获取默认状态
|
||||
"""
|
||||
# 先调用父类方法创建记录
|
||||
records = super().create(vals_list)
|
||||
|
||||
# 对创建的记录进行状态调整
|
||||
for record in records:
|
||||
try:
|
||||
# 只处理收料入库的质检单且未手动设置状态的记录
|
||||
if (record.picking_id and
|
||||
record.picking_id.picking_type_id.code == 'incoming' and
|
||||
record.quality_state in ['none', 'waiting']): # 只调整默认状态
|
||||
|
||||
# 查找匹配的质量控制点配置
|
||||
quality_point = record.point_id
|
||||
if not quality_point and record.product_id:
|
||||
# 如果没有直接关联的质量点,则根据产品和作业类型查找
|
||||
domain = self.env['quality.point']._get_domain(
|
||||
record.product_id,
|
||||
record.picking_id.picking_type_id,
|
||||
measure_on='product'
|
||||
)
|
||||
quality_point = self.env['quality.point'].search(domain, limit=1)
|
||||
|
||||
# 如果找到配置且有默认状态值,则更新记录状态
|
||||
if quality_point and quality_point.quality_status:
|
||||
original_state = record.quality_state
|
||||
record.quality_state = quality_point.quality_status
|
||||
|
||||
_logger.info(
|
||||
f"质量检查单状态已更新: {record.name}, "
|
||||
f"产品: {record.product_id.name}, "
|
||||
f"收料单: {record.picking_id.name}, "
|
||||
f"状态: {original_state} -> {quality_point.quality_status}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
_logger.warning(f"更新质量检查单状态时发生错误: {record.name}, 错误: {str(e)}")
|
||||
|
||||
return records
|
||||
140
sf_purchase_arrival_inform/models/storage_list.py
Normal file
140
sf_purchase_arrival_inform/models/storage_list.py
Normal file
@@ -0,0 +1,140 @@
|
||||
from odoo import models, fields, api
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class StorageList(models.Model):
|
||||
_name = 'storage.list'
|
||||
_description = '收料入库明细'
|
||||
_order = 'create_date desc'
|
||||
|
||||
# 基础关联字段
|
||||
purchase_order_id = fields.Many2one('purchase.order', string='采购订单', required=True)
|
||||
picking_id = fields.Many2one('stock.picking', string='收料入库单', readonly=True)
|
||||
product_id = fields.Many2one('product.product', string='产品', required=True)
|
||||
|
||||
# 产品信息(基于product_id的related字段)
|
||||
product_code = fields.Char(related='product_id.default_code', string='产品料号', store=True)
|
||||
product_remark = fields.Text(string='产品说明')
|
||||
part_number = fields.Char(string='零件图号')
|
||||
|
||||
# 数量字段
|
||||
ordered_quantity = fields.Float(string='需求数量', required=True)
|
||||
# 到货数量,默认=需求数量
|
||||
current_arrival_quantity = fields.Float(string='到货数量', required=True)
|
||||
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
# 如果没有设置current_arrival_quantity,则默认等于ordered_quantity
|
||||
if 'current_arrival_quantity' not in vals and 'ordered_quantity' in vals:
|
||||
vals['current_arrival_quantity'] = vals['ordered_quantity']
|
||||
return super().create(vals)
|
||||
|
||||
@api.constrains('current_arrival_quantity')
|
||||
def _check_current_arrival_quantity(self):
|
||||
for line in self:
|
||||
if line.current_arrival_quantity <= 0:
|
||||
raise ValidationError('到货数量必须大于0')
|
||||
if line.current_arrival_quantity > line.ordered_quantity:
|
||||
raise ValidationError('当前到货数量不能超过需求数量')
|
||||
|
||||
def button_confirm(self):
|
||||
"""更新采购订单行的收料数量"""
|
||||
for record in self:
|
||||
# 查找对应的采购订单行
|
||||
order_line = self.env['purchase.order.line'].search([
|
||||
('order_id', '=', record.purchase_order_id.id),
|
||||
('product_id', '=', record.product_id.id)
|
||||
], limit=1)
|
||||
|
||||
if order_line:
|
||||
# 累加当前记录的到货数量到采购订单行
|
||||
order_line.arrival_quantity += record.current_arrival_quantity
|
||||
|
||||
# 更新质量检查单状态为待处理
|
||||
if self:
|
||||
self._update_quality_check_status(self[0].purchase_order_id)
|
||||
|
||||
|
||||
def _update_quality_check_status(self, purchase_order):
|
||||
"""更新质量检查单状态为待处理
|
||||
Args:
|
||||
purchase_order: 采购订单记录
|
||||
Returns:
|
||||
int: 更新的质量检查单数量
|
||||
"""
|
||||
try:
|
||||
# 获取当前到货通知涉及的收料入库单
|
||||
storage_records = self.env['storage.list'].search([
|
||||
('purchase_order_id', '=', purchase_order.id)
|
||||
])
|
||||
if not storage_records:
|
||||
return 0
|
||||
|
||||
# 收集所有相关的picking_id和product_id(过滤空值)
|
||||
picking_ids = [pid for pid in storage_records.mapped('picking_id.id') if pid]
|
||||
product_ids = [pid for pid in storage_records.mapped('product_id.id') if pid]
|
||||
|
||||
if not picking_ids or not product_ids:
|
||||
return 0
|
||||
|
||||
# 构建质量检查单搜索域,包含等待和待处理状态
|
||||
base_domain = [
|
||||
('quality_state', 'in', ['waiting', 'none']),
|
||||
('product_id', 'in', product_ids),
|
||||
]
|
||||
|
||||
# 方法1:通过picking_id精确匹配质量检查单
|
||||
quality_checks_by_picking = self.env['quality.check'].search(
|
||||
base_domain + [('picking_id', 'in', picking_ids)]
|
||||
)
|
||||
|
||||
# 方法2:通过move_id匹配(更精确,因为一个picking可能有多个move)
|
||||
stock_moves = self.env['stock.move'].search([
|
||||
('picking_id', 'in', picking_ids),
|
||||
('product_id', 'in', product_ids),
|
||||
])
|
||||
|
||||
quality_checks_by_move = self.env['quality.check']
|
||||
if stock_moves:
|
||||
quality_checks_by_move = self.env['quality.check'].search(
|
||||
base_domain + [('move_id', 'in', stock_moves.ids)]
|
||||
)
|
||||
|
||||
# 方法3:通过move_line_id匹配(最精确)
|
||||
move_lines = self.env['stock.move.line'].search([
|
||||
('picking_id', 'in', picking_ids),
|
||||
('product_id', 'in', product_ids),
|
||||
])
|
||||
|
||||
quality_checks_by_move_line = self.env['quality.check']
|
||||
if move_lines:
|
||||
quality_checks_by_move_line = self.env['quality.check'].search(
|
||||
base_domain + [('move_line_id', 'in', move_lines.ids)]
|
||||
)
|
||||
|
||||
# 合并所有匹配的质量检查单(去重)
|
||||
all_quality_checks = quality_checks_by_picking | quality_checks_by_move | quality_checks_by_move_line
|
||||
|
||||
if not all_quality_checks:
|
||||
return 0
|
||||
|
||||
# 批量更新状态为待处理
|
||||
all_quality_checks.write({'quality_state': 'none'})
|
||||
|
||||
# 记录日志
|
||||
product_names = storage_records.mapped('product_id.name')
|
||||
purchase_order.message_post(
|
||||
body=f"到货通知确认:已更新 {len(all_quality_checks)} 个质量检查单状态为待处理<br/>"
|
||||
f"涉及产品:{', '.join(product_names)}<br/>"
|
||||
f"涉及收料入库单:{', '.join([p.name or '' for p in storage_records.mapped('picking_id')])}"
|
||||
)
|
||||
|
||||
return len(all_quality_checks)
|
||||
|
||||
except Exception as e:
|
||||
# 记录错误日志,但不阻断流程
|
||||
purchase_order.message_post(
|
||||
body=f"更新质量检查单状态时发生错误:{str(e)}"
|
||||
)
|
||||
return 0
|
||||
4
sf_purchase_arrival_inform/security/ir.model.access.csv
Normal file
4
sf_purchase_arrival_inform/security/ir.model.access.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_storage_list,storage.list,model_storage_list,purchase.group_purchase_user,1,1,1,1
|
||||
access_purchase_confirm_wizard,purchase.confirm.wizard,model_purchase_confirm_wizard,purchase.group_purchase_user,1,1,1,1
|
||||
access_purchase_confirm_wizard_line,purchase.confirm.wizard.line,model_purchase_confirm_wizard_line,purchase.group_purchase_user,1,1,1,1
|
||||
|
27
sf_purchase_arrival_inform/views/product_category.xml
Normal file
27
sf_purchase_arrival_inform/views/product_category.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<!-- 继承产品分类视图 -->
|
||||
<record id="product_category_form_view_inherit" model="ir.ui.view">
|
||||
<field name="name">product.category.form.inherit</field>
|
||||
<field name="model">product.category</field>
|
||||
<field name="inherit_id" ref="stock.product_category_form_view_inherit" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='removal_strategy_id']" position="after">
|
||||
<field name="arrival_inform"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="quality_view_form" model="ir.ui.view">
|
||||
<field name="name">arrival.inform.quality.point.view.form</field>
|
||||
<field name="model">quality.point</field>
|
||||
<field name="inherit_id" ref="mrp_workorder.quality_point_view_form_inherit_mrp"/>
|
||||
<field name="mode">primary</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="picking_type_ids" position="after">
|
||||
<field name="quality_status"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
58
sf_purchase_arrival_inform/views/purchase_view.xml
Normal file
58
sf_purchase_arrival_inform/views/purchase_view.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<!-- 继承采购订单视图 -->
|
||||
<record id="purchase_order_view_tree_inherit" model="ir.ui.view">
|
||||
<field name="name">purchase.order.tree.inherit</field>
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='date_planned']" position="after">
|
||||
<field name="total_received_quantity"/>
|
||||
</xpath>
|
||||
<xpath expr="//tree" position="inside">
|
||||
<button name="open_arrival_inform" string="到货通知" type="object" class="btn-primary"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="purchase_order_form" model="ir.ui.view">
|
||||
<field name="name">purchase.order.form</field>
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='order_line']/tree" position="inside">
|
||||
<field name="arrival_quantity"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- 到货通知form视图 -->
|
||||
<record id="storage_list_wrapper_form" model="ir.ui.view">
|
||||
<field name="name">storage.list.wrapper.form</field>
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="选择到货通知" create="false" duplicate="false">
|
||||
<group>
|
||||
<field name="name" readonly="1"/>
|
||||
</group>
|
||||
|
||||
<field name="storage_list_ids">
|
||||
<tree string="收料入库明细" editable="bottom" create="false" delete="true" export="false">
|
||||
<field name="product_code"/>
|
||||
<field name="product_id" readonly="1"/>
|
||||
<field name="product_remark" widget="section_and_note_text" readonly="1"/>
|
||||
<field name="part_number" readonly="1"/>
|
||||
<field name="ordered_quantity" readonly="1"/>
|
||||
<field name="current_arrival_quantity" attrs="{'invisible': [('ordered_quantity', '=', '0')]}"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
<footer>
|
||||
<button name="confirm_arrival_inform" string="确认" type="object" class="btn-primary" data-hotkey="q"/>
|
||||
<button string="取消" class="btn-secondary" special="cancel" data-hotkey="z"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
2
sf_purchase_arrival_inform/wizard/__init__.py
Normal file
2
sf_purchase_arrival_inform/wizard/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import purchase_confirm_wizard
|
||||
|
||||
64
sf_purchase_arrival_inform/wizard/purchase_confirm_wizard.py
Normal file
64
sf_purchase_arrival_inform/wizard/purchase_confirm_wizard.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
|
||||
class PurchaseConfirmWizard(models.TransientModel):
|
||||
_name = 'purchase.confirm.wizard'
|
||||
_description = '采购订单确认向导'
|
||||
|
||||
purchase_order_id = fields.Many2one('purchase.order', string='采购订单', required=True)
|
||||
line_ids = fields.One2many('purchase.confirm.wizard.line', 'wizard_id', string='产品明细')
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
"""创建向导时自动生成产品明细"""
|
||||
records = super().create(vals_list)
|
||||
|
||||
for record in records:
|
||||
if record.purchase_order_id:
|
||||
# 自动创建产品明细行
|
||||
line_data = []
|
||||
for line in record.purchase_order_id.order_line:
|
||||
line_data.append({
|
||||
'wizard_id': record.id,
|
||||
'product_id': line.product_id.id,
|
||||
'product_name': line.product_id.name,
|
||||
'product_qty': line.product_qty,
|
||||
'product_uom': line.product_uom.name,
|
||||
'uom_rounding': line.product_uom.rounding,
|
||||
})
|
||||
|
||||
if line_data:
|
||||
self.env['purchase.confirm.wizard.line'].create(line_data)
|
||||
|
||||
return records
|
||||
|
||||
def action_confirm(self):
|
||||
"""确认采购订单"""
|
||||
if self.purchase_order_id:
|
||||
# 调用原始的确认方法
|
||||
self.purchase_order_id._execute_original_confirm()
|
||||
|
||||
# 返回关闭向导并刷新采购订单页面
|
||||
return {
|
||||
'type': 'ir.actions.act_window_close',
|
||||
'infos': {
|
||||
'title': _('成功'),
|
||||
'message': _('采购订单已确认成功!'),
|
||||
}
|
||||
}
|
||||
|
||||
def action_cancel(self):
|
||||
"""取消操作"""
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
|
||||
class PurchaseConfirmWizardLine(models.TransientModel):
|
||||
_name = 'purchase.confirm.wizard.line'
|
||||
_description = '采购订单确认向导明细'
|
||||
|
||||
wizard_id = fields.Many2one('purchase.confirm.wizard', string='向导', ondelete='cascade')
|
||||
product_id = fields.Many2one('product.product', string='产品')
|
||||
product_name = fields.Char(string='产品名称')
|
||||
product_qty = fields.Float(string='数量')
|
||||
product_uom = fields.Char(string='单位')
|
||||
uom_rounding = fields.Float(string='舍入精度')
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<!-- 采购订单确认向导视图 -->
|
||||
<record id="purchase_confirm_wizard_form" model="ir.ui.view">
|
||||
<field name="name">purchase.confirm.wizard.form</field>
|
||||
<field name="model">purchase.confirm.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="采购订单确认">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<strong>确认提示:</strong>以下产品数量将按单位舍入精度向上取整处理,请核实后确认是否继续。
|
||||
</div>
|
||||
|
||||
<group>
|
||||
<field name="purchase_order_id" readonly="1"/>
|
||||
</group>
|
||||
|
||||
<separator string="产品明细信息"/>
|
||||
|
||||
<field name="line_ids" readonly="1" nolabel="1" widget="one2many_list">
|
||||
<tree decoration-info="True" create="false" edit="false">
|
||||
<field name="product_name" string="产品名称" width="40%"/>
|
||||
<field name="product_qty" string="订购数量" width="20%"/>
|
||||
<field name="product_uom" string="计量单位" width="20%"/>
|
||||
<field name="uom_rounding" string="舍入精度" widget="float" digits="[16,6]" width="20%"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
<footer>
|
||||
<button name="action_confirm" string="确认订单" type="object" class="btn-primary"/>
|
||||
<button name="action_cancel" string="取消" type="object" class="btn-secondary"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -22,6 +22,7 @@
|
||||
'data/report_actions.xml',
|
||||
'views/view.xml',
|
||||
'views/quality_cnc_test_view.xml',
|
||||
'views/stock_picking.xml',
|
||||
'views/mrp_workorder.xml',
|
||||
'views/quality_check_view.xml',
|
||||
'views/quality_company.xml',
|
||||
|
||||
@@ -200,11 +200,11 @@
|
||||
<p></p>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<!-- 页脚固定在底部 -->
|
||||
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
|
||||
<t t-call="sf_quality.report_quality_footer"/>
|
||||
<!-- </div> -->
|
||||
|
||||
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
|
||||
<t t-call="sf_quality.report_quality_footer"/>
|
||||
<!-- </div> -->
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
@@ -329,9 +329,11 @@
|
||||
</div> -->
|
||||
|
||||
<!-- 页脚固定在底部 -->
|
||||
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
|
||||
<t t-call="sf_quality.html_report_quality_footer"/>
|
||||
<!-- </div> -->
|
||||
<!-- <t t-if="loop.index == len(docs) - 1">-->
|
||||
<!-- <div style="position: absolute; bottom: 0; left: 0; right: 0;"> -->
|
||||
<t t-call="sf_quality.html_report_quality_footer"/>
|
||||
<!-- </div> -->
|
||||
<!-- </t>-->
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
@@ -1,59 +1,185 @@
|
||||
from odoo import api, models
|
||||
import logging
|
||||
|
||||
from odoo import api, models, fields
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
whether_show_quality_check = fields.Boolean('是否显示质量检测按钮', default=True)
|
||||
|
||||
def _compute_check(self):
|
||||
super()._compute_check()
|
||||
for picking in self:
|
||||
picking_to_quality = picking.get_picking_to_quality()
|
||||
if not picking_to_quality:
|
||||
picking.quality_check_todo = False
|
||||
picking.whether_show_quality_check = False
|
||||
break
|
||||
else:
|
||||
picking.whether_show_quality_check = True
|
||||
need_quality_line = picking.get_need_quality_line(picking_to_quality)
|
||||
if not need_quality_line or all(not line.get('need_done_check_ids') for line in need_quality_line):
|
||||
picking.quality_check_todo = False
|
||||
|
||||
|
||||
def check_quality(self):
|
||||
self.ensure_one()
|
||||
# checkable_products = self.mapped('move_line_ids').mapped('product_id')
|
||||
# checks = self.check_ids.filtered(lambda check: check.quality_state == 'none' and (
|
||||
# check.product_id in checkable_products or check.measure_on == 'operation'))
|
||||
checks = self.env['quality.check']
|
||||
picking_to_quality = self._get_picking_to_quality()
|
||||
need_quality_line = self.get_need_quality_line(picking_to_quality)
|
||||
if need_quality_line and any(line.get('need_done_check_ids') for line in need_quality_line):
|
||||
for item in need_quality_line:
|
||||
checks += item.get('need_done_check_ids')
|
||||
if checks:
|
||||
return checks.action_open_quality_check_wizard()
|
||||
return False
|
||||
|
||||
def button_validate(self):
|
||||
"""
|
||||
"""=
|
||||
出厂检验报告上传
|
||||
"""
|
||||
|
||||
out_quality_checks = self.env['quality.check'].search(
|
||||
[('picking_id', '=', self.id), ('test_type_id.name', '=', '出厂检验报告')])
|
||||
[('picking_id', '=', self.id), ('test_type_id.name', '=', '出厂检验报告'),
|
||||
('quality_state', '=', 'pass')])
|
||||
# out_quality_checks 可能存在多个
|
||||
if out_quality_checks:
|
||||
for out_quality_check in out_quality_checks:
|
||||
if not out_quality_check.is_factory_report_uploaded:
|
||||
if out_quality_check and self.state == 'assigned':
|
||||
out_quality_check.upload_factory_report()
|
||||
quality_action = self.pinking_checkout_quality()
|
||||
if quality_action:
|
||||
return quality_action
|
||||
res = super(StockPicking, self).button_validate()
|
||||
return res
|
||||
|
||||
def pinking_checkout_quality(self):
|
||||
"""
|
||||
调拨单若关联了质量检查单,验证调拨单时,应校验是否有不合格品,若存在,应弹窗提示:
|
||||
“警告:存在不合格产品XXXX n 件、YYYYY m件,继续调拨请点“确认”,否则请取消?”
|
||||
"""
|
||||
context = self.env.context
|
||||
if not context.get('again_validate') and self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail'):
|
||||
# 回滚事务,为二次确认/取消做准备
|
||||
self.env.cr.rollback()
|
||||
quality_check_ids = self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail')
|
||||
product_list = list(set([quality_check_id.product_id for quality_check_id in quality_check_ids]))
|
||||
fail_check_text = ''
|
||||
for product_id in product_list:
|
||||
check_ids = quality_check_ids.filtered(lambda qc: qc.product_id == product_id)
|
||||
if all(check_id.measure_on == 'move_line' for check_id in check_ids):
|
||||
number = sum(check_ids.mapped('qty_line'))
|
||||
else:
|
||||
number = sum(self.move_ids_without_package.filtered(
|
||||
lambda ml: ml.product_id == product_id).mapped('quantity_done'))
|
||||
if number == 0:
|
||||
number = sum(self.move_ids_without_package.filtered(
|
||||
lambda ml: ml.product_id == product_id).mapped('reserved_availability'))
|
||||
if number == 0:
|
||||
number = sum(self.move_ids_without_package.filtered(
|
||||
lambda ml: ml.product_id == product_id).mapped('product_uom_qty'))
|
||||
fail_check_text = (f'{fail_check_text}、{product_id.display_name} {number}件'
|
||||
if fail_check_text != '' else f'{product_id.display_name} {number}件')
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'picking.validate.check.wizard',
|
||||
'name': '质检不合格提示',
|
||||
'view_mode': 'form',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_picking_id': self.id,
|
||||
'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?',
|
||||
'again_validate': True}
|
||||
}
|
||||
res = super(StockPicking, self).button_validate()
|
||||
try:
|
||||
self.ensure_one()
|
||||
context = self.env.context
|
||||
if not context.get('pinking_checkout_quality'):
|
||||
picking_to_quality = self._get_picking_to_quality()
|
||||
if not picking_to_quality: return False
|
||||
need_quality_val = self.get_need_quality_line(picking_to_quality)
|
||||
if any(line.get('fail_check_ids') for line in need_quality_val):
|
||||
# 回滚事务,为二次确认/取消做准备
|
||||
self.env.cr.rollback()
|
||||
# 获取存在失败的 质检单 调拨单明细行
|
||||
check_list = [item for item in need_quality_val if item.get('fail_check_ids')]
|
||||
fail_check_text = ''
|
||||
for item in check_list:
|
||||
move_id, pre_done_qty = item.get('move_id'), item.get('pre_done_qty')
|
||||
fail_check_text = (f'{fail_check_text}、{move_id.product_id.display_name} {pre_done_qty}件'
|
||||
if fail_check_text != '' else f'{move_id.product_id.display_name} {pre_done_qty}件')
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'picking.validate.check.wizard',
|
||||
'name': '质检不合格提示',
|
||||
'view_mode': 'form',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_picking_id': self.id,
|
||||
'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?',
|
||||
'pinking_checkout_quality': True}
|
||||
}
|
||||
else:
|
||||
return False
|
||||
except Exception as e:
|
||||
logging.info('pinking_checkout_quality()方法报错:%s' % e)
|
||||
raise ValidationError('调拨单验证质检单是否合格时报错,请联系管理员处理!!')
|
||||
|
||||
def get_need_quality_line(self, picking_to_quality):
|
||||
"""
|
||||
# 对需要进行质检,还没有质检完成的明细行进行统计
|
||||
# 1、当【质量标准_控制方式】=“产品、作业”,仅校验“预完成数量”>0的产品行对应的质检单必须处理。
|
||||
2、当【质量标准_控制方式】=“数量”时,仅校验“预完成数量”>0的产品行对应的质检单必须处理:
|
||||
1)每一类的“总单数”=【调拨单_需求】时,则已处理的质检单“单数”≥“预完成数量”时,可执行调拨单验证;
|
||||
2)每一类的“总单数”<【调拨单_需求】时,则已处理的质检单“单数”≥0时,可执行调拨单验证;
|
||||
"""
|
||||
res = []
|
||||
for item in picking_to_quality:
|
||||
need_done_check_ids = self.env['quality.check']
|
||||
fail_check_ids = self.env['quality.check']
|
||||
move_id, pre_done_qty, check_ids = item.values()
|
||||
check_ids_1 = check_ids.filtered(lambda qc: qc.measure_on in ('operation', 'product'))
|
||||
if check_ids_1:
|
||||
check_ids_1_done = check_ids_1.filtered(lambda qc: qc.quality_state in ('pass', 'fail'))
|
||||
check_ids_1_fail = check_ids_1.filtered(lambda qc: qc.quality_state == 'fail')
|
||||
check_ids_1_none = check_ids_1.filtered(lambda qc: qc.quality_state == 'none')
|
||||
if check_ids_1 and not check_ids_1_done:
|
||||
need_done_check_ids += check_ids_1_none
|
||||
if check_ids_1_fail:
|
||||
fail_check_ids += check_ids_1_fail
|
||||
|
||||
check_ids_2 = check_ids.filtered(lambda qc: qc.measure_on == 'move_line')
|
||||
if check_ids_2:
|
||||
check_ids_2_done = check_ids_2.filtered(lambda qc: qc.quality_state in ('pass', 'fail'))
|
||||
check_ids_2_fail = check_ids_2.filtered(lambda qc: qc.quality_state == 'fail')
|
||||
check_ids_2_none = check_ids_2.filtered(lambda qc: qc.quality_state == 'none')
|
||||
# 每一类的“总单数”=【调拨单_需求】时,则已处理的质检单“单数”≥“预完成数量”时,可执行调拨单验证;
|
||||
if len(check_ids_2) >= move_id.product_uom_qty and len(check_ids_2_done) < pre_done_qty:
|
||||
need_done_check_ids += check_ids_2_none
|
||||
# 每一类的“总单数”<【调拨单_需求】时,则已处理的质检单“单数”≥0时,可执行调拨单验证
|
||||
elif len(check_ids_2) < move_id.product_uom_qty and len(check_ids_2_done) == 0:
|
||||
need_done_check_ids += check_ids_2_none
|
||||
if check_ids_2_fail:
|
||||
fail_check_ids += check_ids_2_fail
|
||||
|
||||
if need_done_check_ids or fail_check_ids:
|
||||
res.append({'move_id': move_id,
|
||||
'pre_done_qty': pre_done_qty,
|
||||
'check_ids': check_ids,
|
||||
'fail_check_ids': fail_check_ids,
|
||||
'need_done_check_ids': need_done_check_ids})
|
||||
return res
|
||||
|
||||
def get_picking_to_quality(self):
|
||||
self.ensure_one()
|
||||
return self._get_picking_to_quality()
|
||||
|
||||
def _get_picking_to_quality(self):
|
||||
"""
|
||||
对需要质检的明细行进行统计(针对“预完成数量”>0的行)
|
||||
"""
|
||||
quality_piking_line_list = []
|
||||
pre_done_qty_lines = self._get_pinking_pre_done_qty()
|
||||
for line in pre_done_qty_lines:
|
||||
move_id, pre_done_qty = line.values()
|
||||
if pre_done_qty == 0:
|
||||
continue
|
||||
product_id = move_id.product_id
|
||||
check_ids = self.check_ids.filtered(lambda c: c.product_id == product_id)
|
||||
quality_piking_line_list.append({'move_id': move_id, 'pre_done_qty': pre_done_qty, 'check_ids': check_ids})
|
||||
return quality_piking_line_list
|
||||
|
||||
def _get_pinking_pre_done_qty(self):
|
||||
"""
|
||||
return: 明细行 及 预完成数量
|
||||
1、若调拨单所有明细行的【完成】=0,且任意行的【预留】<【需求】,则验证时将会话是否需创建欠单。
|
||||
---->此时“预完成数量”=【预留】
|
||||
2、若调拨单任意行的0<【完成】<【需求】,且则验证时将会话是否需创建欠单
|
||||
---->此时“预完成数量”=【完成】
|
||||
"""
|
||||
# if all(move_id.quantity_done == 0 for move_id in self.move_ids_without_package):
|
||||
# pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.reserved_availability} for move_id in
|
||||
# self.move_ids_without_package]
|
||||
# else:
|
||||
# pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.quantity_done} for move_id in
|
||||
# self.move_ids_without_package]
|
||||
pre_done_qty = []
|
||||
for move_id in self.move_ids_without_package:
|
||||
if move_id.quantity_done > 0:
|
||||
pre_done_qty.append({'move_id': move_id, 'pre_done_qty': move_id.quantity_done})
|
||||
else:
|
||||
pre_done_qty.append({'move_id': move_id, 'pre_done_qty': move_id.reserved_availability})
|
||||
return pre_done_qty
|
||||
|
||||
28
sf_quality/views/stock_picking.xml
Normal file
28
sf_quality/views/stock_picking.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="stock_picking_view_form_inherit_quality_sf_quality" model="ir.ui.view">
|
||||
<field name="name">stock.picking.view.form.sf.quality</field>
|
||||
<field name="model">stock.picking</field>
|
||||
<field name="inherit_id" ref="quality_control.stock_picking_view_form_inherit_quality"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<field name="whether_show_quality_check" invisible="1"/>
|
||||
</xpath>
|
||||
<xpath expr="//button[@name='action_open_quality_check_picking'][1]" position="attributes">
|
||||
<attribute name="attrs">{'invisible': ['|', '|','|', ('check_ids', '=', []), ('quality_check_fail', '=',
|
||||
True), ('quality_check_todo', '!=', True), ('whether_show_quality_check', '!=', True)]}
|
||||
</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//button[@name='action_open_quality_check_picking'][2]" position="attributes">
|
||||
<attribute name="attrs">{'invisible': ['|', '|','|', ('check_ids', '=', []), ('quality_check_fail', '=',
|
||||
True), ('quality_check_todo', '=', True), ('whether_show_quality_check', '!=', True)]}
|
||||
</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//button[@name='action_open_quality_check_picking'][3]" position="attributes">
|
||||
<attribute name="attrs">{'invisible': ['|', '|',('check_ids', '=', []), ('quality_check_fail', '!=',
|
||||
True), ('whether_show_quality_check', '!=', True)]}
|
||||
</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -155,7 +155,7 @@ class ReSaleOrder(models.Model):
|
||||
'glb_url': item['glb_url'],
|
||||
'remark': item.get('remark'),
|
||||
'embryo_redundancy_id': item.get('embryo_redundancy_id'),
|
||||
'is_incoming_material': True if item.get('embryo_redundancy_id') else False,
|
||||
'is_incoming_material': True if item.get('incoming_size') else False,
|
||||
'manual_quotation': item.get('manual_quotation'),
|
||||
'model_id': item['model_id'],
|
||||
'delivery_end_date': item['delivery_end_date']
|
||||
@@ -287,7 +287,7 @@ class ResaleOrderLine(models.Model):
|
||||
check_status = fields.Selection(related='order_id.check_status')
|
||||
remark = fields.Char('备注')
|
||||
|
||||
is_incoming_material = fields.Boolean('客供料', compute='_compute_is_incoming_material', store=True)
|
||||
is_incoming_material = fields.Boolean('客供料', store=True)
|
||||
embryo_redundancy_id = fields.Many2one('sf.embryo.redundancy', '坯料冗余')
|
||||
manual_quotation = fields.Boolean('人工编程', default=False)
|
||||
model_url = fields.Char('模型文件地址')
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# 'security/sf_stock_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'wizard/wizard_view.xml',
|
||||
'views/product.xml',
|
||||
'views/view.xml',
|
||||
'views/shelf_location.xml',
|
||||
'views/change_stock_move_views.xml',
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
from . import model
|
||||
from . import sync_common
|
||||
from . import product
|
||||
|
||||
@@ -471,7 +471,7 @@ class ShelfLocation(models.Model):
|
||||
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"""
|
||||
@@ -594,7 +594,7 @@ class ShelfLocation(models.Model):
|
||||
_layer_capacity = _cc_code % record.shelf_id.layer_capacity
|
||||
if _layer_capacity == 0:
|
||||
_layer_capacity = record.shelf_id.layer_capacity
|
||||
else:
|
||||
else:
|
||||
_layer_capacity = _layer_capacity
|
||||
_layer = _layer+1
|
||||
_layer_capacity = f"{_layer_capacity:02d}"
|
||||
@@ -634,7 +634,7 @@ class SfShelfLocationLot(models.Model):
|
||||
for item in self:
|
||||
if item.qty_num > item.qty:
|
||||
raise ValidationError('变更数量不能比库存数量大!!!')
|
||||
|
||||
|
||||
|
||||
|
||||
class SfStockMoveLine(models.Model):
|
||||
@@ -899,7 +899,7 @@ class SfStockMoveLine(models.Model):
|
||||
def _compute_current_location_id(self):
|
||||
# 批量获取所有相关记录的picking
|
||||
pickings = self.mapped('picking_id')
|
||||
|
||||
|
||||
# 构建源picking的移库行与目标位置的映射
|
||||
origin_location_map = {}
|
||||
for picking in pickings:
|
||||
@@ -907,11 +907,11 @@ class SfStockMoveLine(models.Model):
|
||||
origin_move = picking.move_ids[:1].move_orig_ids[:1]
|
||||
if not origin_move:
|
||||
continue
|
||||
|
||||
|
||||
origin_picking = origin_move.picking_id
|
||||
if not origin_picking:
|
||||
continue
|
||||
|
||||
|
||||
# 为每个picking构建lot_id到location的映射
|
||||
origin_location_map[picking.id] = {
|
||||
move_line.lot_id.id: move_line.destination_location_id
|
||||
@@ -919,17 +919,17 @@ class SfStockMoveLine(models.Model):
|
||||
lambda ml: ml.destination_location_id and ml.lot_id
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
# 批量更新current_location_id
|
||||
for record in self:
|
||||
current_picking = record.picking_id
|
||||
if not current_picking:
|
||||
record.current_location_id = False
|
||||
continue
|
||||
|
||||
|
||||
# 获取当前picking对应的lot_location映射
|
||||
lot_dest_map = origin_location_map.get(current_picking.id, {})
|
||||
|
||||
|
||||
# 查找匹配的lot_id
|
||||
for move_line in current_picking.move_line_ids:
|
||||
if move_line.lot_id and move_line.lot_id.id in lot_dest_map:
|
||||
@@ -1082,6 +1082,10 @@ class SfStockPicking(models.Model):
|
||||
重写验证方法,当验证时意味着调拨单已经完成,已经移动到了目标货位,所以需要将当前货位的状态改为空闲
|
||||
"""
|
||||
res = super(SfStockPicking, self).button_validate()
|
||||
if any(ml.state == 'done' for ml in self.move_line_ids):
|
||||
# 验证产品库存为负库存问题
|
||||
self.move_ids.product_id.verify_product_repertory(self.location_id)
|
||||
|
||||
for line in self.move_line_ids:
|
||||
if line:
|
||||
if line.destination_location_id:
|
||||
|
||||
29
sf_warehouse/models/product.py
Normal file
29
sf_warehouse/models/product.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from odoo import models, fields
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class SfProductCategory(models.Model):
|
||||
_inherit = 'product.category'
|
||||
|
||||
negative_inventory_allowed = fields.Boolean('可负库存', default=True)
|
||||
|
||||
|
||||
class SfProductTemplate(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
def verify_product_repertory(self, location_id):
|
||||
"""
|
||||
验证产品 负库存
|
||||
"""
|
||||
if not location_id:
|
||||
raise ValidationError('当前位置为空!!')
|
||||
elif len(location_id) != 1:
|
||||
raise ValidationError(f'存在多个当前位置{[item.name for item in location_id]}')
|
||||
elif location_id.usage == 'supplier':
|
||||
return True
|
||||
for pp in self:
|
||||
if not pp.categ_id.negative_inventory_allowed:
|
||||
sq = pp.stock_quant_ids.filtered(lambda sq: sq.quantity < 0 and sq.location_id == location_id)
|
||||
if sq:
|
||||
raise ValidationError(
|
||||
f'产品{pp.name}的产品类型设置为不可负库存,当前操作会导致产品{pp.name}在库存{location_id.name}上的库存数量为负!!!')
|
||||
17
sf_warehouse/views/product.xml
Normal file
17
sf_warehouse/views/product.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="product_category_form_view_sf_warehouse" model="ir.ui.view">
|
||||
<field name="name">product.category.property.form.warehouse</field>
|
||||
<field name="model">product.category</field>
|
||||
<field name="inherit_id" ref="account.view_category_property_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='account_property']" position="after">
|
||||
<group name="other">
|
||||
<group string="其他">
|
||||
<field name="negative_inventory_allowed"/>
|
||||
</group>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user