簡體   English   中英

_約束,無法創建退款發票Odoo v10社區

[英]_constraints, cannot create refund invoice Odoo v10 community

我有這個約束:

_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,並且已經在py文件中寫入了required = True

當您在py文件中寫入必填字段時,在Database表中必填字段

在復制方法中,您正在更新'nro_ctrl':無 因此,由於在必填字段中沒有值,因此您在創建時會出錯。

如果發票中需要nro_ctrl字段,那么您必須在退款的復制方法中提供唯一值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM