Browse Source

commit inicial

Rodney Enciso Arias 8 years ago
commit
42b227cd18

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+import models
+import report

BIN
__init__.pyc


+ 32 - 0
__openerp__.py

@@ -0,0 +1,32 @@
+{
+    'name': 'Sale Discount on Total Amount',
+    'version': '1.0',
+    'category': 'sale',
+    'sequence': 6,
+    'summary': "Discount on total in Sale and invoice with Discount limit and approval",
+    'author': 'Cybrosys Techno Solutions',
+    'company': 'Cybrosys Techno Solutions',
+    'website': 'http://www.cybrosys.com',
+
+    'description': """
+
+Sale Discount for Total Amount
+=======================
+Module to manage discount on total amount in Sale.
+        as an specific amount or 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,
+}

+ 32 - 0
__openerp__.py~

@@ -0,0 +1,32 @@
+{
+    'name': 'Sale Discount on Total Amount',
+    'version': '1.0',
+    'category': 'sale',
+    'sequence': 6,
+    'summary': "A module meant to provide discount for total amount and Discount limit with approval in sales",
+    'author': 'Cybrosys Techno Solutions',
+    'company': 'Cybrosys Techno Solutions',
+    'website': 'http://www.cybrosys.com',
+
+    'description': """
+
+Sale Discount for Total Amount
+=======================
+Module to manage discount on total amount in Sale.
+        as an specific amount or 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,
+}

+ 3 - 0
models/__init__.py

@@ -0,0 +1,3 @@
+import account_invoice
+import sale
+import sale_discount_approval

BIN
models/__init__.pyc


+ 87 - 0
models/account_invoice.py

@@ -0,0 +1,87 @@
+from openerp import api, models, fields
+from openerp.osv import osv
+import openerp.addons.decimal_precision as dp
+
+
+class AccountInvoiceLine(models.Model):
+    _inherit = "account.invoice.line"
+
+    discount = fields.Float(string='Discount (%)',
+                            digits=(16, 10),
+                            # digits= dp.get_precision('Discount'),
+                            default=0.0)
+
+class AccountInvoice(models.Model):
+    _inherit = "account.invoice"
+
+    @api.one
+    @api.depends('invoice_line.price_subtotal', 'tax_line.amount')
+    def _compute_amount(self):
+        disc = 0.0
+        for inv in self:
+            for line in inv.invoice_line:
+                print line.discount
+                disc += (line.quantity * line.price_unit) * line.discount / 100
+        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)
+        self.amount_discount = disc
+        self.amount_total = self.amount_untaxed + self.amount_tax
+
+    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.multi
+    def compute_discount(self, discount):
+        for inv in self:
+            val1 = val2 = 0.0
+            disc_amnt = 0.0
+            val2 = sum(line.amount for line in self.tax_line)
+            for line in inv.invoice_line:
+                val1 += (line.quantity * line.price_unit)
+                line.discount = discount
+                disc_amnt += (line.quantity * line.price_unit) * discount / 100
+            total = val1 + val2 - disc_amnt
+            self.amount_discount = disc_amnt
+            self.amount_tax = val2
+            self.amount_total = total
+
+    @api.onchange('discount_type', 'discount_rate')
+    def supply_rate(self):
+        for inv in self:
+            if inv.discount_rate != 0:
+                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':
+                    self.compute_discount(inv.discount_rate)
+                else:
+                    total = 0.0
+                    discount = 0.0
+                    for line in inv.invoice_line:
+                        total += (line.quantity * line.price_unit)
+                    if inv.discount_rate != 0:
+                        discount = (inv.discount_rate / total) * 100
+                    self.compute_discount(discount)
+
+    @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
+

BIN
models/account_invoice.pyc


+ 109 - 0
models/sale.py

