59 lines
2.9 KiB
Python
59 lines
2.9 KiB
Python
from odoo import fields, models, api, _
|
|
|
|
|
|
class MrpProduction(models.Model):
|
|
_inherit = 'mrp.production'
|
|
|
|
pr_mp_count = fields.Integer('采购申请单数量', compute='_compute_pr_mp_count', store=True)
|
|
|
|
@api.depends('state')
|
|
def _compute_pr_mp_count(self):
|
|
for item in self:
|
|
# if item.product_id.product_tmpl_id.single_manufacturing == True and not item.is_remanufacture:
|
|
# first_order = self.env['mrp.production'].search(
|
|
# [('origin', '=', item.origin), ('product_id', '=', item.product_id.id)], limit=1, order='id asc')
|
|
# pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', first_order.name)])
|
|
# item.pr_mp_count = len(pr_ids)
|
|
# else:
|
|
# pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', item.name)])
|
|
# item.pr_mp_count = len(pr_ids)
|
|
# 由于采购申请合并了所有销售订单行的采购,所以不区分产品
|
|
mrp_names = self.env['mrp.production'].search([('origin', '=', item.origin)]).mapped('name')
|
|
pr_ids = self.env['purchase.request'].sudo().search([('origin', 'in', mrp_names)])
|
|
item.pr_mp_count = len(pr_ids)
|
|
# pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', item.name), ('is_subcontract', '!=', 'True')])
|
|
|
|
def action_view_pr_mp(self):
|
|
"""
|
|
采购请求
|
|
"""
|
|
self.ensure_one()
|
|
# pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', self.name),('is_subcontract', '!=', True)])
|
|
# if self.product_id.product_tmpl_id.single_manufacturing == True and not self.is_remanufacture:
|
|
# first_order = self.env['mrp.production'].search(
|
|
# [('origin', '=', self.origin), ('product_id', '=', self.product_id.id)], limit=1, order='id asc')
|
|
# pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', first_order.name)])
|
|
# else:
|
|
# pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', self.name)])
|
|
# 由于采购申请合并了所有销售订单行的采购,所以不区分产品
|
|
mrp_names = self.env['mrp.production'].search([('origin', '=', self.origin)]).mapped('name')
|
|
pr_ids = self.env['purchase.request'].sudo().search([('origin', 'in', mrp_names)])
|
|
|
|
|
|
action = {
|
|
'res_model': 'purchase.request',
|
|
'type': 'ir.actions.act_window',
|
|
}
|
|
if len(pr_ids) == 1:
|
|
action.update({
|
|
'view_mode': 'form',
|
|
'res_id': pr_ids[0].id,
|
|
})
|
|
else:
|
|
action.update({
|
|
'name': _("从 %s生成采购请求单", self.name),
|
|
'domain': [('id', 'in', pr_ids)],
|
|
'view_mode': 'tree,form',
|
|
})
|
|
return action
|