Odoo Help

0

Adding a global discount to sale.order, how?

By
E.M.
on 2/7/16, 3:12 PM 730 views

Hi,

I am trying to extend the sale.order class, but I do not know how to use the new field discount_rate in _amount_all.

Could someone help and clarify how to add this field?


This is the code to inherit the sale.order class adding the two new fields:
# -*- coding: utf-8 -*-
from openerp import models, fields, api
class SaleOrderDiscount(models.Model):
_inherit = 'sale.order'
discount_rate = fields.Float(
string='Discount Rate (%)',
readonly=False
)
amount_discount = fields.Float(
string='Amount Discount'
)
@api.onchange('discount_rate', 'amount_untaxed')
def calculate_discount(self):
self.amount_discount = self.amount_untaxed * (self.discount_rate / 100)
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
cur_obj = self.pool.get('res.currency')
res = {}
for order in self.browse(cr, uid, ids, context=context):
res[order.id] = {
'amount_untaxed': 0.0,
'amount_discount': 0.0,
'amount_tax': 0.0,
'amount_total': 0.0,
}
val = val1 = 0.0
cur = order.pricelist_id.currency_id
for line in order.order_line:
val1 += line.price_subtotal
val += self._amount_line_tax(cr, uid, line, context=context)
val2 = val1 * (self.discount_rate / 100)
res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)
res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur, val1)
res[order.id]['amount_discount'] = cur_obj.round(cr, uid, cur, val2)
res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax'] - res[order.id]['amount_discount']
return res

1

Ray Carnes

--Ray Carnes--
16599
| 9 7 9
Atlanta, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0; Odoo 8.0, 9.0, 10.0.

Completed Odoo Functional and Technical Training.

Major Skills:

  • User Needs and GAP Analysis;

  • Functional and Technical Design;

  • Prototyping and Proof of Concepts;

  • Requirements Specifications;

  • Agile Implementation;

  • Data Migration;

  • Configuration & Customization (UI and code);

  • Integration - Odoo and non Odoo Applications and Services;

  • Training and Knowledge Transfer;

  • Go Live Support;

  • Helpdesk;

  • Version Upgrades and Migration.

  • Accounting Expert.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

I am a skilled Communicator and I only take the serious things seriously!

Ray Carnes
On 2/7/16, 4:42 PM

Have you seen "Global Discount on Sales Orders" at https://apps.openerp.com/apps/modules/8.0/global_discount/

Thanks Ray, I checked it out and it is great and easy. However I would like to be able to add a true global discount Ialso for the shake of trying to finally understand how Odoo works, (which is being quite challenging)

E.M.
on 2/8/16, 2:04 AM

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

Question tools

1 follower(s)

Stats

Asked: 2/7/16, 3:12 PM
Seen: 730 times
Last updated: 2/7/16, 4:42 PM