This question has been flagged
5 Replies
9415 Views

Hello, I am using v9 and I am trying to apply global discount in customer invoices. I am trying the user solution given here:

https://www.odoo.com/forum/help-1/question/how-to-give-discount-on-the-total-of-a-sales-order-6600

I have created a float field called x_global_invoice_discount , I am displaying that field in the account.invoice form and I have placed the method inside the file "/addons/account/models/account_invoice.py" in the class AccountInvoice but I am getting "undifiend object 'apply.discount' in model 'account.invoice'"

If i place the code in the file "/addons/sale/sale.py" in the class AccountInvoice then no error, but nothing happens. I am tailing the log file and the onchange event doesn't trigger :/

I am new in odoo and in python as I was writing in php and java so far... some help will be much appreciated!

The goal is: The user will add all the products he wants, then he will input the discount (eg 10%) and the value of that field should be applied in the discount field in the invoice lines. Finally the order total should be updated. In a most advanced version of this the discount should be put in each customer and applied automatically in the invoice lines.

I can provide additional info and screenshots if needed.


Avatar
Discard
Best Answer

Please refer this link. This may help you.

Visit : https://www.odoo.com/apps/modules/11.0/tis_sales_purchase_global_discount/

Avatar
Discard

well, in case you haven't found the best solution for your problem,

let me provide you with these:
- https://apps.odoo.com/apps/modules/14.0/base_global_discount
- https://apps.odoo.com/apps/modules/13.0/account_global_discount

those are exactly what I found and the most suitable one!
most importantly, they are FREE!

Author Best Answer

Thank you for your answer Ermin. I have tried quite a few modules but unfortunately the v8 and v7modules don't work on v9. The v9 module you are suggesting does not calculate the discount on the product lines also it is a paid one and I am not willing to pay 25E for such a simple task, moreover it has only 1-star rating.

I am a programmer myself but unfamiliar with python and odoo so I am asking for some help with the code :)

Avatar
Discard

I did mention the modules for 8.0 as a guide to coding it yourself or you might even think about porting one of the modules to 9.0.

Author

after a lot trial and error I have modified a v.8 module to work on v.9 but I am encountering a very strange bug which I cant seem to fix nor understand why it is happening. I have added some code that reads the value of the global discount and places it in the line.discount field of each product. The first time I click "update" to update the invoice lines with the new discount everything works fine. If I change the global discount again then only the 1st product discount field is updated. The other products' discount fields keep the old value. I keep banging my head on the wall with that but I can't figure it out....

I would really appreciate it if you could help me!