13 changed files with 72 additions and 378 deletions
@ -1,34 +0,0 @@ |
|||||
{ |
|
||||
'name': 'Sale Discount for Total Amount', |
|
||||
'version': '1.0', |
|
||||
'category': 'sale', |
|
||||
'sequence': 6, |
|
||||
'summary': "extension of default Sale Management module meant to provide discount for total amount", |
|
||||
'author': 'Cybrosys Techno Solutions', |
|
||||
'company': 'Cybrosys Techno Solutions', |
|
||||
'website': 'http://www.cybrosys.com', |
|
||||
|
|
||||
'description': """ |
|
||||
|
|
||||
Sale Discount for Total Amount |
|
||||
======================= |
|
||||
Module to manage discount for total amount in Sale. |
|
||||
Two Type of Discount, |
|
||||
Discount by a fixed value, |
|
||||
Discount by a percentage... |
|
||||
""", |
|
||||
'depends': ['sale', 'base', 'stock'], |
|
||||
'data': [ |
|
||||
'views/sale_view.xml', |
|
||||
'views/account_invoice_view.xml', |
|
||||
'views/invoice_report.xml', |
|
||||
'views/sale_order_report.xml', |
|
||||
'views/sale_discount_approval_view.xml', |
|
||||
'views/sale_discount_approval_workflow.xml' |
|
||||
|
|
||||
], |
|
||||
'demo': [ |
|
||||
], |
|
||||
'installable': True, |
|
||||
'auto_install': False, |
|
||||
} |
|
@ -1,2 +0,0 @@ |
|||||
import account_invoice |
|
||||
import sale |
|
@ -1,88 +0,0 @@ |
|||||
from openerp import api, models, fields |
|
||||
from openerp.osv import osv |
|
||||
import openerp.addons.decimal_precision as dp |
|
||||
|
|
||||
|
|
||||
class AccountInvoice(models.Model): |
|
||||
_inherit = "account.invoice" |
|
||||
|
|
||||
@api.one |
|
||||
@api.depends('invoice_line.price_subtotal', 'tax_line.amount') |
|
||||
def _compute_amount(self): |
|
||||
self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line) |
|
||||
self.amount_tax = sum(line.amount for line in self.tax_line) |
|
||||
if self.discount_type == 'percent': |
|
||||
self.amount_discount = ((self.amount_untaxed + self.amount_tax) * self.discount_rate) / 100 |
|
||||
elif self.discount_type == 'amount': |
|
||||
self.amount_discount = self.discount_rate |
|
||||
self.amount_total = self.amount_untaxed + self.amount_tax - self.amount_discount |
|
||||
|
|
||||
discount_type = fields.Selection([('percent', 'Percentage'), ('amount', 'Amount')], 'Discount Type', readonly=True, |
|
||||
states={'draft': [('readonly', False)]}) |
|
||||
discount_rate = fields.Float('Discount rate', digits_compute=dp.get_precision('Account'), readonly=True, |
|
||||
states={'draft': [('readonly', False)]}) |
|
||||
amount_discount = fields.Float(string='Discount', digits=dp.get_precision('Account'), |
|
||||
readonly=True, compute='_compute_amount') |
|
||||
amount_untaxed = fields.Float(string='Subtotal', digits=dp.get_precision('Account'), |
|
||||
readonly=True, compute='_compute_amount', track_visibility='always') |
|
||||
amount_tax = fields.Float(string='Tax', digits=dp.get_precision('Account'), |
|
||||
readonly=True, compute='_compute_amount') |
|
||||
amount_total = fields.Float(string='Total', digits=dp.get_precision('Account'), |
|
||||
readonly=True, compute='_compute_amount') |
|
||||
|
|
||||
@api.onchange('discount_type', 'discount_rate') |
|
||||
def compute_discount(self): |
|
||||
for inv in self: |
|
||||
amount = sum(line.price_subtotal for line in self.invoice_line) |
|
||||
tax = sum(line.amount for line in self.tax_line) |
|
||||
if inv.discount_type == 'percent': |
|
||||
if inv.discount_rate == 100: |
|
||||
disc_amnt = amount + tax |
|
||||
else: |
|
||||
disc_amnt = (amount + tax) * inv.discount_rate / 100 |
|
||||
total = amount + tax - disc_amnt |
|
||||
self.amount_discount = disc_amnt |
|
||||
self.amount_total = total |
|
||||
else: |
|
||||
total = (amount + tax) - inv.discount_rate |
|
||||
self.amount_discount = inv.discount_rate |
|
||||
self.amount_total = total |
|
||||
|
|
||||
@api.model |
|
||||
def _prepare_refund(self, invoice, date=None, period_id=None, description=None, journal_id=None): |
|
||||
res = super(AccountInvoice, self)._prepare_refund(invoice, date, period_id, |
|
||||
description, journal_id) |
|
||||
res.update({ |
|
||||
'discount_type': self.discount_type, |
|
||||
'discount_rate': self.discount_rate, |
|
||||
}) |
|
||||
return res |
|
||||
|
|
||||
|
|
||||
class invoice_line(osv.Model): |
|
||||
_inherit = 'account.invoice.line' |
|
||||
|
|
||||
def move_line_get(self, cr, uid, invoice_id, context=None): |
|
||||
res = super(invoice_line, self).move_line_get(cr, uid, invoice_id, context=context) |
|
||||
inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id, context=context) |
|
||||
|
|
||||
if inv.type in ('out_invoice', 'out_refund') and inv.discount_type: |
|
||||
prop = self.pool.get('ir.property').get(cr, uid, 'property_account_income_categ', 'product.category', |
|
||||
context=context) |
|
||||
prop_id = prop and prop.id or False |
|
||||
account_id = self.pool.get('account.fiscal.position').map_account(cr, uid, inv.fiscal_position or False, |
|
||||
prop_id) |
|
||||
sign = -1 |
|
||||
|
|
||||
res.append({ |
|
||||
'name': 'Discount', |
|
||||
'price_unit': sign * inv.amount_discount, |
|
||||
'quantity': 1, |
|
||||
'price': sign * inv.amount_discount, |
|
||||
'account_id': account_id, |
|
||||
'product_id': False, |
|
||||
'uos_id': False, |
|
||||
'account_analytic_id': False, |
|
||||
'taxes': False, |
|
||||
}) |
|
||||
return res |
|
@ -1,91 +0,0 @@ |
|||||
from openerp.osv import fields, osv |
|
||||
from openerp import api |
|
||||
import openerp.addons.decimal_precision as dp |
|
||||
|
|
||||
|
|
||||
class SaleOrder(osv.Model): |
|
||||
_inherit = 'sale.order' |
|
||||
|
|
||||
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 = val2 = 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) |
|
||||
if order.discount_type == 'amount': |
|
||||
val2 = order.discount_rate |
|
||||
elif order.discount_type == 'percent': |
|
||||
val2 = ((val1 + val) * order.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 |
|
||||
|
|
||||
def _get_order(self, cr, uid, ids, context=None): |
|
||||
result = {} |
|
||||
for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context): |
|
||||
result[line.order_id.id] = True |
|
||||
return result.keys() |
|
||||
|
|
||||
_columns = { |
|
||||
'discount_type': fields.selection([ |
|
||||
('percent', 'Percentage'), |
|
||||
('amount', 'Amount')], 'Discount type'), |
|
||||
'discount_rate': fields.float('Discount Amount', digits_compute=dp.get_precision('Account'), |
|
||||
readonly=True, |
|
||||
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, ), |
|
||||
'amount_discount': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Discount', |
|
||||
multi='sums', help="The total discount."), |
|
||||
'amount_untaxed': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), |
|
||||
string='Untaxed Amount', |
|
||||
multi='sums', help="The amount without tax.", track_visibility='always'), |
|
||||
'amount_tax': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Taxes', |
|
||||
multi='sums', help="The tax amount."), |
|
||||
'amount_total': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Total', |
|
||||
multi='sums', help="The total amount."), |
|
||||
} |
|
||||
|
|
||||
_defaults = { |
|
||||
'discount_type': 'percent', |
|
||||
} |
|
||||
|
|
||||
@api.onchange('discount_type', 'discount_rate') |
|
||||
def compute_discount(self): |
|
||||
for order in self: |
|
||||
val1 = val2 = 0.0 |
|
||||
for line in order.order_line: |
|
||||
val1 += line.price_subtotal |
|
||||
val2 += self._amount_line_tax(line) |
|
||||
if order.discount_type == 'percent': |
|
||||
if order.discount_rate == 100: |
|
||||
disc_amnt = val1 + val2 |
|
||||
else: |
|
||||
disc_amnt = (val1 + val2) * order.discount_rate / 100 |
|
||||
total = val1 + val2 - disc_amnt |
|
||||
self.currency_id = order.pricelist_id.currency_id |
|
||||
self.amount_discount = disc_amnt |
|
||||
self.amount_total = total |
|
||||
else: |
|
||||
total = (val1 + val2) - order.discount_rate |
|
||||
self.currency_id = order.pricelist_id.currency_id |
|
||||
self.amount_discount = order.discount_rate |
|
||||
self.amount_total = total |
|
||||
|
|
||||
def _prepare_invoice(self, cr, uid, order, lines, context=None): |
|
||||
invoice_vals = super(SaleOrder, self)._prepare_invoice(cr, uid, order, lines, context=context) |
|
||||
invoice_vals.update({ |
|
||||
'discount_type': order.discount_type, |
|
||||
'discount_rate': order.discount_rate |
|
||||
}) |
|
||||
return invoice_vals |
|
@ -1,87 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<openerp> |
|
||||
<data> |
|
||||
<template id="report_invoice_document" inherit_id="account.report_invoice_document"> |
|
||||
<xpath expr="//table" position="replace"> |
|
||||
<table class="table table-condensed"> |
|
||||
<thead> |
|
||||
<tr> |
|
||||
<th>Description</th> |
|
||||
<th>Quantity</th> |
|
||||
<th class="text-right">Unit Price</th> |
|
||||
<!--<span t-foreach="o.invoice_line" t-as="l">--> |
|
||||
<!--<span t-if="l.discount">--> |
|
||||
<span t-if="o.amount_discount"> |
|
||||
<th class="text-right" groups="sale.group_discount_per_so_line">Discount (%)</th> |
|
||||
</span> |
|
||||
<!--</span>--> |
|
||||
<th class="text-right">Taxes</th> |
|
||||
<th class="text-right">Amount</th> |
|
||||
</tr> |
|
||||
</thead> |
|
||||
<tbody class="invoice_tbody"> |
|
||||
<tr t-foreach="o.invoice_line" t-as="l"> |
|
||||
<td><span t-field="l.name"/></td> |
|
||||
<td> |
|
||||
<span t-field="l.quantity"/> |
|
||||
<span t-field="l.uos_id" groups="product.group_uom"/> |
|
||||
</td> |
|
||||
<td class="text-right"> |
|
||||
<span t-field="l.price_unit"/> |
|
||||
</td> |
|
||||
<span t-if="o.amount_discount"> |
|
||||
<td class="text-right" groups="sale.group_discount_per_so_line"> |
|
||||
<span t-field="l.discount"/> |
|
||||
</td> |
|
||||
</span> |
|
||||
<td class="text-right"> |
|
||||
<span t-esc="', '.join(map(lambda x: x.name, l.invoice_line_tax_id))"/> |
|
||||
</td> |
|
||||
<td class="text-right"> |
|
||||
<span t-field="l.price_subtotal" |
|
||||
t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/> |
|
||||
</td> |
|
||||
</tr> |
|
||||
</tbody> |
|
||||
</table> |
|
||||
</xpath> |
|
||||
|
|
||||
<xpath expr="//div[@class='col-xs-4 pull-right']/table/tr[2]" position="after"> |
|
||||
<!--<t t-if="o.type=='out_invoice' or o.type=='out_refund'">--> |
|
||||
<t t-if="o.discount_rate"> |
|
||||
<tr> |
|
||||
<td>Discount</td> |
|
||||
<td class="text-right"> |
|
||||
<span t-field="o.amount_discount" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/> |
|
||||
</td> |
|
||||
</tr> |
|
||||
</t> |
|
||||
|
|
||||
<!--</t>--> |
|
||||
</xpath> |
|
||||
<!--<xpath expr="//div[@class='col-xs-4 pull-right']" position="before">--> |
|
||||
<!--<t t-if="o.type=='out_invoice' or o.type=='out_refund'">--> |
|
||||
<!--<div class="col-xs-4">--> |
|
||||
<!--<t t-if="o.discount_rate">--> |
|
||||
<!--<table class="table table-condensed">--> |
|
||||
<!--<tr class="border-black">--> |
|
||||
<!--<td>Discount Type</td>--> |
|
||||
<!--<td class="text-right">--> |
|
||||
<!--<span t-field="o.discount_type"/>--> |
|
||||
<!--</td>--> |
|
||||
<!--</tr>--> |
|
||||
<!--<tr>--> |
|
||||
<!--<td>Discount rate</td>--> |
|
||||
<!--<td class="text-right">--> |
|
||||
<!--<span t-field="o.discount_rate"/>--> |
|
||||
<!--</td>--> |
|
||||
<!--</tr>--> |
|
||||
<!--<tr class="border-black"></tr>--> |
|
||||
<!--</table>--> |
|
||||
<!--</t>--> |
|
||||
<!--</div>--> |
|
||||
<!--</t>--> |
|
||||
<!--</xpath>--> |
|
||||
</template> |
|
||||
</data> |
|
||||
</openerp> |
|
@ -1,40 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<openerp> |
|
||||
<data> |
|
||||
<template id="report_sale_order_document" inherit_id="sale.report_saleorder_document"> |
|
||||
|
|
||||
<xpath expr="//div[@class='col-xs-4 pull-right']/table/tr[2]" position="after"> |
|
||||
<t t-if="o.discount_rate"> |
|
||||
<tr> |
|
||||
<td>Discount</td> |
|
||||
<td class="text-right"> |
|
||||
<span t-field="o.amount_discount" t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'/> |
|
||||
</td> |
|
||||
</tr> |
|
||||
</t> |
|
||||
</xpath> |
|
||||
|
|
||||
<!--<xpath expr="//div[@class='col-xs-4 pull-right']" position="before">--> |
|
||||
<!--<div class="col-xs-4">--> |
|
||||
<!--<t t-if="o.discount_rate">--> |
|
||||
<!--<table class="table table-condensed">--> |
|
||||
<!--<tr class="border-black">--> |
|
||||
<!--<td>Discount Type</td>--> |
|
||||
<!--<td class="text-right">--> |
|
||||
<!--<span t-field="o.discount_type"/>--> |
|
||||
<!--</td>--> |
|
||||
<!--</tr>--> |
|
||||
<!--<tr>--> |
|
||||
<!--<td>Discount Rate</td>--> |
|
||||
<!--<td class="text-right">--> |
|
||||
<!--<span t-field="o.discount_rate"/>--> |
|
||||
<!--</td>--> |
|
||||
<!--</tr>--> |
|
||||
<!--<tr class="border-black"></tr>--> |
|
||||
<!--</table>--> |
|
||||
<!--</t>--> |
|
||||
<!--</div>--> |
|
||||
<!--</xpath>--> |
|
||||
</template> |
|
||||
</data> |
|
||||
</openerp> |
|
Loading…
Reference in new issue