10 changed files with 318 additions and 10 deletions
@ -1,2 +1,3 @@ |
|||||
import account_invoice |
import account_invoice |
||||
import sale |
import sale |
||||
|
import sale_discount_approval |
||||
|
@ -0,0 +1,3 @@ |
|||||
|
import account_invoice |
||||
|
import sale |
||||
|
sale_discount_approval |
@ -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 |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 58 KiB |
@ -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> |
@ -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…
Reference in new issue