0

我正在尝试创建一个覆盖销售订单确认按钮的 Odoo 模块。我按照我找到的信息,创建了以下代码,但它不起作用。

from odoo import models, fields, api
import logging
_logger = logging.getLogger(__name__) 

class saleoverride(models.Model):
    _name = 'saleoverride.saleoverride'
    _description = 'saleoverride'
    _inherit = 'sale.order'

    name = fields.Char()
    # value = fields.Integer()
    # value2 = fields.Float(compute="_value_pc", store=True)
    description = fields.Text()

    transaction_ids = fields.Many2many('payment.transaction', 'saleoverride_transaction_rel', 'saleoverride_id', 'transaction_id',
                                   string='Transactions', copy=False, readonly=True)
    tag_ids = fields.Many2many('crm.tag', 'saleoverride_tag_rel', 'saleoverride_id', 'tag_id', string='Tags')

    @api.model
    def action_confirm(self):
        res = super(SaleOrder, self).action_confirm()
        _logger.info("saleoverride_action_confirm")
        _logger.info(self)
        return res

我试图在日志文件中搜索消息,但找不到任何东西。有人能帮我吗?

谢谢!

4

2 回答 2

1

问题是您没有扩展sale.order模型,而是saleoverride.saleoverride基于sale.order.

检查 odoo 文档:继承和扩展

from odoo import models, fields, api
import logging
_logger = logging.getLogger(__name__) 

class saleoverride(models.Model):
    _description = 'saleoverride'
    _inherit = 'sale.order'

    name = fields.Char()
    # value = fields.Integer()
    # value2 = fields.Float(compute="_value_pc", store=True)
    description = fields.Text()

    transaction_ids = fields.Many2many('payment.transaction', 'saleoverride_transaction_rel', 'saleoverride_id', 'transaction_id',
                                   string='Transactions', copy=False, readonly=True)
    tag_ids = fields.Many2many('crm.tag', 'saleoverride_tag_rel', 'saleoverride_id', 'tag_id', string='Tags')

    def action_confirm(self):
        res = super(SaleOrder, self).action_confirm()
        _logger.info("saleoverride_action_confirm")
        _logger.info(self)
        return res

_name = 'saleoverride.saleoverride'从您的课程中移除会为sale.order.

还要删除装饰器,因为原始功能没有。

于 2021-03-28T16:28:13.160 回答
0

当您想覆盖插件中的代码时,您所能做的就是继承它。因此,您不能在覆盖现有代码时定义名称。删除:_name ='saleoverride.saleoverride'

于 2021-05-19T04:25:53.413 回答