@@ -0,0 +1,109 @@
+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,
+            }
+            cur = order.pricelist_id.currency_id
+            val1 = val2 = val3 = 0.0
+            for line in order.order_line:
+                val1 += line.price_subtotal
+                val2 += self._amount_line_tax(cr, uid, line, context=context)
+                val3 += (line.product_uom_qty * line.price_unit) * line.discount / 100
+            res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur, val1)
+            res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val2)
+            res[order.id]['amount_discount'] = cur_obj.round(cr, uid, cur, val3)
+            res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
+        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', 'Porsentaje %'),
+            ('amount', 'Monto')], 'Tipo de Descuento'),
+        'discount_rate': fields.float('Descuento', 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='Descuento',
+                                           multi='sums', store=True, help="The total discount."),
+        'amount_untaxed': fields.function(_amount_all, digits_compute=dp.get_precision('Account'),
+                                          string='Untaxed Amount',
+                                          multi='sums', store=True, help="The amount without tax.", track_visibility='always'),
+        'amount_tax': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Taxes',
+                                      multi='sums', store=True, help="The tax amount."),
+        'amount_total': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Total',
+                                        multi='sums', store=True, help="The total amount."),
+    }
+
+    _defaults = {
+        'discount_type': 'percent',
+    }
+
+    @api.multi
+    def compute_discount(self, discount):
+        for order in self:
+            val1 = val2 = 0.0
+            disc_amnt = 0.0
+            for line in order.order_line:
+                val1 += (line.product_uom_qty * line.price_unit)
+                line.discount = discount
+                val2 += self._amount_line_tax(line)
+                disc_amnt += (line.product_uom_qty * line.price_unit * line.discount)/100
+            total = val1 + val2 - disc_amnt
+            self.currency_id = order.pricelist_id.currency_id
+            self.amount_discount = disc_amnt
+            self.amount_tax = val2
+            self.amount_total = total
+
+    @api.onchange('discount_type', 'discount_rate')
+    def supply_rate(self):
+        for order in self:
+            if order.discount_rate != 0:
+                if order.discount_type == 'percent':
+                    self.compute_discount(order.discount_rate)
+                else:
+                    total = 0.0
+                    for line in order.order_line:
+                        total += (line.product_uom_qty * line.price_unit)
+                    discount = (order.discount_rate / total) * 100
+                    self.compute_discount(discount)
+
+    @api.multi
+    def button_dummy(self):
+        self.supply_rate()
+        return True
+
+    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
+
+class SaleOrderLine(osv.Model):
+    _inherit = "sale.order.line"
+
+    _columns = {
+    'discount': fields.float(string='Discount (%)',
+                            digits=(16, 10),
+                            # digits= dp.get_precision('Discount'),
+                            default=0.0),
+    }

BIN
models/sale.pyc


+ 102 - 0
models/sale_discount_approval.py

