In the timesheets in odoo, is there any solution to predefine an text in the textfield like here in the picture?
Example: If I want all time the text: "Hi I'm a test text" in this field every time I create a new timesheet.
Where I can define this as a standard of this field?
If you use the new API, you can put a 'default' attribute on your field definition like this :
your_field = fields.Char(default='Your default text')
If you use the old API, you have to define a '_defaults' dictionnary in your class like this :
_defaults = {
'your_field': lambda *a: 'Your default text',
}
Related
My customer connexion form has a password field which contains pattern=".{5,}". Since it's not a registration form, I would want to remove this HTML attribute.
Thus, I opened classes/form/CustomerLoginForm.php and I saw a FormFormatterInterface was used here: classes/form/CustomerLoginFormatter.php.
The latter contains:
public function getFormat()
{
return [
[...],
'password' => (new FormField)
->setName('password')
->setType('password')
->setRequired(true)
->setLabel($this->translator->trans(
'Password', [], 'Shop.Forms.Labels'
))
->addConstraint('isPasswd'),
];
}
No line specify this HTML pattern attribute.
Where could I remove it? Should I write some setter or add some constraint in the above code? (in an override of course)
You can remove that pattern from the file: /themes/classic/templates/_partials/form-fields.tpl
Search for this line and remove or change as your needs: pattern=".{literal}{{/literal}5,{literal}}{/literal}"
I'm developing on Odoo 10.
I created a dynamic form view which search and display a product from its barcode, but I've got a problem.
Since the view has no initial record to display it is opened in edit mode, and that's ok, because I want to type the 'barcode' field.
But, after the product is displayed, when I exit from that view the 'can_be_discarded' function is fired, opening the confirm dialog.
Have I to create a new view type inheriting from FormView or is there a way to workaround this problem?
The view is a classic form view, with nothing special.
Here's the server code instead.
class ProductFromBarcode(models.TransientModel):
_name = 'levelprime_product_general_status.product_from_barcode'
_inherits = { 'product.product': 'product_id' }
product_id = fields.Many2one(
comodel_name='product.product',
store=False)
product_barcode = fields.Integer(help='Insert the barcode to search '
'the correspondent product',
store=False)
#api.onchange('product_barcode')
def on_barcode_changed(self):
if self.product_barcode != 0:
self.product_id = self.get_product_from_barcode(self.product_barcode)
#api.model
def get_product_from_barcode(self, barcode):
r = self.env['product.product'].search([('barcode', '=', barcode)])
if r:
return r
Ok, I think I'm in the right way, there are some rendering problem to solve, but the main behavior is what I was searching for.
I created a new type of view which inherit from the 'FormView' one and override the 'can_be_discarded' method to not execute controls about the data changes.
JS
odoo.define('levelprime_product_general_status.readonly_formview', function(require) {
'use strict'
var core = require('web.core')
var FormView = require('web.FormView')
var ReadOnly_FormView = FormView.extend({
init: function() {
this._super.apply(this, arguments)
},
start: function() {
this._super.apply(this, arguments)
},
can_be_discarded: function() {
return $.Deferred().resolve()
}
})
core.view_registry.add('readonly_form', ReadOnly_FormView)
return ReadOnly_FormView
})
PY
class ViewExtension(models.Model):
_inherit = 'ir.ui.view'
type = fields.Selection(selection_add=[
('readonly_form', 'ReadOnly Form Version')])
Then you can simply use the tag in the xml.
You have used _inherits = { 'product.product': 'product_id' } in your wizard.
When using _inherits you will do a kind of polymorphic model in the database way.
For example product.product inherits product.template or res.users inherits res.partner.
This mean we create a model that gets the know how of a Model but adds aditional data/columns in a new database table. So when you create a user, all partner data is stored in res_partner table (and a partner is created) and all user related info is stored in res_users table.
In your code when wizard (levelprime_product_general_status.product_from_barcode) record will create then all product.product/product.template fields are required,due to that reason you are getting this type of error.
You can check difference between _inherit & _inherits from following link.
https://www.odoo.com/forum/how-to/developers-13/the-different-openerp-model-inheritance-mechanisms-what-s-the-difference-between-them-and-when-should-they-be-used-46
You need to follow following code.
class ProductFromBarcode(models.TransientModel):
_name = 'levelprime_product_general_status.product_from_barcode'
product_id= fields.Many2one(comodel_name='product.product',string="Product")
product_barcode = fields.Char(help='Insert the barcode to search '
'the correspondent product',
"Barcode")
#api.onchange('product_barcode')
def on_barcode_changed(self):
if self.product_barcode:
self.product_id = self.get_product_from_barcode(self.product_barcode)
#api.model
def get_product_from_barcode(self,barcode):
r = self.env['product.product'].search([('barcode', '=', barcode)])
if r:
return r
else:
return False
In above code just create wizard & add two fields.
This may help you.
from what you are saying you are using inherits to show the information of the product selected by the barcode remove it and use related field:
add the fields that you are showing on the form view to you model
name = fields.Char(related='product_id.name', readonly=True)
Now you can use name on your view it's like compute field or proxy.
you can make them readonly if you want to display them.
In playframework-2.2 I have a custom form with a List<Long> selected
In the template, how can I access this List for iteration?
form("selected").value gives me the string representation
however
form("selected[0]").value gives me the value at posistion 0.
You could use #repeat helper.
E.g provided by play docs
#repeat(myForm("emails"), min = 1) { emailField =>
#inputText(emailField)
}
See more
Currently the additional field is calculted in the grid columnCfgs using an xtype of templatecolumn. I need to add this field to the grid data store so that it can be used to filter the grid data.
Model classes fields property is processed in a special fashion. Instead of replacing the parent class' ones as a normal property would, child fields are appended to them.
See this example:
Ext.define('Base', {
extend: 'Ext.data.Model'
,fields: ['foo','bar']
});
Ext.define('Extended', {
extend: 'Base'
,fields: ['baz']
});
var record = Ext.create('Extended');
record.fields.each(function(field) {
console.log(field.name);
});
That gives the following output:
foo
bar
id
baz
I know that I can register a new meta tag in Yii and I know how to do it, but I need to
replace the default tag that I have set, because when I am on a article, I want to insert the
short description of the article in the meta tag;
How can I manage the meta tags?
If you're on the latest version you can give the metatag an id.
->registerMetaTag('example', 'description', null, array(), 'mytagid');
Calling registerMetaTag again with the same id will overwrite it.
http://www.yiiframework.com/doc/api/1.1/CClientScript#registerMetaTag-detail
You can set Meta tag per page using:
Yii::app()->clientScript->registerMetaTag("This is my meta description", 'description');
Yii::app()->clientScript->registerMetaTag("These, are, my, keywords", 'keywords');
This can be set in the Controller or the view, and obviously depending on how you are querying your articles, you can make the content part dynamic like so (assuming $model is your selected article and meta_description is your model attribute storing the meta description):
Yii::app()->clientScript->registerMetaTag($model->meta_description, 'description');
Documentation on the Yii site can be found here
You can try this:
1) In 'components/Controller.php':
public $metaDescription;
public $metaKeywords;
public function getMetaDescription() {
if(!$this->metaDescription)
return Yii::app()->settings->getValue('meta_description'); //return default description
return $this->metaDescription;
}
public function getMetaKeywords() {
if(!$this->metaKeywords)
return Yii::app()->settings->getValue('meta_keywords'); //return default keywords
return $this->metaKeywords;
}
2) In your main.php layout:
...
Yii::app()->clientScript->registerMetaTag($this->getMetaDescription(), 'description');
Yii::app()->clientScript->registerMetaTag($this->getMetaKeywords(), 'keywords');
...
3) In your other layouts:
...
// If you don't do that, the description and keywords will be default for this page.
$this->metaDescription = 'Your description here';
$this->metaKeywords = 'your, keywords, here';
...
Note, that Yii::app()->settings->getValue('meta_description') and Yii::app()->settings->getValue('meta_keywords') is my default values that takes from DB.