如何在销售订单中覆盖one2many中的删除按钮

时间:2017-05-25 11:39:54

标签: xml python-2.7 openerp unlink one2many

在one2many行删除按钮,当该行中的布尔字段为true时,该行不会删除并引发异常。我喜欢以下代码

但我不会在代码中受到影响。该行没有任何回复删除。拜托......告诉我任何一个

提前感谢....

from odoo import api, models, fields, _, SUPERUSER_ID
import string
from odoo import exceptions
from odoo.exceptions import ValidationError


class ouc_sale_order(models.Model):
    _inherit = 'sale.order'
    c_state = fields.Selection(
        [("draft", "Draft Proforma Invoice"), ("sent", "Proforma Invoice Sent"), ("cancel", "Cancelled"),
         ("waiting_date", "Waiting Schedule"), ("progress", "Sales Order"), ("manual", "Sale to Invoice"),
         ("shipping_except", "Shipping Exception"), ("invoice_except", "Invoice Exception"), ("done", "Done")],
        string='State')


class ouc_sales_order_line(models.Model):
    _inherit = 'sale.order.line'

    c_status = fields.Selection([('New', 'New'), ('renewal', 'Renewal'), ('upgrade', 'Upgrade'), ('upsell', 'Upsell'), ('PDC', 'PDC'),
         ('etc', 'etc')], string='Status', default='New')
    c_fptags_id = fields.Many2one('ouc.fptag', string='FPTAGs')
    c_product_template_id = fields.Many2one('product.template', string='Product Template', related='product_id.product_tmpl_id')
    c_package_id = fields.Many2one('ouc.package', string='Packages')
    c_pkg_expiry_in_month = fields.Integer(string='Package Expires After(Months)', related='c_package_id.validity')
    c_subtotaltax = fields.Float('Subtotal with Tax')
    c_taxamount = fields.Float('Tax Amount')
    c_client_id = fields.Char('Client Id')
    c_default_discount = fields.Float('Default Discount (%)')
    c_max_discount = fields.Float('Maximum Discount (%)')
    c_subscription_status = fields.Boolean(string='Subscription')


#@api.multi
#def unlink(self):
#    for record in self:
#        if record.c_subscription_status:
#            raise exceptions.ValidationError(_('You didn\'t delete this record'))
#    return super(ouc_sales_order_line,self).unlink()

1 个答案:

答案 0 :(得分:0)

你的这段代码正在工作!!!

刚做了一点修正>在字段中添加了default = False。(没有必要,但是很好的做法!)

class ouc_sales_order_line(models.Model):
    _inherit = 'sale.order.line'

    c_subscription_status = fields.Boolean(string='Subscription', default=False)

    @api.multi
    def unlink(self):
       for record in self:
           if record.c_subscription_status:
               raise ValidationError(_('You didn\'t delete this record'))
       return super(ouc_sales_order_line, self).unlink()
  

获取在order_line删除记录和>中将布尔字段设置为TRUE的顺序保存>它会引发你提出的验证错误!