2017-04-20 57 views
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字段。

任何想法?

回答

2

您已創建新字段nro_ctrl並且您已在py文件中寫入required = True

當您在py文件中寫入必填字段時,則需要在數據庫表中需要

在您更新的複製方法中'nro_ctrl':無。由於這個原因,你在創建時出錯,因爲沒有值不允許在必填字段中。

如果nro_ctrl字段在發票中是必需的,那麼您必須賦予退款複製方法的唯一值。

+0

嗨,非常感謝,但我不確定我是否完全理解您的觀點,請您舉個例子嗎?,您的意思是複製方法上的字典上的nro_ctrl值?但這不是適得其反的嗎? – NeoVe

+0

你有更新的default.update({'nro_ctrl':無}),由於這個原因你得到錯誤的必填字段。 –

+0

好的,但是我應該使用nro_ctrl的唯一值是什麼:self.nro_ctrl例如?而不是nro_ctrl:無? – NeoVe

相關問題