default_get records from data file - odoo-8

how can i pre load records from data by default_get method.
i have data file with this kind of records data/project_data.xml
<record id="project_document_type_gal" model="project.part.template">
<field name="code">ŪK</field>
<field name="sequence">49</field>
<field name="group_id" ref="project_custom.project_document_kv"/>
<field name="description">UK (UK)</field>
</record>
<record id="project_document_type_sem" model="project.part.template">
<field name="code">SEM</field>
<field name="sequence">50</field>
<field name="group_id" ref="project_custom.project_document_kv"/>
<field name="description">SEM (SEM)</field>
</record>
class ProjectPartTemplate(models.Model):
_name = 'project.part.template'
_inherit = 'project.object'
class ProjectObject(models.AbstractModel):
_name = 'project.object'
_rec_name = 'code'
sequence = fields.Integer('Sequence')
code = fields.Char('Code', required=True)
description = fields.Char(required=True)
project_default_stage = fields.Boolean(
'Default for new projects',
help='Will be used for new projects', default=True)
and wizard.
class ProjectPartWizard(models.TransientModel):
_name = 'project.part.wizard'
_description = 'Part wizard'
part_ids = fields.Many2many('project.part')
#api.model
def default_get(self, fields_list):
result = super(ProjectPartWizard, self).default_get(fields_list)
part_ids = []
if self._context.get('active_model') == 'project.project':
project = self.env['project.project'].browse(
self._context.get('active_id'))
project and part_ids.extend(project.project_part_ids.ids)
# TODO load all part from template
result.update(part_ids=[(6, 0, part_ids)])
return result
UPDATE
<xpath expr="//field[#name='task_count']/.." position="before">
<button string="Generate Parts" class="oe_stat_button"
name="%(project_part_wizard_action)d"
type="action" icon="fa-th">
</button>
</xpath>
here is button
so there is a templates and i need to that all templates would be in wizard pre-loaded when i open it. how can i do it with default_get

Related

Odoo duplicate many2many fields

A model [m] with a many2many field [m2m]
Field [m2m] have attribute [copy=False]
A form view [v] display the [m] and the field [m2m] with widget [many2many_tags]
I have tested that the python object did return a with False on field [m2m]
but the javascript, keep render the tags on web.
model.py
class model(models.Model):
_name = "m"
m2m = fields.Many2many('sale.order', string="SO", copy=False)
XML File
<record ...>
<form>
<group>
<field name="name"/>
<field name="ref"/>
<field name="so_m2m" widget="many2many_tags" options="{'no_create_edit': True}"/>
</group>
</form>
</record>
When I duplicate the current record, the field [m2m] is keeps the old tag from old record which is not expected.
After clicking the save button, the old tag will disappear.
Try one thing here :
Whatever your third table is there, both fields used in many2many relation, from third table keep them as a copy false.
i.e.
m2m = fields.Many2many('sale.order','sale_order_another_table_rel', 'sale_order_field','antother_table_field', string="SO", copy=False)
Into new table :
_name = 'sale.order.another.table.rel'
sale_order_field_id = // copy=false
another_table_field_id = //copy = false
Hopefully work.

Odoo 8 strange behavious using new api to inherit old api model

I added two fields to stock.picking using new api:
class StockPicking(models.Model):
_inherit = "stock.picking"
address = fields.Char(related='partner_id.street', string="Address")
sector = fields.Char(related="partner_id.sector", string="Sector")
Then I added onchange method to load stock pickings in One2Many field defined using tree:
<field name="line_ids" >
<tree>
<field name="name" />
<field name="partner_id" />
<field name="address"/>
<field name="sector"/>
<field name="state" />
</tree>
</field>
I used a simple domain with search [('id', '<', '10')] then I changed line_ids value but no line was loaded in the web view.
After many times trying to find a log error with no success I changed the code from the new API to the old API:
class StockPicking(osv.osv):
_inherit = "stock.picking"
_columns = {
'address': fields.related('partner_id', 'street', type='char', relation='res.partner', string='Address'),
'sector': fields.related('partner_id', 'sector', type='many2one', relation='sector', string='Sector')
}
For a reason that I do not know It worked.
Did someone know why this did not work using the new API?

Unable to use related field in domain filter

