Use #Size annotation on Entity Column amount - size

"HV000030: No validator could be found for constraint 'org.hibernate.validator.constraints.Length' validating type 'java.lang.Long'. Check configuration for 'amount'",

Related

Odoo 12: Many2one ondelete message?

Is it possible to change(edit) default ondelete message in Many2one field?
My field is:
parent_id = fields.Many2one("pgp.organizational.classifications", string="Parent classification", select=True, ondelete='restrict')
Default message is like this, but I won't to add my message:
"Odoo Server Error - Greška kod provjere
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[objekt s referencom: pgp.organizational.classifications - pgp.organizational.classifications] "
You cannot change it in the Many2one field's declaration.
Code which generates this message is there: https://github.com/odoo/odoo/blob/12.0/odoo/service/model.py#L120-L154
Seems to be tricky to overload
Restricting and cascading deletes are the two most common options. RESTRICT prevents deletion of a referenced row. NO ACTION means that if any referencing rows still exist when the constraint is checked, an error is raised; this is the default behavior if you do not specify anything. (The essential difference between these two choices is that NO ACTION allows the check to be deferred until later in the transaction, whereas RESTRICT does not.) CASCADE specifies that when a referenced row is deleted, row(s) referencing it should be automatically deleted as well. There are two other options: SET NULL and SET DEFAULT. These cause the referencing columns to be set to nulls or default values, respectively, when the referenced row is deleted. Note that these do not excuse you from observing any constraints. For example, if an action specifies SET DEFAULT but the default value would not satisfy the foreign key, the operation will fail.
I solved it by overloading unlink method.
Here is the code if it helps someone:
> #api.multi
> def unlink(self):
> for field in self:
> if field.parent_id:
> raise UserError(_('It is not possible to delete a record that is already used in transactions!'))
> return super(YourClass, self).unlink()

How to create a MVC Model from SQL Server 2014 Functions

I am using SQL Server 2014 and I have a function that takes start and finish date as parameters and returns a table.
In SQL Server when I call my function I use;
SELECT *
FROM PV_GetLogByDT ('2015-11-01', '2016-03-04')
Now I want to use this function to create a MODEL for my MVC project. How can I do that?
When I do I get this error:
Microsoft Visual Studio
Error
There was an error running the selected code generator:
'Unable to retrieve metadata for 'LTKB.CARD.Models.PV_GetCARDLogByDT_Result'. One or more validation errors were detected during model generation:
CARDNOLIST: : EntityType 'CARDNOLIST' has no key defined. Define the key for this EntityType.
CARDPASSLIST: : EntityType 'CARDPASSLIST' has no key defined. Define the key for this EntityType.
CARDPINLIST: : EntityType 'CARDPINLIST' has no key defined. Define the key for this EntityType.
RESULTLIST: : EntityType 'RESULTLIST' has no key defined. Define the key for this EntityType.
CARDNOLIST: EntityType: EntitySet 'CARDNOLIST' is based on type 'CARDNOLIST' that has no keys defined.
CARDPASSLIST: EntityType: EntitySet 'CARDPASSLIST' is based on type 'CARDPASSLIST' that has no keys defined.
CARDPINLIST: EntityType: EntitySet 'CARDPINLIST' is based on type 'CARDPINLIST' that has no keys defined.
RESULTLIST: EntityType: EntitySet 'RESULTLIST' is based on type 'RESULTLIST' that has no keys defined.
OK
If you use EF it can help you. It explain step by step
http://www.entityframeworktutorial.net/stored-procedure-in-entity-framework.aspx

How to create a relation fields in odoo?