@@ -0,0 +1,102 @@
+from openerp import api, models, fields
+from openerp.osv import fields, osv
+from openerp import SUPERUSER_ID
+
+##############################################################sale settings##############################################################
+
+class Sale_config_settings(osv.TransientModel):
+    _inherit = 'sale.config.settings'
+    _columns = {
+        'limit_discount': fields.integer('Discount limit requires approval %', required=True,
+                                         help="Discount after which approval of sale is required."),
+        'module_sale_discount_approval': fields.boolean("Force two levels of approvals",
+                                                        help='Provide a double validation mechanism for sale exceeding minimum discount.\n'
+                                                        ),
+    }
+
+    _defaults = {
+        'limit_discount': 40,
+    }
+
+    def get_default_limit_discount(self, cr, uid, ids, context=None):
+        ir_values = self.pool.get('ir.values')
+        limit_discount = ir_values.get_default(cr, uid, 'sale.config.settings', 'limit_discount')
+        return {
+            'limit_discount': limit_discount,
+        }
+
+    def set_limit_discount(self, cr, uid, ids, context=None):
+        ir_values = self.pool.get('ir.values')
+        wizard = self.browse(cr, uid, ids)[0]
+        if wizard.limit_discount:
+            limit_discount = wizard.limit_discount
+            ir_values.set_default(cr, SUPERUSER_ID, 'sale.config.settings', 'limit_discount', limit_discount)
+
+    def get_default_module_sale_discount_approval(self, cr, uid, ids, context=None):
+        ir_values = self.pool.get('ir.values')
+        module_sale_discount_approval = ir_values.get_default(cr, uid, 'sale.config.settings',
+                                                              'module_sale_discount_approval')
+        return {
+            'module_sale_discount_approval': module_sale_discount_approval == 'True',
+        }
+
+    def set_module_sale_discount_approval(self, cr, uid, ids, context=None):
+        ir_values = self.pool.get('ir.values')
+        wizard = self.browse(cr, uid, ids)[0]
+        if wizard.module_sale_discount_approval:
+            module_sale_discount_approval = 'True'
+        else:
+            module_sale_discount_approval = 'False'
+
+        ir_values.set_default(cr, SUPERUSER_ID, 'sale.config.settings', 'module_sale_discount_approval',
+                              module_sale_discount_approval)
+
+
+#######################################################sale order workflow##############################################################
+
+class SaleInherit(osv.Model):
+    _inherit = 'sale.order'
+
+    _columns = {
+        'state': fields.selection([('draft', 'Draft Quotation'),
+                                   ('sent', 'Quotation Sent'),
+                                   ('cancel', 'Cancelled'),
+                                   ('waiting_date', 'Waiting Schedule'),
+                                   ('waitingapproval', 'Waiting Approval'),
+                                   ('progress', 'Sales Order'),
+                                   ('manual', 'Sale to Invoice'),
+                                   ('shipping_except', 'Shipping Exception'),
+                                   ('invoice_except', 'Invoice Exception'),
+                                   ('done', 'Done')], required=True, track_visibility='onchange'),
+    }
+
+    def action_button_confirm(self, cr, uid, ids, context=None):
+        discnt = 0.0
+        no_line = 0.0
+        line_dicnt = 0.0
+        prod_price = 0.0
+        conf = self.pool.get('ir.values')
+        sale_obj = self.browse(cr, uid, ids, context)
+        double_valid = conf.get_default(cr, uid, 'sale.config.settings', 'module_sale_discount_approval')
+        if double_valid == 'True':
+            min_disct = conf.get_default(cr, uid, 'sale.config.settings', 'limit_discount')
+            for line in sale_obj.order_line:
+                no_line += 1
+                discnt += line.discount
+            discnt = (discnt / no_line)
+            if discnt >= min_disct:
+                assert len(ids) == 1, 'This option should only be used for a single id at a time.'
+                self.signal_workflow(cr, uid, ids, 'order_toapprov')
+                return True
+            else:
+                return super(SaleInherit, self).action_button_confirm(cr, uid, ids, context)
+        else:
+            return super(SaleInherit, self).action_button_confirm(cr, uid, ids, context)
+
+        ####################################### workflow functions#############################################################################
+
+    @api.one
+    def wait_approval(self):
+
+        self.state = 'waitingapproval'
+        return True

BIN
models/sale_discount_approval.pyc


+ 2 - 0
report/__init__.py

@@ -0,0 +1,2 @@
+import sale_report
+import invoice_report

BIN
report/__init__.pyc


+ 23 - 0
report/invoice_report.py

@@ -0,0 +1,23 @@
+from openerp.osv import fields, osv
+import openerp.addons.decimal_precision as dp
+
+
+class DiscountInvoiceReport(osv.osv):
+    _inherit = 'account.invoice.report'
+
+    _columns = {
+        'discount': fields.float('Discount', readonly=True,digits=dp.get_precision('Discount')),
+    }
+
+    def _select(self):
+        res = super(DiscountInvoiceReport,self)._select()
+        select_str = res + """, sub.discount / cr.rate as discount """
+        return select_str
+
+    def _sub_select(self):
+        res = super(DiscountInvoiceReport,self)._sub_select()
+        select_str = res + """,SUM(CASE
+            WHEN ai.type::text = ANY (ARRAY['out_refund'::character varying::text, 'in_invoice'::character varying::text])
+            THEN - ((ail.quantity / u.factor * u2.factor) * ail.price_unit * (ail.discount) / 100.0)
+            ELSE ((ail.quantity / u.factor * u2.factor) * ail.price_unit * (ail.discount) / 100.0) END) as discount"""
+        return select_str

BIN
report/invoice_report.pyc


+ 15 - 0
report/sale_report.py

