purchase diuscount (doesn't work)

bzr revid: rde-8d74ed8c35efcc66a819fc5b14c5623316e02131
This commit is contained in:
rde 2007-01-18 16:56:51 +00:00
parent b50b4f02a6
commit f9416858b7
8 changed files with 526 additions and 0 deletions

View File

@ -0,0 +1 @@
import purchase_discount

View File

@ -0,0 +1,11 @@
{
"name" : "Purchase Order Lines With Discounts",
"author" : "Tiny",
"version" : "1.0",
"category" : "Generic Modules/Sales & Purchases",
"depends" : ["base", "account", "stock"],
"demo_xml" : [],
"update_xml" : ["purchase_discount_view.xml", "purchase_discount_report.xml"],
"active": False,
"installable": True
}

View File

@ -0,0 +1,73 @@
##############################################################################
#
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from osv import fields
from osv import osv
import time
import netsvc
import ir
from mx import DateTime
import pooler
class purchase_order_line(osv.osv):
_name = "purchase.order.line"
_inherit = "purchase.order.line"
_columns = {
'discount': fields.float('Discount (%)', digits=(16,2)),
}
_defaults = {
'discount': lambda *a: 0.0,
}
purchase_order_line()
class purchase_order(osv.osv):
_name = "purchase.order"
_inherit = "purchase.order"
def _amount_untaxed(self, cr, uid, ids, field_name, arg, context):
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"
cr.execute(sql_req)
res = dict(cr.fetchall())
print "_amount_untaxed : res = "+str(res)
return res
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
print "_amount_tax(self, cr, uid, ids, field_name, arg, context):"
res = {}
for order in self.browse(cr, uid, ids):
val = 0.0
for line in order.order_line:
for tax in line.taxes_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+=c['amount']
res[order.id]=round(val,2)
print "_amount_tax : res = "+str(res)
return res
purchase_order()

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<terp>
<data>
<report id="report_purchase_discount_order"
name="purchase.discount.order"
string="Print Order"
model="purchase.order"
rml="purchase_discount/report/order.rml"
auto="False"/>
</data>
</terp>

View File

@ -0,0 +1,27 @@
<terp>
<data>
<record model="ir.ui.view" id="purchase_discount_order_line_form">
<field name="name">purchase_discount.order.line.form</field>
<field name="model">purchase.order.line</field>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_line_form"/>
<field name="arch" type="xml">
<field name="price_unit" position="after">
<field name="discount"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="purchase_discount_order_line_tree">
<field name="name">purchase_discount.order.line.tree</field>
<field name="model">purchase.order.line</field>
<field name="type">tree</field>
<field name="inherit_id" ref="purchase.purchase_order_line_tree"/>
<field name="arch" type="xml">
<field name="price_unit" position="after">
<field name="discount"/>
</field>
</field>
</record>
</data>
</terp>

View File

@ -0,0 +1,29 @@
##############################################################################
#
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import order

View File

@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import time
from report import report_sxw
from osv import osv
import pooler
class order(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(order, self).__init__(cr, uid, name, context)
self.localcontext.update({
'time': time,
'get_line_tax': self._get_line_tax,
'get_tax': self._get_tax,
'get_product_code': self._get_product_code,
})
def _get_line_tax(self, line_obj):
self.cr.execute("SELECT tax_id FROM purchase_order_taxe WHERE order_line_id=%d" % (line_obj.id))
res = self.cr.fetchall() or None
if not res:
return ""
if isinstance(res, list):
tax_ids = [t[0] for t in res]
else:
tax_ids = res[0]
res = [tax.name for tax in pooler.get_pool(cr.dbname).get('account.tax').browse(self.cr, self.uid, tax_ids)]
return ",\n ".join(res)
def _get_tax(self, order_obj):
self.cr.execute("SELECT DISTINCT tax_id FROM purchase_order_taxe, purchase_order_line, purchase_order \
WHERE (purchase_order_line.order_id=purchase_order.id) AND (purchase_order.id=%d)" % (order_obj.id))
res = self.cr.fetchall() or None
if not res:
return []
if isinstance(res, list):
tax_ids = [t[0] for t in res]
else:
tax_ids = res[0]
tax_obj = pooler.get_pool(cr.dbname).get('account.tax')
res = []
for tax in tax_obj.browse(self.cr, self.uid, tax_ids):
self.cr.execute("SELECT DISTINCT order_line_id FROM purchase_order_line, purchase_order_taxe \
WHERE (purchase_order_taxe.tax_id=%d) AND (purchase_order_line.order_id=%d)" % (tax.id, order_obj.id))
lines = self.cr.fetchall() or None
if lines:
if isinstance(lines, list):
line_ids = [l[0] for l in lines]
else:
line_ids = lines[0]
base = 0
for line in pooler.get_pool(cr.dbname).get('purchase.order.line').browse(self.cr, self.uid, line_ids):
base += line.price_subtotal
res.append({'code':tax.name,
'base':base,
'amount':base*tax.amount})
return res
def _get_product_code(self, product_id, partner_id):
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]
report_sxw.report_sxw('report.purchase.order','purchase.order','addons/purchase/report/order.rml',parser=order)

View File

@ -0,0 +1,287 @@
<?xml version="1.0"?>
<document filename="test.pdf">
<template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
<pageTemplate id="first">
<frame id="first" x1="42.0" y1="42.0" width="511" height="758"/>
</pageTemplate>
</template>
<stylesheet>
<blockTableStyle id="Standard_Outline">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Tableau6">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Tableau10">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Tableau2">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="GRID" colorName="black"/>
<blockBackground colorName="#e6e6e6" start="0,0" stop="0,0"/>
<blockBackground colorName="#e6e6e6" start="1,0" stop="1,0"/>
<blockBackground colorName="#e6e6e6" start="2,0" stop="2,0"/>
<blockBackground colorName="#e6e6e6" start="3,0" stop="3,0"/>
<blockBackground colorName="#e6e6e6" start="4,0" stop="4,0"/>
<blockBackground colorName="#e6e6e6" start="5,0" stop="5,0"/>
<blockBackground colorName="#e6e6e6" start="6,0" stop="6,0"/>
<blockBackground colorName="#e6e6e6" start="7,0" stop="7,0"/>
</blockTableStyle>
<blockTableStyle id="Tableau3">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Tableau5">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Tableau1">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Tableau4">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<initialize>
<paraStyle name="all" alignment="justify"/>
</initialize>
<paraStyle name="P1" fontName="Times-Roman" fontSize="9.0" leading="11"/>
<paraStyle name="P2" fontName="Times-Bold" fontSize="10.0" leading="13"/>
<paraStyle name="P3" fontName="Times-Roman" fontSize="10.0" leading="13"/>
<paraStyle name="P4" fontName="Times-Roman" fontSize="10.0" leading="13"/>
<paraStyle name="P5" fontName="Times-Roman" fontSize="10.0" leading="13"/>
<paraStyle name="P6" fontName="Times-Roman" fontSize="9.0" leading="11"/>
<paraStyle name="P7" fontName="Times-Roman" fontSize="11.0" leading="14"/>
<paraStyle name="P8" fontName="Times-Roman" fontSize="4.0" leading="5"/>
<paraStyle name="P9" fontName="Times-Roman"/>
<paraStyle name="P10" fontName="Times-Roman" fontSize="16.0" leading="20"/>
<paraStyle name="P11" fontName="Times-Roman" fontSize="11.0" leading="14"/>
<paraStyle name="P12" fontName="Times-Bold" fontSize="8.0" leading="10"/>
<paraStyle name="P13" fontName="Times-Bold" fontSize="8.0" leading="10" alignment="CENTER"/>
<paraStyle name="P14" fontName="Times-BoldItalic" fontSize="6.0" leading="8" alignment="LEFT"/>
<paraStyle name="P15" fontName="Times-Roman" fontSize="9.0" leading="11" alignment="LEFT"/>
<paraStyle name="P16" fontName="Times-Roman" fontSize="9.0" leading="11" alignment="CENTER"/>
<paraStyle name="P17" fontName="Times-Roman" fontSize="9.0" leading="11" alignment="RIGHT"/>
<paraStyle name="P18" fontName="Times-BoldItalic" fontSize="9.0" leading="11" alignment="LEFT"/>
<paraStyle name="P19" fontName="Times-Italic" fontSize="9.0" leading="11" alignment="LEFT"/>
<paraStyle name="P20" fontName="Times-Roman" fontSize="7.0" leading="9"/>
<paraStyle name="P21" fontName="Times-Bold" fontSize="9.0" leading="11" alignment="RIGHT"/>
<paraStyle name="P22" fontName="Times-Roman" fontSize="7.0" leading="9"/>
<paraStyle name="P23" fontName="Times-Bold" fontSize="9.0" leading="11" alignment="RIGHT"/>
<paraStyle name="P24" fontName="Times-Bold" fontSize="9.0" leading="11"/>
<paraStyle name="P25" fontName="Times-Roman" alignment="LEFT"/>
<paraStyle name="Standard" fontName="Times-Roman"/>
<paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/>
<paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="Table Contents" fontName="Times-Roman"/>
<paraStyle name="Table Heading" fontName="Times-Roman" alignment="CENTER"/>
<paraStyle name="Caption" fontName="Times-Roman" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="Index" fontName="Times-Roman"/>
</stylesheet>
<story>
<para style="P1">[[ repeatIn(objects,'o') ]]</para>
<para style="P1">
<font color="white"> </font>
</para>
<blockTable colWidths="241.0,57.0,213.0" style="Tableau6">
<tr>
<td>
<blockTable colWidths="241.0" style="Tableau10">
<tr>
<td>
<para style="P2">Shipping address :</para>
</td>
</tr>
<tr>
<td>
<para style="P3">[[ repeatIn(o.dest_address_id and [o.dest_address_id] or [],'addr') ]]</para>
<para style="P4">[[ o.partner_id.title or '' ]] [[ o.partner_id.name ]]</para>
<para style="P4">[[ addr.title or '' ]] [[ addr.name ]]</para>
<para style="P4">[[ addr.street ]]</para>
<para style="P4">[[ addr.street2 or '' ]]</para>
<para style="P5"><font face="Times-Roman">[[ addr.zip or '' ]]</font> [[ addr.city or '' ]]</para>
<para style="P5">[[ addr.state_id and addr.state_id.name or '' ]]</para>
<para style="P5">[[ addr.country_id and addr.country_id.name or '' ]]</para>
</td>
</tr>
</blockTable>
<para style="P6">
<font color="white"> </font>
</para>
</td>
<td>
<para style="P6">
<font color="white"> </font>
</para>
</td>
<td>
<para style="P7">[[ o.partner_id.title or '' ]] [[ o.partner_id.name ]]</para>
<para style="P7">[[ o.partner_address_id.title or '' ]] [[ o.partner_address_id.name ]]</para>
<para style="P7">[[ o.partner_address_id.street ]]</para>
<para style="P7">[[ o.partner_address_id.street2 or '' ]]</para>
<para style="P7">[[ o.partner_address_id.zip or '' ]] [[ o.partner_address_id.city or '' ]]</para>
<para style="P7">[[ o.partner_address_id.state_id and o.partner_address_id.state_id.name or '' ]]</para>
<para style="P7">[[ o.partner_address_id.country_id and o.partner_address_id.country_id.name or '' ]]</para>
<para style="P8">
<font color="white"> </font>
</para>
<para style="P4">Tél. : [[ o.partner_address_id.phone or '' ]]</para>
<para style="P4">Fax : [[ o.partner_address_id.fax or '' ]]</para>
<para style="P4">TVA : [[ o.partner_id.vat or '' ]]</para>
</td>
</tr>
</blockTable>
<para style="P9">
<font color="white"> </font>
</para>
<para style="P10">[[ o.state=='draft' and 'Quotation ' or 'Order ' ]] N° : [[ o.name ]]</para>
<para style="P10">
<font color="white"> </font>
</para>
<para style="P11">Our order reference : [[ o.ref or '' ]]</para>
<para style="P11">Your order reference : [[ o.partner_ref or '' ]]</para>
<para style="P11">Date ordered : [[ time.strftime('%d/%m/%Y', time.strptime(o.date_order, '%Y-%m-%d')) ]]</para>
<para style="P11">Validated by : [[ o.validator and o.validator.name or '' ]]</para>
<para style="P9">
<font color="white"> </font>
</para>
<blockTable colWidths="195.0,51.0,46.0,45.0,31.0,56.0,43.0,43.0" repeatRows="1" style="Tableau2">
<tr>
<td>
<para style="P12">Product Description</para>
</td>
<td>
<para style="P13">Applicable Taxes</para>
</td>
<td>
<para style="P13">Date Promised</para>
</td>
<td>
<para style="P13">Qty</para>
</td>
<td>
<para style="P13">UoM</para>
</td>
<td>
<para style="P13">Unit Price</para>
</td>
<td>
<para style="P13">Discount (%)</para>
</td>
<td>
<para style="P13">Net Price</para>
</td>
</tr>
</blockTable>
<section>
<para style="P14">[[ repeatIn(o.order_line,'line') ]]</para>
<blockTable colWidths="195.0,51.0,46.0,45.0,31.0,56.0,43.0,43.0" style="Tableau3">
<tr>
<td>
<para style="P15">[[ line.name ]]</para>
</td>
<td>
<para style="P16">[[ ', '.join(map(lambda x: x.name, line.taxes_id))]]</para>
</td>
<td>
<para style="P16">[[ time.strftime('%d/%m/%Y', time.strptime( line.date_planned, '%Y-%m-%d')) ]]</para>
</td>
<td>
<para style="P17">[[ line.product_qty ]]</para>
</td>
<td>
<para style="P15">[[ line.product_uom.name ]]</para>
</td>
<td>
<para style="P17">[[ '%.2f' % line.price_unit ]]</para>
</td>
<td>
<para style="P17">[[ '%.2f'%line.discount ]]</para>
</td>
<td>
<para style="P17">[[ '%.2f' % line.price_subtotal ]]</para>
</td>
</tr>
</blockTable>
<blockTable colWidths="43.0,333.0,135.0" style="Tableau5">
<tr>
<td>
<para style="P18">[[ repeatIn((line.notes and [line.notes]) or [], 'l') ]]</para>
</td>
<td>
<para style="P19">[[ l or removeParentNode('table') ]]</para>
</td>
<td>
<para style="P18">
<font color="white"> </font>
</para>
</td>
</tr>
</blockTable>
</section>
<para style="Standard">
<font color="white"> </font>
</para>
<blockTable colWidths="376.0,65.0,69.0" style="Tableau1">
<tr>
<td>
<para style="P20">
<font color="white"> </font>
</para>
</td>
<td>
<para style="P21">Net Total :</para>
</td>
<td>
<para style="P21">[[ '%.2f' % o.amount_untaxed ]] [[ o.pricelist_id.currency_id.name ]]</para>
</td>
</tr>
<tr>
<td>
<para style="P20">
<font color="white"> </font>
</para>
</td>
<td>
<para style="P21">Taxes :</para>
</td>
<td>
<para style="P21">[[ '%.2f' % o.amount_tax ]] [[ o.pricelist_id.currency_id.name ]]</para>
</td>
</tr>
<tr>
<td>
<para style="P22">
<font color="white"> </font>
</para>
</td>
<td>
<para style="P23">TOTAL :</para>
</td>
<td>
<para style="P23">[[ '%.2f' % o.amount_total ]] [[ o.pricelist_id.currency_id.name ]]</para>
</td>
</tr>
</blockTable>
<para style="P24">
<font color="white"> </font>
</para>
<blockTable colWidths="510.0" style="Tableau4">
<tr>
<td>
<para style="P25">[[ o.notes or '' ]] [[ setTag('para','xpre') ]]</para>
</td>
</tr>
</blockTable>
<para style="P25">
<font color="white"> </font>
</para>
</story>
</document>