Hi,
I am trying to create a module that extends hr_payroll odoo12. When I install the module extension I get this error.
Error:
Odoo Server Error
Traceback (most recent call last):
File "/home/viscar/odoo12/odoo/http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/viscar/odoo12/odoo/http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/viscar/odoo12/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/home/viscar/odoo12/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "/home/viscar/odoo12/odoo/http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/viscar/odoo12/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/home/viscar/odoo12/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/home/viscar/odoo12/odoo/http.py", line 941, in __call__
return self.method(*args, **kw)
File "/home/viscar/odoo12/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/home/viscar/odoo12/addons/web/controllers/main.py", line 966, in call_button
action = self._call_kw(model, method, args, {})
File "/home/viscar/odoo12/addons/web/controllers/main.py", line 954, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/viscar/odoo12/odoo/api.py", line 749, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File "/home/viscar/odoo12/odoo/api.py", line 736, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-61>", line 2, in button_immediate_install
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 74, in check_and_log
return method(self, *args, **kwargs)
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 445, in button_immediate_install
return self._button_immediate_function(type(self).button_install)
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 561, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "/home/viscar/odoo12/odoo/modules/registry.py", line 86, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 421, in load_modules
loaded_modules, update_module, models_to_check)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 313, in load_marked_modules
perform_checks=perform_checks, models_to_check=models_to_check
File "/home/viscar/odoo12/odoo/modules/loading.py", line 222, in load_module_graph
load_data(cr, idref, mode, kind='data', package=package, report=report)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 68, in load_data
tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
File "/home/viscar/odoo12/odoo/tools/convert.py", line 806, in convert_file
raise ValueError("Can't load unknown file type %s.", filename)
ValueError: ("Can't load unknown file type %s.", 'models/shift_model.py')
Here is my __manifest__.py
{'name': 'Shift Allowance',
'version': '12.0.1.0.0',
'summary': 'Calculates shift allowance for external empoloyees',
'category': 'Tools',
'author': 'Eliza ',
'depends': ['base'],
'external_dependencies': {"python": ['numpy']},
'data': ['models/shift_model.py', 'views/shift_views.xml'],
'installable': True,
'application': False,
'auto_install': False,
}
I have an init within models, and alongside manifest with imports just as recommended.
Here is the shift_model.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api
import numpy as np
class ShiftAllowance(models.Model):
# _name ='shift.allowance'
_description = 'Shift Allowance'
_inherit = 'hr.contract'
# field types working shifts
BasicPayRate = fields.Integer(default=0)
WeekdayDay = fields.Integer(default=0)
WeekdayNight = fields.Integer(default=0)
WeekendDay = fields.Integer(default=0)
WeekendNight = fields.Integer(default=0)
ShiftAllowance = fields.Float()
@api.multi
def userDetails(self):
"""
This function prompts the user for input variables and
returns a dictionary of said varibales
"""
# picks data provided by user and saves it in a dict.
# A dictionary to hold the input variables
work_details = {}
current_user = self.env.user.user_id.id
if current_user:
# work_details["weekdayDay"] = int(self.env['hr.contract.weekdayDay'])
work_details["weekdayDay"] = int(self.weekdayDay)
work_details["weekdayNight"] = int(self.weekdayNight)
work_details["weekendDay"] = int(self.weekendDay)
work_details["weekendNight"] = int(self.weekendNight)
return work_details
# ,WeekdayDay, WeekdayNight, WeekendDay, WeekendNight
# import pdb; pdb.set_trace()
@api.multi
def basic_pay_rate(self):
# picks the basic pay rate as provided by the user
basic_rate = int(self.BasicPayRate)
return basic_rate
# create two arrays weekday and weekend
@api.multi
def shiftWorked(self, work_details):
# Get user work details first
# weekdayShift
WDS = np.array([work_details["weekdayDay"], work_details["weekdayNight"]]).reshape(2, 1)
# WeekendShift
WES = np.array([work_details["weekendDay"], work_details["weekendNight"]]).reshape(2, 1)
# print (WDS,WES)
return WDS, WES
@api.multi
def matrix(self, WDS, WES):
# Get shifts worked
WDS, WES = shiftWorked()
# our constant matrix
OurMatrix = np.array([[1, 9, 2], [7, 0, 5]])
# multiply it by our weekday shifts
WDMatrix = OurMatrix * WDS
# Get the total for the weekdays
WDTotal = WDMatrix.sum(axis=0)
# multiply it by our weekend shifts
WEMatrix = OurMatrix * WES
# Get the total for the weekends
WETotal = WEMatrix.sum(axis=0)
return WDTotal, WETotal
@api.multi
def ratesCalc(self, WDTotal, WETotal):
# Get shift totals
WDTotal, WETotal = matrix()
# our weekday rates
WDRates = np.array([22/100, 0/100, 15/100])
# our weekend rates
WERates = np.array([27/100, 10/100, 20/100])
# multiply weekdayTotals by weekday rates
effectiveWDHrs = WDTotal * WDRates
# multiply weekendTotals by weekend rates
effectiveWEHrs = WETotal * WERates
# Get the total effective hours
effectiveHours = np.concatenate((effectiveWDHrs, effectiveWEHrs), axis=None)
# Get the sum of the hours
totalEffectiveHours = np.sum((effectiveHours), dtype=np.float)
return totalEffectiveHours
# Calculate the amount payable per employee
@api.multi
def amountPayable(self, basic_rate, totalEffectiveHours):
# Get user's basic pay rate
# Get total effective hours
# A constant
Anumber = 21/8
# to get the hourly rate multiply the two
HrlyRate = basic_rate * Anumber
# now get the amount payable
AmountPayable = HrlyRate * totalEffectiveHours
return AmountPayable
# link to the button compute shift allowance so that on click it performs this function
@api.multi
def final_calc(amountPayable):
return amountPayable()
This confirms my original assumption: You need to remove "'models/shift_model.py'" from your __manifest__.py and instead reference it by using the described __init__.py files.
Something like this?
'data': ['models/__init__.py', 'views/shift_views.xml'],
I have made the above change, yet I am still getting the same error.
Error:
Odoo Server Error
Traceback (most recent call last):
File "/home/viscar/odoo12/odoo/http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/viscar/odoo12/odoo/http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/viscar/odoo12/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/home/viscar/odoo12/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "/home/viscar/odoo12/odoo/http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/viscar/odoo12/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/home/viscar/odoo12/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/home/viscar/odoo12/odoo/http.py", line 941, in __call__
return self.method(*args, **kw)
File "/home/viscar/odoo12/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/home/viscar/odoo12/addons/web/controllers/main.py", line 966, in call_button
action = self._call_kw(model, method, args, {})
File "/home/viscar/odoo12/addons/web/controllers/main.py", line 954, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/viscar/odoo12/odoo/api.py", line 749, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File "/home/viscar/odoo12/odoo/api.py", line 736, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-61>", line 2, in button_immediate_install
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 74, in check_and_log
return method(self, *args, **kwargs)
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 445, in button_immediate_install
return self._button_immediate_function(type(self).button_install)
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 561, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "/home/viscar/odoo12/odoo/modules/registry.py", line 86, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 421, in load_modules
loaded_modules, update_module, models_to_check)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 313, in load_marked_modules
perform_checks=perform_checks, models_to_check=models_to_check
File "/home/viscar/odoo12/odoo/modules/loading.py", line 222, in load_module_graph
load_data(cr, idref, mode, kind='data', package=package, report=report)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 68, in load_data
tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
File "/home/viscar/odoo12/odoo/tools/convert.py", line 806, in convert_file
raise ValueError("Can't load unknown file type %s.", filename)
ValueError: ("Can't load unknown file type %s.", 'models/__init__.py')
You should not reference any Python file in the 'data' attribute. Just having the __init__.py files in these folders is already enough for your modified model to be found. Your data attribute should look like this:
'data': ['views/shift_views.xml'],
I have enforced the change and this is the error I am getting.
Despite the file being present
Error:
Odoo Server Error
Traceback (most recent call last):
File "/home/viscar/odoo12/odoo/http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/viscar/odoo12/odoo/http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/viscar/odoo12/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/home/viscar/odoo12/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "/home/viscar/odoo12/odoo/http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/viscar/odoo12/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/home/viscar/odoo12/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/home/viscar/odoo12/odoo/http.py", line 941, in __call__
return self.method(*args, **kw)
File "/home/viscar/odoo12/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/home/viscar/odoo12/addons/web/controllers/main.py", line 966, in call_button
action = self._call_kw(model, method, args, {})
File "/home/viscar/odoo12/addons/web/controllers/main.py", line 954, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/viscar/odoo12/odoo/api.py", line 749, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File "/home/viscar/odoo12/odoo/api.py", line 736, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-61>", line 2, in button_immediate_install
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 74, in check_and_log
return method(self, *args, **kwargs)
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 445, in button_immediate_install
return self._button_immediate_function(type(self).button_install)
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 561, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "/home/viscar/odoo12/odoo/modules/registry.py", line 86, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 421, in load_modules
loaded_modules, update_module, models_to_check)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 313, in load_marked_modules
perform_checks=perform_checks, models_to_check=models_to_check
File "/home/viscar/odoo12/odoo/modules/loading.py", line 222, in load_module_graph
load_data(cr, idref, mode, kind='data', package=package, report=report)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 68, in load_data
tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
File "/home/viscar/odoo12/odoo/tools/convert.py", line 796, in convert_file
with file_open(pathname, 'rb') as fp:
File "/home/viscar/odoo12/odoo/tools/misc.py", line 199, in file_open
return _fileopen(name, mode=mode, basedir=rtp, pathinfo=pathinfo, basename=basename)
File "/home/viscar/odoo12/odoo/tools/misc.py", line 257, in _fileopen
raise IOError('File not found: %s' % basename)
OSError: File not found: new_shift_test/views/shift_views.xml
My bad, there was a typo.
It works!
The error is no longer there.
This is my shift_view.xml.
<?xml version="1.0"?>
<data>
<xpath expr="//page[@name='information']" position="after">
<page string="Shift Allowance" name="shift_allowance">
<group>
<group name="shift_allowance" string="Shift Allowance Details">
<button string="Compute Allowance" class="oe_highlight" name="Compute Allowance" type="object"/>
<field name="weekdayDay"/>
<field name="weekdayNight"/>
<field name="weekendDay"/>
<field name="weekendNight"/>
<field name="BasicPayRate"/>
<field name="ShiftAllowance"/>
</group>
</group>
</page>
</xpath>
</data>
I get an assertion error:
I have had this error before on a different project and each time there has been no direct fix. Most of the time there ends up being something wrong with the code.
Do you spot anything odd with the code.
Odoo Server Error
Traceback (most recent call last):
File "/home/viscar/odoo12/odoo/http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/viscar/odoo12/odoo/http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/viscar/odoo12/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/home/viscar/odoo12/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "/home/viscar/odoo12/odoo/http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/viscar/odoo12/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/home/viscar/odoo12/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/home/viscar/odoo12/odoo/http.py", line 941, in __call__
return self.method(*args, **kw)
File "/home/viscar/odoo12/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/home/viscar/odoo12/addons/web/controllers/main.py", line 966, in call_button
action = self._call_kw(model, method, args, {})
File "/home/viscar/odoo12/addons/web/controllers/main.py", line 954, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/viscar/odoo12/odoo/api.py", line 749, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File "/home/viscar/odoo12/odoo/api.py", line 736, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-61>", line 2, in button_immediate_install
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 74, in check_and_log
return method(self, *args, **kwargs)
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 445, in button_immediate_install
return self._button_immediate_function(type(self).button_install)
File "/home/viscar/odoo12/odoo/addons/base/models/ir_module.py", line 561, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "/home/viscar/odoo12/odoo/modules/registry.py", line 86, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 421, in load_modules
loaded_modules, update_module, models_to_check)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 313, in load_marked_modules
perform_checks=perform_checks, models_to_check=models_to_check
File "/home/viscar/odoo12/odoo/modules/loading.py", line 222, in load_module_graph
load_data(cr, idref, mode, kind='data', package=package, report=report)
File "/home/viscar/odoo12/odoo/modules/loading.py", line 68, in load_data
tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
File "/home/viscar/odoo12/odoo/tools/convert.py", line 802, in convert_file
convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
File "/home/viscar/odoo12/odoo/tools/convert.py", line 852, in convert_xml_import
relaxng.assert_(doc)
File "src/lxml/lxml.etree.pyx", line 3501, in lxml.etree._Validator.assert_ (src/lxml/lxml.etree.c:184715)
AssertionError: Element data has extra content: xpath, line 3
I'm glad your original error could be fixed this way. I think in this case the question should be marked as solved and a new one should be created concerning your view, because the topic is completely different. Currently your new question is hard to find for people who could answer it as well as others with similar issues in the future.
On first sight, your view looks like it is meant to override some other view, but it lacks the required <record> definition to tell the system which view to override.
Where can I specify that it is solved?
Well, I am trying to extend an existing page by adding a group of fields.
You should be able to click the checkmark icon on the left side of an answer.
To override an existing view you should check how this is done by Odoo itself (e.g. here: https://github.com/odoo/odoo/blob/12.0/addons/sale_stock/views/sale_order_views.xml ). If you need specific help, I would suggest to create a separate question, so this can be answered in more detail than here in the comments.
Hi,
Thank you for the fix, by the way, there are no assertion errors.
I am concerned that odoo can't find my python file. because now I am getting the error below.
I have defined the fields in the py file, the one above.(I wish the formatting was better tho)
raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating constraint
Field `weekdayDay` does not exist
You have defined your fields with a leading uppercase character in your Python file. You should change it to "weekdayDay" instead of "WeekdayDay" (and similar for all other fields). Keep in mind that you always need to restart your Odoo instance after modifying Python files.
Bless you! Marcel,
Everything works fine, the view is visible. All that is left is checking if my code actually works.
This is a win, I had spent two months on it.
I have a different blocker. It's about creating a qweb for 'printing individual leave'. I had posted the question a while back, the answers helped but I am still stuck. If you could help me, please. I am updating my current progress on the question.