@@ -0,0 +1,15 @@
+from openerp.osv import fields, osv
+import openerp.addons.decimal_precision as dp
+
+
+class DiscountSaleReport(osv.osv):
+    _inherit = 'sale.report'
+
+    _columns = {
+        'discount': fields.float('Discount', readonly=True, digits=dp.get_precision('Discount')),
+    }
+
+    def _select(self):
+        res = super(DiscountSaleReport,self)._select()
+        select_str = res+""",sum(l.product_uom_qty * cr.rate * l.price_unit * (l.discount) / 100.0) as discount"""
+        return select_str

BIN
report/sale_report.pyc


BIN
static/description/Disc_appr_conf.png


BIN
static/description/Disc_appr_wrkfl.png


BIN
static/description/Discount_inv_amnt.png


BIN
static/description/Discount_so_perc.png


BIN
static/description/icon.png


+ 39 - 0
static/description/index.html

@@ -0,0 +1,39 @@
+<section class="oe_container">
+    <div class="oe_row">
+        <h2 class="oe_slogan">Discount On Total in Sale and Invoice</h2>
+        <!--<h3 class="oe_slogan">It Fits Your Sales Approach</h3>-->
+        <div>
+            <p>
+                This module allows you to mention discount on Total of sale order and Total of Customer Invoice in two ways
+            </p>
+            <hr>
+            <p>
+                1. As percentage<br>
+                    Select 'Percentage' from Discount type and give discount percentage as Discount rate.
+                    System will update the value of Discount and Total
+            </p>
+            <div class="oe_row_img oe_centered oe_mt32">
+                <img class="oe_picture oe_screenshot" src="Discount_so_perc.png">
+            </div>
+            <hr>
+            <p>
+                2. As amount<br>
+                Select 'Amount' from Discount type and give discount amount as Discount rate.
+                System will update the value of Discount and Total
+            </p>
+            <div class="oe_row_img oe_centered oe_mt32">
+                <img class="oe_picture oe_screenshot" src="Discount_inv_amnt.png">
+            </div>
+            <hr>
+            <p>
+                And the module also allows you to set a limit for total discount in percentage. Exceeding this limit
+                will require approval.
+            </p>
+            <div class="oe_row_img oe_centered oe_mt32">
+                <img class="oe_picture oe_screenshot" src="Disc_appr_conf.png"><hr>
+                <img class="oe_picture oe_screenshot" src="Disc_appr_wrkfl.png">
+            </div>
+        </div>
+
+    </div>
+</section>

+ 39 - 0
static/description/index.html~

@@ -0,0 +1,39 @@
+<section class="oe_container">
+    <div class="oe_row">
+        <h2 class="oe_slogan">Discount On Sale</h2>
+        <!--<h3 class="oe_slogan">It Fits Your Sales Approach</h3>-->
+        <div>
+            <p>
+                This module allows you to mention discount on Total of sale order and Total of Customer Invoice in two ways
+            </p>
+            <hr>
+            <p>
+                1. As percentage<br>
+                    Select 'Percentage' from Discount type and give discount percentage as Discount rate.
+                    System will update the value of Discount and Total
+            </p>
+            <div class="oe_row_img oe_centered oe_mt32">
+                <img class="oe_picture oe_screenshot" src="Discount_so_perc.png">
+            </div>
+            <hr>
+            <p>
+                2. As amount<br>
+                Select 'Amount' from Discount type and give discount amount as Discount rate.
+                System will update the value of Discount and Total
+            </p>
+            <div class="oe_row_img oe_centered oe_mt32">
+                <img class="oe_picture oe_screenshot" src="Discount_inv_amnt.png">
+            </div>
+            <hr>
+            <p>
+                And the module also allows you to set a limit for total discount in percentage. Exceeding this limit
+                will require approval.
+            </p>
+            <div class="oe_row_img oe_centered oe_mt32">
+                <img class="oe_picture oe_screenshot" src="Disc_appr_conf.png"><hr>
+                <img class="oe_picture oe_screenshot" src="Disc_appr_wrkfl.png">
+            </div>
+        </div>
+
+    </div>
+</section>

