我尝试编写一个继承其他模块的Odoo 9模块,当我尝试安装新模块时,出现了这个错误:
Odoo服务器错误
Traceback (most recent call last):
File "/opt/odoo/openerp/http.py", line 648, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/openerp/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/openerp/http.py", line 321, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/openerp/http.py", line 314, in checked_call
result = self.endpoint(*a, **kw)
File "/opt/odoo/openerp/http.py", line 964, in __call__
return self.method(*args, **kw)
File "/opt/odoo/openerp/http.py", line 514, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/addons/web/controllers/main.py", line 892, in call_button
action = self._call_kw(model, method, args, {})
File "/opt/odoo/addons/web/controllers/main.py", line 880, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/opt/odoo/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/openerp/addons/base/module/wizard/base_module_upgrade.py", line 87, in upgrade_module
openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True)
File "/opt/odoo/openerp/modules/registry.py", line 386, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/opt/odoo/openerp/modules/loading.py", line 338, in load_modules
loaded_modules, update_module)
File "/opt/odoo/openerp/modules/loading.py", line 237, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/opt/odoo/openerp/modules/loading.py", line 123, in load_module_graph
load_openerp_module(package.name)
File "/opt/odoo/openerp/modules/module.py", line 331, in load_openerp_module
__import__('openerp.addons.' + module_name)
File "/opt/odoo/openerp/modules/module.py", line 61, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/opt/odoo/addons/old_residual/__init__.py", line 3, in <module>
from . import models
File "/opt/odoo/addons/old_residual/models/__init__.py", line 3, in <module>
from . import old_residual
File "/opt/odoo/addons/old_residual/models/old_residual.py", line 14
for invoice in self:
^
IndentationError: expected an indented block**
答案 0 :(得分:0)
# -*- coding: utf-8 -*-
from openerp import models, fields, api
class old_residual(models.Model):
_inherit = "account.invoice"
old_residual = fields.Monetary(string='Nợ cũ',currency_field='company_currency_id', compute='_compute_o$
@api.multi
def _compute_old_residual(self):
for invoice in self:
invs = self.search([('state', '=', 'open'), ('partner_id', '=', invoice.partner_id.id)])
out_invoice = 0
in_invoice = 0
out_refund = 0
in_refund = 0
for inv in invs:
if inv.type == 'out_invoice':
out_invoice += inv.residual
if inv.type == 'in_invoice':
in_invoice += inv.residual
if inv.type == 'out_refund':
out_refund += inv.residual
if inv.type == 'in_refund':
in_refund += inv.residual
invoice.old_residual = out_invoice + in_refund - in_invoice - out_refund - invoice.amount_total
答案 1 :(得分:0)
在函数声明之后,您应该提供意图,即
@api.multi
def _compute_old_residual(self):
for invoice in self:
invs = self.search([('state', '=', 'open'), ('partner_id', '=', invoice.partner_id.id)])