There are no proper examples on how to create relational fields in openerp like one2many, many2many, many2one and one2one. So can anyone show me with example on sales module.
Might helps you,
_columns = {
'current_rate': fields.related('company_currency_id','rate_silent', type='float', relation='res.currency',digits_compute=dp.get_precision( 'Account'), string='Current Rate', readonly=True),
}
Here,
company_currency_id => the field in the same model through which the new field will be relate,
rate_silent => is the field which you are going to relate with new field, means the field from source model,
relation => is the source model name,
type => is the datatype of the source field
Note : When you update value in your newly defined related field it
will be updated in source field as well, though it's always advisable
to set readonly in newly defined field.
I don't have particular example of sales module. But you can get the general idea from below syntax.It would be helpful for any kind of application.
class openerp.fields.Many2one(comodel_name=None, string=None, **kwargs)
Bases: openerp.fields._Relational
The value of such a field is a recordset of size 0 (no record) or 1 (a single record).
Parameters
comodel_name -- name of the target model (string)
domain -- an optional domain to set on candidate values on the client side (domain or string)
context -- an optional context to use on the client side when handling that field (dictionary)
ondelete -- what to do when the referred record is deleted; possible values are: 'set null', 'restrict', 'cascade'
auto_join -- whether JOINs are generated upon search through that field (boolean, by default False)
delegate -- set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)
The attribute comodel_name is mandatory except in the case of related fields or field extensions.
=======================================================================
class openerp.fields.One2many(comodel_name=None, inverse_name=None, string=None, **kwargs)
Bases: openerp.fields._RelationalMulti
One2many field; the value of such a field is the recordset of all the records in comodel_name such that the field inverse_name is equal to the current record.
Parameters
comodel_name -- name of the target model (string)
inverse_name -- name of the inverse Many2one field in comodel_name (string)
domain -- an optional domain to set on candidate values on the client side (domain or string)
context -- an optional context to use on the client side when handling that field (dictionary)
auto_join -- whether JOINs are generated upon search through that field (boolean, by default False)
limit -- optional limit to use upon read (integer)
The attributes comodel_name and inverse_name are mandatory except in the case of related fields or field extensions.
==========================================================================
class openerp.fields.Many2many(comodel_name=None, relation=None, column1=None, column2=None, string=None, **kwargs)
Bases: openerp.fields._RelationalMulti
Many2many field; the value of such a field is the recordset.
Parameters----------------------------------------------------------------
comodel_name -- name of the target model (string)
The attribute comodel_name is mandatory except in the case of related fields or field extensions.
Parameters
relation -- optional name of the table that stores the relation in the database (string)
column1 -- optional name of the column referring to "these" records in the table relation (string)
column2 -- optional name of the column referring to "those" records in the table relation (string)
The attributes relation, column1 and column2 are optional. If not given, names are automatically generated from model names, provided model_name and comodel_name are different!
Parameters
domain -- an optional domain to set on candidate values on the client side (domain or string)
context -- an optional context to use on the client side when handling that field (dictionary)
limit -- optional limit to use upon read (integer)

Hector API - Create Column Family - key validation class

Hey guys I am trying to load a schema into a Cassandra 0.8.2 database via Hector.
I want to add a column family (in a particular keyspace) & specify its name, comparator type, key validation class, and default validation class via Hector.
I've looked through the documentation here:
https://github.com/rantav/hector/blob/master/core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java
for the function that to do this, but it seems I must have the Column Family already created (via the Cassandra CLI) to specify the default validation class, & key validation class when creating the Column Family via the CLI. Am I correct in this assumption? Am I missing any methods? Is it possible to alter the default validation class & key validation class of a Cassandra column family via Hector?
You can do that with hector. There is an example in CassandraClusterTest where you can see new column families being created with the validation class set. There are methods on BasicColumnFamilyDefinition to set the key validation class and comparator as well.

NHibernate Validator and Schema Export question

I'm learning to use NHibernate validator and it's Fluent API (Loquacious).
I have noticed is that I can't set an integer property or nullable int property (int?) to be not nullable. Well, why not?
In a database, an integer column can have null values. Even worse, when I generate DDL using SchemaExport, the integer column wont be picking up that non-nullabity (unless I express it in the Nhibernate mappings).
If you specify the validators using ValidatorDef<>, this is detected by the the schema export, and you'll get the appropriate SQL definitions, example:
public class InvoiceValidationDef : ValidationDef<Invoice>
{
public InvoiceValidationDef()
{
...
Define(x => x.Description).NotNullable().And.MaxLength(255);
...
}
}
Results in
create table Invoices (
...
Description NVARCHAR2(255) not null,
...
)
You gave the answer already. The validator is not scanned by schema export. You have to use the mapping.
NHibernate Validator sits on top of NHibernate. It is used to validate entities against NHibernate mappings and custom rules. For configuring field properties, such as whether they are nullable, this is done in the NHibernate mappings as it affects not only the validations done, but also the generated SQL statements.