Purchase discount, report is not overridden correctly (discount column is not added)
bzr revid: rde-eb2cbe0b9f3f95e00a713286f51ecb9a338935bb
This commit is contained in:
parent
7f6d21432d
commit
5c795d67a1
|
@ -1 +1,2 @@
|
||||||
import purchase_discount
|
import purchase_discount
|
||||||
|
import report
|
||||||
|
|
|
@ -37,8 +37,18 @@ import pooler
|
||||||
class purchase_order_line(osv.osv):
|
class purchase_order_line(osv.osv):
|
||||||
_name = "purchase.order.line"
|
_name = "purchase.order.line"
|
||||||
_inherit = "purchase.order.line"
|
_inherit = "purchase.order.line"
|
||||||
|
|
||||||
|
def _amount_line(self, cr, uid, ids, prop, unknow_none,unknow_dict):
|
||||||
|
res = {}
|
||||||
|
cur_obj=self.pool.get('res.currency')
|
||||||
|
for line in self.browse(cr, uid, ids):
|
||||||
|
cur = line.order_id.pricelist_id.currency_id
|
||||||
|
res[line.id] = cur_obj.round(cr, uid, cur, line.price_unit * line.product_qty * (1 - (line.discount or 0.0) /100.0))
|
||||||
|
return res
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'discount': fields.float('Discount (%)', digits=(16,2)),
|
'discount': fields.float('Discount (%)', digits=(16,2)),
|
||||||
|
'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal'),
|
||||||
}
|
}
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'discount': lambda *a: 0.0,
|
'discount': lambda *a: 0.0,
|
||||||
|
@ -51,23 +61,34 @@ class purchase_order(osv.osv):
|
||||||
|
|
||||||
def _amount_untaxed(self, cr, uid, ids, field_name, arg, context):
|
def _amount_untaxed(self, cr, uid, ids, field_name, arg, context):
|
||||||
id_set = ",".join(map(str, ids))
|
id_set = ",".join(map(str, ids))
|
||||||
sql_req="SELECT s.id,COALESCE(SUM(l.price_unit*l.product_qty*(100-l.discount))/100.0,0)::decimal(16,2) AS amount FROM purchase_order s LEFT OUTER JOIN purchase_order_line l ON (s.id=l.order_id) WHERE s.id IN ("+id_set+") GROUP BY s.id"
|
sql_req="SELECT s.id,COALESCE(SUM(l.price_unit*l.product_qty*(100.0-l.discount))/100.0,0) AS amount FROM purchase_order s LEFT OUTER JOIN purchase_order_line l ON (s.id=l.order_id) WHERE s.id IN ("+id_set+") GROUP BY s.id"
|
||||||
cr.execute(sql_req)
|
cr.execute(sql_req)
|
||||||
|
|
||||||
res = dict(cr.fetchall())
|
res = dict(cr.fetchall())
|
||||||
print "_amount_untaxed : res = "+str(res)
|
|
||||||
|
cur_obj=self.pool.get('res.currency')
|
||||||
|
for id in res.keys():
|
||||||
|
order=self.browse(cr, uid, [id])[0]
|
||||||
|
cur=order.pricelist_id.currency_id
|
||||||
|
res[id]=cur_obj.round(cr, uid, cur, res[id])
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
|
||||||
print "_amount_tax(self, cr, uid, ids, field_name, arg, context):"
|
|
||||||
res = {}
|
res = {}
|
||||||
|
cur_obj=self.pool.get('res.currency')
|
||||||
for order in self.browse(cr, uid, ids):
|
for order in self.browse(cr, uid, ids):
|
||||||
val = 0.0
|
val = 0.0
|
||||||
|
cur=order.pricelist_id.currency_id
|
||||||
for line in order.order_line:
|
for line in order.order_line:
|
||||||
for tax in line.taxes_id:
|
for c in self.pool.get('account.tax').compute(cr, uid, line.taxes_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_qty, order.partner_address_id.id, line.product_id):
|
||||||
for c in self.pool.get('account.tax').compute(cr, uid, [tax.id], line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_qty, order.partner_address_id.id):
|
val+= cur_obj.round(cr, uid, cur, c['amount'])
|
||||||
val+=c['amount']
|
res[order.id]=cur_obj.round(cr, uid, cur, val)
|
||||||
res[order.id]=round(val,2)
|
|
||||||
|
|
||||||
print "_amount_tax : res = "+str(res)
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
|
||||||
|
'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
|
||||||
|
}
|
||||||
|
|
||||||
purchase_order()
|
purchase_order()
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<terp>
|
<terp>
|
||||||
<data>
|
<data>
|
||||||
<report id="report_purchase_discount_order"
|
<report id="purchase.report_purchase_order"
|
||||||
name="purchase.discount.order"
|
name="purchase.order"
|
||||||
string="Print Order"
|
string="Print Order"
|
||||||
model="purchase.order"
|
model="purchase.order"
|
||||||
rml="purchase_discount/report/order.rml"
|
rml="purchase_discount/report/order.rml"
|
||||||
|
|
|
@ -33,6 +33,7 @@ import pooler
|
||||||
|
|
||||||
class order(report_sxw.rml_parse):
|
class order(report_sxw.rml_parse):
|
||||||
def __init__(self, cr, uid, name, context):
|
def __init__(self, cr, uid, name, context):
|
||||||
|
print "foo"
|
||||||
super(order, self).__init__(cr, uid, name, context)
|
super(order, self).__init__(cr, uid, name, context)
|
||||||
self.localcontext.update({
|
self.localcontext.update({
|
||||||
'time': time,
|
'time': time,
|
||||||
|
@ -84,4 +85,4 @@ class order(report_sxw.rml_parse):
|
||||||
product_obj=pooler.get_pool(self.cr.dbname).get('product.product')
|
product_obj=pooler.get_pool(self.cr.dbname).get('product.product')
|
||||||
return product_obj._product_code(self.cr, self.uid, [product_id], name=None, arg=None, context={'partner_id': partner_id})[product_id]
|
return product_obj._product_code(self.cr, self.uid, [product_id], name=None, arg=None, context={'partner_id': partner_id})[product_id]
|
||||||
|
|
||||||
report_sxw.report_sxw('report.purchase.order','purchase.order','addons/purchase/report/order.rml',parser=order)
|
report_sxw.report_sxw('report.purchase.order','purchase.order','addons/purchase_discount/report/order.rml',parser=order)
|
||||||
|
|
Loading…
Reference in New Issue