Accept Merge Request #2146: (feature/搜索优化 -> develop)
Merge Request: 采购申请关闭修改 Created By: @管欢 Reviewed By: @胡尧 Approved By: @胡尧 Accepted By: @管欢 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2146
This commit is contained in:
@@ -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,11 +37,13 @@ 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
|
product_id = line_item.product_id.id
|
||||||
qty = line_item.product_qty
|
qty = line_item.product_qty
|
||||||
|
product_rounding[product_id] = line_item.product_id.uom_id.rounding
|
||||||
if product_id in product_summary:
|
if product_id in product_summary:
|
||||||
product_summary[product_id] += qty
|
product_summary[product_id] += qty
|
||||||
else:
|
else:
|
||||||
@@ -50,7 +53,7 @@ class PurchaseRequest(models.Model):
|
|||||||
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))
|
||||||
@@ -64,17 +67,17 @@ class PurchaseRequest(models.Model):
|
|||||||
# 添加确认框
|
# 添加确认框
|
||||||
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 +99,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")
|
||||||
|
|||||||
Reference in New Issue
Block a user