无需新增模块,在Odoo中实现AccountVoucher批量验证
Odoo批量选中凭证验证实现方案(不新增模块)
1. 扩展模型,添加批量验证方法
在你已有的AccountVoucher继承类中,新增批量验证方法,用于将选中记录标记为已验证:
class AccountVoucher(models.Model): _inherit = 'account.voucher' validated = fields.Boolean('已验证') def action_batch_validate(self): # 为所有选中记录设置已验证状态 self.write({'validated': True}) # 给用户弹出成功提示 self.env.user.notify_success(message="选中的凭证已全部完成验证")
2. 修改列表视图,添加批量验证按钮
通过视图继承,在删除按钮后方插入批量验证按钮:
<odoo> <record id="view_account_voucher_tree_inherit" model="ir.ui.view"> <field name="name">account.voucher.tree.inherit</field> <field name="model">account.voucher</field> <field name="inherit_id" ref="account.view_account_voucher_tree"/> <field name="arch" type="xml"> <!-- 定位删除按钮,在其后添加批量验证按钮 --> <xpath expr="//button[@name='unlink']" position="after"> <button name="action_batch_validate" string="批量验证" type="object" class="oe_highlight" attrs="{'invisible': [('validated', '=', True)]}"/> </xpath> </field> </record> </odoo>
class="oe_highlight":让按钮高亮显示,提升辨识度attrs属性:可选配置,当记录已验证时自动隐藏按钮,避免重复操作
3. 生效配置
将上述Python代码放入现有模块的models目录对应文件中,XML代码放入views目录对应文件中,然后在Odoo后台更新该模块即可。
内容的提问来源于stack exchange,提问作者odoo newbie
相关产品推荐
相关产品推荐

