Odoo Help

0
3 Answers
0
Mohamed Sabry
12/7/18, 3:15 AM

Hi Pranav,

Thank you for your response.

Yes am using odoo classes, but sorry i didn't get why i have to inherit the phone.book? I need none of the fields declared in it,actually the other model in the second Module(waseel_crm) has its own fields. I just need the unlink function. And if i assumed that i will inherit to access the functions of the (phonebook.py) model why do i have to re-declare the unlink function after inheriting as you did?

1 Comment
Pranav P S
12/8/18, 11:42 PM

So you are using same class in new module.

Just call self.unlink()

0
Avatar

subbarao

--subbarao--

1040
| 5 1 4
Chennai, India
--subbarao--


subbarao
12/6/18, 8:20 AM

Hello Mohamed,

self.env['phone.book'].search([]).unlink()

inside search pass your domain or else it will call unlink() for all phonebook records

Don' t forgot add first module dependency on second module


 

0
Pranav P S
12/6/18, 8:05 AM

Hi Sabry,

As per my understanding you are using standard odoo class.

If you have defined class PhoneBook as standard odoo class(models.Model) you can inherit the class and call super function.
Eg:

class PhoneBook(models.Model):
    _name = 'phone.book'

    @api.multi

    def unlink(self):
        for rec in self:
            if rec.name == 'JOHN':
                raise NameError('Record with name John can\'t be deleted')


And in new python file inherit it



class PhoneBook(models.Model):
    _inherit = 'phone.book'


    @api.multi

    def unlink(self):
        for rec in self:
            if rec.name == 'JOHN':
                raise NameError('Record with name John can\'t be deleted')


Or else if you are using a normal python class you have to import it properly thats it.

Ask a Question
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now