Compare commits
7 Commits
feature/需求
...
feature/搜索
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4225a8fe1b | ||
|
|
a828c823dd | ||
|
|
9cf2bac9c6 | ||
|
|
38109028d4 | ||
|
|
cf16a9dd59 | ||
|
|
1b0dd96b40 | ||
|
|
2c52372b0a |
@@ -2,13 +2,14 @@ import re
|
|||||||
import ast
|
import ast
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
from odoo.tools import float_compare
|
||||||
|
|
||||||
|
|
||||||
class PurchaseRequest(models.Model):
|
class PurchaseRequest(models.Model):
|
||||||
_inherit = 'purchase.request'
|
_inherit = 'purchase.request'
|
||||||
_description = '采购申请'
|
_description = '采购申请'
|
||||||
|
|
||||||
# 为state添加取消状态
|
# 为state添加取消状态
|
||||||
state = fields.Selection(
|
state = fields.Selection(
|
||||||
selection_add=[('cancel', '已取消')],
|
selection_add=[('cancel', '已取消')],
|
||||||
ondelete={'cancel': 'set default'} # 添加 ondelete 策略
|
ondelete={'cancel': 'set default'} # 添加 ondelete 策略
|
||||||
@@ -36,45 +37,48 @@ class PurchaseRequest(models.Model):
|
|||||||
lines = self.mapped("line_ids.purchase_lines.order_id")
|
lines = self.mapped("line_ids.purchase_lines.order_id")
|
||||||
# 采购单产品和数量
|
# 采购单产品和数量
|
||||||
product_summary = {}
|
product_summary = {}
|
||||||
|
product_rounding = {}
|
||||||
if lines:
|
if lines:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
for line_item in line.order_line:
|
for line_item in line.order_line:
|
||||||
product_id = line_item.product_id.id
|
if line_item.state == 'purchase':
|
||||||
qty = line_item.product_qty
|
product_id = line_item.product_id.id
|
||||||
if product_id in product_summary:
|
qty = line_item.product_qty
|
||||||
product_summary[product_id] += qty
|
product_rounding[product_id] = line_item.product_id.uom_id.rounding
|
||||||
else:
|
if product_id in product_summary:
|
||||||
product_summary[product_id] = qty
|
product_summary[product_id] += qty
|
||||||
|
else:
|
||||||
|
product_summary[product_id] = qty
|
||||||
|
|
||||||
# 校验产品数量
|
# 校验产品数量
|
||||||
discrepancies = []
|
discrepancies = []
|
||||||
for product_id, qty in product_qty_map.items():
|
for product_id, qty in product_qty_map.items():
|
||||||
if product_id in product_summary:
|
if product_id in product_summary:
|
||||||
if product_summary[product_id] != qty:
|
if float_compare(product_summary[product_id], qty, precision_rounding=product_rounding[product_id]) < 0:
|
||||||
discrepancies.append((product_id, qty, product_summary[product_id]))
|
discrepancies.append((product_id, qty, product_summary[product_id]))
|
||||||
else:
|
else:
|
||||||
discrepancies.append((product_id, qty, 0))
|
discrepancies.append((product_id, qty, 0))
|
||||||
|
|
||||||
if discrepancies:
|
if discrepancies:
|
||||||
# 弹出提示框
|
# 弹出提示框
|
||||||
message = "产品数量不一致:\n"
|
message = "产品与采购数量不一致:\n"
|
||||||
for product_id, required_qty, order_qty in discrepancies:
|
for product_id, required_qty, order_qty in discrepancies:
|
||||||
product_name = self.env['product.product'].browse(product_id).display_name # 获取产品名称
|
product_name = self.env['product.product'].browse(product_id).display_name # 获取产品名称
|
||||||
message += f"产品 {product_name},需求数量 {required_qty},关联采购订单数量 {order_qty}(含询价状态)\n"
|
message += f"产品 {product_name},需求数量 {required_qty},关联采购订单确认的数量 {order_qty}。\n"
|
||||||
# 添加确认框
|
# 添加确认框
|
||||||
message += "确认关闭?"
|
message += "确认关闭?"
|
||||||
return {
|
return {
|
||||||
'name': _('采购申请'),
|
'name': _('采购申请'),
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'views': [(self.env.ref(
|
'views': [(self.env.ref(
|
||||||
'jikimo_purchase_request.purchase_request_wizard_wizard_form_view').id,
|
'jikimo_purchase_request.purchase_request_wizard_wizard_form_view').id,
|
||||||
'form')],
|
'form')],
|
||||||
'res_model': 'purchase.request.wizard',
|
'res_model': 'purchase.request.wizard',
|
||||||
'target': 'new',
|
'target': 'new',
|
||||||
'context': {
|
'context': {
|
||||||
'default_purchase_request_id': self.id,
|
'default_purchase_request_id': self.id,
|
||||||
'default_message': message,
|
'default_message': message,
|
||||||
}}
|
}}
|
||||||
return super(PurchaseRequest, self).button_done()
|
return super(PurchaseRequest, self).button_done()
|
||||||
|
|
||||||
|
|
||||||
@@ -96,7 +100,8 @@ class PurchaseRequestLine(models.Model):
|
|||||||
('outsourcing', "委外加工"),
|
('outsourcing', "委外加工"),
|
||||||
], string='供货方式', compute='_compute_supply_method', store=True)
|
], string='供货方式', compute='_compute_supply_method', store=True)
|
||||||
|
|
||||||
purchase_request_count = fields.Integer(string='采购申请数量', compute='_compute_purchase_request_count', readonly=True)
|
purchase_request_count = fields.Integer(string='采购申请数量', compute='_compute_purchase_request_count',
|
||||||
|
readonly=True)
|
||||||
purchase_count = fields.Integer(string="采购订单数量", compute="_compute_purchase_count", readonly=True)
|
purchase_count = fields.Integer(string="采购订单数量", compute="_compute_purchase_count", readonly=True)
|
||||||
|
|
||||||
@api.depends("purchase_lines")
|
@api.depends("purchase_lines")
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//button[@name='button_done']" position="attributes">
|
<xpath expr="//button[@name='button_done']" position="attributes">
|
||||||
<attribute name="class"/>
|
<attribute name="class"/>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//button[@name='button_in_progress']" position="attributes">
|
||||||
|
<attribute name="invisible">1</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//button[@name='button_in_progress']/following-sibling::button[1]" position="attributes">
|
<xpath expr="//button[@name='button_in_progress']/following-sibling::button[1]" position="attributes">
|
||||||
<attribute name="class">oe_highlight</attribute>
|
<attribute name="class">oe_highlight</attribute>
|
||||||
|
|||||||
@@ -227,22 +227,30 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
# finish_move.move_dest_ids.move_line_ids.reserved_uom_qty = 0
|
# finish_move.move_dest_ids.move_line_ids.reserved_uom_qty = 0
|
||||||
else:
|
else:
|
||||||
next_workorder = sorted_workorders[position + 1]
|
next_workorder = sorted_workorders[position + 1]
|
||||||
next_state = next_workorder.state
|
# 持续获取下一个工单,直到找到一个不是返工的工单
|
||||||
if next_state not in ['pending', 'waiting', 'ready']:
|
while next_workorder and next_workorder.state == 'rework':
|
||||||
raise UserError('下工序已经开始,无法回退')
|
position += 1
|
||||||
if next_workorder.is_subcontract:
|
if position + 1 < len(sorted_workorders):
|
||||||
next_workorder.picking_ids.write({'state': 'waiting'})
|
next_workorder = sorted_workorders[position + 1]
|
||||||
next_workorder.state = 'pending'
|
|
||||||
self.time_ids.date_end = None
|
|
||||||
cur_workorder.state = 'progress'
|
|
||||||
cur_workorder.production_id.state = 'progress'
|
|
||||||
quality_check = self.env['quality.check'].search(
|
|
||||||
[('workorder_id', '=', self.id)])
|
|
||||||
for check_order in quality_check:
|
|
||||||
if check_order.point_id.is_inspect:
|
|
||||||
check_order.quality_state = 'waiting'
|
|
||||||
else:
|
else:
|
||||||
check_order.quality_state = 'none'
|
next_workorder = None
|
||||||
|
if next_workorder:
|
||||||
|
next_state = next_workorder.state
|
||||||
|
if next_state not in ['pending', 'waiting', 'ready']:
|
||||||
|
raise UserError('下工序已经开始,无法回退')
|
||||||
|
if next_workorder.is_subcontract:
|
||||||
|
next_workorder.picking_ids.write({'state': 'waiting'})
|
||||||
|
next_workorder.state = 'pending'
|
||||||
|
self.time_ids.date_end = None
|
||||||
|
cur_workorder.state = 'progress'
|
||||||
|
cur_workorder.production_id.state = 'progress'
|
||||||
|
quality_check = self.env['quality.check'].search(
|
||||||
|
[('workorder_id', '=', self.id)])
|
||||||
|
for check_order in quality_check:
|
||||||
|
if check_order.point_id.is_inspect:
|
||||||
|
check_order.quality_state = 'waiting'
|
||||||
|
else:
|
||||||
|
check_order.quality_state = 'none'
|
||||||
|
|
||||||
def _compute_working_users(self):
|
def _compute_working_users(self):
|
||||||
super()._compute_working_users()
|
super()._compute_working_users()
|
||||||
|
|||||||
Reference in New Issue
Block a user