Integration of OpenERP (Odoo) with external systems - odoo

Is there a simple way of associating a new custom field (in the customer record or in an order items) in OpenERP (oodo) with an external link (ie Description or an iframe) so that it can link to a different system?
Is there a simple way of initializing this link with a (new) GUID, when the record is created?
Is there a simple way injecting client side JavaScript into standard OpenERP pages?
Do I need to create a new module for this?

For OpenERP 7.0+
You can add an additional field of type text/char for the link to any object like the sale.order/purchase.order/any other object. This is both possible per module or webclient (if you have technical rights).
The simplest way to create a GUID whenever a record is created is to extend that record and override the constructor:
class extended_sale_order(osv.osv):
_name = 'sale.order' # override current sale.order by replacing it (same name)
_inherit = 'sale.order' # inherit from "original" sale.order
_columns = {
'GUID': field.text('GUID') # add GUID textfield
}
def create(self, cr, uid, vals, context=None):
'''
On sale.order construction create a GUID and replace the GUID field in
sale.order with the generated value.
'''
guid = generate_guid() # implement this or use oerp sequences
vals['GUID'] = guid
result = super(extended_sale_order,self).create(cr,uid,vals,context)
return result
Yes, you can add script/html directly into the views like described on OpenERP Bay Blog (I can't add more than 2 links.. spam protection probably, you can easily find the block with most search engines). The modifications can be done either with the web client and technical rights in the UI section or using a module which modifies the view - or by using the widget or another extension point for view related modifications which can use JS.
The crucial part is where to put the GUID creation on record creation logic. If you can do that in JS - for example by creating a new GUID and put it in the field whenever a new record is created with the form - and you know the objects are always created per web-client form it is okay. For a hack.
Writing a module and putting the logic into the Business-object is the clean solution for that. The development documentation for OERP modules is sufficient for this and there are good Tutorials out in the net for small problems like adding just an additional Field.
An OpenERP Module Programmer would probably just
create a Module
inherit the Model/Object which should be modified
add a field which holds the guid/link
optionally create a calculated field which builds the link from the guid field so you only need to save the guid or which creates arbitrary html which should inserted into the view
add some logic to the constructor to create and save the guid
inherit the views where the link should be placed
add the fields/content which should be shown f.e. using the xpath expression to place your new viewpart/field/content behind some other field
install and test it
restart the server whenever python code is changed
update the the module whenever xml is changed
Or short, yes these modifications are simple if you have sufficient knowledge of the technical parts of OpenERP and yes you should put that in a module to keep it clean.

Related

How to do right rest api update?

I am developing rest api update method for user profile resource user/profile. I am disappointed what http method should i use. Update contains some required attributes so it more PUT request, where client need to fill all attributes. But how it can extend attributes in future. If i will decide to add new attribute then it will automatically clear because client is not implement it yet.
But what if this new attribute has default value or is set by another route?
Can i use PUT with not stricting number of attributes and use old data if new isn't come in request. Or how it can be done normally?
HTTP is an application whose application domain is the transfer of documents over a network -- Webber, 2011.
PUT is the appropriate method to use when "saving" a new version of a document onto a web server.
how it can extend attributes in future.
You design your schemas to be forward and backward compatible; in practice, what this means is that you can add new optional elements with reasonable default values. When you need to add a new required element, you change the name of the schema.
You'll find prior art in this topic by searching XML literature for must ignore.
You understand correctly: PUT is for complete replacement, so values that you don't include would be lost.
Instead, use the PATCH method, which is for making partial updates. You can update only the properties you include values for.

AEM OSGi Configuration Multified Property with two or more fields

Currently, we are able to use #Property(unbounded=PropertyUnbounded.ARRAY) to create a property in OSGi Configuration with Multiple-Values.
Is it possible to create a property in OSGi Configuration that behaves same as that of multifield functionality of AEM authoring dialogs? On click of Add button, the property field with all its-sub fields gets increased. So that we can add multiple entries of key/value pair.
[
{
"path":"/content/demo/page1",
"date":"20-12-2018",
"language":"english"
},
{
"path":"/content/demo/page2",
"date":"23-10-2019",
"language":"french"
}
]
The same key/value pair to be configured using OSGi Configuration and fetched as required.
The felix console allows you to add multi-value properties. however, they are typically a single field value. Meaning, you cannot create the complex data structure in your question. However, I have seen implementations that allowed you to enter an ordered CSV. For example, you could have a multivalued String OSGI property where each property is of the format:
<path>,<date>,<language>
your first entry then becomes:
/content/demo/page1,20-12-2018,english
Or, you could even enter the whole JSON as a string value, then parse it when you need it. But that becomes ugly to enter very quickly.
You can use the above with any serializable data structure, but the more complex it gets, the harder it is to enter in a single input field.
Another option would be to create a page with a component that has a multifield and just point your OSGI config to the path of that page/component, then in your OSGI service, lookup that path and extract the configuration.

Xtext disable validation check for specfic product

I have two products. For example A and B. In A product i need to enable to one validation which is present in AValidator.xtend file and B product is depends on A so when i run B product that check needs to be disable the warning.
AValidator.xtend:
#Check
def validateElement(Element e)
{
warning('''Element «e.name» missing in files.''', e, package.Literals.NAMED__NAME)
}
The same check should not be work for BProduct.
Is there any override function can do for these?
Many thanks in advance.
There are two ways to solve this:
You can add a system property (probably a boolean flag) which enables this feature. In the ini file of A, you enable the option. In B, you omit it.
You can split the plugin into a library and then two plugins which you use in the products.
Splitting the plugin works like this:
You need to create a new plugin and copy all the shared code into it. It can also contain the code from the validation which is the same for both products. Give the validation code the name SharedValidator
In this plugin, you need to rename DslRuntimeModule (Dsl is the name of your grammer, it extends AbstractDslRuntimeModule which contains the binding for the validation). Rename it to SharedDslRuntimeModule.
Then you create a plugin for product A. It contains the specific validation. This class needs to extend SharedValidator.
You also need to create a binding which extends SharedDslRuntimeModule and so you can bind the new validator class.
That's the rough outline. You will have to copy/change several other files (like the DslStandaloneSetup and the plugin.xml), too, but those changes should become obvious when you fix the compile errors.
... Maybe a flag is more simple.
Solution for this problem is Creating extension point.
I have created one extension point in AProduct validator plugin with the name of interface IProdcutEnabled with one method.
And Added that extension point in BProduct validator plugin.
Then AProduct validator class,Validation i checked whether extension point is used by any product or not. If it's used don't show warning.

Rails 3: Choose and run a Mechanize script from inside Rails action.

My application scrapes information from various sites using Mechanize. Naturally, each site requires custom Mechanize code. Each site is stored in my database, including the url to scrape and the string name of an .rb file containing that site's Mechanize code. For this case, let's assume the scripts are available in the assets folder.
I would like to call http://example.com/site/:id, then have the show action dynamically choose which Mechanize script to run (say, #site.name + ".rb" ). The script will massage the data into a common model, so all sites can use the same show template.
I can't find a way to dynamically load a .rb script within an action and obtain the result. It may be easier to have the scripts return a JSON string, which I can parse before passing on to the template, but I can't see a solution for that either. Ideally, the script will run in the action's scope. The ugly solution is an enormous if-else chain (testing the site name to determine which code block to run), but there must be a better way.
Any suggestions would be greatly appreciated, as would any general solutions to running different code dependent upon the properties of database objects.
If you have all the code in your app already why are you eval'ing Ruby code?
Create classes like:
class GoogleSpider < Spider; end
class NewYorkTimesSpider < Spider; end
class SomeOtherSpider < Spider; end
And the site class will hold the class name that will be used, so you would be able to easily do something like this in your controller action:
def show
#site = Site.find(params[:id])
# name contains SomeOtherSpider
#process_output = #site.name.constantize.new.process
# do something with the output here
end
And then you don't need to mess around evaluating Ruby code, just call the class needed. You can even make them all singletons or keep them all in a hash for faster access.

Rails - where do the model instance variables come from?

I come from an ASP.NET MVC background and am currently going through the following Rails tutorial: http://guides.rubyonrails.org/getting_started.html
I have created a "Post" model which contains some instance variables, but they do not seem to have been defined in the model. They must come from somewhere else. Where are they defined?
Googled "activerecord model" and this was in the top result:
Active Record objects don’t specify their attributes directly, but rather infer them from the table definition with which they’re linked. Adding, removing, and changing attributes and their type is done directly in the database. Any change is instantly reflected in the Active Record objects. The mapping that binds a given Active Record class to a certain database table will happen automatically in most common cases, but can be overwritten for the uncommon ones.
You can have virtual variables that don't correlate to fields in a table/model. A common example is the 'password' and 'password_confirmation' variables used in authentication. You have them exist temporarily until you encrypt it and save it to another field like 'encrypted_password'.
You can declare them but that's not required. You don't have to define or declare them anywhere... just start using them. Of course, they're not persistent though, so won't be saved.