On the sale order report in Odoo, I'm displaying the customer_lead field. This field is defined as float and I'd like to change it to Int just because I need a number of days (2, 4, 5, etc)
I tried to add this code inside my python file but it's not changing it to Int
from odoo import fields, models, api
class SaleOrderLine(models.Model):
_inherit = 'sale.order.form'
customer_lead = fields.Int(string='Cust. Lead.')
How can the default field type be changed?
If you change the field type from Float to Integer, you will lose the field values.
Odoo defined the widget attribute to customize the field's behavior so you can use the integer widget in the view definition
<field name="customer_lead" widget="integer"/>
To automatically display the integer part of the float value
You can also use the same in the QWEB report, just specify the widget you want to use in the field options:
<field name="customer_lead" t-options="{'widget': 'integer'}"/>
Note that Odoo uses the integer widget on the available_threshold field in the form view
Related
example/models/example.py
class Example(models.Model)
_name = 'example.model'
product_tmpl_id = fields.Many2one('product.template','Product Template',delegate=True,ondelete='cascade',required=True)
example/models/product_template.py
class ProductTemplate(models.Model)
_inherit='product.template
example_ids = fields.One2many('example.model','product_tmpl_id',string='Item')
example/views/example.xml
<form>
<field name="product_tmpl_id" widget="many2one"/>
</form>
My understanding was that a product_template record would be automatically created with example, but this field is required and not letting me save a new record. When I perform an import of the example data adding these columns at the beginning for product_template ("exampleNN", "name", "type", "categ_id/id", "sale_ok", "purchase_ok",...) I get a matching product template with an id of "exampleNN_product_template" and identical name (though example does not have name so it must be using product template).
product_tmpl_id does not like being on the form view as it is required, yet not created yet with delegation inheritance. I used tree view instead to see product_tmpl_id. I was curious about its value after doing an import.
I add a button that open a new wizard, this last is contain only one field is number , that's number is the number of fields that i want to creat on my tree notebook tree view with default value
for example if i type 20 , thene whene i submit should i get 20 entries in the tree view
Here is a capture of the model :
Look to my code :
#api.multi
def creat_fields(self):
numbers = self.w_qtt
for values in numbers:
# self.env['sale.order.line'].create(lignes_vales)
self.env['sale.order.line'].create({
'contrat_name_id': self.w_contrat_name,
'contrat_lignes_id' : self.w_contrat_line,
'product_id' : self.w_product_name,
'bons_po' : self.w_po_number,
'product_uom_qty' : 1,
'price_unit' : self.w_prix,
})
and on the xml :
<footer>
<button string="Cancel" class="oe_link" special="cancel"/>
<button
name="creat_fields"
string="Enregistrer"
class="oe_highlight"
context="{'default_source_record_id': active_id}"/>
</footer>
I'm assuming that this is a one2many field. One2many fields are linked to your model by specifying the record id number in a field that you specify when you define the many2one field.
For example:
child_ids = fields.One2many('child.model.name', 'parent_id', 'Child Records')
So when you create a new line using the one2many field, a new record is created of model "child.model.name" and the parent_id field is set to the id of the current record.
So to create a number of empty lines in your form, all you have to do is create records with the "parent_id" field set to the originating records id.
Firstly, you will need to pass the originating record's id to the wizard, which you would do in the button definition:
<button name="%(wizard_action)d"
string="Wizard Button"
type="action"
context="{'default_source_record_id': active_id}" />
You will need a field called "source_record_id" in your wizard, which will be a many2one field with the same model that you are calling it from, and you will need to have that field in your wizard view, but you can make it invisible if you want.
In the code you're calling from the wizard, you will create a loop to call the create method on the "child.model.name" model to create that number of empty records. It would look something like this:
iterations = self.nombre
for i in range(iterations):
self.env['child.model.name'].create({
'parent_id': self.source_record_id.id
})
That will create the empty records and they will be displayed in your one2many field.
This is with Odoo 10 and the default bootstrap-datetimepicker.
I have a field in my view that has a "Start of event" datetime. I'd like the date picker that shows up to work in 5 minute intervals (minuteStepping: 5) and to show the time picker along with the date picker (sideBySide: true).
I've confirmed that this works as I want it to by editing addons/web/static/src/js/widgets/date_picker.js manually.
However, I'd prefer to just give the two options I want to change as a parameter to my <field ..> definition under my <form> tag in the view XML. The source Widget accepts an options parameter in its init method that it extends to end up with the final options object, but I've been unable to insert my configuration options into this object.
I tried giving it as <field ... options="{...}" and as .. t-field-options='..', but I'm guessing the latter won't work since I'm not in a qweb context in my view, and the first one isn't read by widgets.
Is there any way I can do this without creating a new widget? (and hopefully without subclassing or extending the existing widget, but keep it as a pure view configuration option instead)?
You can see a great example in this module. https://github.com/OCA/web/tree/10.0/web_m2x_options
In the file. static/src/js/form.js.
The module has overridden the fields Many2one to add different options can be set in the XML declaration of field.
Example : <field name="partner_id" options="{'search_more':true}" />
In this example. The search more button is visible in all cases.
You can use the logic of this module as a base of your widget extension.
Installation:
In a First time, you must download the Github repository.
https://github.com/jo541/web
Select the branch 10.0.
In the repository, there are a named module "web_widget_datepicker_options". This module gives you the possibility to specify any options as you want for a specific field.
After download and install the module on Odoo. You needing to reload the cache of your browser to be sure.
Modification:
Now you can modify your form view. For an example, I will use the view form sale.order.
In the form view sale.order, you have a field "date_order". If you would like to have the time step 5 by 5.
<field name="date_order" options="{'datepicker':{'minuteStepping': 5}}" attrs="{'invisible': [('state', 'in', ['sale', 'done', 'cancel'])]}"/>
All the options in the dict of the key datepicker will be adding to the option of the bootstrap datepicker.
I want to add a new category of Salary Structure by data file. Here is my current code
<record id="MEALS" model="hr.salary.rule.category">
<field name="name">Meals</field>
<field name="code">MEALS</field>
<field name="parent_id" eval=""></field>
</record>
All I need is a category with no parent category but with these code parent category of it is Base for new structures. I've tried with evals="0", evals = " " or remove field parent_id out of .How can I add null value into this field ?
This behaviour is a little weird .AFAIK If you don't include the parent_id field, it should work and have a null value because that field doesn't have a default value on it. (Except you've extended the model and added a default on that field).
The only fields where null values don't work in the Odoo ORM are Integer and float fields. (That's the reason they always have an initial value of 0 or 0.0 in a form view).
quoting the docs:
field
Each record can be composed of field tags, defining values to
set when creating the record. A record with no field will use all
default values (creation) or do nothing (update).
A field has a mandatory name attribute, the name of the field to set,
and various methods to define the value itself:
Nothing
if no value is provided for the field, an implicit False will
be set on the field. Can be used to clear a field, or avoid using a
default value for the field.
Try this <field name="parent_id" /> or <field name="parent_id" eval="False" />
If the above don't work then double check your codebase and make sure you're not setting any default value on the field.
In OpenERP version 7, I need to show or hide a field in the Form View of the "Add Object" based on the values from the Parent Object.
For example, I have a field demo_field1 in sale_order. When I create a Sale Order Line, I do not want to show the field "th_weight" if the demo_field1 for the Sale Order is greater than 200.
using attrs="{'invisible': [('demo_field', '>', '200')]}" or attrs="{'invisible': [('order_id.demo_field', '>', '200')]}" shows invalid field in domain.
How to achieve this?
I also had the same issue some time before. What i did was to add a related field in the sale_order_line and define attriute based on that related field. ie;
In sale order line i defined a related field to the field demo_field1 as:
'test_field_new': fields.related('order_id', 'client_order_ref', string="Test Field", type="float")
But the related field will only be loaded at the time of saving the record. So i passed the default value of the field test_field_new from xml file as:
<field name="order_line" context="{'default_test_field_new': demo_field1}"/>
so that when i click on "Add new item" in one2many field, the value of the field demo_field1 will be loaded by default to test_field_new and i defined the attribute using the field test_field_new.
<field name="price_unit" attrs="{'invisible': [('test_field_new', '>', 200)]}"/>
I am not sure this is a clean method to do...