Field declaration in odoo v8, team_manager is a new class:
class team_manager(osv.osv):
_name = "team.manager"
_columns = {
'is_manager': fields.related('manager_id', 'manager', type='boolean', relation="hr.employee", string='Managers', readonly=True, store=True)
}
The xml file code for 'Form View'
<separator string="Team Work" attrs="{'invisible':[('is_manager','=',False)]}"/>
<field name="child_line" context="{'manager_id':id}" attrs="{'invisible':[('is_manager','=',False)]}">
<tree editable="=top">
<field name="employee_id"/>...
</tree>
</field>
While opening the form I am getting the error like
Odoo Client Error
Error: Unknown field is_manager in domain [["is_manager","=",false]]
http://localhost:8069/web/static/src/js/view_form.js:1702
Can't we use related filed in domain? or Does my syntax need changes?
You need to add is_manager field to the form view.
Add the following line before child_line field:
<field name="is_manager" invisible="True"/>

SharePoint 2013 customize custom field filter

I've created a custom field in SharePoint 2013.
<FieldTypes>
<FieldType>
<Field Name="TypeName">CrossSiteLookupField</Field>
<Field Name="ParentType">Text</Field>
<Field Name="TypeDisplayName">Cross-Site Lookup Field</Field>
<Field Name="TypeShortDescription"> Cross-Site Lookup Field </Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowOnColumnTemplateCreate">TRUE</Field>
<Field Name="ShowOnListCreate">TRUE</Field>
<Field Name="ShowOnDocumentLibraryCreate">TRUE</Field>
<Field Name="ShowOnSurveyCreate">FALSE</Field>
<Field Name="ShowInFileDlg">FALSE</Field>
<Field Name="Sortable">TRUE</Field>
<Field Name="Filterable">TRUE</Field>
<Field Name="AllowBaseTypeRendering">FALSE</Field>
<Field Name="CAMLRendering">TRUE</Field>
<Field Name="AllowGridEditing">FALSE</Field>
<Field Name="FieldTypeClass">CrossSiteLookupField.CrossSiteLookupField,$SharePoint.Project.AssemblyFullName$</Field>
<Field Name="FieldEditorUserControl">/_controltemplates/15/CrossSiteLookupFieldAdminTemplate.ascx</Field>
</FieldType>
</FieldTypes>
My CrossSiteLookupField class inherits from SPFieldText. The method 'public override string GetValidatedString(object value)' returns e.g. '4;#Test' (like a SPFieldLookup). Now the filter shows '4;#Test' but I would like the have 'Test' displayed only.
The second question is: If I have a multivalue separated with '; ', I would like to have two filter rows.
The functionality should be equal to Lookup and LookupMulti.
How can I do this?
Thx
I had the same problem.
You can change the Filter.aspx page in C: \ Program Files \ Common Files \ microsoft shared \ Web Server Extensions \ 15 \ TEMPLATE \ LAYOUTS.
This page creates the option of select the filter.
Adding the javascript you can change these options.
With this code:
$(document).ready(function ()
{
var presentText;
$("select > options").each(function ()
{
var originalText = $(this).text();
if (originalText.indexOf("#") >= 0)
{
var textElement = originaltext;
if (textElement == presentText)
$(this).remove();
else {
var newText = originalText.substring(2, originalText.indexOf("#", 2));
if (newText == "")
newText = "Empty";
if (originalText.indexOf("true") >= 0)
newText += "(Validated)";
else
newText += "(not valid)";
$(this).text(newText);
}
presentText = textElement;
}
});
});
Edit the voices of the filters:
original option
to :
modified option

How to Display linqxml list data to datatable

I have an xml like this
<?xml version="1.0" encoding="utf-8"?>
<content>
<field title="Year">
<description>Numeric data</description>
<comment>1234</comment>
</field>
<field title="mail">
<description>Numeric data</description>
<comment>ABCD</comment>
</field>
<field title="Year">
<description>AlphNumeric Data</description>
<comment>ABCD1234</comment>
</field>
</content>
i tried below linq query to extract data based on the title attribute.
var Data = XDocument.Load(Xmlpath).Root
.Descendants("field")
.Where(element => element.Attribute("title").Value.Contains("Year"))
.Descendants()
.Where(element => element.Name == "description" || element.Name == "comment")
.Select(element => new { element.Name, element.Value }).ToList();
for eg i want to show all datas that comes under title "year", the output should be displayed into a datatable like this
Description Comment
numeric data 1234
Alphanumeric Data ABCD1234
But i dont know how to convert var data to datatable or iterarte though var data .Can somebody help me? is it possible to display the result from linq query by modifying the query itself?
DataTable's have a method (ReadXml) that reads XML. Have you tried using that?

Resources