我有这个约束:
_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
字段。
有什么想法吗?
答案 0 :(得分:2)
您已创建新字段 nro_ctrl ,并且您已在py文件中写入 required = True 。
当您在py文件中必填字段时,数据库表中 。
在复制方法中,您正在更新'nro_ctrl':无。由于这个原因,您在创建时遇到错误,因为没有任何值不允许在必填字段中。
如果发票中需要 nro_ctrl 字段,则您必须在退款的复制方法中提供唯一值。