_ constraints,无法创建退款发票ODOO V10社区



我有此约束:

_constraints = [
    (_unique_invoice_per_partner,
     _('The Document you have been entering for this Partner has already'
       ' been recorded'),
     ['Control Number (nro_ctrl)', 'Reference (reference)']),
]

这是关于这个领域的:

nro_ctrl = fields.Char(
    string='Control Number', size=32, readonly=True, required=True,
    states={'draft': [('readonly', False)]},
    help="Number used to manage pre-printed invoices, by law you will"
         " need to put here this number to be able to declarate on"
         " Fiscal reports correctly.")

如果我创建发票,验证并付款(此字段在account.invoice模型上(。

但是,如果我创建退款,则说明字段未正确设置:

The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[object with reference: nro_ctrl - nro.ctrl] 

我也有这样的方法,从理论上讲,该方法应允许"复制"或复制发票,其中包括:

@api.multi
def copy(self, default=None):
    """ Allows you to duplicate a record,
    child_ids, nro_ctrl and reference fields are
    cleaned, because they must be unique
    """
    # NOTE: Use argument name ids instead of id for fix the pylint error
    # W0621 Redefining buil-in 'id'
    #if default is None:
        #default = {}
    default = self._context.copy() #default.copy()
    default.update({
        'nro_ctrl': None, 
        'supplier_invoice_number': None,
        'sin_cred': False,
        # No cleaned in this copy because it is related to the previous
        # document, if previous document says so this too
        'date_document': False,
        'invoice_printer': '',
        'fiscal_printer': '',
        # No cleaned in this copy because it is related to the previous
        # document, if previous document says so this too
        # loc_req':False,
        'z_report': '',
    })
    return super(AccountInvoice, self).copy(default)

这是我从V8到V10社区进行的迁移。

我不知道此copy方法是否还需要。

如何牢记此约束来创建退款?我的意思是,使用nro_ctrl字段。

有什么想法?

您已经创建了新字段 nro_ctrl ,并且您已经写了 quilt = true = true 在py文件中。

当您写 PY文件中的必需字段 时,数据库表中需要

在复制方法中,您正在更新'nro_ctrl':无。由于这个原因,您在创建中遇到错误,因为没有任何值在必需的字段中不允许。

如果 nro_ctrl 在发票中需要字段,则必须在退款的复制方法中给出唯一的价值。

最新更新