Compare commits
43 Commits
feature/禁止
...
feature/72
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9af458b11e | ||
|
|
cdf6a36c30 | ||
|
|
8e8f5eb8be | ||
|
|
cdbc277a94 | ||
|
|
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 | ||
|
|
d02babaf0a | ||
|
|
acb6fd42ca | ||
|
|
c2cb24c60b |
@@ -41,8 +41,10 @@ class StockPicking(models.Model):
|
|||||||
if backorder_ids:
|
if backorder_ids:
|
||||||
purchase_request_lines = self.move_ids.move_orig_ids.purchase_line_id.purchase_request_lines
|
purchase_request_lines = self.move_ids.move_orig_ids.purchase_line_id.purchase_request_lines
|
||||||
if purchase_request_lines:
|
if purchase_request_lines:
|
||||||
purchase_request_lines.move_dest_ids = [
|
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')
|
(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
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ class StockRule(models.Model):
|
|||||||
_inherit = 'stock.rule'
|
_inherit = 'stock.rule'
|
||||||
|
|
||||||
def _run_buy(self, procurements):
|
def _run_buy(self, procurements):
|
||||||
res = super(StockRule, self)._run_buy(procurements)
|
|
||||||
# 判断是否根据规则生成新的采购申请单据,如果生成则修改状态为 approved
|
# 判断是否根据规则生成新的采购申请单据,如果生成则修改状态为 approved
|
||||||
origins = list(set([procurement[0].origin for procurement in procurements]))
|
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:
|
for origin in origins:
|
||||||
pr_ids = self.env["purchase.request"].sudo().search(
|
pr_ids = self.env["purchase.request"].sudo().search(
|
||||||
[('origin', 'like', origin), ('rule_new_add', '=', True), ('state', '=', 'draft')])
|
[('origin', 'like', origin), ('rule_new_add', '=', True), ('state', '=', 'draft')])
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ wechatpy==1.8.18
|
|||||||
pycryptodome==3.22.0
|
pycryptodome==3.22.0
|
||||||
openupgradelib==3.10.0
|
openupgradelib==3.10.0
|
||||||
opcua==0.98.13
|
opcua==0.98.13
|
||||||
openpyxl
|
openpyxl
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class MrsMaterialModel(models.Model):
|
|||||||
materials_num = fields.Char("编码号")
|
materials_num = fields.Char("编码号")
|
||||||
name = fields.Char('型号名')
|
name = fields.Char('型号名')
|
||||||
need_h = fields.Boolean("热处理", default="false")
|
need_h = fields.Boolean("热处理", default="false")
|
||||||
|
need_m = fields.Boolean("是否磁吸", default="false")
|
||||||
mf_materia_post = fields.Char("热处理后密度")
|
mf_materia_post = fields.Char("热处理后密度")
|
||||||
density = fields.Float("密度(kg/m³)")
|
density = fields.Float("密度(kg/m³)")
|
||||||
materials_id = fields.Many2one('sf.production.materials', "材料名")
|
materials_id = fields.Many2one('sf.production.materials', "材料名")
|
||||||
|
|||||||
@@ -263,6 +263,7 @@
|
|||||||
<field name="materials_no" readonly="1" force_save="1"/>
|
<field name="materials_no" readonly="1" force_save="1"/>
|
||||||
<field name="gain_way" required="0"/>
|
<field name="gain_way" required="0"/>
|
||||||
<field name="density" readonly="1" required="1" class="custom_required"/>
|
<field name="density" readonly="1" required="1" class="custom_required"/>
|
||||||
|
<field name="need_m" default="false" readonly="1"/>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="rough_machining" required="1"/>
|
<field name="rough_machining" required="1"/>
|
||||||
@@ -306,6 +307,7 @@
|
|||||||
<field name="tensile_strength"/>
|
<field name="tensile_strength"/>
|
||||||
<field name="hardness" optional="show"/>
|
<field name="hardness" optional="show"/>
|
||||||
<field name="need_h"/>
|
<field name="need_h"/>
|
||||||
|
<field name="need_m"/>
|
||||||
<field name="apply" widget="many2many_tags" optional="show"/>
|
<field name="apply" widget="many2many_tags" optional="show"/>
|
||||||
<field name="density" optional="show"/>
|
<field name="density" optional="show"/>
|
||||||
<field name="rough_machining" optional="hide"/>
|
<field name="rough_machining" optional="hide"/>
|
||||||
@@ -352,6 +354,7 @@
|
|||||||
<field name="materials_no"/>
|
<field name="materials_no"/>
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="need_h"/>
|
<field name="need_h"/>
|
||||||
|
<field name="need_m"/>
|
||||||
<field name="mf_materia_post"/>
|
<field name="mf_materia_post"/>
|
||||||
<field name="density"/>
|
<field name="density"/>
|
||||||
<field name='materials_id' default="default" invisible="1"/>
|
<field name='materials_id' default="default" invisible="1"/>
|
||||||
|
|||||||
@@ -18,3 +18,12 @@ class MrpBom(models.Model):
|
|||||||
subcontract = self.get_supplier(product.materials_type_id)
|
subcontract = self.get_supplier(product.materials_type_id)
|
||||||
bom_id.subcontractor_id = subcontract.partner_id.id
|
bom_id.subcontractor_id = subcontract.partner_id.id
|
||||||
return bom_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
|
||||||
@@ -5,38 +5,42 @@ from odoo.tools import float_compare
|
|||||||
class PurchaseOrder(models.Model):
|
class PurchaseOrder(models.Model):
|
||||||
_inherit = 'purchase.order'
|
_inherit = 'purchase.order'
|
||||||
|
|
||||||
demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
|
|
||||||
string="需求计划明细", readonly=True)
|
|
||||||
|
|
||||||
def button_confirm(self):
|
def button_confirm(self):
|
||||||
if self.demand_plan_line_id:
|
if self.order_line[0].demand_plan_line_id:
|
||||||
self = self.with_context(
|
self = self.with_context(
|
||||||
demand_plan_line_id=self.demand_plan_line_id.id
|
demand_plan_line_id=self.order_line[0].demand_plan_line_id.id
|
||||||
)
|
)
|
||||||
res = super(PurchaseOrder, self).button_confirm()
|
res = super(PurchaseOrder, self).button_confirm()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.depends('origin', 'demand_plan_line_id')
|
@api.depends('origin')
|
||||||
def _compute_purchase_type(self):
|
def _compute_purchase_type(self):
|
||||||
for purchase in self:
|
for purchase in self:
|
||||||
if purchase.order_line[0].product_id.categ_id.name == '坯料':
|
if purchase.order_line[0].product_id.categ_id.name == '坯料':
|
||||||
if purchase.order_line[0].product_id.materials_type_id.gain_way == '外协':
|
if purchase.order_line[0].product_id.materials_type_id.gain_way == '外协':
|
||||||
purchase.purchase_type = 'outsourcing'
|
purchase.purchase_type = 'outsourcing'
|
||||||
else:
|
else:
|
||||||
if purchase.demand_plan_line_id.supply_method == 'outsourcing':
|
if purchase.order_line[0].demand_plan_line_id.supply_method == 'outsourcing':
|
||||||
purchase.purchase_type = 'outsourcing'
|
purchase.purchase_type = 'outsourcing'
|
||||||
|
|
||||||
elif purchase.demand_plan_line_id.supply_method == 'purchase':
|
elif purchase.order_line[0].demand_plan_line_id.supply_method == 'purchase':
|
||||||
purchase.purchase_type = 'outside'
|
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
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
res = super(PurchaseOrder, self).create(vals)
|
res = super(PurchaseOrderLine, self).create(vals)
|
||||||
if not res.demand_plan_line_id:
|
if not res.demand_plan_line_id:
|
||||||
origin = [origin.replace(' ', '') for origin in res.origin.split(',')]
|
origin = [origin.replace(' ', '') for origin in res.order_id.origin.split(',')]
|
||||||
if self.env.context.get('demand_plan_line_id'):
|
if self.env.context.get('demand_plan_line_id'):
|
||||||
res.demand_plan_line_id = 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.origin:
|
elif 'MO' in res.order_id.origin:
|
||||||
# 原单据是制造订单
|
# 原单据是制造订单
|
||||||
mp_ids = self.env['mrp.production'].sudo().search([('name', 'in', origin)])
|
mp_ids = self.env['mrp.production'].sudo().search([('name', 'in', origin)])
|
||||||
if mp_ids:
|
if mp_ids:
|
||||||
|
|||||||
@@ -28,83 +28,8 @@ class PurchaseRequestLine(models.Model):
|
|||||||
class PurchaseRequestLineMakePurchaseOrder(models.TransientModel):
|
class PurchaseRequestLineMakePurchaseOrder(models.TransientModel):
|
||||||
_inherit = "purchase.request.line.make.purchase.order"
|
_inherit = "purchase.request.line.make.purchase.order"
|
||||||
|
|
||||||
def make_purchase_order(self):
|
@api.model
|
||||||
res = []
|
def _prepare_purchase_order_line(self, po, item):
|
||||||
purchase_obj = self.env["purchase.order"]
|
ret = super(PurchaseRequestLineMakePurchaseOrder, self)._prepare_purchase_order_line(po, item)
|
||||||
po_line_obj = self.env["purchase.order.line"]
|
ret['demand_plan_line_id'] = item.line_id.demand_plan_line_id.id
|
||||||
purchase = False
|
return ret
|
||||||
|
|
||||||
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",
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class ReSaleOrder(models.Model):
|
|||||||
groups='mrp.group_mrp_user', store=True)
|
groups='mrp.group_mrp_user', store=True)
|
||||||
|
|
||||||
demand_plan_ids = fields.Many2many(comodel_name="sf.demand.plan",
|
demand_plan_ids = fields.Many2many(comodel_name="sf.demand.plan",
|
||||||
string="需求计划", readonly=True)
|
string="需求计划", readonly=True)
|
||||||
|
|
||||||
demand_plan_count = fields.Integer(
|
demand_plan_count = fields.Integer(
|
||||||
string="需求计划生成计数",
|
string="需求计划生成计数",
|
||||||
@@ -47,9 +47,9 @@ class ReSaleOrder(models.Model):
|
|||||||
if demand_plan.product_id.machining_drawings_name:
|
if demand_plan.product_id.machining_drawings_name:
|
||||||
filename_url = demand_plan.product_id.machining_drawings_name.rsplit('.', 1)[0]
|
filename_url = demand_plan.product_id.machining_drawings_name.rsplit('.', 1)[0]
|
||||||
wizard_vals = {
|
wizard_vals = {
|
||||||
'demand_plan_id': demand_plan.id,
|
|
||||||
'model_id': demand_plan.model_id,
|
'model_id': demand_plan.model_id,
|
||||||
'filename_url': filename_url,
|
'filename_url': filename_url,
|
||||||
|
'machining_drawings': product.machining_drawings,
|
||||||
'type': '1',
|
'type': '1',
|
||||||
}
|
}
|
||||||
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.tools import float_compare
|
from odoo.tools import float_compare
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class SfDemandPlan(models.Model):
|
class SfDemandPlan(models.Model):
|
||||||
@@ -10,8 +11,7 @@ class SfDemandPlan(models.Model):
|
|||||||
_description = 'sf_demand_plan'
|
_description = 'sf_demand_plan'
|
||||||
|
|
||||||
state = fields.Selection([
|
state = fields.Selection([
|
||||||
('10', '需求确认'),
|
('10', '待工艺设计'),
|
||||||
('20', '待工艺设计'),
|
|
||||||
('30', '部分下达'),
|
('30', '部分下达'),
|
||||||
('40', '已下达'),
|
('40', '已下达'),
|
||||||
('50', '取消'),
|
('50', '取消'),
|
||||||
@@ -36,6 +36,9 @@ class SfDemandPlan(models.Model):
|
|||||||
|
|
||||||
blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类',
|
blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类',
|
||||||
related='product_id.blank_type')
|
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)
|
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)
|
is_incoming_material = fields.Boolean('客供料', related='sale_order_line_id.is_incoming_material', store=True)
|
||||||
pending_qty = fields.Float(
|
pending_qty = fields.Float(
|
||||||
@@ -72,6 +75,8 @@ class SfDemandPlan(models.Model):
|
|||||||
('4', '低'),
|
('4', '低'),
|
||||||
], string='优先级', default='3')
|
], string='优先级', default='3')
|
||||||
|
|
||||||
|
overdelivery_allowed = fields.Boolean('可超量发货', default=False)
|
||||||
|
|
||||||
hide_button_release_plan = fields.Boolean(
|
hide_button_release_plan = fields.Boolean(
|
||||||
string='显示下达计划按钮',
|
string='显示下达计划按钮',
|
||||||
compute='_compute_hide_button_release_plan',
|
compute='_compute_hide_button_release_plan',
|
||||||
@@ -83,6 +88,8 @@ class SfDemandPlan(models.Model):
|
|||||||
compute='_compute_readonly_custom_made_type',
|
compute='_compute_readonly_custom_made_type',
|
||||||
default=False
|
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')
|
@api.depends('product_id.part_number', 'product_id.model_name')
|
||||||
def _compute_part_number(self):
|
def _compute_part_number(self):
|
||||||
@@ -108,7 +115,10 @@ class SfDemandPlan(models.Model):
|
|||||||
def _compute_embryo_long(self):
|
def _compute_embryo_long(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
if line.product_id:
|
if line.product_id:
|
||||||
line.embryo_long = f"{round(line.product_id.model_long, 3)}*{round(line.product_id.model_width, 3)}*{round(line.product_id.model_height, 3)}"
|
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:
|
else:
|
||||||
line.embryo_long = None
|
line.embryo_long = None
|
||||||
|
|
||||||
@@ -146,9 +156,8 @@ class SfDemandPlan(models.Model):
|
|||||||
for line in self:
|
for line in self:
|
||||||
sum_plan_uom_qty = sum(line.line_ids.mapped('plan_uom_qty'))
|
sum_plan_uom_qty = sum(line.line_ids.mapped('plan_uom_qty'))
|
||||||
pending_qty = line.product_uom_qty - sum_plan_uom_qty
|
pending_qty = line.product_uom_qty - sum_plan_uom_qty
|
||||||
rounding = line.product_id.uom_id.rounding or 0.01
|
|
||||||
if float_compare(pending_qty, 0,
|
if float_compare(pending_qty, 0,
|
||||||
precision_rounding=rounding) == -1:
|
precision_rounding=line.product_id.uom_id.rounding) == -1:
|
||||||
line.pending_qty = 0
|
line.pending_qty = 0
|
||||||
else:
|
else:
|
||||||
line.pending_qty = pending_qty
|
line.pending_qty = pending_qty
|
||||||
@@ -168,7 +177,9 @@ class SfDemandPlan(models.Model):
|
|||||||
def _compute_state(self):
|
def _compute_state(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
status_line = line.line_ids.filtered(lambda p: p.status == '60')
|
status_line = line.line_ids.filtered(lambda p: p.status == '60')
|
||||||
if line.sale_order_id.state == 'cancel':
|
if not line.line_ids:
|
||||||
|
line.state = '10'
|
||||||
|
elif line.sale_order_id.state == 'cancel':
|
||||||
line.state = '50'
|
line.state = '50'
|
||||||
line.line_ids.status = '100'
|
line.line_ids.status = '100'
|
||||||
elif len(line.line_ids) == len(status_line):
|
elif len(line.line_ids) == len(status_line):
|
||||||
@@ -185,16 +196,38 @@ class SfDemandPlan(models.Model):
|
|||||||
lambda p: p.status in ('50', '60') and p.new_supply_method == 'custom_made')
|
lambda p: p.status in ('50', '60') and p.new_supply_method == 'custom_made')
|
||||||
line.readonly_custom_made_type = bool(production_demand_plan)
|
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):
|
def name_get(self):
|
||||||
result = []
|
result = []
|
||||||
for plan in self:
|
for plan in self:
|
||||||
result.append((plan.id, plan.sale_order_id.name))
|
result.append((plan.id, plan.demand_plan_number))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def button_production_release_plan(self):
|
def button_production_release_plan(self):
|
||||||
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
|
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
|
||||||
sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty'))
|
sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty'))
|
||||||
if sum_product_uom_qty > self.product_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 {
|
return {
|
||||||
'name': _('需求计划'),
|
'name': _('需求计划'),
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
@@ -210,3 +243,18 @@ class SfDemandPlan(models.Model):
|
|||||||
else:
|
else:
|
||||||
for demand_plan_line_id in line_ids:
|
for demand_plan_line_id in line_ids:
|
||||||
demand_plan_line_id.action_confirm()
|
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
|
||||||
|
|||||||
@@ -21,17 +21,15 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
status = fields.Selection([
|
status = fields.Selection([
|
||||||
('10', '草稿'),
|
('10', '草稿'),
|
||||||
('20', '待确认'),
|
('20', '待确认'),
|
||||||
('30', '需求确认'),
|
('30', '待工艺设计'),
|
||||||
('50', '待下达生产'),
|
('50', '待下达生产'),
|
||||||
('60', '已下达'),
|
('60', '已下达'),
|
||||||
('100', '取消'),
|
('100', '取消'),
|
||||||
], string='状态', default='30', readonly=True)
|
], string='状态', default='30', readonly=True)
|
||||||
demand_plan_id = fields.Many2one(comodel_name="sf.demand.plan",
|
demand_plan_id = fields.Many2one(comodel_name="sf.demand.plan",
|
||||||
string="物料需求", readonly=True)
|
string="物料需求", readonly=True)
|
||||||
sale_order_id = fields.Many2one(comodel_name="sale.order", related='demand_plan_id.sale_order_id',
|
sale_order_id = fields.Many2one(comodel_name="sale.order", string="销售订单", readonly=True)
|
||||||
string="销售订单", readonly=True)
|
sale_order_line_id = fields.Many2one(comodel_name="sale.order.line", string="销售订单明细", readonly=True)
|
||||||
sale_order_line_id = fields.Many2one(comodel_name="sale.order.line", related='demand_plan_id.sale_order_line_id',
|
|
||||||
string="销售订单明细", readonly=True)
|
|
||||||
sale_order_line_number = fields.Char(string='销售订单行', compute='_compute_sale_order_line_number', store=True)
|
sale_order_line_number = fields.Char(string='销售订单行', compute='_compute_sale_order_line_number', store=True)
|
||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
related='sale_order_id.company_id',
|
related='sale_order_id.company_id',
|
||||||
@@ -58,7 +56,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
custom_made_type = fields.Selection([
|
custom_made_type = fields.Selection([
|
||||||
('automation', "自动化产线加工"),
|
('automation', "自动化产线加工"),
|
||||||
('manual', "人工线下加工"),
|
('manual', "人工线下加工"),
|
||||||
], string='自制类型', compute='_compute_custom_made_type', store=True)
|
], string='产线类型', compute='_compute_custom_made_type', store=True)
|
||||||
|
|
||||||
supply_method = fields.Selection([
|
supply_method = fields.Selection([
|
||||||
('automation', "自动化产线加工"),
|
('automation', "自动化产线加工"),
|
||||||
@@ -83,6 +81,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
related='product_id.blank_type')
|
related='product_id.blank_type')
|
||||||
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型',
|
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型',
|
||||||
related='product_id.blank_precision')
|
related='product_id.blank_precision')
|
||||||
|
unit_number = fields.Float('单件用量', digits=(16, 3), related='product_id.unit_number')
|
||||||
embryo_long = fields.Char('坯料尺寸(mm)', related='demand_plan_id.embryo_long')
|
embryo_long = fields.Char('坯料尺寸(mm)', related='demand_plan_id.embryo_long')
|
||||||
materials_id = fields.Char('材料', related='demand_plan_id.materials_id')
|
materials_id = fields.Char('材料', related='demand_plan_id.materials_id')
|
||||||
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
|
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
|
||||||
@@ -171,6 +170,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
finished_product_arrival_date = fields.Date('采购计划到货(成品)')
|
finished_product_arrival_date = fields.Date('采购计划到货(成品)')
|
||||||
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
||||||
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
|
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
|
||||||
|
manual_quotation = fields.Boolean('人工编程', related='product_id.manual_quotation', default=False)
|
||||||
|
|
||||||
@api.constrains('plan_uom_qty')
|
@api.constrains('plan_uom_qty')
|
||||||
def _check_plan_uom_qty(self):
|
def _check_plan_uom_qty(self):
|
||||||
@@ -178,15 +178,22 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
if line_ids:
|
if line_ids:
|
||||||
raise ValidationError(_("计划量不能小于等于0"))
|
raise ValidationError(_("计划量不能小于等于0"))
|
||||||
|
|
||||||
@api.constrains('new_supply_method')
|
@api.constrains('supply_method')
|
||||||
def _check_new_supply_method(self):
|
def _check_supply_method(self):
|
||||||
product_name = []
|
product_name = []
|
||||||
|
product = []
|
||||||
for line in self:
|
for line in self:
|
||||||
if line.new_supply_method == 'purchase' and line.is_incoming_material:
|
if line.supply_method == 'purchase' and line.is_incoming_material:
|
||||||
product_name.append(line.product_id.display_name)
|
product_name.append(line.product_id.display_name)
|
||||||
|
if line.supply_method == 'automation' and line.manual_quotation:
|
||||||
|
product.append(line.product_id.display_name)
|
||||||
|
|
||||||
if product_name:
|
if product_name:
|
||||||
unique_product_names = list(set(product_name))
|
unique_product_names = list(set(product_name))
|
||||||
raise UserError('当前(%s)产品为客供料,不能选择外购' % ','.join(unique_product_names))
|
raise UserError('当前(%s)产品为客供料,不能选择外购' % ','.join(unique_product_names))
|
||||||
|
if product:
|
||||||
|
unique_product = list(set(product))
|
||||||
|
raise UserError('当前(%s)产品为人工编程,不能选择自动化产线加工' % ','.join(unique_product))
|
||||||
|
|
||||||
@api.depends('new_supply_method')
|
@api.depends('new_supply_method')
|
||||||
def _compute_custom_made_type(self):
|
def _compute_custom_made_type(self):
|
||||||
@@ -215,9 +222,8 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
@api.depends('sale_order_line_id.qty_to_deliver')
|
@api.depends('sale_order_line_id.qty_to_deliver')
|
||||||
def _compute_qty_to_deliver(self):
|
def _compute_qty_to_deliver(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
rounding = line.product_id.uom_id.rounding or 0.01
|
|
||||||
if float_compare(line.sale_order_line_id.qty_to_deliver, 0,
|
if float_compare(line.sale_order_line_id.qty_to_deliver, 0,
|
||||||
precision_rounding=rounding) == -1:
|
precision_rounding=line.product_id.uom_id.rounding) == -1:
|
||||||
line.qty_to_deliver = 0
|
line.qty_to_deliver = 0
|
||||||
else:
|
else:
|
||||||
line.qty_to_deliver = line.sale_order_line_id.qty_to_deliver
|
line.qty_to_deliver = line.sale_order_line_id.qty_to_deliver
|
||||||
@@ -285,11 +291,15 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
def _compute_material_check(self):
|
def _compute_material_check(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
if record.mrp_production_ids and record.mrp_production_ids.move_raw_ids:
|
if record.mrp_production_ids and record.mrp_production_ids.move_raw_ids:
|
||||||
|
# 获取完成的制造订单
|
||||||
|
done_manufacturing = record.mrp_production_ids.filtered(lambda mo: mo.state == 'done')
|
||||||
|
product_qty = sum(done_manufacturing.mapped('product_qty'))
|
||||||
|
# 需求数量-完成数量
|
||||||
|
product_uom_qty = record.plan_uom_qty - product_qty
|
||||||
total_reserved_availability = sum(
|
total_reserved_availability = sum(
|
||||||
record.mrp_production_ids.mapped('move_raw_ids.reserved_availability'))
|
record.mrp_production_ids.mapped('move_raw_ids.reserved_availability'))
|
||||||
rounding = record.product_id.uom_id.rounding or 0.01
|
if float_compare(total_reserved_availability, product_uom_qty,
|
||||||
if float_compare(total_reserved_availability, record.plan_uom_qty,
|
precision_rounding=record.product_id.uom_id.rounding) >= 0:
|
||||||
precision_rounding=rounding) >= 0:
|
|
||||||
record.material_check = '1' # 已齐套
|
record.material_check = '1' # 已齐套
|
||||||
else:
|
else:
|
||||||
record.material_check = '0' # 未齐套
|
record.material_check = '0' # 未齐套
|
||||||
@@ -343,9 +353,12 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
pro_plan.do_production_schedule()
|
pro_plan.do_production_schedule()
|
||||||
|
|
||||||
def update_sale_order_state(self):
|
def update_sale_order_state(self):
|
||||||
demand_plan = self.env['sf.demand.plan'].sudo().search([('sale_order_id', '=', self.sale_order_id.id)])
|
# demand_plan = self.env['sf.demand.plan'].sudo().search([('sale_order_id', '=', self.sale_order_id.id)])
|
||||||
demand_plan_state = demand_plan.filtered(lambda line: line.state != '40')
|
# demand_plan_state = demand_plan.filtered(lambda line: line.state != '40')
|
||||||
if not demand_plan_state:
|
production_demand_plan = self.env['sf.production.demand.plan'].sudo().search(
|
||||||
|
[('sale_order_id', '=', self.sale_order_id.id)])
|
||||||
|
production_demand_plan_state = production_demand_plan.filtered(lambda line: line.status in ('10', '20', '30'))
|
||||||
|
if not production_demand_plan_state:
|
||||||
# 修改销售订单为加工中
|
# 修改销售订单为加工中
|
||||||
self.sale_order_id.state = 'processing'
|
self.sale_order_id.state = 'processing'
|
||||||
|
|
||||||
@@ -364,11 +377,12 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
return action
|
return action
|
||||||
|
|
||||||
def button_action_print(self):
|
def button_action_print(self):
|
||||||
|
model_id = self.mapped('model_id')
|
||||||
return {
|
return {
|
||||||
'res_model': 'sf.demand.plan.print.wizard',
|
'res_model': 'sf.demand.plan.print.wizard',
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'name': _("打印"),
|
'name': _("打印"),
|
||||||
'domain': [('demand_plan_id', 'in', self.ids)],
|
'domain': [('model_id', 'in', model_id)],
|
||||||
'views': [[self.env.ref('sf_demand_plan.action_plan_print_tree').id, 'list']],
|
'views': [[self.env.ref('sf_demand_plan.action_plan_print_tree').id, 'list']],
|
||||||
'target': 'new',
|
'target': 'new',
|
||||||
}
|
}
|
||||||
@@ -581,20 +595,31 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
# programming_no = list(set(programming_mrp_production_ids))
|
# programming_no = list(set(programming_mrp_production_ids))
|
||||||
# numbers_str = "、".join(programming_no)
|
# numbers_str = "、".join(programming_no)
|
||||||
# raise ValidationError(f"编程单号:{numbers_str},请去云平台处理")
|
# raise ValidationError(f"编程单号:{numbers_str},请去云平台处理")
|
||||||
|
@api.model
|
||||||
def button_delete(self):
|
def unlink(self):
|
||||||
self.ensure_one()
|
for item in self:
|
||||||
if len(self.demand_plan_id.line_ids) == 1:
|
if item.status not in ('10', '20', '30'):
|
||||||
raise ValidationError(f"最后一条计划,不能删除!")
|
raise ValidationError(u'只能删除状态为【草稿,待确认,待工艺设计】的需求计划。')
|
||||||
self.unlink()
|
else:
|
||||||
|
super(SfProductionDemandPlan, item).unlink()
|
||||||
|
|
||||||
def button_batch_release_plan(self):
|
def button_batch_release_plan(self):
|
||||||
filtered_plan = self.filtered(lambda mo: mo.status == '30')
|
filtered_plan = self.filtered(lambda mo: mo.status == '30')
|
||||||
if not filtered_plan:
|
if not filtered_plan:
|
||||||
raise UserError(_("没有需要下达的计划!"))
|
raise UserError(_("没有需要下达的计划!"))
|
||||||
|
check_overdelivery_allowed = False
|
||||||
|
if not self.demand_plan_id.overdelivery_allowed:
|
||||||
|
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||||
|
if self.location_id.id == customer_location_id:
|
||||||
|
check_overdelivery_allowed = True
|
||||||
# 按产品分组并计算总数
|
# 按产品分组并计算总数
|
||||||
product_data = {}
|
product_data = {}
|
||||||
for plan in filtered_plan:
|
for plan in filtered_plan:
|
||||||
|
check_overdelivery_allowed = False
|
||||||
|
if not plan.demand_plan_id.overdelivery_allowed:
|
||||||
|
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||||
|
if plan.location_id.id == customer_location_id:
|
||||||
|
check_overdelivery_allowed = True
|
||||||
if plan.product_id not in product_data:
|
if plan.product_id not in product_data:
|
||||||
# 初始化产品数据,从产品上获取需求量
|
# 初始化产品数据,从产品上获取需求量
|
||||||
product_data[plan.product_id] = {
|
product_data[plan.product_id] = {
|
||||||
@@ -604,15 +629,23 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
|
|
||||||
# 累加计划数量
|
# 累加计划数量
|
||||||
product_data[plan.product_id]['plan_uom_qty'] += plan.plan_uom_qty
|
product_data[plan.product_id]['plan_uom_qty'] += plan.plan_uom_qty
|
||||||
|
product_data[plan.product_id]['overdelivery_allowed'] = check_overdelivery_allowed
|
||||||
# 检查需求超过计划数量的产品
|
# 检查需求超过计划数量的产品
|
||||||
warning_messages = []
|
warning_messages = []
|
||||||
|
error_messages = []
|
||||||
for product, data in product_data.items():
|
for product, data in product_data.items():
|
||||||
if data['plan_uom_qty'] > data['product_uom_qty']:
|
if data['overdelivery_allowed'] and float_compare(data['plan_uom_qty'], data['product_uom_qty'],precision_rounding=product.uom_id.rounding) == 1:
|
||||||
|
error_messages.append(f"您正在下达的产品 {product.display_name},已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
||||||
|
elif float_compare(data['plan_uom_qty'], data['product_uom_qty'],
|
||||||
|
precision_rounding=product.uom_id.rounding) == 1:
|
||||||
warning_messages.append(
|
warning_messages.append(
|
||||||
_("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") %
|
_("您正在下达的产品 %s,计划量%s,需求数量为%s,已超过需求数量") %
|
||||||
(product.display_name, data['plan_uom_qty'], data['product_uom_qty'])
|
(product.display_name, data['plan_uom_qty'], data['product_uom_qty'])
|
||||||
)
|
)
|
||||||
if warning_messages:
|
if error_messages:
|
||||||
|
error_message = "\n".join(error_messages)
|
||||||
|
raise ValidationError(error_message)
|
||||||
|
elif warning_messages:
|
||||||
warning_message = "\n".join(warning_messages)
|
warning_message = "\n".join(warning_messages)
|
||||||
return {
|
return {
|
||||||
'name': _('需求计划'),
|
'name': _('需求计划'),
|
||||||
@@ -629,9 +662,17 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
|
|
||||||
def button_release_plan(self):
|
def button_release_plan(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if not self.new_supply_method:
|
check_overdelivery_allowed = False
|
||||||
raise ValidationError(f"供货方式不能为空!")
|
if not self.demand_plan_id.overdelivery_allowed:
|
||||||
if self.plan_uom_qty > self.product_uom_qty:
|
customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers')
|
||||||
|
if self.location_id.id == customer_location_id:
|
||||||
|
check_overdelivery_allowed = True
|
||||||
|
if check_overdelivery_allowed:
|
||||||
|
if float_compare(self.plan_uom_qty, self.product_uom_qty,
|
||||||
|
precision_rounding=self.product_id.uom_id.rounding) == 1:
|
||||||
|
raise ValidationError(f"已禁止向合作伙伴/客户超量发货,请更换“补货原因”或将“可超量发货”设置为“是”。")
|
||||||
|
elif float_compare(self.plan_uom_qty, self.product_uom_qty,
|
||||||
|
precision_rounding=self.product_id.uom_id.rounding) == 1:
|
||||||
return {
|
return {
|
||||||
'name': _('需求计划'),
|
'name': _('需求计划'),
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
@@ -654,6 +695,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
self._action_launch_stock_rule()
|
self._action_launch_stock_rule()
|
||||||
if self.supply_method in ('automation', 'manual'):
|
if self.supply_method in ('automation', 'manual'):
|
||||||
self.write({'status': '50'})
|
self.write({'status': '50'})
|
||||||
|
self.update_sale_order_state()
|
||||||
else:
|
else:
|
||||||
self.write({'status': '60'})
|
self.write({'status': '60'})
|
||||||
self.update_sale_order_state()
|
self.update_sale_order_state()
|
||||||
@@ -690,9 +732,9 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
|
|
||||||
# 复制成品模板上的属性
|
# 复制成品模板上的属性
|
||||||
self.product_id.product_tmpl_id.copy_template(product_template_id)
|
self.product_id.product_tmpl_id.copy_template(product_template_id)
|
||||||
|
future_time = datetime.now() + timedelta(hours=8)
|
||||||
# 生成BOM单据编码
|
# 生成BOM单据编码
|
||||||
code = f"{self.product_id.default_code}-{bom_type}-{datetime.now().strftime('%Y%m%d%H%M%S')}"
|
code = f"{self.product_id.default_code}-{bom_type}-{future_time.strftime('%Y%m%d%H%M%S')}"
|
||||||
|
|
||||||
order_id = self.sale_order_id
|
order_id = self.sale_order_id
|
||||||
product = self.product_id
|
product = self.product_id
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
th[data-name=processing_time] + th::before{
|
/*.demand_plan_tree th[data-name=planned_start_date] + th::before{*/
|
||||||
content: '待执行单据';
|
/* content: '待执行单据';*/
|
||||||
line-height: 38px;
|
/* line-height: 38px;*/
|
||||||
}
|
/*}*/
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
<field name="model_id" optional="hide"/>
|
<field name="model_id" optional="hide"/>
|
||||||
<field name="part_name"/>
|
<field name="part_name"/>
|
||||||
<field name="part_number"/>
|
<field name="part_number"/>
|
||||||
|
<field name="manual_quotation" optional="hide"/>
|
||||||
<field name="is_incoming_material"/>
|
<field name="is_incoming_material"/>
|
||||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
<field name="readonly_custom_made_type" invisible="1"/>
|
<field name="readonly_custom_made_type" invisible="1"/>
|
||||||
@@ -31,13 +32,14 @@
|
|||||||
<field name="product_uom_qty"/>
|
<field name="product_uom_qty"/>
|
||||||
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
<field name="deadline_of_delivery"/>
|
<field name="deadline_of_delivery"/>
|
||||||
<field name="inventory_quantity_auto_apply"/>
|
<field name="inventory_quantity_auto_apply" optional="hide"/>
|
||||||
<field name="qty_delivered"/>
|
<field name="qty_delivered" optional="hide"/>
|
||||||
<field name="qty_to_deliver"/>
|
<field name="qty_to_deliver" optional="hide"/>
|
||||||
<field name="model_long"/>
|
<field name="model_long"/>
|
||||||
<field name="blank_type" optional="hide"/>
|
<field name="blank_type" optional="hide"/>
|
||||||
<field name="blank_precision"/>
|
<field name="blank_precision"/>
|
||||||
<field name="embryo_long"/>
|
<field name="embryo_long"/>
|
||||||
|
<field name="unit_number" optional="hide"/>
|
||||||
<field name="materials_id"/>
|
<field name="materials_id"/>
|
||||||
<field name="model_machining_precision"/>
|
<field name="model_machining_precision"/>
|
||||||
<field name="model_process_parameters_ids" widget="many2many_tags"/>
|
<field name="model_process_parameters_ids" widget="many2many_tags"/>
|
||||||
|
|||||||
@@ -14,12 +14,15 @@
|
|||||||
<sheet>
|
<sheet>
|
||||||
<group>
|
<group>
|
||||||
<group>
|
<group>
|
||||||
|
<field name="demand_plan_number"/>
|
||||||
<field name="product_id"/>
|
<field name="product_id"/>
|
||||||
<field name="part_name"/>
|
<field name="part_name"/>
|
||||||
<field name="part_number"/>
|
<field name="part_number"/>
|
||||||
<field name="materials_id"/>
|
<field name="materials_id"/>
|
||||||
<field name="blank_type"/>
|
<field name="blank_type"/>
|
||||||
<field name="embryo_long"/>
|
<field name="blank_precision"/>
|
||||||
|
<field name="embryo_long"/>
|
||||||
|
<field name="manual_quotation"/>
|
||||||
<field name="is_incoming_material"/>
|
<field name="is_incoming_material"/>
|
||||||
<field name="pending_qty"/>
|
<field name="pending_qty"/>
|
||||||
<field name="planned_qty"/>
|
<field name="planned_qty"/>
|
||||||
@@ -35,12 +38,14 @@
|
|||||||
<field name="model_machining_precision"/>
|
<field name="model_machining_precision"/>
|
||||||
<field name="inventory_quantity_auto_apply"/>
|
<field name="inventory_quantity_auto_apply"/>
|
||||||
<field name="priority" attrs="{'readonly': [('state', 'in', ('40','50'))]}"/>
|
<field name="priority" attrs="{'readonly': [('state', 'in', ('40','50'))]}"/>
|
||||||
|
<field name="overdelivery_allowed"/>
|
||||||
|
<field name="origin"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<notebook>
|
<notebook>
|
||||||
<page string="计划">
|
<page string="计划">
|
||||||
<field name="line_ids" attrs="{'readonly': [('state', 'in', ('40','50'))]}">
|
<field name="line_ids" attrs="{'invisible': [('state', 'in', ('40','50'))]}">
|
||||||
<tree editable="bottom" delete="false">
|
<tree editable="bottom" create="false" delete="false">
|
||||||
<field name="status"/>
|
<field name="status"/>
|
||||||
<field name="readonly_custom_made_type" invisible="1"/>
|
<field name="readonly_custom_made_type" invisible="1"/>
|
||||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
@@ -51,6 +56,7 @@
|
|||||||
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
||||||
<field name="location_id" optional="hide"/>
|
<field name="location_id" optional="hide"/>
|
||||||
<field name="bom_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="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
<field name="blank_arrival_date"/>
|
<field name="blank_arrival_date"/>
|
||||||
<field name="finished_product_arrival_date"/>
|
<field name="finished_product_arrival_date"/>
|
||||||
@@ -69,10 +75,39 @@
|
|||||||
class="btn-primary"
|
class="btn-primary"
|
||||||
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||||
/>
|
/>
|
||||||
<button name="button_delete" type="object" string="删除"
|
</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"
|
class="btn-primary"
|
||||||
attrs="{'invisible': [('status', 'not in', ('10','20','30'))]}"
|
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
|
||||||
confirm='是否确认删除?'/>
|
/>
|
||||||
|
<button name="button_release_production" type="object" string="下发生产"
|
||||||
|
class="btn-primary"
|
||||||
|
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||||
|
/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</page>
|
</page>
|
||||||
|
|||||||
@@ -9,11 +9,6 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
|||||||
_name = 'sf.demand.plan.print.wizard'
|
_name = 'sf.demand.plan.print.wizard'
|
||||||
_description = u'打印向导'
|
_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')
|
model_id = fields.Char('模型ID')
|
||||||
filename_url = fields.Char('文件名/URL')
|
filename_url = fields.Char('文件名/URL')
|
||||||
type = fields.Selection([
|
type = fields.Selection([
|
||||||
@@ -25,7 +20,7 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
|||||||
('success', '成功'),
|
('success', '成功'),
|
||||||
('fail', '失败'),
|
('fail', '失败'),
|
||||||
], string='状态', default='not_start')
|
], 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('程序单')
|
cnc_worksheet = fields.Binary('程序单')
|
||||||
|
|
||||||
@@ -44,14 +39,17 @@ class SfDemandPlanPrintWizard(models.TransientModel):
|
|||||||
# 执行打印
|
# 执行打印
|
||||||
self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
|
self.env['jikimo.printing'].sudo().print_pdf(pdf_data)
|
||||||
record.status = 'success'
|
record.status = 'success'
|
||||||
t_part, c_part = record.demand_plan_id.print_count.split('C')
|
production_demand_plan_id = self.env['sf.production.demand.plan'].sudo().search(
|
||||||
t_num = int(t_part[1:])
|
[('model_id', '=', record.model_id)])
|
||||||
c_num = int(c_part)
|
for production_demand_plan in production_demand_plan_id:
|
||||||
if record.type == '1':
|
t_part, c_part = production_demand_plan.print_count.split('C')
|
||||||
t_num += 1
|
t_num = int(t_part[1:])
|
||||||
elif record.type == '2':
|
c_num = int(c_part)
|
||||||
c_num += 1
|
if record.type == '1':
|
||||||
record.demand_plan_id.print_count = f"T{t_num}C{c_num}"
|
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({
|
success_records.append({
|
||||||
'filename_url': record.filename_url,
|
'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(
|
demand_plan_print = self.env['sf.demand.plan.print.wizard'].sudo().search(
|
||||||
[('model_id', '=', record.model_id), ('type', '=', '2')])
|
[('model_id', '=', record.model_id), ('type', '=', '2')])
|
||||||
if demand_plan_print:
|
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})
|
{'cnc_worksheet': record.cnc_worksheet, 'filename_url': record.cnc_worksheet_name})
|
||||||
else:
|
else:
|
||||||
demand_plan = self.env['sf.production.demand.plan'].sudo().search(
|
wizard_vals = {
|
||||||
[('product_id', '=', record.product_id.id)])
|
'model_id': record.model_id,
|
||||||
if demand_plan:
|
'type': '2',
|
||||||
wizard_vals = {
|
'cnc_worksheet': record.cnc_worksheet,
|
||||||
'demand_plan_id': demand_plan.id,
|
'filename_url': record.cnc_worksheet_name
|
||||||
'model_id': demand_plan.model_id,
|
}
|
||||||
'type': '2',
|
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
||||||
'cnc_worksheet': record.cnc_worksheet,
|
|
||||||
'filename_url': record.cnc_worksheet_name
|
|
||||||
}
|
|
||||||
self.env['sf.demand.plan.print.wizard'].sudo().create(wizard_vals)
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -6,50 +6,50 @@ from odoo import models, fields, api, _
|
|||||||
class StockRuleInherit(models.Model):
|
class StockRuleInherit(models.Model):
|
||||||
_inherit = 'stock.rule'
|
_inherit = 'stock.rule'
|
||||||
|
|
||||||
@api.model
|
# @api.model
|
||||||
def _run_buy(self, procurements):
|
# def _run_buy(self, procurements):
|
||||||
# 判断补货组的采购类型
|
# # 判断补货组的采购类型
|
||||||
procurements_group = {'standard': [], 'outsourcing': []}
|
# procurements_group = {'standard': [], 'outsourcing': []}
|
||||||
for procurement, rule in procurements:
|
# for procurement, rule in procurements:
|
||||||
is_outsourcing = False
|
# is_outsourcing = False
|
||||||
product = procurement.product_id
|
# product = procurement.product_id
|
||||||
# 获取主 BOM
|
# # 获取主 BOM
|
||||||
bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)], limit=1)
|
# bom = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)], limit=1)
|
||||||
|
#
|
||||||
if bom:
|
# if bom:
|
||||||
# 遍历 BOM 中的组件(即坯料等)
|
# # 遍历 BOM 中的组件(即坯料等)
|
||||||
for line in bom.bom_line_ids:
|
# for line in bom.bom_line_ids:
|
||||||
raw_material = line.product_id
|
# raw_material = line.product_id
|
||||||
# 检查路线
|
# # 检查路线
|
||||||
for route in raw_material.route_ids:
|
# for route in raw_material.route_ids:
|
||||||
# print('route.name:', route.name)
|
# # print('route.name:', route.name)
|
||||||
if route.name == '按订单补给外包商':
|
# if route.name == '按订单补给外包商':
|
||||||
is_outsourcing = True
|
# is_outsourcing = True
|
||||||
|
#
|
||||||
if is_outsourcing:
|
# if is_outsourcing:
|
||||||
procurements_group['outsourcing'].append((procurement, rule))
|
# procurements_group['outsourcing'].append((procurement, rule))
|
||||||
else:
|
# else:
|
||||||
procurements_group['standard'].append((procurement, rule))
|
# procurements_group['standard'].append((procurement, rule))
|
||||||
|
#
|
||||||
for key, value in procurements_group.items():
|
# for key, value in procurements_group.items():
|
||||||
super(StockRuleInherit, self)._run_buy(value)
|
# super(StockRuleInherit, self)._run_buy(value)
|
||||||
|
#
|
||||||
if key == 'outsourcing':
|
# if key == 'outsourcing':
|
||||||
for procurement, rule in value:
|
# for procurement, rule in value:
|
||||||
supplier = procurement.values.get('supplier')
|
# supplier = procurement.values.get('supplier')
|
||||||
if supplier:
|
# if supplier:
|
||||||
domain = rule._make_po_get_domain(procurement.company_id, procurement.values,
|
# domain = rule._make_po_get_domain(procurement.company_id, procurement.values,
|
||||||
supplier.partner_id)
|
# supplier.partner_id)
|
||||||
logging.info("domain=============: %s", domain)
|
# logging.info("domain=============: %s", domain)
|
||||||
po = self.env['purchase.order'].sudo().search([
|
# po = self.env['purchase.order'].sudo().search([
|
||||||
('partner_id', '=', supplier.partner_id.id),
|
# ('partner_id', '=', supplier.partner_id.id),
|
||||||
('company_id', '=', procurement.company_id.id), # 保证公司一致
|
# ('company_id', '=', procurement.company_id.id), # 保证公司一致
|
||||||
('origin', 'like', procurement.origin), # 根据来源匹配
|
# ('origin', 'like', procurement.origin), # 根据来源匹配
|
||||||
('state', '=', 'draft') # 状态为草稿
|
# ('state', '=', 'draft') # 状态为草稿
|
||||||
], limit=1)
|
# ], limit=1)
|
||||||
logging.info("po=: %s", po)
|
# logging.info("po=: %s", po)
|
||||||
if po:
|
# if po:
|
||||||
po.write({'purchase_type': 'outsourcing'})
|
# po.write({'purchase_type': 'outsourcing'})
|
||||||
|
|
||||||
# # 首先调用父类的 _run_buy 方法,以保留原有逻辑
|
# # 首先调用父类的 _run_buy 方法,以保留原有逻辑
|
||||||
# super(StockRuleInherit, self)._run_buy(procurements)
|
# super(StockRuleInherit, self)._run_buy(procurements)
|
||||||
|
|||||||
@@ -217,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[
|
origin_production = production.move_dest_ids and production.move_dest_ids[
|
||||||
0].raw_material_production_id or False
|
0].raw_material_production_id or False
|
||||||
orderpoint = production.orderpoint_id
|
orderpoint = production.orderpoint_id
|
||||||
@@ -442,7 +443,7 @@ class ProductionLot(models.Model):
|
|||||||
@api.model
|
@api.model
|
||||||
def _get_next_serial(self, company, product):
|
def _get_next_serial(self, company, product):
|
||||||
"""Return the next serial number to be attributed to the 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(
|
last_serial = self.env['stock.lot'].search(
|
||||||
[('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'ilike', product.name)],
|
[('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'ilike', product.name)],
|
||||||
limit=1, order='name desc')
|
limit=1, order='name desc')
|
||||||
@@ -453,7 +454,9 @@ class ProductionLot(models.Model):
|
|||||||
return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name if (
|
return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name if (
|
||||||
not move_line_id or
|
not move_line_id or
|
||||||
(last_serial and last_serial.name > move_line_id.lot_name)) else move_line_id.lot_name, 2)[1]
|
(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')
|
qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from . import ftp_operate
|
from . import ftp_operate
|
||||||
from . import res_config_setting
|
from . import res_config_setting
|
||||||
from . import sync_common
|
from . import sync_common
|
||||||
from . import order_price
|
from . import order_price
|
||||||
@@ -1506,149 +1506,149 @@ class SyncMulti_Mounting_Type(models.Model):
|
|||||||
raise ValidationError("联装类型认证未通过")
|
raise ValidationError("联装类型认证未通过")
|
||||||
|
|
||||||
|
|
||||||
class SyncFixtureModel(models.Model):
|
# class SyncFixtureModel(models.Model):
|
||||||
_inherit = 'sf.fixture.model'
|
# _inherit = 'sf.fixture.model'
|
||||||
_description = '同步夹具型号列表'
|
# _description = '同步夹具型号列表'
|
||||||
|
|
||||||
url = '/api/fixture_model/list'
|
# url = '/api/fixture_model/list'
|
||||||
|
|
||||||
# 定时同步夹具型号列表
|
# # 定时同步夹具型号列表
|
||||||
def sync_fixture_model_yesterday(self):
|
# def sync_fixture_model_yesterday(self):
|
||||||
config = self.env['res.config.settings'].get_values()
|
# config = self.env['res.config.settings'].get_values()
|
||||||
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
# headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||||
strUrl = config['sf_url'] + self.url
|
# strUrl = config['sf_url'] + self.url
|
||||||
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
# r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||||
r = r.json()
|
# r = r.json()
|
||||||
result = json.loads(r['result'])
|
# result = json.loads(r['result'])
|
||||||
if result['status'] == 1:
|
# if result['status'] == 1:
|
||||||
if result.get('fixture_model_yesterday_list'):
|
# if result.get('fixture_model_yesterday_list'):
|
||||||
for item in result['fixture_model_yesterday_list']:
|
# for item in result['fixture_model_yesterday_list']:
|
||||||
if item:
|
# if item:
|
||||||
fixture_model = self.search([("code", '=', item['code']), ('active', 'in', [True, False])])
|
# fixture_model = self.search([("code", '=', item['code']), ('active', 'in', [True, False])])
|
||||||
val = {
|
# val = {
|
||||||
"name": item['name'],
|
# "name": item['name'],
|
||||||
"code": item['code'],
|
# "code": item['code'],
|
||||||
"fixture_material_id": self.env['sf.fixture.material'].search(
|
# "fixture_material_id": self.env['sf.fixture.material'].search(
|
||||||
[('code', '=', item['fixture_material_code'])]).id,
|
# [('code', '=', item['fixture_material_code'])]).id,
|
||||||
"multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
|
# "multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
|
||||||
[('code', '=', item['multi_mounting_type_code'])]).id,
|
# [('code', '=', item['multi_mounting_type_code'])]).id,
|
||||||
"brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_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']),
|
# "model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
|
||||||
"status": item['status'],
|
# "status": item['status'],
|
||||||
"active": item['active'],
|
# "active": item['active'],
|
||||||
}
|
# }
|
||||||
if not fixture_model:
|
# if not fixture_model:
|
||||||
self.create(val)
|
# self.create(val)
|
||||||
else:
|
# else:
|
||||||
fixture_model.write(val)
|
# fixture_model.write(val)
|
||||||
|
|
||||||
else:
|
# else:
|
||||||
raise ValidationError("夹具型号认证未通过")
|
# raise ValidationError("夹具型号认证未通过")
|
||||||
|
|
||||||
# 定时同步所有夹具型号列表
|
# # 定时同步所有夹具型号列表
|
||||||
def sync_all_fixture_model(self):
|
# def sync_all_fixture_model(self):
|
||||||
config = self.env['res.config.settings'].get_values()
|
# config = self.env['res.config.settings'].get_values()
|
||||||
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
# headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||||
strUrl = config['sf_url'] + self.url
|
# strUrl = config['sf_url'] + self.url
|
||||||
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
# r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||||
r = r.json()
|
# r = r.json()
|
||||||
result = json.loads(r['result'])
|
# result = json.loads(r['result'])
|
||||||
# print('result:%s' % result)
|
# # print('result:%s' % result)
|
||||||
if result['status'] == 1:
|
# if result['status'] == 1:
|
||||||
if result.get('fixture_model_all_list'):
|
# if result.get('fixture_model_all_list'):
|
||||||
for item in result['fixture_model_all_list']:
|
# for item in result['fixture_model_all_list']:
|
||||||
if item:
|
# if item:
|
||||||
fixture_model = self.search([('code', '=', item['code']), ('active', 'in', [True, False])])
|
# fixture_model = self.search([('code', '=', item['code']), ('active', 'in', [True, False])])
|
||||||
val = {
|
# val = {
|
||||||
"name": item['name'],
|
# "name": item['name'],
|
||||||
"code": item['code'],
|
# "code": item['code'],
|
||||||
"fixture_material_id": self.env['sf.fixture.material'].search(
|
# "fixture_material_id": self.env['sf.fixture.material'].search(
|
||||||
[('code', '=', item['fixture_material_code'])]).id,
|
# [('code', '=', item['fixture_material_code'])]).id,
|
||||||
"multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
|
# "multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
|
||||||
[('code', '=', item['multi_mounting_type_code'])]).id,
|
# [('code', '=', item['multi_mounting_type_code'])]).id,
|
||||||
"brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_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']),
|
# "model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
|
||||||
"status": item['status'],
|
# "status": item['status'],
|
||||||
"active": item['active'],
|
# "active": item['active'],
|
||||||
}
|
# }
|
||||||
if not fixture_model:
|
# if not fixture_model:
|
||||||
self.create(val)
|
# self.create(val)
|
||||||
else:
|
# else:
|
||||||
fixture_model.write(val)
|
# fixture_model.write(val)
|
||||||
else:
|
# else:
|
||||||
raise ValidationError("夹具型号认证未通过")
|
# raise ValidationError("夹具型号认证未通过")
|
||||||
|
|
||||||
|
|
||||||
class SyncfixtureMaterialsBasicParameters(models.Model):
|
# class SyncfixtureMaterialsBasicParameters(models.Model):
|
||||||
_inherit = 'sf.fixture.materials.basic.parameters'
|
# _inherit = 'sf.fixture.materials.basic.parameters'
|
||||||
_description = '同步夹具型号基本参数列表'
|
# _description = '同步夹具型号基本参数列表'
|
||||||
|
|
||||||
url = '/api/fixture_parameters/list'
|
# url = '/api/fixture_parameters/list'
|
||||||
|
|
||||||
# 定时同步夹具型号基本信息
|
# # 定时同步夹具型号基本信息
|
||||||
def sync_fixture_materials_basic_parameters_yesterday(self):
|
# def sync_fixture_materials_basic_parameters_yesterday(self):
|
||||||
config = self.env['res.config.settings'].get_values()
|
# config = self.env['res.config.settings'].get_values()
|
||||||
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
# headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||||
strUrl = config['sf_url'] + self.url
|
# strUrl = config['sf_url'] + self.url
|
||||||
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
# r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||||
r = r.json()
|
# r = r.json()
|
||||||
result = json.loads(r['result'])
|
# result = json.loads(r['result'])
|
||||||
if result['status'] == 1:
|
# if result['status'] == 1:
|
||||||
if result.get('fixture_parameters_yesterday_list'):
|
# if result.get('fixture_parameters_yesterday_list'):
|
||||||
all_list = result.get('fixture_parameters_yesterday_list')
|
# all_list = result.get('fixture_parameters_yesterday_list')
|
||||||
if all_list.get('zero_chuck_all_list'):
|
# if all_list.get('zero_chuck_all_list'):
|
||||||
self._write_or_create(all_list.get('zero_chuck_yesterday_list'), '零点卡盘')
|
# self._write_or_create(all_list.get('zero_chuck_yesterday_list'), '零点卡盘')
|
||||||
if all_list.get('zero_tray_all_list'):
|
# if all_list.get('zero_tray_all_list'):
|
||||||
self._write_or_create(all_list.get('zero_tray_yesterday_list'), '零点托盘')
|
# self._write_or_create(all_list.get('zero_tray_yesterday_list'), '零点托盘')
|
||||||
if all_list.get('pneumatic_fixture_all_list'):
|
# if all_list.get('pneumatic_fixture_all_list'):
|
||||||
self._write_or_create(all_list.get('pneumatic_fixture_yesterday_list'), '气动夹具')
|
# self._write_or_create(all_list.get('pneumatic_fixture_yesterday_list'), '气动夹具')
|
||||||
if all_list.get('jaw_vice_all_list'):
|
# if all_list.get('jaw_vice_all_list'):
|
||||||
self._write_or_create(all_list.get('jaw_vice_yesterday_list'), '虎钳夹具')
|
# self._write_or_create(all_list.get('jaw_vice_yesterday_list'), '虎钳夹具')
|
||||||
if all_list.get('magnet_fixture_all_list'):
|
# if all_list.get('magnet_fixture_all_list'):
|
||||||
self._write_or_create(all_list.get('magnet_fixture_yesterday_list'), '磁吸夹具')
|
# self._write_or_create(all_list.get('magnet_fixture_yesterday_list'), '磁吸夹具')
|
||||||
if all_list.get('adapter_board_all_list'):
|
# if all_list.get('adapter_board_all_list'):
|
||||||
self._write_or_create(all_list.get('adapter_board_yesterday_list'), '转接板(锁板)夹具')
|
# self._write_or_create(all_list.get('adapter_board_yesterday_list'), '转接板(锁板)夹具')
|
||||||
if all_list.get('scroll_chuck_all_list'):
|
# if all_list.get('scroll_chuck_all_list'):
|
||||||
self._write_or_create(all_list.get('scroll_chuck_yesterday_list'), '三爪卡盘')
|
# self._write_or_create(all_list.get('scroll_chuck_yesterday_list'), '三爪卡盘')
|
||||||
else:
|
# else:
|
||||||
raise ValidationError("夹具型号基本参数认证未通过")
|
# raise ValidationError("夹具型号基本参数认证未通过")
|
||||||
|
|
||||||
# 定时同步所有夹具型号基本信息
|
# # 定时同步所有夹具型号基本信息
|
||||||
def sync_all_fixture_materials_basic_parameters(self):
|
# def sync_all_fixture_materials_basic_parameters(self):
|
||||||
config = self.env['res.config.settings'].get_values()
|
# config = self.env['res.config.settings'].get_values()
|
||||||
headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
# headers = Common.get_headers(self, config['token'], config['sf_secret_key'])
|
||||||
strUrl = config['sf_url'] + self.url
|
# strUrl = config['sf_url'] + self.url
|
||||||
r = requests.post(strUrl, json={}, data=None, headers=headers)
|
# r = requests.post(strUrl, json={}, data=None, headers=headers)
|
||||||
r = r.json()
|
# r = r.json()
|
||||||
result = json.loads(r['result'])
|
# result = json.loads(r['result'])
|
||||||
if result['status'] == 1:
|
# if result['status'] == 1:
|
||||||
if result.get('fixture_parameters_all_list'):
|
# if result.get('fixture_parameters_all_list'):
|
||||||
all_list = result.get('fixture_parameters_all_list')
|
# all_list = result.get('fixture_parameters_all_list')
|
||||||
if all_list.get('zero_chuck_all_list'):
|
# if all_list.get('zero_chuck_all_list'):
|
||||||
self._write_or_create(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'):
|
# if all_list.get('zero_tray_all_list'):
|
||||||
self._write_or_create(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'):
|
# if all_list.get('pneumatic_fixture_all_list'):
|
||||||
self._write_or_create(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'):
|
# if all_list.get('jaw_vice_all_list'):
|
||||||
self._write_or_create(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'):
|
# if all_list.get('magnet_fixture_all_list'):
|
||||||
self._write_or_create(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'):
|
# if all_list.get('adapter_board_all_list'):
|
||||||
self._write_or_create(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'):
|
# if all_list.get('scroll_chuck_all_list'):
|
||||||
self._write_or_create(all_list.get('scroll_chuck_all_list'), '三爪卡盘')
|
# self._write_or_create(all_list.get('scroll_chuck_all_list'), '三爪卡盘')
|
||||||
else:
|
# else:
|
||||||
raise ValidationError("夹具型号基本参数认证未通过")
|
# raise ValidationError("夹具型号基本参数认证未通过")
|
||||||
|
|
||||||
def _write_or_create(self, fixture_parameters_list, material_name):
|
# def _write_or_create(self, fixture_parameters_list, material_name):
|
||||||
for item in fixture_parameters_list:
|
# for item in fixture_parameters_list:
|
||||||
if item:
|
# if item:
|
||||||
basic_parameters = self.search([('code', '=', item.get('code')), ('active', 'in', [True, False])])
|
# basic_parameters = self.search([('code', '=', item.get('code')), ('active', 'in', [True, False])])
|
||||||
if not basic_parameters:
|
# if not basic_parameters:
|
||||||
self.create(self._get_basic_parameters_list(item, material_name))
|
# self.create(self._get_basic_parameters_list(item, material_name))
|
||||||
else:
|
# else:
|
||||||
basic_parameters.write(self._get_basic_parameters_list(item, material_name))
|
# basic_parameters.write(self._get_basic_parameters_list(item, material_name))
|
||||||
|
|
||||||
|
|
||||||
class SyncFunctionalFixtureType(models.Model):
|
class SyncFunctionalFixtureType(models.Model):
|
||||||
@@ -3230,4 +3230,109 @@ class EmbryoRedundancySync(models.Model):
|
|||||||
"height": item['height'],
|
"height": item['height'],
|
||||||
"active": item['active'],
|
"active": item['active'],
|
||||||
"remark": item['remark'],
|
"remark": item['remark'],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# ✅ Redis 无数据时,请求 MRS 端刷新 Redis 缓存
|
||||||
|
if not all_list:
|
||||||
|
config = self.env['res.config.settings'].get_values()
|
||||||
|
headers = Common.get_headers(config['token'], config['sf_secret_key'])
|
||||||
|
refresh_url = config['mrs_url'] + '/api/refresh_redis/fixture_param'
|
||||||
|
|
||||||
|
try:
|
||||||
|
res = requests.post(refresh_url, headers=headers, json={}, timeout=10)
|
||||||
|
res.raise_for_status()
|
||||||
|
except Exception as e:
|
||||||
|
raise ValidationError(f"Redis 无数据,MRS 缓存刷新失败: {str(e)}")
|
||||||
|
|
||||||
|
# 再次尝试从 Redis 获取
|
||||||
|
all_list = rc.get_json(key)
|
||||||
|
if not all_list:
|
||||||
|
raise ValidationError("Redis 刷新后仍无数据,无法同步夹具基本参数")
|
||||||
|
|
||||||
|
# ✅ 同步函数作为局部函数定义在方法体内部
|
||||||
|
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'), '磁吸托盘')
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# ✅ Redis 没数据时,请求 MRS 接口刷新
|
||||||
|
if not all_list:
|
||||||
|
config = self.env['res.config.settings'].get_values()
|
||||||
|
headers = Common.get_headers(config['token'], config['sf_secret_key'])
|
||||||
|
refresh_url = config['mrs_url'] + '/api/refresh_redis/fixture_model'
|
||||||
|
|
||||||
|
try:
|
||||||
|
res = requests.post(refresh_url, headers=headers, json={}, timeout=10)
|
||||||
|
res.raise_for_status()
|
||||||
|
except Exception as e:
|
||||||
|
raise ValidationError(f"Redis 无数据,MRS 刷新失败: {str(e)}")
|
||||||
|
|
||||||
|
# 再次尝试获取 Redis
|
||||||
|
all_list = rc.get_json(key)
|
||||||
|
if not all_list:
|
||||||
|
raise ValidationError("刷新后仍无 Redis 数据,无法同步夹具型号")
|
||||||
|
|
||||||
|
# ✅ 开始同步夹具型号
|
||||||
|
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)
|
||||||
@@ -45759,6 +45759,11 @@ msgstr ""
|
|||||||
msgid "热处理"
|
msgid "热处理"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: sf_base
|
||||||
|
#: model:ir.model.fields,field_description:sf_base.field_sf_materials_model__need_m
|
||||||
|
msgid "是否磁吸"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#. module: sf_base
|
#. module: sf_base
|
||||||
#: model:ir.model.fields,field_description:sf_base.field_sf_materials_model__mf_materia_post
|
#: model:ir.model.fields,field_description:sf_base.field_sf_materials_model__mf_materia_post
|
||||||
msgid "热处理后密度"
|
msgid "热处理后密度"
|
||||||
|
|||||||
Reference in New Issue
Block a user