Browse Source

Discount approval added

master
cybroodoo 9 years ago
parent
commit
d0b9235080
  1. 8
      sale_discount_total/__openerp__.py
  2. 8
      sale_discount_total/__openerp__.py~
  3. 1
      sale_discount_total/models/__init__.py
  4. 3
      sale_discount_total/models/__init__.py~
  5. 129
      sale_discount_total/models/sale_discount_approval.py
  6. BIN
      sale_discount_total/static/description/Disc_appr_conf.png
  7. BIN
      sale_discount_total/static/description/Disc_appr_wrkfl.png
  8. 21
      sale_discount_total/static/description/index.html
  9. 28
      sale_discount_total/views/sale_discount_approval_view.xml
  10. 130
      sale_discount_total/views/sale_discount_approval_workflow.xml

8
sale_discount_total/__openerp__.py

@ -3,7 +3,7 @@
'version': '1.0', 'version': '1.0',
'category': 'sale', 'category': 'sale',
'sequence': 6, 'sequence': 6,
'summary': "extension of default Sale Management module meant to provide discount for total amount", 'summary': "A module meant to provide discount for total amount and Discount limit with approval in sales",
'author': 'Cybrosys Techno Solutions', 'author': 'Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions', 'company': 'Cybrosys Techno Solutions',
'website': 'http://www.cybrosys.com', 'website': 'http://www.cybrosys.com',
@ -21,8 +21,10 @@ Module to manage discount for total amount in Sale.
'data': [ 'data': [
'views/sale_view.xml', 'views/sale_view.xml',
'views/account_invoice_view.xml', 'views/account_invoice_view.xml',
'views/invoice_report.xml', 'views/invoice_report.xml',
'views/sale_order_report.xml' 'views/sale_order_report.xml',
'views/sale_discount_approval_view.xml',
'views/sale_discount_approval_workflow.xml'
], ],
'demo': [ 'demo': [

8
sale_discount_total/__openerp__.py~

@ -3,7 +3,7 @@
'version': '1.0', 'version': '1.0',
'category': 'sale', 'category': 'sale',
'sequence': 6, 'sequence': 6,
'summary': "extension of default Sale Management module meant to provide discount for total amount", 'summary': "extension of default Sale Management module meant to provide discount for total amount and Discount limit with approval,
'author': 'Cybrosys Techno Solutions', 'author': 'Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions', 'company': 'Cybrosys Techno Solutions',
'website': 'http://www.cybrosys.com', 'website': 'http://www.cybrosys.com',
@ -20,7 +20,11 @@ Module to manage discount for total amount in Sale.
'depends': ['sale', 'base', 'stock'], 'depends': ['sale', 'base', 'stock'],
'data': [ 'data': [
'views/sale_view.xml', 'views/sale_view.xml',
'views/account_invoice_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': [ 'demo': [

1
sale_discount_total/models/__init__.py

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

3
sale_discount_total/models/__init__.py~

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

129
sale_discount_total/models/sale_discount_approval.py

@ -0,0 +1,129 @@
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 sale_obj.discount_type == "percent":
# dicnt_amt = sale_obj.discount_rate
# if dicnt_amt >= 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:
#
# for line in sale_obj.order_line:
# no_line += 1
# discnt = discnt + line.discount
# if dicnt_amt:
# discnt = (discnt / no_line) + dicnt_amt
# else:
# discnt = (discnt / no_line)
#
# else:
# dicnt_amt = sale_obj.discount_rate
# for line in sale_obj.order_line:
# prod_price = prod_price + line.price_unit
# no_line += 1
# if line.discount:
# line_dicnt = line_dicnt + line.discount
# line_dicnt = line_dicnt/no_line
# prcnt = 100 - (((prod_price - dicnt_amt) * 100) / prod_price)
# discnt = prcnt + line_dicnt
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
sale_discount_total/static/description/Disc_appr_conf.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
sale_discount_total/static/description/Disc_appr_wrkfl.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

21
sale_discount_total/static/description/index.html

@ -6,23 +6,34 @@
<p> <p>
This module allows you to mention discount on Total of sale order and Total of Customer Invoice in two ways This module allows you to mention discount on Total of sale order and Total of Customer Invoice in two ways
</p> </p>
<hr>
<p> <p>
1. As percentage<br> 1. As percentage<br>
Select 'Percentage' from Discount type and give discount percentage as Discount rate. Select 'Percentage' from Discount type and give discount percentage as Discount rate.
System will update the value of Discount and Total System will update the value of Discount and Total
</p> </p>
<div class="oe_row_img oe_centered oe_mt32">
<img class="oe_picture oe_screenshot" src="Discount_so_perc.png">
</div>
<hr>
<p> <p>
2. As amount<br> 2. As amount<br>
Select 'Amount' from Discount type and give discount amount as Discount rate. Select 'Amount' from Discount type and give discount amount as Discount rate.
System will update the value of Discount and Total System will update the value of Discount and Total
</p> </p>
<div class="oe_row_img oe_centered oe_mt32">
<img class="oe_picture oe_screenshot" src="Discount_inv_amnt.png">
</div>
<hr>
<p> <p>
The total discount amount will be present in Printable PDF Reports. And the module also allows you to set a limit for total discount in percentage. Exceeding this limit
will require approval.
</p> </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>
<div class="oe_row_img oe_centered oe_mt32">
<img class="oe_picture oe_screenshot" src="Discount_so_perc.png">
<img class="oe_picture oe_screenshot" src="Discount_inv_amnt.png">
</div>
</div> </div>
</section> </section>

28
sale_discount_total/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>

130
sale_discount_total/views/sale_discount_approval_workflow.xml

@ -0,0 +1,130 @@
<?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>
</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>
Loading…
Cancel
Save