- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在将一些模块从 v8 迁移到 v10,我有这个模型:
class SearchInfoPartnerSeniat(models.TransientModel):
_name = "search.info.partner.seniat"
vat = fields.Char(
string='ID Number (Cedula, Passport, VAT Number)', size=64,
help='The VAT number must be in this format J1234567890, if you'
' are looking for a cedula 12345678 and passport D123456789',
required=True)
name = fields.Char(string='Partner', size=256, help='Partner name')
wh_iva_agent = fields.Boolean(
string='Withholding Agent', help='It is withholding agent')
wh_iva_rate = fields.Float(
string='Percent of withholding',
help='What is the percentil of withholding that you must to apply'
' to this supplier if you are withholding agent')
vat_subjected = fields.Boolean(
string='Pay VAY',
help='Pay VAT, in spanish known as : Contribuyente formal')
@api.model
def search_partner_seniat(self):
""" Check vat of the partner and update iva rate
"""
self.ensure_one()
vat = self.vat.upper()
res = {
'name': _('The requested contributor does not exist'),
'vat_subjected': False,
'vat': vat,
'wh_iva_agent': False,
'wh_iva_rate': 0.0
}
if 'VE' in vat:
vat = vat[2:]
# assumption: both methods in new api style
if self.env['res.partner'].check_vat_ve(vat): # check_vat_ve() should be @api.model
res = self.env['seniat.url']._dom_giver(vat) # _dom_giver() should be @api.model
self.write(res)
return {
'type': 'ir.actions.act_window',
'res_model': 'search.info.partner.seniat',
'view_mode': 'form',
'view_type': 'form',
'res_id': self.id,
'views': [(False, 'form')],
'target': 'new',
}
这是我的观点:
<record model="ir.ui.view" id="view_vat_search">
<field name="name">search.info.partner.seniat.form</field>
<field name="model">search.info.partner.seniat</field>
<field name="arch" type="xml">
<form string="Wizard to search partner on SENIAT" version="7.0">
<group colspan="4">
<field name="vat"/>
<button name="search_partner_seniat" string="Search RIF" type="object" icon="fa-bars"/>
</group>
<separator string="VAT number consulted"/>
<group colspan="4">
<field name="name" readonly="True"/>
<field name="wh_iva_agent" readonly="True"/>
<field name="wh_iva_rate" readonly="True"/>
<field name="vat_subjected" readonly="True"/>
</group>
</form>
</field>
</record>
<record id="wizard_vat_search_action" model="ir.actions.act_window">
<field name="name">Wizard Search VAT</field>
<field name="res_model">search.info.partner.seniat</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_vat_search"/>
<field name="target">new</field>
</record>
每次我单击搜索 RIF
按钮时,它都会向我抛出以下错误:
Traceback (most recent call last):
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/model.py", line 119, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 866, in call_button
action = self._call_kw(model, method, args, {})
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 854, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 679, in call_kw
return call_kw_model(method, model, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 662, in call_kw_model
recs = self.with_context(context or {})
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 4850, in with_context
context = dict(args[0] if args else self._context, **kwargs)
TypeError: cannot convert dictionary update sequence element #0 to a sequence
我不知道这里可能出了什么问题,这是关于字典返回的吗?
有什么想法吗?
方法_dom_giver
和check_vat_ve
如下:
@api.multi
def _dom_giver(self, cr, uid, vat, context=None):
""" Check and validates that the vat is a passport,
id or rif, to send information to SENIAT and returns the
partner info that provides.
"""
if context is None:
context = {}
url_obj = self.browse(cr, uid, self.search(cr, uid, []))[0]
url1 = url_obj.name + '%s'
url2 = url_obj.url_seniat + '%s'
vat = self._validate_rif(cr, uid, vat, context=None)
if vat:
return self._get_rif(cr, uid, vat, url1, url2, context=context)
else:
return False
@api.model
def check_vat_ve(self, vat, context=None):
""" Check Venezuelan VAT number, locally called RIF.
RIF: JXXXXXXXXX RIF VENEZOLAN
IDENTIFICATION CARD: VXXXXXXXXX
FOREIGN IDENTIFICATION CARD: EXXXXXXXXX
"""
if context is None:
context = {}
if re.search(r'^[VJEGP][0-9]{9}$', vat):
return True
if re.search(r'^([VE][0-9]{1,8}|[D][0-9]{9})$', vat):
return True
return False
编辑
方法_validate_rif
@api.multi
def _validate_rif(self, cr, uid, vat, context=None):
'''validates if the VE VAT NUMBER is right
@param vat: string: Vat number to Check
returns vat when right otherwise returns False
'''
if not vat:
return False
if 'VE' in vat:
vat = vat[2:]
if re.search(r'^[VJEGP][0-9]{9}$', vat):
valid_digit = self._get_valid_digit(cr, uid, vat, context=context)
if valid_digit is None:
return False
if int(vat[9]) == valid_digit:
return vat
else:
self._print_error(_('Vat Error !'), _('Invalid VAT!'))
elif re.search(r'^([VE][0-9]{1,8})$', vat):
vat = vat[0] + vat[1:].rjust(8, '0')
valid_digit = self._get_valid_digit(cr, uid, vat, context=context)
vat += str(valid_digit)
return vat
return False
和_get_rif
方法
def _get_rif(self, cr, uid, vat, url1, url2, context=None):
""" Partner information transforms XML to string and returns.
"""
if context is None:
context = {}
xml_data = self._load_url(3, url1 % vat)
if not self._eval_seniat_data(xml_data, vat, context=context):
dom = parseString(xml_data)
return self._parse_dom(cr, uid, dom, vat, url2, context=context)
最佳答案
按钮必须使用@api.multi
+ self.ensure_one()
:
@api.multi
def search_partner_seniat(self):
self.ensure_one()
# do stuff
参见invoice example .
关于python - 类型错误 : cannot convert dictionary update sequence element #0 to a sequence - Odoo v10 community,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42742836/
我正在用 Python (2.6) 编写一个应用程序,需要我使用字典作为数据存储。 我很好奇拥有一个大字典是否更节省内存,或者将其分解为许多(很多)较小的字典,然后拥有一个包含对所有较小字典的引用的“
Convert this [ "Cat" : ["A" : 1, "B": 2], "Mat" : ["C" : 3, "D": 4] ] Into [ "A" : 1,
有什么很酷的快速方法可以让两个字典创建第三个字典,以内连接方式将第一个字典的键映射到第二个字典的值? Dictionary dic1 = new Dictionary {{a1,b1},{a2,b2}
我希望将字典相互嵌套,以便容纳 block 的 xy 坐标。所以我会 IDictionary, IDictionary> 键 Dictionary 包含列、行组合,而值 Dictionary 包含 x
在 C# 中,我需要将数据保存在字典对象中,如下所示: Dictionary> MyDict = new Dictionary>(); 现在我意识到,在某些情况下我需要一些其他(不是字典类的)
第一个Dictionary就像 Dictionary ParentDict = new Dictionary(); ParentDict.Add("A_1", "1")
我似乎无法理解这个问题。我需要使用 LINQ 按内部字典的值对字典进行排序。有什么想法吗? 最佳答案 你的意思是你想要所有的值,按内部值排序? from outerPair in outer from
我想建模一个模式,其中响应是字典: { 'id1': { 'type': 'type1', 'active': true, }, 'id2': { 'type':
我有以下代码要添加或更新(如果已经存在)dict()-dict 中的值: if id not in self.steps: self.steps[ id ] = step else:
我有一个包含字典的 Swift 字典,我想使用存储的属性来访问键值: var json = [NSObject:AnyObject]() var title: String { get
我想创建一个 Dictionary>结构,我想提供一个 IEqualityComparer在包含 APerson 的second 字典中作为关键 如果我只有内部字典,那就是 var f = new D
我有一个集合,其中包含如下文档:文档 1: { "company": "ABC" "application": { "app-1": {"earning_from_src_A": 50,
我正在快速学习。 我发现 dictionary 就像 hash 用于 PHP 或其他一些语言。 那我怎么制作dictionary的dictionary呢?? 我有这样的数据 key:J name:jh
这个问题在这里已经有了答案: Explode a dict - Get all combinations of the values in a dictionary (2 个答案) 关闭 5 个月前
我是编程新手,所以如果我的问题看起来很愚蠢,我很抱歉。我想问一下有没有办法从 Multi.Dictionary 返回key当我有值(value)? 这是我的代码: Dim myDict Set myD
我试图找出标准 Ada 库是否配备了“字典”类型(我的意思是:一种以 格式存储值的数据结构,我可以从中检索 value 使用相应的唯一 key)。 这样的数据结构存在吗?如果是这样,有人可以提供一个
我究竟做错了什么?根据我的测试,objDic.exists 永远不会给出 False! dim objDic set objDic = createobject("scripting.
我想创建一个复合类型,其中包含一个字典作为其命名字段之一。但是明显的语法不起作用。我敢肯定有一些我不明白的基本原理。下面是一个例子: type myType x::Dict() end Jul
julia> hotcell2vocab = Dict([(cell, i-1+vocab_start) for (i,cell) in enumerate(h
我有一个简单的问题:我对 Dictionary.Value 集合进行了很多次迭代,这让我很烦,我必须调用 .ToList() 然后才能调用 .ForEach(),因为它似乎没有可枚举的Dictiona
我是一名优秀的程序员,十分优秀!