From 27dd75b17639bac6cc56e9544f9d4eaf6830c997 Mon Sep 17 00:00:00 2001
From: ced <>
Date: Wed, 17 Jan 2007 06:57:07 +0000
Subject: [PATCH] ACCOUNT: split to new module account_cash_discount
bzr revid: ced-97c375b39b7e521bc78173c9ef01698f7142b64b
---
addons/account/account.py | 39 ----------
addons/account/account_invoice_view.xml | 2 -
addons/account/account_view.xml | 31 --------
addons/account/invoice.py | 11 +--
addons/account_cash_discount/__init__.py | 29 +++++++
addons/account_cash_discount/__terp__.py | 18 +++++
.../account_cash_discount.py | 78 +++++++++++++++++++
.../account_cash_discount_view.xml | 47 +++++++++++
.../account_tax_include/invoice_tax_incl.py | 6 +-
addons/l10n_ch/__terp__.py | 2 +-
10 files changed, 177 insertions(+), 86 deletions(-)
create mode 100644 addons/account_cash_discount/__init__.py
create mode 100644 addons/account_cash_discount/__terp__.py
create mode 100644 addons/account_cash_discount/account_cash_discount.py
create mode 100644 addons/account_cash_discount/account_cash_discount_view.xml
diff --git a/addons/account/account.py b/addons/account/account.py
index 919871202f1..f1f80316814 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -44,7 +44,6 @@ class account_payment_term(osv.osv):
'active': fields.boolean('Active'),
'note': fields.text('Description'),
'line_ids': fields.one2many('account.payment.term.line', 'payment_id', 'Terms'),
- 'cash_discount_ids': fields.one2many('account.cash.discount', 'payment_id', 'Cash Discounts'),
}
_defaults = {
'active': lambda *a: 1,
@@ -71,30 +70,6 @@ class account_payment_term(osv.osv):
amount -= amt
return result
- def get_discounts(self,cr,uid,id,base_date, context={}):
- """
- return the list of (date,percentage) ordered by date for the
- payment term with the corresponding id. return [] if no cash
- discount are defined. base_date is the date from where the
- discounts are computed.
- """
-
- pt = self.browse(cr, uid, id, context)
-
- if not pt.cash_discount_ids:
- return []
-
- res=[]
- for d in pt.cash_discount_ids:
- res.append(
- ((mx.DateTime.strptime(base_date,'%Y-%m-%d') +\
- RelativeDateTime(days=d.delay+1)).strftime("%Y-%m-%d"),
- d.discount)
- )
-
- res.sort(cmp=lambda x,y: cmp(x[0],y[0]))
- return res
-
account_payment_term()
class account_payment_term_line(osv.osv):
@@ -262,20 +237,6 @@ class account_account(osv.osv):
account_account()
-class account_cash_discount(osv.osv):
- _name = "account.cash.discount"
- _description = "Cash Discount" #A reduction in the price if payment is made within a stipulated period.
- _columns = {
- 'name': fields.char('Name', size=32),
- 'delay': fields.integer('Number of Days', required=True),
- 'discount': fields.float('Discount (%)',digits=(16,6),required=True),
- 'payment_id': fields.many2one('account.payment.term','Associated Payment Term'),
- 'credit_account_id': fields.many2one('account.account', 'Credit Account'),
- 'debit_account_id': fields.many2one('account.account', 'Debit Account'),
- }
-account_cash_discount()
-
-
class account_journal_view(osv.osv):
_name = "account.journal.view"
_description = "Journal View"
diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml
index 2643e3b6ee8..1dea5dfe275 100644
--- a/addons/account/account_invoice_view.xml
+++ b/addons/account/account_invoice_view.xml
@@ -110,7 +110,6 @@
-
@@ -141,7 +140,6 @@
-
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index 4679ebf913a..73793f8de85 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -1096,35 +1096,6 @@
-
-
-
-
- account.cash.discount.form
- account.cash.discount
- form
-
-
-
-
-
-
- account.cash.discount.tree
- account.cash.discount
- tree
-
-
-
-
-
-
-
-
-
@@ -1175,8 +1146,6 @@
-
-
diff --git a/addons/account/invoice.py b/addons/account/invoice.py
index 1199fba14d8..07c59f51bd8 100644
--- a/addons/account/invoice.py
+++ b/addons/account/invoice.py
@@ -107,8 +107,6 @@ class account_invoice(osv.osv):
'date_invoice': fields.date('Date Invoiced', required=True, states={'open':[('readonly',True)],'close':[('readonly',True)]}),
'date_due': fields.date('Due Date', states={'open':[('readonly',True)],'close':[('readonly',True)]}),
- 'date_discount': fields.date('Discount Date', states={'open':[('readonly',True)],'close':[('readonly',True)]},
- help='The date of the first cash discount'),
'partner_id': fields.many2one('res.partner', 'Partner', change_default=True, readonly=True, required=True, states={'draft':[('readonly',False)]}, relate=True),
'partner_bank_id': fields.many2one('res.partner.bank', 'Partner bank'),
@@ -210,11 +208,6 @@ class account_invoice(osv.osv):
res= {'value':{'date_due': pterm_list[-1]}}
- disc_list= pt_obj.get_discounts(cr,uid,payment_term_id,date_invoice)
- if disc_list :
- res = res or {'value':{}}
- res['value'].update({'date_discount': disc_list[0][0] })
-
return res
@@ -586,8 +579,6 @@ class account_invoice_line(osv.osv):
tax_obj = self.pool.get('account.tax')
cur_obj = self.pool.get('res.currency')
ait_obj = self.pool.get('account.invoice.tax')
-#TODO: rewrite using browse instead of the manual SQL queries
-# cr.execute('SELECT id FROM account_invoice_line WHERE invoice_id=%d', (invoice_id,))
inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id)
cur = inv.currency_id
@@ -597,7 +588,7 @@ class account_invoice_line(osv.osv):
'name':line.name,
'price_unit':line.price_unit,
'quantity':line.quantity,
- 'price':round(line.quantity*line.price_unit * (1.0- (line.discount or 0.0)/100.0),2),
+ 'price':cur_obj.round(cr, uid, cur, line.quantity*line.price_unit * (1.0- (line.discount or 0.0)/100.0)),
'account_id':line.account_id.id
})
for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, (line.price_unit *(1.0-(line['discount'] or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id, line.product_id):
diff --git a/addons/account_cash_discount/__init__.py b/addons/account_cash_discount/__init__.py
new file mode 100644
index 00000000000..db89eddac5b
--- /dev/null
+++ b/addons/account_cash_discount/__init__.py
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
+# Fabien Pinckaers
+#
+# 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 account_cash_discount
diff --git a/addons/account_cash_discount/__terp__.py b/addons/account_cash_discount/__terp__.py
new file mode 100644
index 00000000000..14d4d837e67
--- /dev/null
+++ b/addons/account_cash_discount/__terp__.py
@@ -0,0 +1,18 @@
+{
+ "name" : "Payement Term with Cash Discount",
+ "version" : "1.0",
+ "depends" : ["account",],
+ "author" : "Tiny",
+ "description" : "",
+ "website" : "http://tinyerp.com/",
+ "category" : "Generic Modules/Accounting",
+ "init_xml" : [
+ ],
+ "demo_xml" : [
+ ],
+ "update_xml" : [
+ "account_cash_discount_view.xml",
+ ],
+ "active": False,
+ "installable": True
+}
diff --git a/addons/account_cash_discount/account_cash_discount.py b/addons/account_cash_discount/account_cash_discount.py
new file mode 100644
index 00000000000..85a36ec6659
--- /dev/null
+++ b/addons/account_cash_discount/account_cash_discount.py
@@ -0,0 +1,78 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2004-2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
+#
+# $Id: account.py 1005 2005-07-25 08:41:42Z nicoe $
+#
+# 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, osv
+import mx.DateTime
+from mx.DateTime import RelativeDateTime
+
+class account_payment_term(osv.osv):
+ _name = "account.payment.term"
+ _inherit = "account.payment.term"
+ _columns = {
+ 'cash_discount_ids': fields.one2many('account.cash.discount', 'payment_id', 'Cash Discounts'),
+ }
+ def get_discounts(self,cr,uid,id,base_date, context={}):
+ """
+ return the list of (date,percentage) ordered by date for the
+ payment term with the corresponding id. return [] if no cash
+ discount are defined. base_date is the date from where the
+ discounts are computed.
+ """
+
+ pt = self.browse(cr, uid, id, context)
+
+ if not pt.cash_discount_ids:
+ return []
+
+ res=[]
+ for d in pt.cash_discount_ids:
+ res.append(
+ ((mx.DateTime.strptime(base_date,'%Y-%m-%d') +\
+ RelativeDateTime(days=d.delay+1)).strftime("%Y-%m-%d"),
+ d.discount)
+ )
+
+ res.sort(cmp=lambda x,y: cmp(x[0],y[0]))
+ return res
+account_payment_term()
+
+class account_cash_discount(osv.osv):
+ _name = "account.cash.discount"
+ _description = "Cash Discount" #A reduction in the price if payment is made within a stipulated period.
+ _columns = {
+ 'name': fields.char('Name', size=32),
+ 'delay': fields.integer('Number of Days', required=True),
+ 'discount': fields.float('Discount (%)', digits=(16,6),required=True),
+ 'payment_id': fields.many2one('account.payment.term','Associated Payment Term'),
+ 'credit_account_id': fields.many2one('account.account', 'Credit Account'),
+ 'debit_account_id': fields.many2one('account.account', 'Debit Account'),
+ }
+account_cash_discount()
+
diff --git a/addons/account_cash_discount/account_cash_discount_view.xml b/addons/account_cash_discount/account_cash_discount_view.xml
new file mode 100644
index 00000000000..aa8dc074cf7
--- /dev/null
+++ b/addons/account_cash_discount/account_cash_discount_view.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+ account.cash.discount.form
+ account.cash.discount
+ form
+
+
+
+
+
+
+ account.cash.discount.tree
+ account.cash.discount
+ tree
+
+
+
+
+
+
+
+
+
+
+ account.payment.term.form
+ account.payment.term
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/account_tax_include/invoice_tax_incl.py b/addons/account_tax_include/invoice_tax_incl.py
index 175b7fa4642..8d1bf2cc171 100644
--- a/addons/account_tax_include/invoice_tax_incl.py
+++ b/addons/account_tax_include/invoice_tax_incl.py
@@ -100,7 +100,7 @@ class account_invoice_line(osv.osv):
'name':line.name,
'price_unit':line.price_unit,
'quantity':line.quantity,
- 'price':round(line.quantity*line.price_unit * (1.0- (line.discount or 0.0)/100.0),2),
+ 'price':cur_obj.round(cr, uid, cur, line.quantity*line.price_unit * (1.0- (line.discount or 0.0)/100.0)),
'account_id':line.account_id.id,
})
for tax in tax_obj.compute_inv(cr, uid, line.invoice_line_tax_id, (line.price_unit *(1.0-(line['discount'] or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id, line.product_id):
@@ -118,8 +118,8 @@ class account_invoice_line(osv.osv):
if inv.type in ('out_invoice','in_invoice'):
val['base_code_id'] = tax['base_code_id']
val['tax_code_id'] = tax['tax_code_id']
- val['base_amount'] = tax['base'] * tax['base_sign']
- val['tax_amount'] = tax['amount'] * tax['tax_sign']
+ val['base_amount'] = val['base'] * tax['base_sign']
+ val['tax_amount'] = val['amount'] * tax['tax_sign']
val['account_id'] = tax['account_collected_id'] or line.account_id.id
else:
val['base_code_id'] = tax['ref_base_code_id']
diff --git a/addons/l10n_ch/__terp__.py b/addons/l10n_ch/__terp__.py
index e79ecead756..718a2fda851 100755
--- a/addons/l10n_ch/__terp__.py
+++ b/addons/l10n_ch/__terp__.py
@@ -7,7 +7,7 @@
"author" : "Camptocamp",
"category" : "Localisation/Europe",
"website": "http://www.tinyerp.com",
- "depends" : ["base", "account"],
+ "depends" : ["base", "account", "account_cash_discount",],
"init_xml" : ["dta/dta_data.xml"],
# "init_xml" : ["zip_code_default.xml"],
"demo_xml" : ["vaudtax_data_demo.xml","dta/dta_demo.xml"],