制造订单详情页添加对应采购申请跳转链接

This commit is contained in:
yuxianghui
2025-03-25 13:28:31 +08:00
parent 29f143a547
commit 2275f7a384
4 changed files with 62 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
'depends': ['sf_manufacturing', 'purchase_request'],
'data': [
'views/sale_order_view.xml',
'views/mrp_production.xml',
'views/purchase_request_view.xml',
'wizard/purchase_request_line_make_purchase_order_view.xml',
],

View File

@@ -2,5 +2,6 @@
from . import product_template
from . import purchase_request
from . import sale_order
from . import mrp_production
from . import purchase_order
from . import stock_rule

View File

@@ -0,0 +1,39 @@
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:
pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', item.name)])
if pr_ids:
item.pr_mp_count = len(pr_ids)
else:
item.pr_mp_count = 0
def action_view_pr_mp(self):
"""
采购请求
"""
self.ensure_one()
pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', self.name)])
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

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="mrp_production_inherited_form_purchase_request" model="ir.ui.view">
<field name="name">mrp.production.inherited.form.purchase.request</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button class="oe_stat_button" name="action_view_pr_mp" type="object" icon="fa-dollar"
attrs="{'invisible': [('pr_mp_count', '=', 0)]}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="pr_mp_count"/>
</span>
<span class="o_stat_text">采购申请</span>
</div>
</button>
</xpath>
</field>
</record>
</odoo>