0

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

但我不会影响代码。删除的行没有任何响应。请....告诉我任何一个

提前致谢....

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()
4

1 回答 1

1

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

刚刚做了一点更正>在字段中添加了 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 的顺序,然后 > 保存 > 它将引发您放置的验证错误!

于 2017-05-25T13:46:40.013 回答