0

UPLOADED MODULE TO GIT --> https://github.com/Kushikime/Invoice_currency_changer


I want to change the _create_invoice() method in sale.advance.payment.inv model.

This method is called from another method of the same class create_invoices()

I was tried to inherit the method. But have success only with create_invoices()

So in result, I want to know why I can't change _create_method() (i know they called private method's but the way of inheriting must be the same I think)

Code:

#original Odoo class
class SaleAdvancePaymentInv(models.TransientModel):
    _name="sale.advance.payment.inv"
    ...
    @api.multi
    def create_invoices(self):
        ...
        self._create_invoice(order, so_line, amount)

    @api.multi
    def _create_invoice(self, order, so_line, amount):
        ...

And here is the code, how i tried to inherit methods:

class myClass(models.TransientModel):
    _inherit="sale.advance.payment.inv"

    #INHERITING create_invoices() **SUCCESS INHERITED**
    @api.multi
    def create_invoices(self):
        _logger.debug("PRINT TRUE IF INHERIT IS SUCCESS")
        #HERE ODOO PRINT THE MESSAGE SUCCESS.
        ...
        self._create_invoice(order, so_line, amount)#HERE I TRY TO CALL THE METHOD WHICH I WAS CREATED FOR INHERITING
        _logger.debug("Print OK if all OK")
        #HERE ODOO IS NOT PRINT ANYTHING
        res = super(myClass, self).create_invoices()
        return res

    #HERE I TRY TO INHERIT THE ORIGINAL _create_invoice() method
    @api.multi
    def _create_invoice(self, order, so_line, amount):
        _logger.debug("PRINT TRUE IF SUCCESS INHERITED")
        #IN DEBUG LOGS ODOO DIDN'T PRINTED ANYTHING HERE

So it's look like after i call _create_invoice() in my inherited method, odoo from that point start to use the code from original class and not from myClass().

any help will be appreciated

KushiNii
  • 7
  • 8
  • So def create_ivoices(...) is inherited properly, but def _create_invoice dont? Can you remove @api.multi decorator and see if it works? –  Jul 04 '18 at 10:13
  • @TadeuszKarpinski Nope, that's doesn't help :c – KushiNii Jul 04 '18 at 11:43
  • And now one obvious question. Does your module depend on the account module? –  Jul 04 '18 at 12:49
  • @TadeuszKarpinski Nope :/ I was set depend only on sales module – KushiNii Jul 04 '18 at 13:01
  • The class which i inheriting is related to sale module – KushiNii Jul 04 '18 at 13:03
  • Your .rar file is full of basics syntax errors(import, identation, never use variables, etc), please resolve that before share some code, and the project is not to large to being charged inside your question. – Juan Salcedo Jul 06 '18 at 02:11
  • 1
    @JuanSalcedo thank you for helpful answer – KushiNii Jul 06 '18 at 05:40
  • You are asking help for a specific problem and not installation problem, if you are gonna share your module, please be sure it is able to install at least. Here we are to give some guide and not for do your work, its my personal opinion, nevertheless if you solve that minimal issues, I'll be pleasure to help you. – Juan Salcedo Jul 07 '18 at 03:45

2 Answers2

0

Your inheritance is already fine, but you should try change _logger.debug(.. for _logger.info( to see your logs, I got this messages from my log console the other mode start the Odoo server in DEBUG mode:

2018-07-04 07:17:34,612 13072 INFO mydatabase odoo.addons.mymodule.models.sale: PRINT TRUE IF INHERIT IS SUCCESS
2018-07-04 07:18:19,591 13072 INFO mydatabase odoo.addons.mymodule.models.sale: PRINT TRUE IF SUCCESS INHERITED
2018-07-04 07:18:23,249 13072 INFO mydatabase werkzeug: 127.0.0.1 - - [04/Jul/2018 07:18:23] "POST /longpolling/poll HTTP/1.1" 200 -
2018-07-04 07:18:49,016 13072 INFO mydatabase odoo.addons.mymodule.models.sale: Print OK if all OK
2018-07-04 07:19:03,848 13072 INFO mydatabase odoo.addons.mymodule.models.sale: PRINT TRUE IF SUCCESS INHERITED

I hope this answer can be helpful for you.

Juan Salcedo
  • 1,598
  • 1
  • 16
  • 28
  • Thank you for the answer, i changed the type of logging, but that's didn't help me, you wanna say that's code example is working? – KushiNii Jul 04 '18 at 08:16
  • Yep, I just put `sale` like a dependency, `sale.py` in a `models` folder and `import sale` in `__init__.py` file, I changed `_logger.debug` for `_logger.info(` and nothing else. I proved it in Odoo .v10. Maybe you can share your module in a github repository to get a better understanding what are you doing. – Juan Salcedo Jul 04 '18 at 19:32
  • yeap i think i will) – KushiNii Jul 05 '18 at 06:57
0

I know it's late but it may be useful for other people. I had the same problem and I solved it by putting the module 'sale' as a dependency in the manifest file. It worked for me.

I hope it is useful.