+ 60 - 0
views/account_invoice_view.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <record id="discount_view_invoice_line_tree" model="ir.ui.view">
+            <field name="name">discount.account.invoice.line.tree</field>
+            <field name="model">account.invoice.line</field>
+            <field name="inherit_id" ref="account.view_invoice_line_tree"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='discount']" position="attributes">
+                    <attribute name="digits">(16, 2)</attribute>
+                </xpath>
+            </field>
+        </record>
+
+        <record id="discount_view_invoice_line_form" model="ir.ui.view">
+            <field name="name">discount.account.invoice.line.form</field>
+            <field name="model">account.invoice.line</field>
+            <field name="inherit_id" ref="account.view_invoice_line_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='discount']" position="attributes">
+                    <attribute name="digits">(16, 2)</attribute>
+                </xpath>
+            </field>
+        </record>
+
+        <record id="discount_account_invoice_view_form1" model="ir.ui.view">
+            <field name="name">discount.account.invoice</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.invoice_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='discount']" position="attributes">
+                    <attribute name="digits">(16, 2)</attribute>
+                </xpath>
+                <xpath expr="//group[@class='oe_subtotal_footer oe_right']" position="replace">
+                    <group col="4">
+                        <group name="discount">
+                            <field name="discount_type"/>
+                            <field name="discount_rate"/>
+                        </group>
+                        <group class="oe_subtotal_footer oe_right">
+                            <field name="amount_untaxed" widget="monetary" options="{'currency_field': 'currency_id'}"/>
+                            <field name="amount_discount" widget='monetary' options="{'currency_field': 'currency_id'}"/>
+                            <div>
+                                <label for="amount_tax"/>
+                                <button name="button_reset_taxes" states="draft,proforma2"
+                                        string="(update)" class="oe_link oe_edit_only"
+                                        type="object" help="Recompute taxes and total"/>
+                            </div>
+                            <field name="amount_tax" nolabel="1" widget="monetary" options="{'currency_field': 'currency_id'}"/>
+                            <field name="amount_total" class="oe_subtotal_footer_separator" widget="monetary" options="{'currency_field': 'currency_id'}"/>
+                            <field name="residual" groups="account.group_account_user" widget="monetary" options="{'currency_field': 'currency_id'}"/>
+                            <field name="reconciled" invisible="1"/>
+                        </group>
+                    </group>
+                </xpath>
+
+            </field>
+        </record>
+    </data>
+</openerp>

+ 84 - 0
views/invoice_report.xml

@@ -0,0 +1,84 @@
+<?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-if="o.amount_discount">-->
+                            <th class="text-right" groups="sale.group_discount_per_so_line">Discount (%)</th>
+                        <!--</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"/>-->
+                                <span t-esc="'%.2f'%(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>

+ 28 - 0
views/sale_discount_approval_view.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+
+        <record id="view_double_sale_configuration" model="ir.ui.view">
+            <field name="name">Sale Application</field>
+            <field name="model">sale.config.settings</field>
+            <field name="inherit_id" ref="sale.view_sales_config"/>
+            <field name="arch" type="xml">
+                    <xpath expr="//div[@name='Sale Features']" position="inside">
+
+                        <div>
+                            <div name="module_sale_discount_approval">
+                               <field name="module_sale_discount_approval" class="oe_inline"/>
+                               <label for="module_sale_discount_approval"/>
+                                <span class="oe_separate-from-text">
+                                   <label for="limit_discount"/>
+                                   <field name="limit_discount" attrs="{'required': [('module_sale_discount_approval','=',True)]}" class="oe_inline"/>
+                               </span>
+                            </div>
+
+                        </div>
+                </xpath>
+            </field>
+        </record>
+
+    </data>
+</openerp>

+ 133 - 0
views/sale_discount_approval_workflow.xml

