Odoo 12: KeyError: 'ir.values' - odoo

I m trying to create a new contact in odoo application but it shows me this error :
KeyError: 'ir.values'
The issue is related with this funtion.
class ResPartner(models.Model):
_inherit = 'res.partner'
def _default_credit_limit(self):
return self.env['ir.values'].get_default('account.config.settings', 'credit_limit')
I don't understand the problem
Can you please help me

KeyError: 'ir.values'
If you run self.env['ir.values'] on Odoo 12, you will get the above error because the ir.values Model does not exist in Odoo 12.
The ir.values Model was removed and replaced with ir.default. For example:
self.env['ir.default'].get('sale.order', 'sale_order_template_id')
You can see the relevant file in the Odoo core code or the commit where most of that Model was added.

Are you sure that this setting even exists anymore? I don't know for sure, but couldn't find it, i'm aware in Odoo 8 it existed. Beside the fact, that i don't think it exists anymore: account.config.settings don't exist for 100% sure, because the settings model was refactored into res.config.settings.
Actually the partner field credit_limit is gone, too. So if you want to use it and have a default outside the code, use ir.default for your desired behaviour.

Related

Where should i'll find the model "sale.order" code in Odoo 11

please guide me how can i see the actual code of sale.order as i have seen many times the
_inherit = 'sale.order'
I have gone through the github url "https://github.com/odoo/odoo/" but didn't ablelto find actual base model code.
The original model sale.order is declared in the sale module, folder models, file sale.py.
Github path: https://github.com/odoo/odoo/blob/11.0/addons/sale/models/sale.py
You can easily find the definition of any model looking for the following regular expression in your Odoo folder:
_name\s?=\s?.your.model.name.
And if you filter the searching to look only in .py files, it will be quicker.

Getting reference from model One2many relationship comodel inside an ir.actions.act_window

Would like to ask on how you can get the id of the comodel inside the ir.actions.act_window.
See my source code: https://gist.github.com/renesansz/2642b02875475383605e
Currently, I cannot get the sprint_id.project_id.current_sprint reference since it's giving me an error of Uncaught Error: NameError: name 'sprint_id' is not defined. So what I wanted to happen is that upon opening the project it should add a default filter for the current sprint of the project.
Do I have any alternative for this kind of approach?
Tried doing domain, but still no luck solving the issue.
Try this: make related field and then use this field in xml view.

How to change default dates values set for hr.holidays form in Odoo 8

I would like to change the defaults values set for date_from and date_to fields in the hr.holidays form but I can't figure out where those values came from.
There is no _defaults in the model and no defaults= in the fields definition.
Any hint ?
I finally figured out where those values are set.
It's hardcoded in the web_calendar.js script. See:
https://github.com/odoo/odoo/blob/8.0/addons/web_calendar/static/src/js/web_calendar.js#L627
You can check the sale module check the sale.py for Odoo 9.0 community addons but Odoo 8.0 some module is not yet migrated for new API and do apply your own function make it as your own logic and call it on your field attribute.
FOR EXAMPLE :
#api.model
def _default_note(self):
return self.env.user.company_id.sale_note
note = fields.Text('Terms and conditions', default=_default_note)
I hope my answer may helpful for you :)

Adding new field on Odoo Product Variant

I am trying to add new field to product.product model.
What I've done so far is:
Add new field on the following model (From Settings > Database Structure > Models):
product.product
with the following details:
Name: x_product_cost
Field Label: Product Cost
Field Type: Float
and leave the rest to default.
The problem is i am unable to show it on the form. This is the only code that is generated when I tried to edit Form:
View Name: product.product.form
Object: product.product
Inherited View: product.template.common.form
Product Variant
lst_price
I can't use product.template model, since that inherits to product.product
Am i missing something here?
PS: I am trying to temporarily fixed assign-different-cost-on-product-variant bug as specified here
https://github.com/odoo/odoo/issues/1198
Can anyone help me with this?
Actually instead of modifying the model from the Odoo configuration, you should create a custom module, in which you will add the new fields and the new behaviors that you need.
To do so you will have to inherit from the models in the python files to extend them, and you will surely have to modify the views as well, so that your custom fields get displayed.
For reference on how to extend models, create a custom module and create the views, you should refer to the Odoo documentation that you can find here.
As an additional note in case you didn't know, but their is a new API that appeared in the version 8 of Odoo, if you can use it, it is much easier and much nicer.

Ohm: how to drop a column/attribute?

There's an attribute that I no longer need, and I would like to drop it. I can't seem to simply remove the attribute from my model code, because there is an error when I load the instance. It complains that the myattrib= method does not exist. I guess it complains because Ohm sees the key in the database, but the attribute :myattrib does not exist in the model code.
How do I delete the column/attribute through Ohm, before I change my code and remove attribute :myattrib?
I tried this and it worked for me: Model.key[:myattrib].del
found it here: http://ohm.keyvalue.org/Ohm/Model.html#delete-instance_method