Compare commits
3 Commits
feature/72
...
feature/20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd6f35a16f | ||
|
|
86bacee926 | ||
|
|
e1644c3aa4 |
@@ -94,20 +94,12 @@ class PurchaseOrder(models.Model):
|
||||
|
||||
def button_cancel(self):
|
||||
"""
|
||||
1. 先将采购订单行与目标库存移动断开链接,避免采购单取消后,调拨单被调整为mts的问题
|
||||
2. 取消采购订单
|
||||
3. 将采购订单行与目标库存移动重新建立链接
|
||||
将取消的采购订单关联的库存移动撤销
|
||||
"""
|
||||
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)]})
|
||||
move_ids = self.order_line.move_dest_ids.filtered(lambda move: move.state != 'done' and not move.scrapped)
|
||||
res =super(PurchaseOrder, self).button_cancel()
|
||||
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})
|
||||
if move_ids.mapped('created_purchase_request_line_id'):
|
||||
move_ids.write({'state': 'waiting', 'is_done': False})
|
||||
return res
|
||||
|
||||
def write(self, vals):
|
||||
|
||||
@@ -44,7 +44,7 @@ class StatusChange(models.Model):
|
||||
else:
|
||||
action.update({
|
||||
'name': _("从 %s生成采购请求单", self.name),
|
||||
'domain': [('id', 'in', pr_ids.ids)],
|
||||
'domain': [('id', 'in', pr_ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
|
||||
@@ -41,10 +41,8 @@ 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') and \
|
||||
not x.created_purchase_request_line_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')
|
||||
]
|
||||
return res
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@ 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')])
|
||||
|
||||
@@ -4,4 +4,4 @@ wechatpy==1.8.18
|
||||
pycryptodome==3.22.0
|
||||
openupgradelib==3.10.0
|
||||
opcua==0.98.13
|
||||
openpyxl
|
||||
openpyxl
|
||||
@@ -2,7 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': '机企猫智能工厂 需求计划',
|
||||
'version': '1.1',
|
||||
'version': '1.0',
|
||||
'summary': '智能工厂计划管理',
|
||||
'sequence': 1,
|
||||
'description': """
|
||||
@@ -10,14 +10,18 @@
|
||||
""",
|
||||
'category': 'sf',
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': ['sf_plan'], #'jikimo_printing',
|
||||
'depends': ['sf_plan'],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'data/stock_route_group.xml',
|
||||
'views/demand_plan_info.xml',
|
||||
'views/demand_plan.xml',
|
||||
'views/stock_route.xml',
|
||||
<<<<<<< HEAD
|
||||
'views/sale_order_views.xml',
|
||||
'views/demand_plan.xml',
|
||||
'views/demand_main_plan.xml',
|
||||
=======
|
||||
'views/demand_plan.xml',
|
||||
>>>>>>> develop
|
||||
'views/stock_route.xml',
|
||||
'wizard/sf_demand_plan_print_wizard_view.xml',
|
||||
'wizard/sf_release_plan_wizard_views.xml',
|
||||
'views/menu_view.xml',
|
||||
|
||||
@@ -6,13 +6,13 @@ 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']
|
||||
DemandPlan = env['sf.demand.main.plan']
|
||||
|
||||
lines = ProductionLine.search([('demand_plan_id', '=', False)])
|
||||
for line in lines:
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import sf_demand_plan
|
||||
from . import mrp_bom
|
||||
from . import mrp_production
|
||||
from . import sf_demand_main_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
|
||||
|
||||
|
||||
@@ -18,12 +18,3 @@ class MrpBom(models.Model):
|
||||
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
|
||||
@@ -21,23 +21,6 @@ class MrpProduction(models.Model):
|
||||
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)])
|
||||
"""获取跟制造订单相关的采购申请单"""
|
||||
pr_ids = self.env['purchase.request'].sudo().search([('origin', '=', self.name)])
|
||||
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)
|
||||
|
||||
@@ -5,44 +5,18 @@ 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
|
||||
demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
|
||||
string="需求计划明细", readonly=True)
|
||||
|
||||
@api.depends('origin')
|
||||
@api.depends('origin', 'demand_plan_line_id')
|
||||
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':
|
||||
if purchase.demand_plan_line_id.supply_method == 'outsourcing':
|
||||
purchase.purchase_type = 'outsourcing'
|
||||
|
||||
elif purchase.order_line[0].demand_plan_line_id.supply_method == 'purchase':
|
||||
elif purchase.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:
|
||||
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
|
||||
|
||||
@@ -28,8 +28,83 @@ class PurchaseRequestLine(models.Model):
|
||||
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
|
||||
def make_purchase_order(self):
|
||||
res = []
|
||||
purchase_obj = self.env["purchase.order"]
|
||||
po_line_obj = self.env["purchase.order.line"]
|
||||
purchase = False
|
||||
|
||||
if len(set([item_id.line_id.supply_method for item_id in self.item_ids])) > 1:
|
||||
raise ValidationError('不同供货方式不可合并创建询价单!')
|
||||
|
||||
for item in self.item_ids:
|
||||
line = item.line_id
|
||||
if item.product_qty <= 0.0:
|
||||
raise UserError(_("Enter a positive quantity."))
|
||||
if self.purchase_order_id:
|
||||
purchase = self.purchase_order_id
|
||||
if not purchase:
|
||||
po_data = self._prepare_purchase_order(
|
||||
line.request_id.picking_type_id,
|
||||
line.request_id.group_id,
|
||||
line.company_id,
|
||||
line.request_id.origin,
|
||||
)
|
||||
po_data['demand_plan_line_id'] = item.line_id.demand_plan_line_id.id
|
||||
# po_data.update({'related_product':line.related_product.id})
|
||||
purchase = purchase_obj.create(po_data)
|
||||
|
||||
# Look for any other PO line in the selected PO with same
|
||||
# product and UoM to sum quantities instead of creating a new
|
||||
# po line
|
||||
domain = self._get_order_line_search_domain(purchase, item)
|
||||
available_po_lines = po_line_obj.search(domain)
|
||||
new_pr_line = True
|
||||
# If Unit of Measure is not set, update from wizard.
|
||||
if not line.product_uom_id:
|
||||
line.product_uom_id = item.product_uom_id
|
||||
# Allocation UoM has to be the same as PR line UoM
|
||||
alloc_uom = line.product_uom_id
|
||||
wizard_uom = item.product_uom_id
|
||||
if available_po_lines and not item.keep_description:
|
||||
new_pr_line = False
|
||||
po_line = available_po_lines[0]
|
||||
po_line.purchase_request_lines = [(4, line.id)]
|
||||
po_line.move_dest_ids |= line.move_dest_ids
|
||||
po_line_product_uom_qty = po_line.product_uom._compute_quantity(
|
||||
po_line.product_uom_qty, alloc_uom
|
||||
)
|
||||
wizard_product_uom_qty = wizard_uom._compute_quantity(
|
||||
item.product_qty, alloc_uom
|
||||
)
|
||||
all_qty = min(po_line_product_uom_qty, wizard_product_uom_qty)
|
||||
self.create_allocation(po_line, line, all_qty, alloc_uom)
|
||||
else:
|
||||
po_line_data = self._prepare_purchase_order_line(purchase, item)
|
||||
if item.keep_description:
|
||||
po_line_data["name"] = item.name
|
||||
if line.related_product:
|
||||
po_line_data.update({'related_product': line.related_product.id})
|
||||
po_line = po_line_obj.create(po_line_data)
|
||||
po_line_product_uom_qty = po_line.product_uom._compute_quantity(
|
||||
po_line.product_uom_qty, alloc_uom
|
||||
)
|
||||
wizard_product_uom_qty = wizard_uom._compute_quantity(
|
||||
item.product_qty, alloc_uom
|
||||
)
|
||||
all_qty = min(po_line_product_uom_qty, wizard_product_uom_qty)
|
||||
self.create_allocation(po_line, line, all_qty, alloc_uom)
|
||||
self._post_process_po_line(item, po_line, new_pr_line)
|
||||
res.append(purchase.id)
|
||||
|
||||
purchase_requests = self.item_ids.mapped("request_id")
|
||||
purchase_requests.button_in_progress()
|
||||
return {
|
||||
"domain": [("id", "in", res)],
|
||||
"name": _("RFQ"),
|
||||
"view_mode": "tree,form",
|
||||
"res_model": "purchase.order",
|
||||
"view_id": False,
|
||||
"context": False,
|
||||
"type": "ir.actions.act_window",
|
||||
}
|
||||
|
||||
@@ -9,24 +9,22 @@ class ReSaleOrder(models.Model):
|
||||
compute='_compute_mrp_production_ids',
|
||||
string='与此销售订单相关联的制造订单',
|
||||
groups='mrp.group_mrp_user', store=True)
|
||||
|
||||
demand_plan_ids = fields.Many2many(comodel_name="sf.demand.plan",
|
||||
string="需求计划", readonly=True)
|
||||
|
||||
demand_plan_ids = fields.Many2many(comodel_name="sf.demand.main.plan",
|
||||
string="需求计划", readonly=True)
|
||||
demand_plan_count = fields.Integer(
|
||||
string="需求计划生成计数",
|
||||
compute='_compute_demand_plan_count'
|
||||
"需求计划生成计数",
|
||||
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)])
|
||||
for record in self:
|
||||
pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', record.name)])
|
||||
if pr_ids:
|
||||
so.purchase_request_purchase_order_count = len(pr_ids)
|
||||
record.purchase_request_purchase_order_count = len(pr_ids)
|
||||
else:
|
||||
so.purchase_request_purchase_order_count = 0
|
||||
|
||||
record.purchase_request_purchase_order_count = 0
|
||||
#计算需求计划生成计数
|
||||
@api.depends('demand_plan_ids.line_ids')
|
||||
def _compute_demand_plan_count(self):
|
||||
for line in self:
|
||||
@@ -35,33 +33,47 @@ class ReSaleOrder(models.Model):
|
||||
|
||||
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})
|
||||
# vals = {
|
||||
# 'sale_order_id': ret.order_id.id,
|
||||
# 'sale_order_line_id': ret.id,
|
||||
# }
|
||||
# demand_plan_info = self.env['sf.demand.main.plan'].sudo().create(vals)
|
||||
# vals.update({'demand_plan_id': demand_plan_info.id, 'plan_uom_qty': ret.product_uom_qty})
|
||||
# demand_plan = self.env['sf.production.demand.plan'].sudo().create(vals)
|
||||
# demand_plan_info.write({'line_ids': demand_plan.ids})
|
||||
# 优化方案1:使用事务确保数据一致性
|
||||
with self.env.cr.savepoint():
|
||||
# 1. 先创建主计划
|
||||
demand_plan_info = self.env['sf.demand.main.plan'].sudo().create({
|
||||
'sale_order_id': ret.order_id.id,
|
||||
'sale_order_line_id': ret.id,
|
||||
})
|
||||
# 2. 创建明细计划时直接建立关联(利用One2many的inverse特性)
|
||||
demand_plan = self.env['sf.production.demand.plan'].sudo().create({
|
||||
'demand_plan_id': demand_plan_info.id,
|
||||
'plan_uom_qty': ret.product_uom_qty,
|
||||
'sale_order_id': ret.order_id.id,
|
||||
'sale_order_line_id': ret.id,
|
||||
})
|
||||
# 3. 不需要手动更新line_ids,Odoo的ORM会自动处理One2many关系
|
||||
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
|
||||
|
||||
#从sf工厂调过来时,调用了,这里重写
|
||||
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
|
||||
@@ -72,3 +84,4 @@ class ReSaleOrder(models.Model):
|
||||
'domain': [('id', 'in', demand_plan_ids)],
|
||||
'view_mode': 'tree',
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,20 @@
|
||||
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'
|
||||
class SfDemandMainPlan(models.Model):
|
||||
_name = 'sf.demand.main.plan'
|
||||
_description = 'sf_demand_main_plan'
|
||||
|
||||
def _get_machining_precision(self):
|
||||
machinings = self.env['sf.machining.accuracy'].sudo().search([])
|
||||
list = [(m.sync_id, m.name) for m in machinings]
|
||||
return list
|
||||
|
||||
state = fields.Selection([
|
||||
('10', '待工艺设计'),
|
||||
('10', '需求确认'),
|
||||
('20', '待工艺设计'),
|
||||
('30', '部分下达'),
|
||||
('40', '已下达'),
|
||||
('50', '取消'),
|
||||
@@ -36,9 +41,6 @@ class SfDemandPlan(models.Model):
|
||||
|
||||
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(
|
||||
@@ -62,10 +64,12 @@ class SfDemandPlan(models.Model):
|
||||
compute='_compute_model_process_parameters_ids'
|
||||
, store=True
|
||||
)
|
||||
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
|
||||
model_machining_precision = fields.Selection(selection=_get_machining_precision, string='精度',
|
||||
related='product_id.model_machining_precision')
|
||||
|
||||
inventory_quantity_auto_apply = fields.Float(
|
||||
string="成品库存",
|
||||
compute='_compute_inventory_quantity_auto_apply'
|
||||
compute='_compute_inventory_quantity_auto_apply', store=True
|
||||
)
|
||||
|
||||
priority = fields.Selection([
|
||||
@@ -75,22 +79,12 @@ class SfDemandPlan(models.Model):
|
||||
('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:
|
||||
@@ -115,10 +109,7 @@ class SfDemandPlan(models.Model):
|
||||
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)}"
|
||||
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
|
||||
|
||||
@@ -156,8 +147,12 @@ class SfDemandPlan(models.Model):
|
||||
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:
|
||||
rounding = line.product_id.uom_id.rounding or 0.01#设置默认精度
|
||||
# 如果精度小于等于0,则设置为0.01
|
||||
if rounding<=0:
|
||||
rounding = 0.01
|
||||
# 如果计划量小于等于0,则设置为0
|
||||
if float_compare(pending_qty, 0, precision_rounding=rounding) == -1:
|
||||
line.pending_qty = 0
|
||||
else:
|
||||
line.pending_qty = pending_qty
|
||||
@@ -170,40 +165,32 @@ class SfDemandPlan(models.Model):
|
||||
@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'))
|
||||
line.hide_button_release_plan = bool(line.line_ids.filtered(lambda p: p.status != '60'))
|
||||
|
||||
def button_release_plan(self):
|
||||
pass
|
||||
|
||||
@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':
|
||||
if 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)
|
||||
res = super(SfDemandMainPlan, self).write(vals)
|
||||
line_ids = self.line_ids.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0)
|
||||
if line_ids:
|
||||
raise ValidationError(f"计划量不能小于等于0")
|
||||
if 'line_ids' in vals:
|
||||
for line in self.line_ids:
|
||||
if not line.sale_order_id:
|
||||
@@ -215,46 +202,5 @@ class SfDemandPlan(models.Model):
|
||||
def name_get(self):
|
||||
result = []
|
||||
for plan in self:
|
||||
result.append((plan.id, plan.demand_plan_number))
|
||||
result.append((plan.id, plan.sale_order_id.name))
|
||||
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')
|
||||
if not self.overdelivery_allowed and line_ids.filtered(lambda p: p.location_id.id == customer_location_id):
|
||||
if float_compare(sum_product_uom_qty, self.product_uom_qty,
|
||||
precision_rounding=self.product_id.uom_id.rounding) == 1:
|
||||
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
@@ -19,7 +19,11 @@ class SfStockRoute(models.Model):
|
||||
[('supply_method', 'in', stock_route_group)])
|
||||
if demand_plan_ids:
|
||||
sr.demand_plan_ids = demand_plan_ids.ids
|
||||
<<<<<<< HEAD
|
||||
continue
|
||||
=======
|
||||
break
|
||||
>>>>>>> develop
|
||||
sr.demand_plan_ids = None
|
||||
|
||||
# def name_get(self):
|
||||
|
||||
@@ -5,12 +5,16 @@ access_sf_production_demand_plan_for_dispatch,sf.production.demand.plan for disp
|
||||
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
|
||||
<<<<<<< HEAD
|
||||
access_sf_demand_main_plan,sf.demand.main.plan,model_sf_demand_main_plan,base.group_user,1,0,0,0
|
||||
access_sf_demand_main_plan_for_dispatch,sf.demand.main.plan for dispatch,model_sf_demand_main_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
|
||||
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
|
||||
=======
|
||||
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
|
||||
>>>>>>> develop
|
||||
|
||||
|
@@ -83,7 +83,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
/*.demand_plan_tree th[data-name=planned_start_date] + th::before{*/
|
||||
/* content: '待执行单据';*/
|
||||
/* line-height: 38px;*/
|
||||
/*}*/
|
||||
th[data-name=processing_time] + th::before{
|
||||
content: '待执行单据';
|
||||
line-height: 38px;
|
||||
}
|
||||
|
||||
70
sf_demand_plan/views/demand_main_plan.xml
Normal file
70
sf_demand_plan/views/demand_main_plan.xml
Normal file
@@ -0,0 +1,70 @@
|
||||
<odoo>
|
||||
<record id="view_sf_demand_main_plan_form" model="ir.ui.view">
|
||||
<field name="name">sf.demand.main.plan.form</field>
|
||||
<field name="model">sf.demand.main.plan</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header>
|
||||
<field name="hide_button_release_plan" invisible="1"/>
|
||||
<!-- <button string="下达计划" name="button_release_plan" type="object"-->
|
||||
<!-- class="btn-primary" attrs="{'invisible': [('hide_button_release_plan', '=', False)]}"/>-->
|
||||
<field name="state" widget="statusbar"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<field name="product_id"/>
|
||||
<field name="part_name"/>
|
||||
<field name="part_number"/>
|
||||
<field name="materials_id"/>
|
||||
<field name="blank_type"/>
|
||||
<field name="embryo_long"/>
|
||||
<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'))]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="计划">
|
||||
<field name="line_ids" attrs="{'readonly': [('state', 'in', ('40','50'))]}">
|
||||
<tree editable="bottom" delete="false">
|
||||
<field name="status"/>
|
||||
<field name="supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
||||
<field name="location_id" optional="hide"/>
|
||||
<field name="bom_id" optional="hide"/>
|
||||
<field name="plan_uom_qty"/>
|
||||
<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 name="button_delete" type="object" string="删除" class="btn-primary" attrs="{'invisible': [('status', 'not in', ('10','20','30'))]}" confirm='是否确认删除?'/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,16 +1,13 @@
|
||||
<odoo>
|
||||
<odoo>
|
||||
<record id="view_sf_production_demand_plan_tree" model="ir.ui.view">
|
||||
<field name="name">sf.production.demand.plan.tree</field>
|
||||
<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" create="false" delete="false">
|
||||
class="demand_plan_tree freeze-columns-before-part_number" create="false" delete="false">
|
||||
<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"/>
|
||||
@@ -22,34 +19,22 @@
|
||||
<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="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="supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<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" optional="hide"/>
|
||||
<field name="qty_delivered" optional="hide"/>
|
||||
<field name="qty_to_deliver" optional="hide"/>
|
||||
<field name="inventory_quantity_auto_apply"/>
|
||||
<field name="qty_delivered"/>
|
||||
<field name="qty_to_deliver"/>
|
||||
<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"/>
|
||||
<field name="product_remark" optional="hide"/>
|
||||
<field name="order_code" optional="hide"/>
|
||||
<field name="sale_order_id" optional="hide"/>
|
||||
<field name="sale_order_line_number" optional="hide"/>
|
||||
<field name="order_state"/>
|
||||
<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"/>
|
||||
@@ -83,14 +68,10 @@
|
||||
<field name="write_uid" optional="hide" string="更新人"/>
|
||||
<field name="print_count"/>
|
||||
<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"/>
|
||||
<button name="action_edit_demand_plan_form" type="object" string="编辑" class="btn-primary"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -128,8 +109,7 @@
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</record>
|
||||
<record id="sf_production_demand_plan_action" model="ir.actions.act_window">
|
||||
<field name="name">需求计划</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
@@ -137,4 +117,4 @@
|
||||
<field name="view_mode">tree</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
<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)]}"
|
||||
/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<xpath expr="//page/field[@name='order_line']/tree/field[@name='supply_method']" position="attributes">
|
||||
<attribute name="invisible">True</attribute>
|
||||
</xpath>
|
||||
</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"
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
from . import sf_demand_plan_print_wizard
|
||||
from . import sf_release_plan_wizard
|
||||
from . import sf_release_plan_wizard
|
||||
@@ -9,6 +9,11 @@ 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([
|
||||
@@ -20,7 +25,7 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
||||
('success', '成功'),
|
||||
('fail', '失败'),
|
||||
], string='状态', default='not_start')
|
||||
machining_drawings = fields.Binary('2D加工图纸')
|
||||
machining_drawings = fields.Binary('2D加工图纸', related='product_id.machining_drawings', store=True)
|
||||
|
||||
cnc_worksheet = fields.Binary('程序单')
|
||||
|
||||
@@ -39,17 +44,14 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
||||
# 执行打印
|
||||
self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
|
||||
record.status = 'success'
|
||||
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}"
|
||||
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}"
|
||||
success_records.append({
|
||||
'filename_url': record.filename_url,
|
||||
})
|
||||
@@ -76,14 +78,18 @@ 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:
|
||||
demand_plan_print.write(
|
||||
self.env['sf.demand.plan.print.wizard'].sudo().write(
|
||||
{'cnc_worksheet': record.cnc_worksheet, 'filename_url': record.cnc_worksheet_name})
|
||||
else:
|
||||
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)
|
||||
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)
|
||||
return res
|
||||
|
||||
@@ -9,12 +9,14 @@ 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)
|
||||
demand_plan_id = fields.Many2one(comodel_name="sf.demand.main.plan",
|
||||
string="需求计划", readonly=True)
|
||||
|
||||
demand_plan_line_id = fields.Many2one(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:
|
||||
demand_plan_line_id.action_confirm()
|
||||
self.demand_plan_line_id.action_confirm()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -217,8 +217,7 @@ class StockRule(models.Model):
|
||||
'''
|
||||
创建制造订单时生成序列号
|
||||
'''
|
||||
if production.product_id.tracking != "none":
|
||||
production.action_generate_serial()
|
||||
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
|
||||
@@ -443,7 +442,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 != "none":
|
||||
if product.tracking == "serial":
|
||||
last_serial = self.env['stock.lot'].search(
|
||||
[('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'ilike', product.name)],
|
||||
limit=1, order='name desc')
|
||||
@@ -454,9 +453,7 @@ 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]
|
||||
else:
|
||||
return "%s-%03d" % (product.name, 1)
|
||||
return False
|
||||
return "%s-%03d" % (product.name, 1)
|
||||
|
||||
qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')
|
||||
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
from . import controllers
|
||||
from . import sync_controller
|
||||
@@ -44,8 +44,7 @@ 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']), ('new_supply_method', '=', 'custom_made')])
|
||||
request.env.ref("base.user_admin")).search([('model_id', '=', ret['folder_name'])])
|
||||
if demand_plan and ret['total_estimated_time']:
|
||||
demand_plan.write(
|
||||
{'processing_time': ret['total_estimated_time']})
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
# study/jikimo_sf/sf_mrs_connect/controllers/sync_controller.py
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
|
||||
class FixtureSyncController(http.Controller):
|
||||
|
||||
@http.route('/api/fixture_model/sync_from_mrs', type='json', auth='none', csrf=False)
|
||||
def sync_model(self, **kw):
|
||||
code = kw.get('code')
|
||||
if not code:
|
||||
return {'status':'fail','msg':'code missing'}
|
||||
request.env['sf.fixture.model'].sudo().sync_from_mrs(code)
|
||||
return {'status':'success'}
|
||||
|
||||
@http.route('/api/fixture_param/sync_from_mrs', type='json', auth='none', csrf=False)
|
||||
def sync_param(self, **kw):
|
||||
code = kw.get('code')
|
||||
if not code:
|
||||
return {'status':'fail','msg':'code missing'}
|
||||
request.env['sf.fixture.materials.basic.parameters']\
|
||||
.sudo().sync_from_mrs(code)
|
||||
return {'status':'success'}
|
||||
@@ -1,14 +0,0 @@
|
||||
# study/jikimo_sf/sf_mrs_connect/models/common.py
|
||||
import time, hashlib
|
||||
|
||||
class Common:
|
||||
@staticmethod
|
||||
def get_headers(token, secret_key):
|
||||
ts = str(int(time.time()))
|
||||
sign = hashlib.sha256(f"{token}{secret_key}{ts}".encode()).hexdigest()
|
||||
return {
|
||||
"token": token,
|
||||
"sign": sign,
|
||||
"timestamp": ts,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
# study/jikimo_sf/sf_mrs_connect/models/redis_utils.py
|
||||
import redis, json, logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class RedisClient:
|
||||
def __init__(self, host='localhost', port=6379, db=0):
|
||||
try:
|
||||
self.client = redis.Redis(host=host, port=port, db=db, decode_responses=True)
|
||||
except Exception as e:
|
||||
_logger.error(f"Redis init error: {e}")
|
||||
self.client = None
|
||||
|
||||
def get_json(self, key):
|
||||
if not self.client:
|
||||
return None
|
||||
try:
|
||||
data = self.client.get(key)
|
||||
return json.loads(data) if data else None
|
||||
except Exception as e:
|
||||
_logger.error(f"Redis GET error [{key}]: {e}")
|
||||
return None
|
||||
|
||||
def set_json(self, key, value, ex=3600):
|
||||
if not self.client:
|
||||
return
|
||||
try:
|
||||
self.client.set(key, json.dumps(value, ensure_ascii=False), ex=ex)
|
||||
except Exception as e:
|
||||
_logger.error(f"Redis SET error [{key}]: {e}")
|
||||
@@ -5,11 +5,9 @@ import base64
|
||||
import traceback
|
||||
|
||||
import requests
|
||||
from odoo import models,api,fields
|
||||
from odoo import models
|
||||
from odoo.exceptions import ValidationError
|
||||
from .redis_utils import RedisClient
|
||||
from .common import Common
|
||||
from odoo.addons.jikimo_sf.sf_base.commons.common import Common
|
||||
from odoo.addons.sf_base.commons.common import Common
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -1508,157 +1506,149 @@ class SyncMulti_Mounting_Type(models.Model):
|
||||
raise ValidationError("联装类型认证未通过")
|
||||
|
||||
|
||||
# class SyncFixtureModel(models.Model):
|
||||
# _inherit = 'sf.fixture.model'
|
||||
# _description = '同步夹具型号列表'
|
||||
class SyncFixtureModel(models.Model):
|
||||
_inherit = 'sf.fixture.model'
|
||||
_description = '同步夹具型号列表'
|
||||
|
||||
# url = '/api/fixture_model/list'
|
||||
url = '/api/fixture_model/list'
|
||||
|
||||
# # 定时同步夹具型号列表
|
||||
# def sync_fixture_model_yesterday(self):
|
||||
# config = self.env['res.config.settings'].get_values()
|
||||
# headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||
# strUrl = config['sf_url'] + self.url
|
||||
# r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||
# r = r.json()
|
||||
# result = json.loads(r['result'])
|
||||
# if result['status'] == 1:
|
||||
# if result.get('fixture_model_yesterday_list'):
|
||||
# for item in result['fixture_model_yesterday_list']:
|
||||
# if item:
|
||||
# fixture_model = self.search([("code", '=', item['code']), ('active', 'in', [True, False])])
|
||||
# val = {
|
||||
# "name": item['name'],
|
||||
# "code": item['code'],
|
||||
# "fixture_material_id": self.env['sf.fixture.material'].search(
|
||||
# [('code', '=', item['fixture_material_code'])]).id,
|
||||
# "multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
|
||||
# [('code', '=', item['multi_mounting_type_code'])]).id,
|
||||
# "brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id,
|
||||
# "model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
|
||||
# "status": item['status'],
|
||||
# "active": item['active'],
|
||||
# }
|
||||
# if not fixture_model:
|
||||
# self.create(val)
|
||||
# else:
|
||||
# fixture_model.write(val)
|
||||
# 定时同步夹具型号列表
|
||||
def sync_fixture_model_yesterday(self):
|
||||
config = self.env['res.config.settings'].get_values()
|
||||
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||
strUrl = config['sf_url'] + self.url
|
||||
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||
r = r.json()
|
||||
result = json.loads(r['result'])
|
||||
if result['status'] == 1:
|
||||
if result.get('fixture_model_yesterday_list'):
|
||||
for item in result['fixture_model_yesterday_list']:
|
||||
if item:
|
||||
fixture_model = self.search([("code", '=', item['code']), ('active', 'in', [True, False])])
|
||||
val = {
|
||||
"name": item['name'],
|
||||
"code": item['code'],
|
||||
"fixture_material_id": self.env['sf.fixture.material'].search(
|
||||
[('code', '=', item['fixture_material_code'])]).id,
|
||||
"multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
|
||||
[('code', '=', item['multi_mounting_type_code'])]).id,
|
||||
"brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id,
|
||||
"model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
|
||||
"status": item['status'],
|
||||
"active": item['active'],
|
||||
}
|
||||
if not fixture_model:
|
||||
self.create(val)
|
||||
else:
|
||||
fixture_model.write(val)
|
||||
|
||||
# else:
|
||||
# raise ValidationError("夹具型号认证未通过")
|
||||
else:
|
||||
raise ValidationError("夹具型号认证未通过")
|
||||
|
||||
# # 定时同步所有夹具型号列表
|
||||
# def sync_all_fixture_model(self):
|
||||
# config = self.env['res.config.settings'].get_values()
|
||||
# headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||
# strUrl = config['sf_url'] + self.url
|
||||
# r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||
# r = r.json()
|
||||
# result = json.loads(r['result'])
|
||||
# # print('result:%s' % result)
|
||||
# if result['status'] == 1:
|
||||
# if result.get('fixture_model_all_list'):
|
||||
# for item in result['fixture_model_all_list']:
|
||||
# if item:
|
||||
# fixture_model = self.search([('code', '=', item['code']), ('active', 'in', [True, False])])
|
||||
# val = {
|
||||
# "name": item['name'],
|
||||
# "code": item['code'],
|
||||
# "fixture_material_id": self.env['sf.fixture.material'].search(
|
||||
# [('code', '=', item['fixture_material_code'])]).id,
|
||||
# "multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
|
||||
# [('code', '=', item['multi_mounting_type_code'])]).id,
|
||||
# "brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id,
|
||||
# "model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
|
||||
# "status": item['status'],
|
||||
# "active": item['active'],
|
||||
# }
|
||||
# if not fixture_model:
|
||||
# self.create(val)
|
||||
# else:
|
||||
# fixture_model.write(val)
|
||||
# else:
|
||||
# raise ValidationError("夹具型号认证未通过")
|
||||
# 定时同步所有夹具型号列表
|
||||
def sync_all_fixture_model(self):
|
||||
config = self.env['res.config.settings'].get_values()
|
||||
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||
strUrl = config['sf_url'] + self.url
|
||||
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||
r = r.json()
|
||||
result = json.loads(r['result'])
|
||||
# print('result:%s' % result)
|
||||
if result['status'] == 1:
|
||||
if result.get('fixture_model_all_list'):
|
||||
for item in result['fixture_model_all_list']:
|
||||
if item:
|
||||
fixture_model = self.search([('code', '=', item['code']), ('active', 'in', [True, False])])
|
||||
val = {
|
||||
"name": item['name'],
|
||||
"code": item['code'],
|
||||
"fixture_material_id": self.env['sf.fixture.material'].search(
|
||||
[('code', '=', item['fixture_material_code'])]).id,
|
||||
"multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
|
||||
[('code', '=', item['multi_mounting_type_code'])]).id,
|
||||
"brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id,
|
||||
"model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
|
||||
"status": item['status'],
|
||||
"active": item['active'],
|
||||
}
|
||||
if not fixture_model:
|
||||
self.create(val)
|
||||
else:
|
||||
fixture_model.write(val)
|
||||
else:
|
||||
raise ValidationError("夹具型号认证未通过")
|
||||
|
||||
|
||||
# class SyncfixtureMaterialsBasicParameters(models.Model):
|
||||
# _inherit = 'sf.fixture.materials.basic.parameters'
|
||||
# _description = '同步夹具型号基本参数列表'
|
||||
class SyncfixtureMaterialsBasicParameters(models.Model):
|
||||
_inherit = 'sf.fixture.materials.basic.parameters'
|
||||
_description = '同步夹具型号基本参数列表'
|
||||
|
||||
# url = '/api/fixture_parameters/list'
|
||||
url = '/api/fixture_parameters/list'
|
||||
|
||||
# # 定时同步夹具型号基本信息
|
||||
# def sync_fixture_materials_basic_parameters_yesterday(self):
|
||||
# config = self.env['res.config.settings'].get_values()
|
||||
# headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||
# strUrl = config['sf_url'] + self.url
|
||||
# r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||
# r = r.json()
|
||||
# result = json.loads(r['result'])
|
||||
# if result['status'] == 1:
|
||||
# if result.get('fixture_parameters_yesterday_list'):
|
||||
# all_list = result.get('fixture_parameters_yesterday_list')
|
||||
# if all_list.get('zero_chuck_all_list'):
|
||||
# self._write_or_create(all_list.get('zero_chuck_yesterday_list'), '零点卡盘')
|
||||
# if all_list.get('zero_tray_all_list'):
|
||||
# self._write_or_create(all_list.get('zero_tray_yesterday_list'), '零点托盘')
|
||||
# if all_list.get('pneumatic_fixture_all_list'):
|
||||
# self._write_or_create(all_list.get('pneumatic_fixture_yesterday_list'), '气动夹具')
|
||||
# if all_list.get('jaw_vice_all_list'):
|
||||
# self._write_or_create(all_list.get('jaw_vice_yesterday_list'), '虎钳夹具')
|
||||
# if all_list.get('magnet_fixture_all_list'):
|
||||
# self._write_or_create(all_list.get('magnet_fixture_yesterday_list'), '磁吸夹具')
|
||||
# if all_list.get('adapter_board_all_list'):
|
||||
# self._write_or_create(all_list.get('adapter_board_yesterday_list'), '转接板(锁板)夹具')
|
||||
# if all_list.get('scroll_chuck_all_list'):
|
||||
# self._write_or_create(all_list.get('scroll_chuck_yesterday_list'), '三爪卡盘')
|
||||
# if all_list.get('air_tray_all_list'):
|
||||
# self._write_or_create(all_list.get('air_tray_all_list'),'气吹托盘')
|
||||
# if all_list.get('magnet_tray_all_list'):
|
||||
# self._write_or_create(all_list.get('magnet_tray_all_list'),'磁吸托盘')
|
||||
# else:
|
||||
# raise ValidationError("夹具型号基本参数认证未通过")
|
||||
# 定时同步夹具型号基本信息
|
||||
def sync_fixture_materials_basic_parameters_yesterday(self):
|
||||
config = self.env['res.config.settings'].get_values()
|
||||
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||
strUrl = config['sf_url'] + self.url
|
||||
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||
r = r.json()
|
||||
result = json.loads(r['result'])
|
||||
if result['status'] == 1:
|
||||
if result.get('fixture_parameters_yesterday_list'):
|
||||
all_list = result.get('fixture_parameters_yesterday_list')
|
||||
if all_list.get('zero_chuck_all_list'):
|
||||
self._write_or_create(all_list.get('zero_chuck_yesterday_list'), '零点卡盘')
|
||||
if all_list.get('zero_tray_all_list'):
|
||||
self._write_or_create(all_list.get('zero_tray_yesterday_list'), '零点托盘')
|
||||
if all_list.get('pneumatic_fixture_all_list'):
|
||||
self._write_or_create(all_list.get('pneumatic_fixture_yesterday_list'), '气动夹具')
|
||||
if all_list.get('jaw_vice_all_list'):
|
||||
self._write_or_create(all_list.get('jaw_vice_yesterday_list'), '虎钳夹具')
|
||||
if all_list.get('magnet_fixture_all_list'):
|
||||
self._write_or_create(all_list.get('magnet_fixture_yesterday_list'), '磁吸夹具')
|
||||
if all_list.get('adapter_board_all_list'):
|
||||
self._write_or_create(all_list.get('adapter_board_yesterday_list'), '转接板(锁板)夹具')
|
||||
if all_list.get('scroll_chuck_all_list'):
|
||||
self._write_or_create(all_list.get('scroll_chuck_yesterday_list'), '三爪卡盘')
|
||||
else:
|
||||
raise ValidationError("夹具型号基本参数认证未通过")
|
||||
|
||||
# # 定时同步所有夹具型号基本信息
|
||||
# def sync_all_fixture_materials_basic_parameters(self):
|
||||
# config = self.env['res.config.settings'].get_values()
|
||||
# headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||
# strUrl = config['sf_url'] + self.url
|
||||
# r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||
# r = r.json()
|
||||
# result = json.loads(r['result'])
|
||||
# if result['status'] == 1:
|
||||
# if result.get('fixture_parameters_all_list'):
|
||||
# all_list = result.get('fixture_parameters_all_list')
|
||||
# if all_list.get('zero_chuck_all_list'):
|
||||
# self._write_or_create(all_list.get('zero_chuck_all_list'), '零点卡盘')
|
||||
# if all_list.get('zero_tray_all_list'):
|
||||
# self._write_or_create(all_list.get('zero_tray_all_list'), '零点托盘')
|
||||
# if all_list.get('pneumatic_fixture_all_list'):
|
||||
# self._write_or_create(all_list.get('pneumatic_fixture_all_list'), '气动夹具')
|
||||
# if all_list.get('jaw_vice_all_list'):
|
||||
# self._write_or_create(all_list.get('jaw_vice_all_list'), '虎钳夹具')
|
||||
# if all_list.get('magnet_fixture_all_list'):
|
||||
# self._write_or_create(all_list.get('magnet_fixture_all_list'), '磁吸夹具')
|
||||
# if all_list.get('adapter_board_all_list'):
|
||||
# self._write_or_create(all_list.get('adapter_board_all_list'), '转接板(锁板)夹具')
|
||||
# if all_list.get('scroll_chuck_all_list'):
|
||||
# self._write_or_create(all_list.get('scroll_chuck_all_list'), '三爪卡盘')
|
||||
# if all_list.get('air_tray_all_list'):
|
||||
# self._write_or_create(all_list.get('air_tray_all_list'),'气吹托盘')
|
||||
# if all_list.get('magnet_tray_all_list'):
|
||||
# self._write_or_create(all_list.get('magnet_tray_all_list'),'磁吸托盘')
|
||||
# else:
|
||||
# raise ValidationError("夹具型号基本参数认证未通过")
|
||||
# 定时同步所有夹具型号基本信息
|
||||
def sync_all_fixture_materials_basic_parameters(self):
|
||||
config = self.env['res.config.settings'].get_values()
|
||||
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||
strUrl = config['sf_url'] + self.url
|
||||
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||
r = r.json()
|
||||
result = json.loads(r['result'])
|
||||
if result['status'] == 1:
|
||||
if result.get('fixture_parameters_all_list'):
|
||||
all_list = result.get('fixture_parameters_all_list')
|
||||
if all_list.get('zero_chuck_all_list'):
|
||||
self._write_or_create(all_list.get('zero_chuck_all_list'), '零点卡盘')
|
||||
if all_list.get('zero_tray_all_list'):
|
||||
self._write_or_create(all_list.get('zero_tray_all_list'), '零点托盘')
|
||||
if all_list.get('pneumatic_fixture_all_list'):
|
||||
self._write_or_create(all_list.get('pneumatic_fixture_all_list'), '气动夹具')
|
||||
if all_list.get('jaw_vice_all_list'):
|
||||
self._write_or_create(all_list.get('jaw_vice_all_list'), '虎钳夹具')
|
||||
if all_list.get('magnet_fixture_all_list'):
|
||||
self._write_or_create(all_list.get('magnet_fixture_all_list'), '磁吸夹具')
|
||||
if all_list.get('adapter_board_all_list'):
|
||||
self._write_or_create(all_list.get('adapter_board_all_list'), '转接板(锁板)夹具')
|
||||
if all_list.get('scroll_chuck_all_list'):
|
||||
self._write_or_create(all_list.get('scroll_chuck_all_list'), '三爪卡盘')
|
||||
else:
|
||||
raise ValidationError("夹具型号基本参数认证未通过")
|
||||
|
||||
# def _write_or_create(self, fixture_parameters_list, material_name):
|
||||
# for item in fixture_parameters_list:
|
||||
# if item:
|
||||
# basic_parameters = self.search([('code', '=', item.get('code')), ('active', 'in', [True, False])])
|
||||
# if not basic_parameters:
|
||||
# self.create(self._get_basic_parameters_list(item, material_name))
|
||||
# else:
|
||||
# basic_parameters.write(self._get_basic_parameters_list(item, material_name))
|
||||
def _write_or_create(self, fixture_parameters_list, material_name):
|
||||
for item in fixture_parameters_list:
|
||||
if item:
|
||||
basic_parameters = self.search([('code', '=', item.get('code')), ('active', 'in', [True, False])])
|
||||
if not basic_parameters:
|
||||
self.create(self._get_basic_parameters_list(item, material_name))
|
||||
else:
|
||||
basic_parameters.write(self._get_basic_parameters_list(item, material_name))
|
||||
|
||||
|
||||
class SyncFunctionalFixtureType(models.Model):
|
||||
@@ -3240,94 +3230,4 @@ class EmbryoRedundancySync(models.Model):
|
||||
"height": item['height'],
|
||||
"active": item['active'],
|
||||
"remark": item['remark'],
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class SyncFixtureModel(models.Model):
|
||||
_inherit = 'sf.fixture.model'
|
||||
_description = 'Redis 优先同步夹具型号'
|
||||
|
||||
def sync_all_fixture_model(self):
|
||||
rc = RedisClient()
|
||||
key = 'mrs:fixture_model_all_list'
|
||||
all_list = rc.get_json(key)
|
||||
if not all_list:
|
||||
raise ValidationError(f"Redis 中未找到 key={key}")
|
||||
|
||||
for item in all_list:
|
||||
if not item or not item.get('code'):
|
||||
continue
|
||||
|
||||
record = self.search([('code', '=', item['code'])], limit=1)
|
||||
vals = {
|
||||
'name': item['name'],
|
||||
'code': item['code'],
|
||||
'fixture_material_id': self.env['sf.fixture.material']
|
||||
.search([('code', '=', item['fixture_material_code'])], limit=1).id,
|
||||
'multi_mounting_type_id': self.env['sf.multi_mounting.type']
|
||||
.search([('code', '=', item['multi_mounting_type_code'])], limit=1).id,
|
||||
'brand_id': self.env['sf.machine.brand']
|
||||
.search([('code', '=', item['brand_code'])], limit=1).id,
|
||||
'model_file': base64.b64decode(item['model_file']) if item.get('model_file') else False,
|
||||
'status': item['status'],
|
||||
'active': item['active'],
|
||||
}
|
||||
if record:
|
||||
record.write(vals)
|
||||
else:
|
||||
self.create(vals)
|
||||
|
||||
|
||||
class SyncfixtureMaterialsBasicParameters(models.Model):
|
||||
_inherit = 'sf.fixture.materials.basic.parameters'
|
||||
_description = 'Redis 优先同步夹具基本参数'
|
||||
|
||||
def sync_all_fixture_materials_basic_parameters(self):
|
||||
rc = RedisClient()
|
||||
key = 'mrs:fixture_param_all_list'
|
||||
all_list = rc.get_json(key)
|
||||
if not all_list:
|
||||
raise ValidationError(f"Redis 中未找到 key={key}")
|
||||
|
||||
def _sync_list(param_list, material_name):
|
||||
for item in param_list or []:
|
||||
if not item or not item.get('code'):
|
||||
continue
|
||||
record = self.search([('code', '=', item['code'])], limit=1)
|
||||
vals = self._get_basic_parameters_list(item, material_name)
|
||||
if record:
|
||||
record.write(vals)
|
||||
else:
|
||||
self.create(vals)
|
||||
|
||||
_sync_list(all_list.get('zero_chuck_all_list'), '零点卡盘')
|
||||
_sync_list(all_list.get('zero_tray_all_list'), '零点托盘')
|
||||
_sync_list(all_list.get('pneumatic_fixture_all_list'), '气动夹具')
|
||||
_sync_list(all_list.get('jaw_vice_all_list'), '虎钳夹具')
|
||||
_sync_list(all_list.get('magnet_fixture_all_list'), '磁吸夹具')
|
||||
_sync_list(all_list.get('adapter_board_all_list'), '转接板(锁板)夹具')
|
||||
_sync_list(all_list.get('scroll_chuck_all_list'), '三爪卡盘')
|
||||
_sync_list(all_list.get('air_tray_all_list'), '气吹托盘')
|
||||
_sync_list(all_list.get('magnet_tray_all_list'), '磁吸托盘')
|
||||
|
||||
def _get_basic_parameters_list(self, item, material_name):
|
||||
"""
|
||||
统一结构化 item 数据,供写入模型字段使用(你应当根据 material_name 自定义字段映射)
|
||||
"""
|
||||
return {
|
||||
'name': item.get('name'),
|
||||
'code': item.get('code'),
|
||||
'length': item.get('length'),
|
||||
'width': item.get('width'),
|
||||
'height': item.get('height'),
|
||||
'diameter': item.get('diameter'),
|
||||
'weight': item.get('weight'),
|
||||
'fixture_model_id': self.env['sf.fixture.model'].search([('code', '=', item.get('fixture_model_code'))], limit=1).id,
|
||||
'materials_model_id': self.env['sf.materials.model'].search([('code', '=', item.get('material_code'))], limit=1).id,
|
||||
'active': item.get('active', True),
|
||||
# 你可以根据 material_name 判断类型并补充字段
|
||||
}
|
||||
})
|
||||
@@ -22,7 +22,6 @@
|
||||
'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',
|
||||
|
||||
@@ -1,29 +1,24 @@
|
||||
import logging
|
||||
|
||||
from odoo import api, models, fields
|
||||
from odoo import api, models
|
||||
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')
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?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>
|
||||
@@ -16,7 +16,6 @@
|
||||
# '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,3 +1,2 @@
|
||||
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,10 +1082,6 @@ 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:
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
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}上的库存数量为负!!!')
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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