@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="utf-8"?>
+  <openerp>
+    <data>
+
+
+        <record id="sale_inherit_wkfform_view" model="ir.ui.view">
+            <field name="name">sale.order.workflow.inherit</field>
+            <field name="model">sale.order</field>
+            <field name="inherit_id" ref="sale.view_order_form"/>
+            <field name="arch" type="xml">
+                <!-- Statusbar widget should also contain the new status -->
+                <field name="state" position="replace">
+                    <field name="state" widget="statusbar" statusbar_visible="draft,sent,progress,done" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>
+                </field>
+                <field name="state" position="before">
+                    <!-- buttonz -->
+                    <button string="Approve Order" type="workflow" name="order_confirm" states="waitingapproval" class="oe_highlight" groups="base.group_sale_manager"/>
+                </field>
+                <xpath expr="//button[@name='action_cancel']" position="attributes">
+                     <attribute name ="states">waitingapproval,manual,progress</attribute>
+                </xpath>
+                <xpath expr="//button[@name='action_cancel']" position="attributes">
+                     <attribute name ="states">waitingapproval,manual,progress</attribute>
+                </xpath>
+            </field>
+        </record>
+
+        <!--activity-->
+        <record id="act_approve" model="workflow.activity">
+            <field name="wkf_id" ref="sale.wkf_sale"/>
+            <field name="name">Waiting Approval</field>
+            <field name="kind">function</field>
+            <field name="action">wait_approval()</field>
+        </record>
+
+        <!--end of activity-->
+        <!--transitions-->
+
+         <record model="workflow.transition" id="sale.trans_draft_router">
+            <field name="act_from" ref="sale.act_draft"/>
+            <field name="act_to" ref="act_approve"/>
+            <field name="signal">order_toapprov</field>
+        </record>
+
+        <record id="sale_trans_draft_router" model="workflow.transition">
+            <field name="act_from" ref="sale.act_draft"/>
+            <field name="act_to" ref="sale.act_router"/>
+            <field name="signal">order_confirm</field>
+        </record>
+
+         <record id="sale_trans_approvd" model="workflow.transition">
+            <field name="act_from" ref="act_approve"/>
+            <field name="act_to" ref="sale.act_router"/>
+            <field name="signal">order_confirm</field>
+        </record>
+
+       <!--end of transition-->
+
+        <!--sale transition inherit-->
+        <record id="sale.trans_draft_sent" model="workflow.transition">
+            <field name="act_from" ref="sale.act_draft"/>
+            <field name="act_to" ref="sale.act_sent"/>
+            <field name="signal">quotation_sent</field>
+        </record>
+
+        <record id="sale.trans_draft_cancel" model="workflow.transition">
+            <field name="act_from" ref="sale.act_draft"/>
+            <field name="act_to" ref="sale.act_cancel"/>
+            <field name="signal">cancel</field>
+        </record>
+
+        <record id="sale.trans_sent_router" model="workflow.transition">
+            <field name="act_from" ref="sale.act_sent"/>
+            <field name="act_to" ref="sale.act_router"/>
+            <field name="signal">order_confirm</field>
+        </record>
+        <record id="sale.trans_sent_cancel" model="workflow.transition">
+            <field name="act_from" ref="sale.act_sent"/>
+            <field name="act_to" ref="sale.act_cancel"/>
+            <field name="signal">cancel</field>
+        </record>
+        <record id="sale.trans_router_wait_invoice" model="workflow.transition">
+            <field name="act_from" ref="sale.act_router"/>
+            <field name="act_to" ref="sale.act_wait_invoice"/>
+        </record>
+        <record id="sale.trans_wait_invoice_all_lines_invoiced" model="workflow.transition">
+            <field name="act_from" ref="sale.act_wait_invoice"/>
+            <field name="act_to" ref="sale.act_invoice_end"/>
+            <field name="signal">all_lines</field>
+        </record>
+        <record id="sale.trans_wait_invoice_cancel2" model="workflow.transition">
+            <field name="act_from" ref="sale.act_wait_invoice"/>
+            <field name="act_to" ref="sale.act_cancel2"/>
+            <field name="signal">cancel</field>
+        </record>
+        <record id="sale.trans_wait_invoice_invoice_manual" model="workflow.transition">
+            <field name="act_from" ref="sale.act_wait_invoice"/>
+            <field name="act_to" ref="sale.act_invoice"/>
+            <field name="signal">manual_invoice</field>
+        </record>
+        <record id="sale.trans_invoice_invoice_end" model="workflow.transition">
+            <field name="act_from" ref="sale.act_invoice"/>
+            <field name="act_to" ref="sale.act_invoice_end"/>
+            <field name="signal">subflow.paid</field>
+        </record>
+        <record id="sale.trans_invoice_invoice_except" model="workflow.transition">
+            <field name="act_from" ref="sale.act_invoice"/>
+            <field name="act_to" ref="sale.act_invoice_except"/>
+            <field name="signal">subflow.cancel</field>
+        </record>
+        <record id="sale.trans_invoice_except_invoice" model="workflow.transition">
+            <field name="act_from" ref="sale.act_invoice_except"/>
+            <field name="act_to" ref="sale.act_invoice"/>
+            <field name="signal">invoice_recreate</field>
+        </record>
+        <record id="sale.trans_invoice_except_invoice_end" model="workflow.transition">
+            <field name="act_from" ref="sale.act_invoice_except"/>
+            <field name="act_to" ref="sale.act_invoice_end"/>
+            <field name="signal">invoice_corrected</field>
+        </record>
+        <record id="sale.trans_invoice_except_invoice_cancel" model="workflow.transition">
+            <field name="act_from" ref="sale.act_invoice_except"/>
+            <field name="act_to" ref="sale.act_invoice_cancel"/>
+            <field name="signal">invoice_cancel</field>
+        </record>
+        <record id="sale.trans_invoice_end_done" model="workflow.transition">
+            <field name="act_from" ref="sale.act_invoice_end"/>
+            <field name="act_to" ref="sale.act_done"/>
+        </record>
+
+        <!--end of sale transitions-->
+    </data>
+  </openerp>

