ACCOUNT: split to new module account_cash_discount

bzr revid: ced-97c375b39b7e521bc78173c9ef01698f7142b64b
This commit is contained in:
ced 2007-01-17 06:57:07 +00:00
parent 654d57da61
commit 27dd75b176
10 changed files with 177 additions and 86 deletions

View File

@ -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"

View File

@ -110,7 +110,6 @@
<field name="amount_total"/>
<field name="currency_id"/>
<field name="date_invoice"/>
<field name="date_discount" select="1"/>
<field name="date_due" select="1"/>
<field name="state"/>
</tree>
@ -141,7 +140,6 @@
<field name="payment_term" on_change="onchange_payment_term(payment_term)" />
<field name="date_due" select="1"/>
<field name="date_discount" select="1"/>
<field name="journal_id" select="1"/>

View File

@ -1096,35 +1096,6 @@
<menuitem name="Financial Management/Configuration/Models/Models Definition" id="menu_action_model_form" action="action_model_form"/>
<!-- cash discount -->
<record model="ir.ui.view" id="view_cash_discount_form">
<field name="name">account.cash.discount.form</field>
<field name="model">account.cash.discount</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Cash Discount">
<field name="name" select="1"/>
<field name="delay" select="1"/>
<field name="discount" select="1"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_cash_discount_tree">
<field name="name">account.cash.discount.tree</field>
<field name="model">account.cash.discount</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Cash Discount" editable="bottom">
<field name="name" select="1"/>
<field name="delay" select="1"/>
<field name="discount" select="1"/>
</tree>
</field>
</record>
<!--
# Payment Terms
-->
@ -1175,8 +1146,6 @@
<field name="note" colspan="3"/>
<separator string="Computation" colspan="4"/>
<field name="line_ids" colspan="3"/>
<separator string="Cash Discount" colspan="4"/>
<field name="cash_discount_ids" colspan="3"/>
</form>
</field>
</record>

View File

@ -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):

View File

@ -0,0 +1,29 @@
##############################################################################
#
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
# Fabien Pinckaers <fp@tiny.Be>
#
# 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

View File

@ -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
}

View File

@ -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()

View File

@ -0,0 +1,47 @@
<?xml version="1.0"?>
<terp>
<data>
<!-- cash discount -->
<record model="ir.ui.view" id="view_cash_discount_form">
<field name="name">account.cash.discount.form</field>
<field name="model">account.cash.discount</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Cash Discount">
<field name="name" select="1"/>
<field name="delay" select="1"/>
<field name="discount" select="1"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_cash_discount_tree">
<field name="name">account.cash.discount.tree</field>
<field name="model">account.cash.discount</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Cash Discount" editable="bottom">
<field name="name" select="1"/>
<field name="delay" select="1"/>
<field name="discount" select="1"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="view_payment_term_form">
<field name="name">account.payment.term.form</field>
<field name="model">account.payment.term</field>
<field name="inherit_id" ref="account.view_payment_term_form"/>
<field name="arch" type="xml">
<field name="line_ids" position="after">
<field name="cash_discount_ids" colspan="3"/>
<separator string="Cash Discount" colspan="4"/>
</field>
</field>
</record>
</data>
</terp>

View File

@ -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']

View File

@ -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"],