'''INSERT INTO
main_parse_user ("user_id","group_id", "username","bio", "first_name")
VALUES (%s,%s,%s,%s,%s)
ON CONFLICT (user_id)
DO UPDATE SET (group_id,username,bio,first_name) =(EXCLUDED.group_id,EXCLUDED.username,coalesce(main_parse_user.bio, EXCLUDED.bio),EXCLUDED.first_name)'''
How can I make the username field so that when adding a new record, make it so that if the value from the loaded request in the username field is empty, just skip this user
I haven't tried anything yet
Related
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()
Odoo do an Auto Populate a Grid when a user Creating a new information with One2many relations fields?
this is my Example Auto Populate
def getCheckListId(self):
self.env.cr.execute("select 1 employee_id,1 PARAM1,1 PARAM2,1 PARAM3,1 PARAM3,1 PARAM4 from hr_employee_checklist ")
checklistTemplates = self.env.cr.fetchall()
return checklistTemplates
And this function will be used as a default in One2ManyFields
employee_checklists = fields.One2many('hr.employee_checklist','employee_id', readonly=False,copy=False, default = getCheckListId)
But I have an error
the error is
AttributeError: 'str' object has no attribute 'iteritems'
Can someone help me with this problem or other ways to populate Grid in Odoo
One2many
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)
So, One2many fields always contains comodel's reference value, you just need to give ids of that relational field, remaining things will maintain by odoo engine it self.
#api.model
def getCheckListId(self):
return self.env['hr.employee.checklist'].search([]).ids
on my edit/add page for SQLFORM.grid I would like to get the values of some fields on process. In case this value in combination with another field (userid) already exists user has to be notified about it.
any suggestions?
You can simply define the validator for one of the fields so it doesn't allow duplicates when the other field is also a duplicate, and then let the standard form validation process handle everything:
db.define_table('mytable',
Field('userid', 'reference auth_user'),
Field('otherfield',
requires=IS_NOT_IN_DB(db(db.mytable.userid == request.vars.userid),
'mytable.otherfield')))
Whenever a form is submitted, the IS_NOT_IN_DB validator will return an error if the value of "otherfield" is duplicated among the set of records where "userid" is also duplicated.
When calling UserManager.GenerateEmailConfirmationToken() I get a token, but the ConfirmationToken column in AspNetUsers table is left empty. Does this method suppose to put the token there automatically, and if so where do I tell it the name of the column to look for. Or maybe I need to manually put the token there myself after calling it ?
(Also the EmailConfirmed column in AspNetUsers stays False after calling UserManager.ConfirmEmail but I presume it happens for the same reasons).
There is no ConfirmationToken column by default in Identity 2.0, are you sure this isn't something you added in your user class?
It is possible to check user by credentials without login for:
exits user
password is correct
is not banned
is activated
...
As I can see, I must write a lot of code for this. Maybe exists any easiest way?
Check the user is valid without logging in with Auth (Native):
$credentials = array('email' => 'xx', 'password' => 'xx', 'deleted_at' => null);
if(Auth::attempt($credentials, false, false)) {
// Exists and password is correct and not banned
}
This requires you to keep the deleted_at field in your table to soft deleting technique (By disabling or enabling a user temporarily).
If you are using a different field to make a user inactive/active then pass that field instead of deleted_at, for example, you may use a field active with value 1 to indicate an active user and 0 for an inactive user, in this case pass active => 1 to check the active field has value 1 as the third item in the credentials array.