+ 46 - 0
views/sale_order_report.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <template id="report_sale_order_document" inherit_id="sale.report_saleorder_document">
+
+             <!--<xpath expr="//td[@groups='sale.group_discount_per_so_line']/span[@t-filed='l.discount']" position="replace">-->
+                 <!--<span t-esc="'%.2f'%(l.discount)"/>-->
+             <!--</xpath>-->
+             <xpath expr="//span[@t-field='l.discount']" position="replace">
+                 <span t-esc="'%.2f'%(l.discount)"/>
+             </xpath>
+             <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>

+ 49 - 0
views/sale_view.xml

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+
+        <record id="discount_view_orer_line_form" model="ir.ui.view">
+            <field name="name">discount.sale.order.line.form</field>
+            <field name="model">sale.order.line</field>
+            <field name="inherit_id" ref="sale.view_order_line_form2"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='discount']" position="attributes">
+                    <attribute name="digits">(16, 2)</attribute>
+                </xpath>
+            </field>
+        </record>
+
+        <record id="discount_sale_view_form" model="ir.ui.view">
+            <field name="name">discount.sale.order.form</field>
+            <field name="model">sale.order</field>
+            <field name="inherit_id" ref="sale.view_order_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//tree/field[@name='discount']" position="attributes">
+                    <attribute name="digits">(16, 2)</attribute>
+                </xpath>
+                <xpath expr="//group[@name='sale_total']" position="replace">
+                    <group col="4">
+                        <group name="discount" colspan="2">
+                            <field name="discount_type"/>
+                            <field name="discount_rate"/>
+                        </group>
+                        <group class="oe_subtotal_footer oe_right" colspan="2" name="sale_total">
+                            <field name="amount_untaxed" widget='monetary' options="{'currency_field': 'currency_id'}"/>
+                            <field name="amount_discount" widget='monetary' options="{'currency_field': 'currency_id'}"/>
+                            <field name="amount_tax" widget='monetary' options="{'currency_field': 'currency_id'}"/>
+                            <div class="oe_subtotal_footer_separator oe_inline">
+                                <label for="amount_total" />
+                                <button name="button_dummy"
+                                        states="draft,sent" string="(update)" type="object" class="oe_edit_only oe_link"/>
+                            </div>
+                            <field name="amount_total" nolabel="1" class="oe_subtotal_footer_separator" widget='monetary' options="{'currency_field': 'currency_id'}"/>
+                        </group>
+                    </group>
+                </xpath>
+                <xpath expr="//button[@string='Create Invoice']" position="attributes">
+                    <attribute name="context">{'discount_type':discount_type,'discount_rate':discount_rate,'amount_discount':amount_discount}</attribute>
+                </xpath>
+            </field>
+        </record>
+    </data>
+</openerp>