[IMP] point_of_sale: convert wizard_discount into osv_memory
bzr revid: sbh@tinyerp.com-20100311073758-9tmnaetye01zfhfn
This commit is contained in:
parent
8cf8c156de
commit
c4d99b22d2
|
@ -45,6 +45,7 @@ Main features :
|
|||
'pos_wizard.xml',
|
||||
'wizard/pos_add_product.xml',
|
||||
'wizard/pos_confirm.xml',
|
||||
'wizard/pos_discount.xml',
|
||||
'pos_view.xml',
|
||||
'pos_sequence.xml',
|
||||
'posrule_data.xml',
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<group colspan="4" col="7">
|
||||
<field name="amount_tax"/>
|
||||
<field name="amount_total"/>
|
||||
<button name="%(pos_discount)d" string="D_iscount" type="action" states="draft"/>
|
||||
<button name="%(action_pos_discount)d" string="D_iscount" type="action" states="draft"/>
|
||||
<button name="dummy_button" string="Compute" type="object" />
|
||||
</group>
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
<!--<wizard string="Cancel" model="pos.order"
|
||||
name="pos.cancel" id="pos_cancel" multi="True"/>-->
|
||||
|
||||
|
||||
<!--
|
||||
<wizard string="Discount" model="pos.order"
|
||||
name="pos.discount" id="pos_discount" menu="False"/>
|
||||
name="pos.discount" id="pos_discount" menu="False"/>-->
|
||||
|
||||
<!-- <wizard id="wizard_pos_payment_report" menu="False"
|
||||
model="pos.order" name="pos.payment.report" string="All paid lines for the current User"/-->
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
import wizard_pos_payment
|
||||
import wizard_default_journal
|
||||
import wizard_refund_order
|
||||
import wizard_discount
|
||||
import wizard_get_sale
|
||||
import wizard_scan_product
|
||||
import wizard_receipt
|
||||
|
@ -39,5 +38,6 @@ import wizard_open_statement
|
|||
import wizard_all_closed_cashbox_of_the_day
|
||||
import pos_add_product
|
||||
import pos_confirm
|
||||
import pos_discount
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!-- Point of Sale Confirm -->
|
||||
|
||||
<record id="view_pos_confirm" model="ir.ui.view">
|
||||
<field name="name">Open Statements</field>
|
||||
<field name="model">pos.confirm</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Open Statements">
|
||||
<label string="Are you sure you want to close your sales ?" colspan="2"/>
|
||||
<newline/>
|
||||
<button icon='gtk-cancel' special="cancel"
|
||||
string="No" />
|
||||
<button name="action_confirm" string="Yes"
|
||||
colspan="1" type="object" icon="gtk-ok"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_pos_confirm" model="ir.actions.act_window">
|
||||
<field name="name">Open Statements</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">pos.confirm</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'record_id' : active_id}</field>
|
||||
</record>
|
||||
<record model="ir.values" id="values_pos_confirm">
|
||||
<field name="model_id" ref="point_of_sale.model_pos_order" />
|
||||
<field name="object" eval="1" />
|
||||
<field name="name">Open Statements</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_pos_confirm'))"/>
|
||||
<field name="key">action</field>
|
||||
<field name="model">pos.order</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,104 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import netsvc
|
||||
from osv import osv,fields
|
||||
from tools.translate import _
|
||||
|
||||
class pos_discount(osv.osv_memory):
|
||||
_name = 'pos.discount'
|
||||
_description = 'Add Discount'
|
||||
|
||||
_columns = {
|
||||
'discount': fields.float('Discount ', required=True),
|
||||
'discount_notes': fields.char('Discount Notes',size= 128, required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'discount': lambda *a: 5,
|
||||
}
|
||||
|
||||
def apply_discount(self, cr, uid, ids, context):
|
||||
"""
|
||||
@summary: To give the discount of product and check the .
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param context: A standard dictionary
|
||||
@return : nothing
|
||||
"""
|
||||
this = self.browse(cr, uid, ids[0], context=context)
|
||||
record_id = context and context.get('record_id',False)
|
||||
if isinstance(record_id, (int, long)):
|
||||
record_id=[record_id]
|
||||
|
||||
order_ref = self.pool.get('pos.order')
|
||||
order_line_ref =self.pool.get('pos.order.line')
|
||||
|
||||
for order in order_ref.browse(cr, uid, record_id, context=context):
|
||||
for line in order.lines :
|
||||
company_discount = order.company_id.company_discount
|
||||
applied_discount =this.discount
|
||||
|
||||
if applied_discount == 0.00:
|
||||
notice = 'No Discount'
|
||||
elif company_discount >= applied_discount:
|
||||
notice = 'Minimum Discount'
|
||||
else:
|
||||
notice = this.discount_notes
|
||||
|
||||
if self.check_discount(cr, uid, record_id,this.discount,context) == 'apply_discount':
|
||||
order_line_ref.write(cr, uid, [line.id],
|
||||
{'discount': this.discount,
|
||||
'price_ded':line.price_unit*line.qty*(this.discount or 0)*0.01 or 0.0,
|
||||
'notice':notice
|
||||
},
|
||||
context=context,)
|
||||
else :
|
||||
order_line_ref.write(cr, uid, [line.id],
|
||||
{'discount': this.discount,
|
||||
'notice': notice,
|
||||
'price_ded':line.price_unit*line.qty*(this.discount or 0)*0.01 or 0.0
|
||||
},
|
||||
context=context,)
|
||||
return {}
|
||||
|
||||
def check_discount(self, cr, uid, record_id,discount, context):
|
||||
"""
|
||||
@summary: Check the discount of define by company .
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param record_id:Current Order id
|
||||
@param discount:Select Discount
|
||||
@param context: A standard dictionary
|
||||
@return : retrun to apply and used the company discount base on condition
|
||||
"""
|
||||
order_ref = self.pool.get('pos.order')
|
||||
for order in order_ref.browse(cr, uid, record_id, context=context):
|
||||
company_disc = order.company_id.company_discount
|
||||
for line in order.lines :
|
||||
prod_disc = discount
|
||||
if prod_disc <= company_disc :
|
||||
return 'apply_discount'
|
||||
else :
|
||||
return 'disc_discount'
|
||||
pos_discount()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!-- Add Product -->
|
||||
|
||||
<record id="view_pos_discount" model="ir.ui.view">
|
||||
<field name="name">Apply Discount</field>
|
||||
<field name="model">pos.discount</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Apply Discount">
|
||||
<group col="2" colspan="4">
|
||||
<field name="discount"/>
|
||||
<field name="discount_notes"/>
|
||||
<button icon='gtk-cancel' special="cancel"
|
||||
string="Close" />
|
||||
<button name="apply_discount" string="Apply Discount"
|
||||
colspan="1" type="object" icon="gtk-ok" />
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_pos_discount" model="ir.actions.act_window">
|
||||
<field name="name">Apply Discount</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">pos.discount</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'record_id' : active_id}</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,145 +0,0 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import pooler
|
||||
import wizard
|
||||
|
||||
_form = """<?xml version="1.0"?>
|
||||
<form string="Discount :">
|
||||
<field name="discount"/>
|
||||
</form>
|
||||
"""
|
||||
disc_form = """<?xml version="1.0"?>
|
||||
|
||||
<form string="Discount Notes :">
|
||||
<label colspan="2" string="Reason For Giving Discount" align="0.0"/>
|
||||
<newline/>
|
||||
<field name="note" nolabel="1"/>
|
||||
</form>
|
||||
"""
|
||||
|
||||
|
||||
_fields = {
|
||||
'discount': {
|
||||
'string': 'Discount percentage',
|
||||
'type': 'float',
|
||||
'required': True,
|
||||
'default': lambda *args: 5
|
||||
},
|
||||
}
|
||||
|
||||
disc_fields = {
|
||||
'note': {
|
||||
'string': 'Discount Notes',
|
||||
'type': 'char',
|
||||
'size': 128,
|
||||
'required': True
|
||||
},
|
||||
}
|
||||
|
||||
class discount_wizard(wizard.interface):
|
||||
|
||||
def apply_discount(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
order_ref = pool.get('pos.order')
|
||||
order_line_ref = pool.get('pos.order.line')
|
||||
for order in order_ref.browse(cr, uid, data['ids'], context=context):
|
||||
for line in order.lines :
|
||||
company_discount = order.company_id.company_discount
|
||||
applied_discount =data['form']['discount']
|
||||
if applied_discount == 0.00:
|
||||
notice = 'No Discount'
|
||||
elif company_discount >= applied_discount:
|
||||
notice = 'Minimum Discount'
|
||||
else:
|
||||
notice = data['form']['note']
|
||||
if self.check_discount(cr, uid, data, context) == 'apply_discount':
|
||||
order_line_ref.write(cr, uid, [line.id],
|
||||
{'discount': data['form']['discount'],
|
||||
'price_ded':line.price_unit*line.qty*(data['form']['discount'] or 0)*0.01 or 0.0,
|
||||
'notice':notice
|
||||
},
|
||||
context=context,)
|
||||
else :
|
||||
order_line_ref.write(cr, uid, [line.id],
|
||||
{'discount': data['form']['discount'],
|
||||
'notice': notice,
|
||||
'price_ded':line.price_unit*line.qty*(data['form']['discount'] or 0)*0.01 or 0.0
|
||||
},
|
||||
context=context,)
|
||||
return {}
|
||||
|
||||
def check_discount(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
order_ref = pool.get('pos.order')
|
||||
for order in order_ref.browse(cr, uid, data['ids'], context=context):
|
||||
company_disc = order.company_id.company_discount
|
||||
for line in order.lines :
|
||||
prod_disc = data['form']['discount']
|
||||
if prod_disc <= company_disc :
|
||||
return 'apply_discount'
|
||||
else :
|
||||
return 'disc_discount'
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'arch': _form,
|
||||
'fields': _fields,
|
||||
'state': (('end', 'Cancel'),
|
||||
('check_disc', 'Apply Discount', 'gtk-ok', True)
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
'check_disc': {
|
||||
'actions': [],
|
||||
'result': {'type':'choice','next_state':check_discount}
|
||||
},
|
||||
|
||||
'disc_discount': {
|
||||
'actions': [],
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'arch': disc_form,
|
||||
'fields':disc_fields,
|
||||
'state': (('end', 'Cancel'),
|
||||
('apply_discount', 'Apply Discount', 'gtk-ok', True)
|
||||
)
|
||||
}
|
||||
},
|
||||
'apply_discount': {
|
||||
'actions': [],
|
||||
'result': {
|
||||
'type': 'action',
|
||||
'action': apply_discount,
|
||||
'state': "end",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
discount_wizard('pos.discount')
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
Loading…
Reference in New Issue