1
我有这样的约束:_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值?但这不是适得其反的吗? – NeoVe
你有更新的default.update({'nro_ctrl':无}),由于这个原因你得到错误的必填字段。 –
好的,但是我应该使用nro_ctrl的唯一值是什么:self.nro_ctrl例如?而不是nro_ctrl:无? – NeoVe