Content migration of plone dexterity content types in plone 5 - migration

I have a dexterity content type defined as model in Employee.xml.
<model xmlns="http://namespaces.plone.org/supermodel/schema"
xmlns:marshal="http://namespaces.plone.org/supermodel/marshal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="plone">
<schema>
<field name="fullname" type="zope.schema.TextLine">
<description />
<required>True</required>
<title>Firstname and Surname</title>
</field>
<field name="position" type="zope.schema.TextLine">
<description />
<required>True</required>
<title>Position</title>
</field>
</schema>
</model>
Very easy. The class is defined in content.py.
class Employee(Item):
"""Convenience subclass for ``Employee`` portal type
"""
There are some instances of Employee in my database.
Now I want to add a new feature to my content type.
class Employee(Item):
"""Convenience subclass for ``Employee`` portal type
"""
def Title(self):
return self.fullname
Now I can see the fullname of the employee in the folder_contents view. But it works only for instances added after the modification. The "old" content seems to need a migration.
My question: How?
The docs did not help. (https://docs.plone.org/develop/plone/persistency/migrations.html)

The older instances haven't been re-indexed, so everything based on the catalog (collections, navigation, search, folder content, etc.) cannot be aware of their new Title attribute.
Just reindex your portal_catalog and it will be fine.

Related

Odoo: How to add custom category name to app module's search panel?

For example i have app with
category = "custom_category"
How can i add this category to my search panel in app module ?
When I created a category, I thought it would come here automatically, but it didn't.
I found the file, where these categories are defined:
15.0/odoo/odoo/addons/base/data/ir_module_category_data.xml
But something is not right here! When I delete a record from here, for example:
<!-- <record model="ir.module.category" id="module_category_human_resources">-->
<!-- <field name="name">Human Resources</field>-->
<!-- <field name="sequence">45</field>-->
<!-- </record>-->
And update the base module, this (Human Resources) field is still in this menu !?
Why it is not deleted? Any advice?
Model 'ir.module.category' doesn't have delete access rights (ref https://github.com/odoo/odoo/blob/a7f7233e0eae8ee101d745a9813cba930fd03dcb/odoo/addons/base/security/ir.model.access.csv#L20). So once a record is created from the xml file, it will not delete if you comment that code line.
You can directly delete it from the database using delete query.
Odoo will only show categories that do not have a parent and that one of the subcategories is linked to a module.
If the category_id field is defined in the search panel, Odoo will use a custom domain:
domain = [('parent_id', '=', False), ('child_ids.module_ids', '!=', False)]
To show the custom category in the search panel:
First, define the module category as follows:
<record model="ir.module.category" id="module_custom_category">
<field name="name">custom_category</field>
<field name="sequence">99</field>
</record>
<record model="ir.module.category" id="module_child_category">
<field name="name">child_category</field>
<field name="parent_id" ref="module_custom_category"/>
</record>
Then set it in a module __manifest__.py file:
'category': 'custom_category/child_category',
Why Odoo did not remove the category after commenting the XML definition?
Odoo will create two categories with the same name (custom_category) with the following XML IDS:
base.module_category_custom_category
stack15.module_custom_category
And use the first one to show it in the search panel.
When you comment record XML definition and upgrade the module, Odoo will remove the category using the module name as a prefix in its XML id (stack15.module_custom_category) and keep the base category (base.module_category_custom_category), so the custom category will be visible even if you uninstall the module.

Domain using objects in Odoo8

In my custom model have a one2many relation.Fields are like,
*.xml
<field name="o2m_field>
<tree>
<field name="a"/> // many2one relation
<field name="b domain=[('name','=',a.second_field)]/> // many2one relation
<field name="c"/>
<field name="d"/>
</tree>
*.py
_name='a.a'
_columns ={
'name':fields.char('Name'),
'second_field':fields.char('Second field')
}
But getting an JS error:Error: AttributeError: object has no attribute 'second_field'.
You can't access second_field directly in domain.
You should create second_field related store False and use in domain.
Ex:
second_field=fields.Char(related="a.second_field",store=False,readonly=True)
<field name="b" domain=[('name','=',second_field)]/>
This may help you.
in the client side when you using attrs, domain or context you cannot use field that are not listed in the same view (even if exists in the Model class), this is why you need always to pass this values to the client side like in this case as Emipro Technologies Pvt. suggested use related field.

How does one link to other defined entities using their id?

When writing XML files I will occasionally need to reference another entity, such as a group, a category, or an action.
How can I accomplish this?
There are two different methods to do this, and which one you use depends on where you are in the record:
in the type="xml" or type="html" portions (such as tree and form views)
everywhere else
Inside the type=["xml" | "html"] portions you need to use %-interpolation:
<button string="..." name="%(fnx_pd.action_add_cleaning_order)d" type="action" />
<field name="item_id" domain="[('categ_id','=',%(fnx_pd.pd_cleaning)d)]" />
The thing you are linking to needs to be inside a %()d or %()s construct: %(module.id_name)d.
If not inside an xml or html segment, then you can use the OpenERP-provided ref() function to get the id:
<field name="value" eval="'ir.actions.server,' + str(ref('action_release'))"/>
<field name="context" eval="{'default_pos_categ_id': ref('point_of_sale.categ_others')}"/>
In both of the above methods, OpenERP will look up the actual value associated with the id given and substitute it into the record.

How to link Leads (emails) to Marketing emails sent in Odoo v8?

I have Leads and all my leads have emails set. Now I have sent emails to leads with "Mass Mailings" from "Marketing". But now when I click on my lead I do not see any link between the Lead (email) to emails I have sent with "Mass Mailings".
Is there a way to make a link between Lead (email) to email I have sent?
The information about sent emails is available trough the model mail.mail.statistics. In this model you have everything you need. The following fields may be of interest for your task:
model - as emails may be related to any Odoo model, this field tells you to which model was related the email. You are interested in records with crm.lead in this field
res_id - the id of the corresponding model instance. In your case this fields links you to the id of your lead.
mail_mail_id_int - the id of the objects of type email.email - the emails themselves
etc.
You can use this to create a list of emails related to a lead and show them in the crm lead form.
To do that, create a new Odoo module, extend the crm.lead object adding a One2many relation to the mail.mail.statistics model and extend the crm.lead view to show this new field.
For instance, in a file called models/lead.py in this new module, put the following:
from openerp import models, fields
class crm_lead(models.Model):
_inherit = 'crm.lead'
emails = fields.One2many(comodel_name='mail.mail.statistics',
inverse_name='res_id',
domain=[('model', '=', 'crm.lead')])
crm_lead()
Respectively, to extend the view, create a file views/lead_view.xml like this:
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="mail_crm_stats.crm_lead_form">
<field name="name">mail_crm_stats.crm_lead.form</field>
<field name="model">crm.lead</field>
<field name="type">form</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[#string='Extra Info']"
position="after">
<page string="Emails sent">
<group name="emails">
<div>
<field name="emails" nolabel="1"
class="oe_inline"/>
</div>
</group>
</page>
</xpath>
</field>
</record>
</data>
</openerp>
Now you should see additional tab 'EMails sent' in your lead form. Of course, this is just and example and the module may be improved to show better information about the sent emails. As the case is interesting I may commit soon a new version in the github repository I created for the purpose..
You can download the entire module and test it from my github repository like this:
git clone https://github.com/andreiboyanov/odoo-mails_crm_stats mails_crm_stats
In V8 there is a fields between leads and Marketing Campaign See in any Lead > Extra Info (tab) > Marketing, You can manually add your campaign to that, but if you need to automatically sync then you need to create a new module for that, but just for now you can manually put entry.You can view various modules on here.

ContentTypeRef not working as expected, inheriting from System instead of mine

I have a SP project with two features:
a first feature that defines some fields, a content type and a list definition
a second feature that defines a list instance of the first feature definition
in the second feature, I use the ContentTypeRef element to bind to the content type defined in the first feature. I saw in many blog post and forum thread that Fields are not correctly populated to the list, but it's not my issue (maybe it's related ?)
The instantiated list defines a content type, but instead of inheriting from my content type, it inherits the "System" content type.
Is this behavior correct ? how can I actually inherits my content type instead of system content type ?
thx in advance
[Edit] the simpliest workaround I found is to copy past the content type definition into the contenttypes element of my list schema... but it's still a copy/paste operation (as ugly as it can be)
Please make sure that your content type ID is valid, I never managed to bypass the item content type (0x01) which means that your content type will have an ID of 0x0100{A-GUID}.
Anyway, even if you defined properly your content type and this one is working as expected when you bind it to a custom list, you'll still need to re-declare it in your list schema with all its field reference and once again, copy most of the definition of your field (I had issue with less than ID, name, display name, type in this area)...
Eg with the last list I created :
<ContentTypes>
<ContentType ID="0x0100FDCCBFFB0FBF4D5C8E069F582412909602" Name="UniverseTranslation" Group="XYZ" Description="Universe Translation" Version="0">
<FieldRefs>
<FieldRef ID="{39BF387B-C20A-4D30-BD17-CB70E4609FA2}" Name="LookupUniverse" DisplayName="Universe" Required="TRUE" />
<FieldRef ID="{824F7063-6D09-48CD-B5BA-FE9B5EE36D6A}" Name="WCC_Language" DisplayName="Language" Required="TRUE" />
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Translation" Required="TRUE" />
<FieldRef ID="{EC8E4DB7-B715-430B-9B4A-F222F025EFAB}" Name="RichDescription" DisplayName="Description"/>
</FieldRefs>
</ContentType>
</ContentTypes>
<Fields>
<Field
ID="{39bf387b-c20a-4d30-bd17-cb70e4609fa2}"
Name="LookupUniverse"
DisplayName="Universe"
Type="Lookup"
ShowField="Title"
Required="TRUE"
EnforceUniqueValues="FALSE"
List="Lists/Universes">
</Field>
<Field
ID="{824F7063-6D09-48CD-B5BA-FE9B5EE36D6A}"
Name="WCC_Language"
DisplayName="Language"
Type="VariationLabelsFieldType"
Required="TRUE">
</Field>
<Field
ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"
Name="Title"
DisplayName="Translation"
Type="Text"
Required="TRUE">
</Field>
<Field
ID="{EC8E4DB7-B715-430B-9B4A-F222F025EFAB}"
Name="RichDescription"
DisplayName="Rich Description"
Type="Note"
NumLines="4"
RichText="TRUE"
RichTextMode="Compatible"
AllowHyperlink="TRUE"
IsolateStyles="FALSE"
AppendOnly="FALSE"
Required="FALSE">
</Field>
</Fields>
If you can post your content type definition and part of your list schema, I'm pretty sure we'll be able to provide a more relevant help.
Kindly
It worked for me by adding the relative folder path for the content type's resource folder. It also worked for adding multiple references for content types to the list as follows:
<ContentTypes>
<ContentType ID="0x01006775E96C04A04F52AC1FCE50F0CB0901" Name="contentType1" Group="Test Content Types" Description="Test Content Type" Inherits="TRUE" Version="0">
<Folder TargetName="contentType1" />
</ContentType>
<ContentType ID="0x0100958BB07B626A494F9201B03E96948F3D" Name="contentType2" Group="Test Content Types" Description="Test Content Type" Inherits="TRUE" Version="0">
<Folder TargetName="contentType2" />
</ContentType>
</ContentTypes>