So I've been looking around the web, on a mission to find a way to create my own sequence for the new API for Odoo 9 that I am using. However, I wasn't able to find a satisfactory answer. As far as I've seen, sequences aren't very well documented in the Odoo Docs.
Here's what I know so far.
From this I know:
<openerp>
<data noupdate="1">
<record model="ir.sequence.type" id="seq_type_obj_id">
<field name="name">obj_id_seq</field>
<field name="code">seq.obj.name</field>
</record>
<record model="ir.sequence" id="seq_obj_id">
<field name="name">obj_id_seq</field>
<field name="code">seq.obj.name</field>
<field name="prefix">prefix</field>
<field name="padding">3</field>
</record>
</data>
</openerp>
But apparently ir.sequence.type is NOT a model that exists and I cannot use, so I removed that record and it compiles/updates without errors.
From previous source, I also know:
my_sequence = self.pool['ir.sequence'].get(cr, uid, seq_obj_name)
self.write(cr, uid, [picking.id], {'ur_emp_no_field': my_sequence})
But this is the old API, so I've changed it to:
# Correct me if I'm wrong here
my_sequence = self.env['ir.sequence'].get('seq.obj.name')
And have added it to the create function, which then writes to an arbitrary field to be stored.
So I've done all this without getting any error messages.
My problem is: The field I'm storing the sequence instance to is not changing. I checked in the sequence settings and the sequence is not being incremented when I create a new record either.
For the sake of clarity:
#api.model
def create(self, vals):
for rec in self:
rec.seq_id = self.env['ir.sequence'].get('seq.obj.name')
return super(PurchaseOrder, self).create(vals)
If someone could give me a thorough explanation of where Odoo does the auto increment, maybe direct me to a proper source, or point out what is wrong with my code and how to fix it, I would much appreciate the effort.
You code didn't update the directory variable. That's the reason of it.
Try with this code.
#api.model
def create(self, vals):
if vals:
vals.update({
'seq_id': self.env['ir.sequence'].get('seq.obj.name')
})
return super(PurchaseOrder, self).create(vals)
Related
How to show/hide menu item based on system parameter?
I've this code to create menu item, and it working fine, but i need to hide it depends on system parameter.
<!-- this is for test, remove this after testing -->
<record id="check_qty_and_move_from_internal_customer_to_customer" model="ir.actions.server">
<field name="name">Cron Run Directly 2</field>
<field name="model_id" ref="model_kiotviet_cron"/>
<field name="binding_model_id" ref="onnet_kiotviet.model_kiotviet_cron"/>
<field name="state">code</field>
<!-- function called -->
<field name="code">model.check_qty_and_move_from_internal_customer_to_customer()</field>
</record>
<!-- this is for test, remove this after testing -->
<menuitem id="check_qty_and_move_from_internal_customer_to_customer" name="Cron Run Directly 2" parent="kiotviet_menu_root"
action="check_qty_and_move_from_internal_customer_to_customer" sequence="6"/>
Does anyone know how to do that? Thanks.
I've found the answer, here is it:
from odoo import models, api, tools, _
class Menu(models.Model):
_inherit = 'ir.ui.menu'
#api.model
#tools.ormcache('frozenset(self.env.user.groups_id.ids)', 'debug')
def _visible_menu_ids(self, debug=False):
menus = super(Menu, self)._visible_menu_ids(debug)
# get system parameter
if not self.env['ir.config_parameter'].sudo().get_param('your_module.your_config_name'):
# get menu item id
menu_item_id = self.env.ref('your_module.menu_item_id').id
# remove it from menus
menus.dis
card(menu_item_id)
return menus
I want to change the domain filter of journal_id field which is currently [('type', 'in', ('bank', 'cash'))] this. I wanna apply only [('type', '=', 'cash')]. But its not changing while I am trying to override it.
I applied xpath and replace it with my custom domain
I created the field again and applied the domain but thats too not giving me the proper result
<xpath expr="//field[#name='journal_id']" position="after">
<field name="journal_id" widget="selection"
domain=" [('employee_id.user_id','=',uid)]"/>
<xpath/>
or
`<field name="journal_id" position="attributes">
<attribute name="domain">[('type','=',cash)]</attribute>
</field>
I want to show only those journal in drop down whose type is 'cash'
Please help out in this.
There is function which is setting domain in payment and you have to find that function and override it according to your requirement.
In Plone 5 you can make use of html templates in the TinyMCE editor by registering the template plugin. The templates are html snippets living in the file system which are also registered in the plone ressource registry. Here is an example:
<?xml version="1.0"?>
<registry>
<record name="plone.templates" interface="Products.CMFPlone.interfaces.controlpanel.ITinyMCESchema" field="templates">
<field type="plone.registry.field.Text">
<default></default>
<description xmlns:ns0="http://xml.zope.org/namespaces/i18n" ns0:domain="plone" ns0:translate="help_tinymce_templates">
Enter the list of templates in json format http://www.tinymce.com/wiki.php/Plugin:template
</description>
<required>False</required>
<title xmlns:ns0="http://xml.zope.org/namespaces/i18n" ns0:domain="plone" ns0:translate="label_tinymce_templates">Templates</title>
</field>
<value>[
{"title": "Template 1", "url": "++theme++mytheme/tinymce-templates/tmpl1.html"},
{"title": "Template 2", "url": "++theme++mytheme/tinymce-templates/tmpl2.html"}
]</value>
</record>
<record name="plone.custom_plugins" interface="Products.CMFPlone.interfaces.controlpanel.ITinyMCESchema" field="custom_plugins">
<field type="plone.registry.field.List">
<default/>
<description xmlns:ns0="http://xml.zope.org/namespaces/i18n" ns0:domain="plone" ns0:translate="">
Enter a list of custom plugins which will be loaded in the editor. Format is pluginname|location, one per line.
</description>
<required>False</required>
<title xmlns:ns0="http://xml.zope.org/namespaces/i18n" ns0:domain="plone" ns0:translate="">Custom plugins</title>
<value_type type="plone.registry.field.TextLine"/>
</field>
<value>
<element>template|+plone+static/components/tinymce-builded/js/tinymce/plugins/template</element>
</value>
</record>
</registry>
My question is: How can the templates be accessed from python code or from TAL? First possibility is to read the file from the filesystem. But then the security layer will be passed by. The second is to request the templates by http. In this case safety is taken into account. But it is rather expensive. Is there a way to access the templates (plone resources) direct without bypassing security?
You can access the templates direcly by the url.
Something like:
portal.restrictedTraverse('++theme++mytheme/tinymce-templates/tmpl2.html')
The same applies to page templates.
How can I select/get a pre created record/value in many2one field
for example: the holidays_status_id in hr_holidays module is a many2one field and it has already 4 values of
Legal Leaves
Sick Leaves
Compensatory Days
Unpaid
what I need to do is dynamically select the legal leaves and customize it in another module.
How can I do it?
Basically the data is coming after once you are installing the module of your hr_holidays.It means the part of first time of module installation.
It is basically a part of the data file which is named as hr_holidays_data.xml file in hr_holidays module.
It must need to add that file location on 'data' key attribute of value in __openerp__.py file
'data': ['hr_holidays_data.xml']
which is part of added into our module menifiest file of each module in Odoo (Formally OpenERP).
<!-- Casual leave -->
<record model="hr.holidays.status" id="holiday_status_cl">
<field name="name" eval="'Legal Leaves '+time.strftime('%Y')"/>
<field name="color_name">black</field>
</record>
<!-- Sick leave -->
<record model="hr.holidays.status" id="holiday_status_sl">
<field name="name">Sick Leaves</field>
<field name="limit">True</field>
<field name="color_name">red</field>
</record>
<!-- Compensatory Days -->
<record model="hr.holidays.status" id="holiday_status_comp">
<field name="name">Compensatory Days</field>
<field name="limit">True</field>
<field name="color_name">lavender</field>
</record>
<!--Unpaid Leave -->
<record model="hr.holidays.status" id="holiday_status_unpaid">
<field name="name">Unpaid</field>
<field name="limit">True</field>
<field name="color_name">brown</field>
</record>
Need to understand the following attribute for more clarification.
1. model :-
which is part of the your own model (class name) or use the existing Odoo Model class.which is basically mentioned on each class of _name attribute in your class.
2. id :
unique id of each record
2.field name:
what ever field you want to add a new record (insert a new record) which is part of the model class fields name.
Each record contain the number of child field name so you can add as per your requirement and do to check after install or upgrade the module.
You may also add our own custom leave with our module with our own separate .xml file and add it as per your need.
I hope my answer may helpful for you :)
I am working on an automated testing app, and am currently in the process of writing a function that compares values between two XML files that should be identical, but may not be. Here is a sample of the XML I'm trying to process:
<?xml version="1.0" encoding="utf-8"?>
<report xmlns="http://www.**.com/**">
<subreport name="RBDReport">
<record rowNumber="1">
<field name="Time">
<value>0</value>
</field>
<field name="Reliability">
<value>1.000000</value>
</field>
<field name="Unreliability">
<value>0.000000</value>
</field>
<field name="Availability">
<value> </value>
</field>
<field name="Unavailability">
<value> </value>
</field>
<field name="Failure Rate">
<value>N/A</value>
</field>
<field name="Number of Failures">
<value> </value>
</field>
<field name="Total Downtime">
<value> </value>
</field>
</record>
(Note there may be multiple <subreport> elements and within those, multiple <record> elements.)
What I'd like is to extract the <value> tags of two documents and then compare their values. That part I know how to do. The problem is the extraction itself.
Since I'm stuck in C++, I'm using MSXML, and have written a wrapper to allow my app to abstract away the actual XML manipulation, in case I ever decide to change my data format.
That wrapper, CSimpleXMLParser, loads an XML document and sets its "top record" to the document element of the XML document. (CRecord being an abstract class with CXMLRecord one of its subclasses, and which gives access to child records singularly or by group, and also allowing access to the "value" of the Record (values for child elements or attributes, in the case of CXMLRecord.) A CXMLRecord contains an MSXML::MSXMLDOMNodePtr and a pointer to an instance of a CSimpleXMLParser.) The wrapper also contains utility functions for returning children, which the CXMLRecord uses to return its child records.
In my code, I do the following (trying to return all <subreport> nodes just to see if it works):
CSimpleXMLParser parserReportData;
parserReportData.OpenXMLDocument(strPathToXML);
bool bGetChildrenSuccess = parserReportData.GetFirstRecord()->GetChildRecords(listpChildren, _T("subreport"));
This is always returning false. The meat of the implementation of CXMLRecord::GetChildRecords() is basically
MSXML2::IXMLDOMNodeListPtr pListChildren = m_pParser->SelectNodes(strPath, m_pXMLNode);
if (pListChildren->Getlength() == 0)
{
return false;
}
for (long l = 0; l < pListChildren->Getlength(); ++l)
{
listRecords.push_back(new CXMLRecord(pListChildren->Getitem(l), m_pParser));
}
return true;
And CSimpleXMLParser::SelectNodes() is:
MSXML2::IXMLDOMNodeListPtr CSimpleXMLParser::SelectNodes(LPCTSTR strXPathFilter, MSXML2::IXMLDOMNodePtr pXMLNode)
{
return pXMLNode->selectNodes(_bstr_t(strXPathFilter));
}
When run, the top record is definitely being set to the <report> element properly. I can do all sorts of things with it, like getting its child nodes (through the MSXML interface, not through my wrapper) or its name, etc. I know that my wrapper can work, because I use it elsewhere in the app for parsing an XML configuration file, and that works flawlessly.
I thought maybe I was doing something faulty with the XPath query expression, but every permutation I could think of gives no joy. The MSXML::IXMLDOMNodeListPtr returned by IXMLDOMNodePtr::SelectNodes() is always of length 0 when I try to deal with this XML file.
This is driving me crazy.
I'm used to doing this with .NET's XmlDocument objects, but I think the effect is the same here:
If the XML document includes a namespace -- even an unnamed one -- then the Xpath query has to use one as well. So, you'll have to add the namespace to the XMLDoument which you might as well give a name in the code, and the include the prefix in the XPATH query (it doesn't matter that the prefixes are different between the xml document and the xpath, as long as the namespaces sort it out)
SO, while you are using an XPath like /report/subreport/record/field/value, you actually need to first set the namespace of your document:
pXMLDoc->setProperty(_bstr_t("SelectionNamespaces"),
_bstr_t("xmlns:r="http://www.**.com/**"));
and then selectNodes() using /r:report/r:subreport/r:record/r:field/r:value
I see no reference to a namespace when you're selecting nodes. I'd expect this to be the fundamental problem.