'In inherited search view field not found
First I Inherit hr.employee model in my custom module and add a field unique_id. Than in my custom module I inherit hr.employee search view for this unique_id field. But throw this error, Field "unique_id " does not exist in model "hr.employee"
Here is python file:
class HrUniqueId(models.Model):
_inherit = "hr.employee"
unique_id = fields.Char(string='ID', required=True, copy=False, readonly=True,
default=lambda self: _('New'))
Here is XMLfile:
<record model="ir.ui.view" id="hr_employee_search_inherit">
<field name="name">hr.employee.search.inherit</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_filter"/>
<field name="arch" type="xml">
<xpath expr="//search" position="inside">
<field name="unique_id" string="Employee Id"/>
</xpath>
</field>
</record>
Error massage is:
<search string="Employees">
<field name="name" string="Employee" filter_domain="['|', ('work_email', 'ilike', self), ('name', 'ilike', self)]"/>
<field name="category_ids" groups="hr.group_hr_user"/>
<field name="job_id"/>
<separator/>
Field "unique_id" does not exist in model "hr.employee"
View error context:
{'file': 'c:\\odoo\\fornew\\fornew\\odoo\\custom\\employee_details\\views\\employee_details.xml',
'line': 3,
'name': 'hr.employee.search.inherit',
'view': ir.ui.view(2023,),
'view.model': 'hr.employee',
'view.parent': ir.ui.view(366,),
'xmlid': 'hr_employee_search_inherit'}
Solution 1:[1]
You need different counters for the input string and the output string, however, as you don't know in advance the length of the output string, you can use a StringBuilder:
char[] ans = s.toCharArray();
StringBuilder out = new StringBuilder();
System.out.println("len=" + s.length());
for (int i = 0; i < ans.length; i++) {
if (i > 0 && ans[i] >= '0' && ans[i] <= '9') {
char prev = ans[i-1];
int count = ans[i] - '0';
for (int j = 0; j < count; ++j) {
out.append(prev);
}
} else {
out.append(ans[i]);
}
}
System.out.println("output=" + out);
UPDATE:
To also reverse words:
char[] ans = s.toCharArray();
List<String> words = new ArrayList<>();
StringBuilder out = new StringBuilder();
System.out.println("len=" + s.length());
for (int i = 0; i < ans.length; i++) {
if (ans[i] == ' ') {
if (out.length() > 0) {
words.add(out.toString());
out.setLength(0);
}
} else if (i > 0 && ans[i] >= '0' && ans[i] <= '9') {
char prev = ans[i-1];
int count = ans[i] - '0';
for (int j = 0; j < count; ++j) {
out.append(prev);
}
} else {
out.append(ans[i]);
}
}
if (out.length() > 0) {
words.add(out.toString());
}
Collections.reverse(words);
String output = words.stream().collect(Collectors.joining(" "));
System.out.println("output=" + output);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
