Odoo mail.template foreign key constraint error - odoo-12

Im trying to add an email template to my custom module, When I add the email template like below I get an error.
odoo.tools.convert.ParseError: "insert or update on table "mail_template" violates foreign key constraint "mail_template_model_id_fkey"
The only way I can get the template installed to odoo is by removing the model_id field.
Ways Ive tried model_id: it_onboarding.it_onboarding ,it_onboarding.model_it_onboarding, model_it_onboarding, it_onboarding. All of those variations on the model name give External ID errors except it_onboarding.it_onboarding which give the foreign key constraint error.
Module name: it_onboarding.it_onboarding
Filename: data/it_request_approval_email.xml
Email Template:
<record id="it_request_email_template" model="mail.template">
<field name="name">New IT Request ${object.reference}</field>
<field name="model_id" ref="it_onboarding.it_onboarding"/>
<field name="subject">${object.reference} needs approval</field>
<field name="email_from">dummy#mail.com</field>
<field name="email_to">dummy#mail.com</field>
<field name="auto_delete" eval="False"/>
<field name="user_signature" eval="False"/>
<field name="body_html" type="html">
<div>
${object.reference} has been received and needs approval
</div>
</field>
Grateful for any ideas
File Structure
-it_onboarding
--controllers
--data
--it_request_approval_email.xml
--sequence.xml
--models
--reports
--security
--static
--views
--__init__.py
--__manifest__.py
Manifest
"data": [
'security/ir.model.access.csv',
'security/security.xml',
'data/sequence.xml',
'views/views.xml',
'views/templates.xml',
'views/it_user_view.xml',
'reports/it_user_report.xml',
'reports/it_request_report.xml',
'reports/approval_email_report.xml',
'data/it_request_approval_email.xml',
],

Try with this variation and if possible please provide a snip or link of your folder structure:
<field name="model_id" ref="folder_name.model_class_name"/>
Cheers!

I found my issue. I was formatting the model_id incorrectly.
Model name: it_onboarding.it_onboarding
model_id: model_it_onboarding_it_onboarding

Related

Annotations are not used in Fiori Elements List Report with TreeTable

