首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >_constraints,无法创建退款发票Odoo v10社区

_constraints,无法创建退款发票Odoo v10社区
EN

Stack Overflow用户
提问于 2017-04-20 19:40:39
回答 1查看 118关注 0票数 1

我有这样的限制:

代码语言:javascript
复制
_constraints = [
    (_unique_invoice_per_partner,
     _('The Document you have been entering for this Partner has already'
       ' been recorded'),
     ['Control Number (nro_ctrl)', 'Reference (reference)']),
]

是关于这个领域的:

代码语言:javascript
复制
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模型上),这个约束是有效的。

但是,如果我创建退款,那么它会说字段设置得不正确:

代码语言:javascript
复制
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] 

我也有这种方法,理论上应该允许“复制”或复制发票,其中包括:

代码语言:javascript
复制
@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场。

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-21 03:57:35

您已经创建了新的字段nro_ctrl,并且在py文件中编写了required=True

当您在py文件中编写必需字段时,数据库表中需要的是

在复制方法中,您正在更新'nro_ctrl':None。由于这个原因,您在创建过程中会出现错误,因为在所需字段中不允许任何值。

如果发票中需要nro_ctrl字段,则必须在副本退款方法中给出唯一的值。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43528483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档