I am trying to override a single method on wizard's class that gets executed when the user click submit.
account_consolidation_custom/wizard/CustomClass.py
class AccountConsolidationConsolidate(models.TransientModel):
_name = 'account.consolidation.consolidate_custom'
_inherit = 'account.consolidation.base'
def get_account_balance(self, account, partner=False, newParam=False):
....my custom code...
account_consolidation_custom/__manifest_.py
{
'name': "account_consolidation_custom",
'summary': """""",
'description': """
""",
'author': "My Company",
'website': "http://www.yourcompany.com",
'category': 'Uncategorized',
'version': '0.1',
'depends': ['base','account_consolidation'],
# always loaded
'data': [],
}
The method's name is exactly the same as the original, but when I click on the submit button, nothing seems to happen, is still calling the method from the base module instead of the custom.
Do you know how to get only one method overwritten instead of the whole wizard class?
You're creating a new wizard/transient model when giving different values to the private attributes _name and _inherit. Instead you should use the original odoo model name account.consolidation.consolidate to both attributes or just remove the _name attribute completely.
Odoo has it's own inheriting mechanism, which is managed by the three class attributes _name, _inherit and _inherits.
I was able to make it work using the following code:
class AccountConsolidationConsolidate(models.TransientModel):
_inherit = 'account.consolidation.consolidate'
def get_account_balance(self, account, partner=False, newParam=False):
....my custom code...
After that I was able to overwrite the base methods.
Related
In this case, I would like that permissions on something be inherited from account.move because it is dependent on it. How do I do that ?
class ResPartner(models.Model):
_inherit = "res.partner"
something = fields.Float('Something', compute="_compute_something")
def _compute_something(self):
self.env['account.move'].search(...)
You can use sudo() in the search method.
sudo() use for super admin permission. you can access all recodes of all modules.
class ResPartner(models.Model):
_inherit = "res.partner"
something = fields.Float('Something', compute="_compute_something")
def _compute_something(self):
self.env['account.move'].sudo().search(...)
I'm trying to add inheritance on existing object in Odoo, which is "mail.alias.mixin" into "utm.campaign" object.
I tried to do _inherit = ["mail.alias.mixin", "utm.campaign"] but when I install my module it always said
File "/home/randy/Odoo/odoo_12/odoo/modules/registry.py", line 180, in __getitem__
return self.models[model_name]
KeyError: None
Here is my code in full:
manifest.py
{
"name": "CRM ext",
"version": "12.4.0.0.0",
'author': 'me',
"description": """
extend CRM.
""",
"depends": [
'crm',
'calendar',
'fetchmail',
'utm',
'web_tour',
'digest',
'mail',
],
'init_xml': [],
'data': [
"security/ir.model.access.csv",
'data/crm_question.xml',
'wizard/lost_and_link_partner_crm_wizard_views.xml',
'views/crm_lead_view.xml',
],
'installable': True,
'active': False,
'application': False,
}
And my utm.py
from odoo import api, fields, models, SUPERUSER_ID
from odoo.http import request
from odoo.tools import pycompat
from odoo.tools.safe_eval import safe_eval
class Campaign(models.Model):
_name = "utm.campaign"
_inherit = ["mail.alias.mixin", "utm.campaign"]
alias_id = fields.Many2one('mail.alias', string='Alias', ondelete="restrict", required=True, help="The email address associated with this campaign. New emails received will automatically create new leads assigned to the campaign.")
crm_team_id = fields.Many2one('crm.team', string="CRM Team")
I except that my inheritance is correct, but It seems that I missing something.
According to Odoo 12 documentation you can inherit from multiple models only if _name is set. In your code _name is equal to parent model and that is same as not setting name. You're not defining new model so you can not inherit from multiple parents.
https://www.odoo.com/documentation/12.0/reference/orm.html#reference-orm-inheritance
_inherit
If _name is set, names of parent models to inherit from. Can be a str if inheriting from a single parent
If _name is unset, name of a single model to extend in-place
I found it,
So "mail.alias.mixin" are abstract object, I miss this one. So, I need to implement all the abstract method too.
Hope this can save someone's day!
I want to inherit #classmethod of class BaseModel(object)
How to inherit or override the #classmethod in our custom module ?
I just ran into this today :)
You can extend it in a couple of ways. It depends if you really need to extend BaseModel or if you need to extend a specific sub class of BaseModel.
Sub Class
For any sub class you can inherit it as you would normally:
from odoo import api, fields, models
class User(models.Model):
_inherit = 'res.users'
#classmethod
def check(cls, db, uid, passwd):
return super(User, cls).check(db, uid, passwd)
Extend BaseModel Directly
In the case of BaseModel itself you are going to need to monkey patch:
from odoo import models
def my_build_model(cls, pool, cr):
# Make any changes I would like...
# This the way of calling super(...) for a monkey-patch
return models.BaseModel._build_model(pool, cr)
models.BaseModel._build_model = my_build_model
In a custom module I have two classes. How can class test in #api.one call test2_func on a button click?
What should I put in def call_test2_func(self)?
For example:
class test(models.Model):
_name = "test.class"
_description = "TEST"
#api.one
def call_test2_func(self):
"""call test2_func here"""
class test2(models.Model):
_name = "test2.class"
_description = "TEST 2"
#api.one
def test2_func(self):
print("TEST 2")
Maybe I should leave a reply instead of a comment. If you're using Odoo and the new OpenERP api you can can access the model dictionaty though self.env in your model classes. So to call the function test2_func in the model test2.class you should write
#api.one
def call_test2_func(self):
self.env["test2.class"].test2_func()
I'm having some trouble to understand how to get field values from another model.
I added a custom field in res.partner module by making a custom module:
class custom_partner_fields(osv.osv):
_inherit = 'res.partner'
_columns = {
'RTN': fields.char('RTN Numerico'),
}
_defaults = {
}
custom_partner_fields()
Then I create a custom xml for the form view when creating a new customer and now I can see RTN field in the customer create form.
Now I want this new field to appear when making a new quotation/sale order.
I would like it to get its value when I select my customer (I believe onchange function should be use but don't know how to use that!),so what I did was create a custom module for it:
class custom_saleorder_fields(osv.osv):
_inherits = 'sale.order'
_columns = {
'partner_rtn': fields.char('RTN'),
}
custom_saleorder_fields()
I believe I need to use something like a function or relational field for this but what I've tried hasn't worked yet.
Then, I created the custom view form the sale order form view and adds my partner_field.
Now, I would like to know how can I access the specific RTN value from res.partner module from custom_saleorder_fields based on the selected customer.
On the other hand, the main purpose of this new value is to displayed in the sale workflow and also print it in a report.
You need to add relational field in sale order model.
Before applying code you should refer that documentation of odoo,
In the Odoo Field Doc you will know how fields.related works.
class custom_saleorder_fields(osv.osv):
_inherits = 'sale.order'
_columns = {
'partner_rtn': fields.related('partner_id','RTN',type="char",relation="res.partner",string="RTN",store=True,readonly=True),
}
custom_saleorder_fields()
bring modelA fields in modelB by relatiional fields
eg use many2one field in another model :
from openerp import models, fields, api
class partsproviderclass(models.Model):
_name='partsprovider.vechicle'
#_rec_name='parts_provider'
id=fields.Integer()
parts_provider=fields.Many2many('supplier.car', string="Parts provider")
parts_name=fields.Many2many('selection.selection',string="Parts Name")
parts_price=fields.Float(string="Price of the Part")
class selectionsxample(models.Model):
_name='selection.selection'
name=fields.Char('name',required=True)
value=fields.Char('value',required=True)