I have created a Fiori Elements List Report and set the table type to TreeTable. The table is displayed as a TreeTable but every entity is displayed as a root entity in the table and the following error is in the log: "Neither navigation paths parameters, nor (complete/valid) tree hierarchy annotations where provided to the TreeBinding.".
The OData service is based on the following projection view:
#Metadata.allowExtensions: true
#ObjectModel.representativeKey: 'Element'
#ObjectModel.dataCategory: #HIERARCHY
#Hierarchy.parentChild: [
{ recurse.child: ['Element'],
recurse.parent: ['ParentElement'],
recurseBy: '_ParentElement',
multipleParents: true,
siblingsOrder: [{by: 'Element', direction: #DESC}],
orphanedNode.handling: #ROOT_NODES
}
]
define root view entity ZC_Element
as projection on ZI_Element
{
#ObjectModel.foreignKey.association: '_Element'
key Element,
ParentElement,
ChildNode,
ParentNode,
HierarchyLevel,
HierarchyTreeSize,
HierarchyRank,
HierarchyParentRank,
HierarchyIsOrphan,
HierarchyIsCycle,
HierarchyDrillState,
CreatedBy,
CreatedAt,
LastChangedBy,
LastChangedAt,
_Element,
_ParentElement
}
The hierarchy, which is at the basis of the views, is as followed:
define hierarchy ZHI_ElementHierarchy
as parent child hierarchy(
source ZHI_ElementRelation
child to parent association _ParentElement
start where
ParentElement is initial
siblings order by
Element
multiple parents allowed
orphans root
)
{
#ObjectModel.foreignKey.association: '_VirtualDirectory'
key Element,
_Element,
ParentElement,
_ParentElement,
$node.parent_id as ParentNode,
$node.node_id as ChildNode,
$node.hierarchy_is_orphan as HierarchyIsOrphan,
$node.hierarchy_level as HierarchyLevel,
$node.hierarchy_rank as HierarchyRank,
$node.hierarchy_parent_rank as HierarchyParentRank,
$node.hierarchy_tree_size as HierarchyTreeSize,
$node.hierarchy_is_cycle as HierarchyIsCycle,
CreatedBy,
CreatedAt,
LastChangedBy,
LastChangedAt
}
The metadata file of the OData service does not contain any hierarchy annotations. I have also attempted to add the following annotations manually to the annotations.xml file but this does not have any effect either:
<Annotations Target="cds_zsd_elements.ElementType">
<Annotation Term="UI.LineItem">
<Collection>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="Element"/>
<PropertyValue Property="sap:hierarchy-node-for" Path="Element"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="ParentElement"/>
<PropertyValue Property="sap:hierarchy-parent-node-for" Path="Element"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="HierarchyLevel"/>
<PropertyValue Property="sap:hierarchy-level-for" Path="Element"/>
</Record>
<Record Type="UI.DataField">
<PropertyValue Property="Value" Path="HierarchyDrillState"/>
<PropertyValue Property="sap:hierarchy-drill-state-for" Path="Element"/>
</Record>
</Collection>
</Annotation>
</Annotations>
I have used the projection view in an ABAP program with ALV TreeTable as well and the output is displayed correctly, so the hierarchy and data seems to be correct. What can I do to get the hierarchy annotations correct?

DMN 1.2: Referencing ItemDefinitions from another ItemDefinition results in an error

I load this DMN file (dmnFile):
<definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc"
xmlns:ns="http://sample.dmn" namespace="http://sample.dmn"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/">
<itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
<itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
<typeRef>NumberDefinition</typeRef>
</itemComponent>
</itemDefinition>
<itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
<typeRef>number</typeRef>
</itemDefinition>
<inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
<variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="MyItemDefinition" />
</inputData>
<decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
<variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
<informationRequirement>
<requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
</informationRequirement>
<context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
<contextEntry>
<variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
<literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
<text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</text>
</literalExpression>
</contextEntry>
<contextEntry>
<literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
<text>containsMyNumber</text>
</literalExpression>
</contextEntry>
</context>
</decision>
</definitions>
like this:
KieServices ks = KieServices.Factory.get();
KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.2"), ks.getResources().newFileSystemResource(dmnFile));
and I get an exception with the following error message:
[Message [id=1, kieBase=defaultKieBase, level=ERROR, path=C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, line=4, column=-1
text=DMN: Unable to resolve type reference '{http://www.omg.org/spec/DMN/20180521/MODEL/}NumberDefinition' on node 'MyItemDefinition' (resource: C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, DMN id: _29d92e98-3c97-67a3-22f1-d342622424f7, The listed type definition was not found) ]]
Type reference with prefix ("ns:NumberDefinition") results in the following error message:
[Message [id=1, kieBase=defaultKieBase, level=ERROR, path=C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, line=4, column=-1
text=DMN: Unable to resolve type reference '{http://www.omg.org/spec/DMN/20180521/MODEL/}ns:NumberDefinition' on node 'MyItemDefinition' (resource: C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, DMN id: _29d92e98-3c97-67a3-22f1-d342622424f7, The listed type definition was not found) ]]
What do I do wrong?
When using DMN 1.1 (xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd") and type references as QNames (with prefixes) I get the expected result.
Since DMNv1.2, the idiomatic way to reference is ns.<itemDef>.
In your original DMN xml file this happens on line 7 and 14.
In summary the file in the idiomatic DMNv1.2 form should be:
<definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc"
xmlns:ns="http://sample.dmn" namespace="http://sample.dmn"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/">
<itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
<itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
<typeRef>ns.NumberDefinition</typeRef>
</itemComponent>
</itemDefinition>
<itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
<typeRef>number</typeRef>
</itemDefinition>
<inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
<variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="ns.MyItemDefinition" />
</inputData>
<decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
<variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
<informationRequirement>
<requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
</informationRequirement>
<context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
<contextEntry>
<variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
<literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
<text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</text>
</literalExpression>
</contextEntry>
<contextEntry>
<literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
<text>containsMyNumber</text>
</literalExpression>
</contextEntry>
</context>
</decision>
</definitions>
That said, with your report we uncovered a bug when the DMN xml file is using the DMN namespace as the default namespace, which we are addressing with
DROOLS-4797.
Thank you for the report !
There is a way to avoid being forced to use ns.<itemDef> and simply use <itemDef>, and that is by setting the default namespace in the DMN xml to be the model's namespace, and just prefixing the DMN xml element with the namespace prefix targeting the DMN namespace.
In other words, the file can make use of <itemDef> reference without having to ns. prefix them:
<semantic:definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc"
xmlns="http://sample.dmn" namespace="http://sample.dmn"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
xmlns:semantic="http://www.omg.org/spec/DMN/20180521/MODEL/">
<semantic:itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
<semantic:itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
<semantic:typeRef>NumberDefinition</semantic:typeRef>
</semantic:itemComponent>
</semantic:itemDefinition>
<semantic:itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
<semantic:typeRef>number</semantic:typeRef>
</semantic:itemDefinition>
<semantic:inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
<semantic:variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="MyItemDefinition" />
</semantic:inputData>
<semantic:decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
<semantic:variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
<semantic:informationRequirement>
<semantic:requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
</semantic:informationRequirement>
<semantic:context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
<semantic:contextEntry>
<semantic:variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
<semantic:literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
<semantic:text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</semantic:text>
</semantic:literalExpression>
</semantic:contextEntry>
<semantic:contextEntry>
<semantic:literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
<semantic:text>containsMyNumber</semantic:text>
</semantic:literalExpression>
</semantic:contextEntry>
</semantic:context>
</semantic:decision>
</semantic:definitions>
In this other variant, the default namespace in the xml is the DMN model's namespace, so any itemDef reference does not need any prefix.
Because the default namespace in the xml is the DMN model's namespace, the xml element need to be prefixed with the namespace prefix targeting now the DMN namespace.
Hope this clarifies and provide an insightful explanation!

Extending Modx modResource schema errors

I'm trying to extend the modx modresource object, but keep getting errors & I can't seem to figure out why. It is related to the schema (I think) but everything looks correct.
Schema:
<?xml version="1.0" encoding="UTF-8"?>
<model package="extresource" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" tablePrefix="modx_" version="1.0.0">
<object class="extResource" extends="modResource">
<composite alias="ResourceData" class="ResourceData" local="id" foreign="internalKey" cardinality="one" owner="local"/>
</object>
<object class="ResourceData" table="resource_data" extends="xPDOSimpleObject">
<field key="internalKey" dbtype="int" precision="11" phptype="integer" null="false" attributes="unsigned"/>
<field key="views" dbtype="int" precision="11" phptype="integer" null="true" />
<field key="starred" dbtype="int" precision="10" phptype="integer" null="false" />
<index alias="internalKey" name="internalKey" primary="false" unique="true" type="BTREE" >
<column key="internalKey" length="" collation="A" null="false" />
</index>
<aggregate alias="Resource" class="modResource" local="internalKey" foreign="id" cardinality="one" owner="foreign"/>
</object>
</model>
I'm testing it using:
$resource = $modx->getObject('modResource', 11112);
echo $resource->get('pagetitle'); //test I have the resource
$data = $resource->getOne('ResourceData');
The errors I get are:
Could not getOne: foreign key definition for alias ResourceData not
found. No foreign key definition for parentClass: modDocument using
relation alias: ResourceData
The table exists & has data, the package is registered in the modx extension packages. I've been over the schema many times & it looks right.
What is causing these errors?
You have to use the right object class in $modx->getObject. Otherwise you will get a modResource object, that does not know the extended object data and relationship.
$resource = $modx->getObject('extResource', 11112);
Does the resource you are loading have its class_key field set to extResource? That's needed for it to load the right resource object class.

OpenERP 7 - Add another status to account.invoice workflow

I wanted to add another status ("advanced") to account.invoice's workflow, between "open" and "paid".
So I inherited the module with
class advance_invoice_workflow(osv.osv) :
_name = 'account.invoice'
_inherit = "account.invoice"
_columns = {
'state': fields.selection([
('draft','Draft'),
('proforma','Pro-forma'),
('proforma2','Pro-forma'),
('open','Open'),
('advanced','Advanced'),
('paid','Paid'),
('paid_advanced','Paid advanced'),
('cancel','Cancelled'),
],'Status', select=True, readonly=True, track_visibility='onchange',
help='* The \'Draft\' status is used when a user is encoding a new and unconfirmed Invoice. \
\n* The \'Pro-forma\' when invoice is in Pro-forma status,invoice does not have an invoice number. \
\n* The \'Open\' status is used when user create invoice,a invoice number is generated.Its in open status till user does not pay invoice. \
\n* The \'Paid\' status is set automatically when the invoice is paid. Its related journal entries may or may not be reconciled. \
\n* The \'Cancelled\' status is used when user cancel invoice. \
'),
}
and declared the status in the XML file by making
<record id="act_advanced" model="workflow.activity">
<field name="wkf_id" ref="account.wkf" />
<field name="name">advanced</field>
<field name="kind">function</field>
<field name="action">set_advanced()</field>
</record>
So I have two transitions:
the first one from open to advanced,
<record id="t2" model="workflow.transition">
<field name="act_from" ref="account.act_open" />
<field name="act_to" ref="act_advanced" />
<field name="trigger_model">account.move.line</field>
<field name="trigger_expr_id">move_line_id_payment_get()</field>
<field name="condition">test_advanced()</field>
<field name="signal">button_confirm_advance</field>
</record>
the second one from advanced to paid
<record id="t1" model="workflow.transition">
<field name="act_from" ref="act_advanced"/>
<field name="act_to" ref="account.act_paid"/>
<field name="trigger_model">account.move.line</field>
<field name="trigger_expr_id">move_line_id_payment_get()</field>
<field name="condition">test_paid()</field>
</record>
From an external module, that does not inherit from account.invoice, but that refers to it, I want to send the signal to the workflow to move from "act_open" to "act_advanced".
So I added a button with name="button_confirm_advance" that binds this action:
def button_confirm_advance(self,cr,uid,ids,context=None):
context = context or {}
for invoice in self.browse(cr,uid,ids,context=context):
wf_service = netsvc.LocalService("workflow")
self.write(cr, uid, [invoice.id],{})
wf_service.trg_validate(uid,'account.invoice',invoice.id,'button_confirm_advance',cr)
return {'type': 'ir.actions.act_window_close'}
All variables are correct, but the trg_validate returns False.
What am I wrong?
Thanks,
Patrizio
I solved delegating the flowchart management to another class that inherits from account.invoice
class advance_invoice_account_ui(osv.osv) :
_name = 'account.invoice'
_inherit = "account.invoice"

Is there a way to make fusion chart's funnel display zero values?

I'm using fusion charts' funnel mode to display some sums which may or may not be 0, grouped into different cathegories. I'm also displaying the number of terms that goes into each sum (for example: $1000, 3 accounts). I want the funnel to display a slice even if its value is 0 and have it displayed like $0, x accounts to give the user information on how many accounts there are in every cathegory even if the final sum is 0.
Xml for the fusioncharts object:
$strXML = "
<chart showhovercap='1' showNames='1' showValues='1' numberSuffix=' lei' decimalPrecision='0' decimalSeparator=',' thousandSeparator='.' formatNumber='1' isSliced='1' slicingDistance='5' bgColor='f5f5f5'>
<set link='".$url1."' name='Negociere' value='".$negociere."' color='FD0006' hoverText='".$nr_negociere.$text_negociere."' />
<set link='".$url2."' name='Ofertare' value='".$oferta."' color='FF4100' hoverText='".$nr_oferta.$text_oferta."' />
<set link='".$url3."' name='Analiza' value='".$analiza."' color='FF8900' hoverText='".$nr_analiza.$text_analiza."' />
<set link='".$url4."' name='Abordare' value='".$abordare."' color='086FA1' hoverText='".$nr_abordare.$text_abordare."' />
<set link='".$url5."' name='Prospectare' value='".$prospectare."' color='00B25C' hoverText='".$nr_prospectare.$text_prospectare."' />
</chart>
";
Could you please try by setting "streamlinedData" attribute to "0" in the element of your XML data?
Ref. Code:
<chart showhovercap='1' showNames='1' showValues='1' numberSuffix='$' decimalPrecision='0' decimalSeparator=',' thousandSeparator='.' formatNumber='1' isSliced='1' slicingDistance='5' bgColor='f5f5f5' streamlinedData='0'>
<set label="Negociere,3 accounts" value="0"/>
<set label="Ofertare, 5 accounts" value="0"/>
<set label="Analiza, 2 accounts" value="1"/>
<set label="Abordare, 1 accounts" value="0"/>
<set label="Prospectare, 2 accounts" value="0"/>
</chart>