2016-08-08 10 views
0

私は 'account.partner.ledger'モジュールを継承しています。顧客を選択すると、顧客の元帳のレポートを印刷することができます。私は、私のカスタムモジュールでメソッドをオーバーライドしようとしましたが、取得しているエラーを解決できませんでした。AttributeError: 'bool'オブジェクトに 'strftime'属性がありません。

コード、

@api.multi 
def onchange_filter(self,filter='filter_no', fiscalyear_id=False): 
    res = super(account_partner_ledger, self).onchange_filter(filter=filter, fiscalyear_id=fiscalyear_id) 
    if filter in ['filter_no', 'unreconciled']: 
     if filter == 'unreconciled': 
      res['value'].update({'fiscalyear_id': False}) 
     res['value'].update({'initial_balance': False, 'period_from': False, 'period_to': False, 'date_from': False ,'date_to': False}) 

    if filter in ['filter_date','filter_period']: 
     res['value'].update({'initial_balance': True, 'period_from': True, 'period_to': True, 'date_from': True ,'date_to': True}) 
    return res 

エラー、

Traceback (most recent call last): 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\http.py", line 544, in _handle_exception 
    return super(JsonRequest, self)._handle_exception(exception) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\http.py", line 581, in dispatch 
    result = self._call_function(**self.params) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\http.py", line 317, in _call_function 
    return checked_call(self.db, *args, **kwargs) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\service\model.py", line 118, in wrapper 
    return f(dbname, *args, **kwargs) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\http.py", line 314, in checked_call 
    return self.endpoint(*a, **kw) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\http.py", line 810, in __call__ 
    return self.method(*args, **kw) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\http.py", line 410, in response_wrap 
    response = f(*args, **kw) 
    File "C:\Users\zendynamix\odooGit\odoo8\addons\web\controllers\main.py", line 944, in call_kw 
    return self._call_kw(model, method, args, kwargs) 
    File "C:\Users\zendynamix\odooGit\odoo8\addons\web\controllers\main.py", line 936, in _call_kw 
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\api.py", line 268, in wrapper 
    return old_api(self, *args, **kwargs) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\api.py", line 399, in old_api 
    result = method(recs, *args, **kwargs) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\models.py", line 5985, in onchange 
    record._onchange_eval(name, field_onchange[name], result) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\models.py", line 5883, in _onchange_eval 
    self.update(self._convert_to_cache(method_res['value'], validate=False)) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\models.py", line 5391, in _convert_to_cache 
    for name, value in values.iteritems() 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\models.py", line 5392, in <dictcomp> 
    if name in fields 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\fields.py", line 1250, in convert_to_cache 
    return self.to_string(value) 
    File "C:\Users\zendynamix\odooGit\odoo8\openerp\fields.py", line 1240, in to_string 
    return value.strftime(DATE_FORMAT) if value else False 
AttributeError: 'bool' object has no attribute 'strftime' 

答えて

1

あなたはOdooはブール値を変換しようとしているので、あなたがエラーを取得している、時には何が起こっているかを理解するために基礎となるコードを見ていますオブジェクトを時間の文字列表現に戻します(Pythonの日付オブジェクトが必要です)

端末を起動してエラーを再現することができます:

>>> True.strftime 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
AttributeError: 'bool' object has no attribute 'strftime' 
>>> 

値が出力から、端末

>>> x = '' 
>>> if x: print('Yeah') 
... 
>>> 
>>> x = True 
>>> if x: print('Yeah') 
... 
Yeah 
>>> x = False 
>>> if x: print('Yeah') 
... 
>>> 
>>> 

からFalseに、テストと評価された場合の値テストの参照する場合、これは、私たちの試験条件odoo

@staticmethod 
def to_string(value): 
    """ Convert a :class:`date` value into the format expected by the ORM. """ 
    return value.strftime(DATE_FORMAT) if value else False 

からto_string方法であり、空の文字列またはFalseはFalseと評価されますが、True値はTrueと評価されるため、日付値をTrueに設定する代わりに空の文字列に設定します。

@api.multi 
def onchange_filter(self,filter='filter_no', fiscalyear_id=False): 
    res = super(account_partner_ledger, self).onchange_filter(filter=filter, fiscalyear_id=fiscalyear_id) 
    if filter in ['filter_no', 'unreconciled']: 
     if filter == 'unreconciled': 
      res['value'].update({'fiscalyear_id': False}) 
     res['value'].update({'initial_balance': False, 'period_from': False, 'period_to': False, 'date_from': False ,'date_to': False}) 

    if filter in ['filter_date','filter_period']: 
     res['value'].update({'initial_balance': 'True', 'period_from': '', 'period_to': '', 'date_from': '', 'date_to': ''}) 

    return res 
+0

空白にそれを変更した後、エラーは消えたが、「を含む初期のバランス」のチェックボックスは、デフォルト – Bhanukiran

+0

編集であなたの質問をチェックして、モジュールあなたを含め取得されていません – danidee

+0

から継承私は私の質問を編集し、継承されたモジュールは 'account.partner.ledger'です – Bhanukiran

1

あなたのコードを見ると、あなたが表示されます:

'date_from': True ,'date_to': True 

これはあなたのエラーが発生します。 これらのフィールドをブール値ではない日付に設定する必要があります。 日付を記入できないようにする必要があるため、値Falseは有効です。

0

strftimeの代わりにstrptimeを使用して問題が解決するかどうかを確認してください。例えば、次のようにあなたがのstrptimeを使用することができます : -

from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT my_date = datetime.strptime(self.date_column, DEFAULT_SERVER_DATETIME_FORMAT)

関連する問題