我有这样的限制:
_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场。
有什么想法吗?
发布于 2017-04-21 03:57:35
您已经创建了新的字段nro_ctrl,并且在py文件中编写了required=True。
当您在py文件中编写必需字段时,数据库表中需要的是。
在复制方法中,您正在更新'nro_ctrl':None。由于这个原因,您在创建过程中会出现错误,因为在所需字段中不允许任何值。
如果发票中需要nro_ctrl字段,则必须在副本退款方法中给出唯一的值。
https://stackoverflow.com/questions/43528483
复制相似问题