From 58d75ac28bd6f8bb3f151058d349010ed5676990 Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Thu, 23 Oct 2008 11:23:55 +0530 Subject: [PATCH] moving module from extra_addons to trunk addons and applying changes according to the the qdp requires bzr revid: mga@mga-laptop-20081023055355-tf0yfsqsrddkom5g --- addons/account_voucher/__init__.py | 3 + addons/account_voucher/__terp__.py | 33 ++ addons/account_voucher/account_report.xml | 54 ++ addons/account_voucher/account_view.xml | 57 ++ .../account_voucher_sequence.xml | 110 ++++ .../account_voucher_wizard.xml | 20 + .../account_voucher_workflow.xml | 75 +++ addons/account_voucher/report/__init__.py | 4 + addons/account_voucher/report/invoice.py | 50 ++ addons/account_voucher/report/invoice.rml | 268 +++++++++ .../account_voucher/report/report_voucher.py | 72 +++ .../account_voucher/report/report_voucher.rml | 381 +++++++++++++ .../report/report_voucher_amount.py | 51 ++ .../report/report_voucher_amount.rml | 353 ++++++++++++ addons/account_voucher/report/tax_report.py | 185 ++++++ addons/account_voucher/report/tax_report.rml | 255 +++++++++ addons/account_voucher/voucher.py | 537 ++++++++++++++++++ addons/account_voucher/voucher_account.py | 125 ++++ addons/account_voucher/voucher_view.xml | 295 ++++++++++ addons/account_voucher/wizard/__init__.py | 1 + addons/account_voucher/wizard/open_voucher.py | 113 ++++ 21 files changed, 3042 insertions(+) create mode 100755 addons/account_voucher/__init__.py create mode 100755 addons/account_voucher/__terp__.py create mode 100755 addons/account_voucher/account_report.xml create mode 100755 addons/account_voucher/account_view.xml create mode 100644 addons/account_voucher/account_voucher_sequence.xml create mode 100644 addons/account_voucher/account_voucher_wizard.xml create mode 100644 addons/account_voucher/account_voucher_workflow.xml create mode 100755 addons/account_voucher/report/__init__.py create mode 100755 addons/account_voucher/report/invoice.py create mode 100755 addons/account_voucher/report/invoice.rml create mode 100755 addons/account_voucher/report/report_voucher.py create mode 100755 addons/account_voucher/report/report_voucher.rml create mode 100755 addons/account_voucher/report/report_voucher_amount.py create mode 100755 addons/account_voucher/report/report_voucher_amount.rml create mode 100755 addons/account_voucher/report/tax_report.py create mode 100755 addons/account_voucher/report/tax_report.rml create mode 100755 addons/account_voucher/voucher.py create mode 100644 addons/account_voucher/voucher_account.py create mode 100755 addons/account_voucher/voucher_view.xml create mode 100644 addons/account_voucher/wizard/__init__.py create mode 100644 addons/account_voucher/wizard/open_voucher.py diff --git a/addons/account_voucher/__init__.py b/addons/account_voucher/__init__.py new file mode 100755 index 00000000000..71118c9f783 --- /dev/null +++ b/addons/account_voucher/__init__.py @@ -0,0 +1,3 @@ +import voucher +import voucher_account +import report \ No newline at end of file diff --git a/addons/account_voucher/__terp__.py b/addons/account_voucher/__terp__.py new file mode 100755 index 00000000000..97105b77379 --- /dev/null +++ b/addons/account_voucher/__terp__.py @@ -0,0 +1,33 @@ +{ + "name" : "India Accounting", + "version" : "1.0", + "author" : "Tiny", + "description": """ + India Accounting module includes all the basic requirenment of + Basic Accounting, plus new things which available are + * Indian Account Chart + * New Invoice - (Local, Retail) + * Invoice Report + * Tax structure + * Journals + * VAT Declaration report + * Accounting Periods + """, + "category" : "Generic Modules/Accounting", + "website" : "http://tinyerp.com", + "depends" : ["base", "account"], + "init_xml" : [ + ], + + "demo_xml" : [ + ], + + "update_xml" : [ + "account_voucher_sequence.xml", + "account_view.xml", + "account_report.xml", + "voucher_view.xml", + ], + "active": False, + "installable": True +} \ No newline at end of file diff --git a/addons/account_voucher/account_report.xml b/addons/account_voucher/account_report.xml new file mode 100755 index 00000000000..caaf5867c0f --- /dev/null +++ b/addons/account_voucher/account_report.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/addons/account_voucher/account_view.xml b/addons/account_voucher/account_view.xml new file mode 100755 index 00000000000..572a0d34095 --- /dev/null +++ b/addons/account_voucher/account_view.xml @@ -0,0 +1,57 @@ + + + + + + account.form + + account.account + form + + + + + + + + + + + + account.form + + account.account + form + + + + + + + + account.form + + account.account + form + + + + + + + + + account.form + + account.account + form + + + + + + + + + + \ No newline at end of file diff --git a/addons/account_voucher/account_voucher_sequence.xml b/addons/account_voucher/account_voucher_sequence.xml new file mode 100644 index 00000000000..70e804de8c6 --- /dev/null +++ b/addons/account_voucher/account_voucher_sequence.xml @@ -0,0 +1,110 @@ + + + + + + Voucher + account.voucher + + + + + Account Cash Received Voucher + account.voucher.rec_voucher + + + + Account Cash Payble Voucher + account.voucher.pay_voucher + + + Account Bank Received Voucher + account.voucher.bank_rec_voucher + + + Account Bank Payble Voucher + account.voucher.bank_pay_voucher + + + Account Contra Voucher + account.voucher.cont_voucher + + + Account Journal Voucher + account.voucher.journal_sale_vou + + + Account Journal Voucher + account.voucher.journal_pur_vou + + + + + Account Cash Received Voucher + account.voucher.rec_voucher + + %(year)s/ + + + + Account Cash Payble Voucher + account.voucher.pay_voucher + + %(year)s/ + + + Account Bank Received Voucher + account.voucher.bank_rec_voucher + + %(year)s/ + + + Account Bank Payble Voucher + account.voucher.bank_pay_voucher + + %(year)s/ + + + Account Contra Voucher + account.voucher.cont_voucher + + %(year)s/ + + + Account Journal Voucher + account.voucher.journal_sale_vou + + %(year)s/ + + + Account Journal Voucher + account.voucher.journal_pur_vou + + %(year)s/ + + + + + + diff --git a/addons/account_voucher/account_voucher_wizard.xml b/addons/account_voucher/account_voucher_wizard.xml new file mode 100644 index 00000000000..ffe7b25c87c --- /dev/null +++ b/addons/account_voucher/account_voucher_wizard.xml @@ -0,0 +1,20 @@ + + + + + + + + \ No newline at end of file diff --git a/addons/account_voucher/account_voucher_workflow.xml b/addons/account_voucher/account_voucher_workflow.xml new file mode 100644 index 00000000000..0299c79997d --- /dev/null +++ b/addons/account_voucher/account_voucher_workflow.xml @@ -0,0 +1,75 @@ + + + + + + account.voucher.basic + account.voucher + True + + + + + True + draft + + + + + performa + open_voucher() + function + + + + + posted + proforma_voucher() + True + function + + + + + cancel + cancel_voucher() + function + + + + + + open_voucher + + + + + + proforma_voucher + + + + + + cancel_voucher + + + + + + cancel_voucher + + + + + + cancel_voucher + + + + + + open_voucher + + + \ No newline at end of file diff --git a/addons/account_voucher/report/__init__.py b/addons/account_voucher/report/__init__.py new file mode 100755 index 00000000000..0fc72ca5647 --- /dev/null +++ b/addons/account_voucher/report/__init__.py @@ -0,0 +1,4 @@ +import invoice +import tax_report +import report_voucher +import report_voucher_amount \ No newline at end of file diff --git a/addons/account_voucher/report/invoice.py b/addons/account_voucher/report/invoice.py new file mode 100755 index 00000000000..e041761bee6 --- /dev/null +++ b/addons/account_voucher/report/invoice.py @@ -0,0 +1,50 @@ +############################################################################## +# +# Copyright (c) 2005-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 + +class account_invoice_tax_retail(report_sxw.rml_parse): + def __init__(self, cr, uid, name, context): + super(account_invoice_tax_retail, self).__init__(cr, uid, name, context) + self.localcontext.update({ + 'time': time, + 'title': self.getTitle, + }) + + def getTitle(self, invoice): + title = ''; + if invoice.retail_tax: + title = invoice.retail_tax[0].swapcase() + invoice.retail_tax[1:] + return title; + +report_sxw.report_sxw( + 'report.tax.retail.account.invoice', + 'account.invoice', + 'addons/india/account/report/invoice.rml', + parser=account_invoice_tax_retail, +) \ No newline at end of file diff --git a/addons/account_voucher/report/invoice.rml b/addons/account_voucher/report/invoice.rml new file mode 100755 index 00000000000..7fce0318d09 --- /dev/null +++ b/addons/account_voucher/report/invoice.rml @@ -0,0 +1,268 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[ repeatIn(objects,'o') ]] + [[ setLang(o.partner_id.lang) ]] + Subject to Ahmedabad jurisdiction + + + + M/S. + [[ o.partner_id.title or '' ]][[ o.partner_id.name ]] + [[ o.address_invoice_id.title or '' ]] [[ o.address_invoice_id.name ]] + [[ o.address_invoice_id.street ]] + [[ o.address_invoice_id.street2 or '' ]] + [[ o.address_invoice_id.zip or '' ]] [[ o.address_invoice_id.city or '' ]] + [[ o.address_invoice_id.state_id and o.address_invoice_id.state_id.name or '' ]] + [[ o.address_invoice_id.country_id and o.address_invoice_id.country_id.name or '' ]] + + + + Tel. : [[ o.address_invoice_id.phone or removeParentNode('para') ]] + Fax : [[ o.address_invoice_id.fax or removeParentNode('para') ]] + VAT : [[ o.partner_id.vat or removeParentNode('para') ]] + + + + + + + + + + + + [[ title(o)]] Invoice [[ ((o.type == 'out_invoice' and (o.state == 'open' or o.state == 'paid')) or removeParentNode('para')) and '' ]] [[ o.number ]] + [[ title(o)]] PRO-FORMA [[ ((o.type == 'out_invoice' and o.state == 'proforma') or removeParentNode('para')) and '' ]] + Draft Invoice [[ ((o.type == 'out_invoice' and o.state == 'draft') or removeParentNode('para')) and '' ]] + [[ title(o)]] Canceled Invoice [[ ((o.type == 'out_invoice' and o.state == 'cancel') or removeParentNode('para')) and '' ]] + [[ title(o)]] Refund [[ (o.type=='out_refund' or removeParentNode('para')) and '' ]] [[ o.number ]] + [[ title(o)]] Supplier Refund [[ (o.type=='in_refund' or removeParentNode('para')) and '' ]] [[ o.number ]] + + [[ title(o)]] Supplier Invoice [[ (o.type=='in_invoice' or removeParentNode('para')) and '' ]] + [[ o.number ]] + + + + + + Document + : + [[o.name]] + + + Invoice Date: + [[o.date_invoice]] + + Customer Ref: [[ o.address_invoice_id.partner_id.ref or '/' ]] + + + + + + + Description + + + Quantity + + + Unit Price + + + Disc. (%) + + + Price + + + +
+ [[repeatIn(o.invoice_line,'l') ]] + + + + [[ l.name ]] + + + [[ formatLang(l.quantity) ]] [[l.uos_id and l.uos_id.name or '' ]] + + + [[ formatLang(l.price_unit) ]] + + + [[ l.discount and formatLang (l.discount) or '' ]] + + + [[ formatLang(l.price_subtotal) ]] [[o.currency_id.code ]] + + + + + + + [[ repeatIn((l.note and l.note.splitlines()) or [], 'note') ]] + + + + + + [[ note or removeParentNode('table') ]] + + + +
+ + + + + + + Tax + + + Base + + + Amount + + + + + [[ repeatIn(o.tax_line,'t') ]] [[ t.name ]] + + + [[ formatLang(t.base) ]] + + + [[ formatLang(t.amount)]] + + + + + + + + + Total (excl. taxes): + + + [[ formatLang(o.amount_untaxed) ]] [[o.currency_id.code ]] + + + + + Taxes: + + + [[ formatLang(o.amount_tax) ]] [[o.currency_id.code ]] + + + + + Total (incl. taxes): + + + [[ formatLang(o.amount_total) ]] [[o.currency_id.code ]] + + + + + + + + + + [[ format(o.comment or '') ]] + + + + [[ format((o.payment_term and o.payment_term.note) or '') ]] +
+
+ diff --git a/addons/account_voucher/report/report_voucher.py b/addons/account_voucher/report/report_voucher.py new file mode 100755 index 00000000000..b3e3c686f58 --- /dev/null +++ b/addons/account_voucher/report/report_voucher.py @@ -0,0 +1,72 @@ +############################################################################## +# +# Copyright (c) 2005-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 tools import amount_to_text_en + + +class report_voucher(report_sxw.rml_parse): + def __init__(self, cr, uid, name, context): + super(report_voucher, self).__init__(cr, uid, name, context) + self.localcontext.update({ + 'time': time, + 'convert':self.convert, + 'debit':self.debit, + 'credit':self.credit, + 'get_ref' : self._get_ref + }) + + def convert(self,amount, cur): + amt_en = amount_to_text_en.amount_to_text(amount,'en',cur); + return amt_en + + def debit(self, move_ids): + debit = 0.0 + for move in move_ids:#self.pool.get('account.move.line').browse(self.cr, self.uid, move_ids): + debit +=move.debit + return debit + + def credit(self, move_ids): + credit = 0.0 + for move in move_ids:#self.pool.get('account.move.line').browse(self.cr, self.uid, move_ids): + credit +=move.credit + return credit + + def _get_ref(self, voucher_id, move_ids): + voucher_line = self.pool.get('account.voucher.line').search(self.cr, self.uid, [('partner_id','=',move_ids.partner_id.id), ('voucher_id','=',voucher_id)]) + if voucher_line: + voucher = self.pool.get('account.voucher.line').browse(self.cr, self.uid, voucher_line)[0] + return voucher.ref + else: + return +report_sxw.report_sxw( + 'report.voucher.cash_receipt', + 'account.voucher', + 'addons/account_voucher/report/report_voucher.rml', + parser=report_voucher,header=False +) \ No newline at end of file diff --git a/addons/account_voucher/report/report_voucher.rml b/addons/account_voucher/report/report_voucher.rml new file mode 100755 index 00000000000..685983045ae --- /dev/null +++ b/addons/account_voucher/report/report_voucher.rml @@ -0,0 +1,381 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[ repeatIn(objects,'voucher') ]] + [[ company.name ]] + [[ company.partner_id.address and company.partner_id.address[0].street ]] + [[ company.partner_id.address and company.partner_id.address[0].zip ]] [[ company.partner_id.address and company.partner_id.address[0].city ]] - [[ company.partner_id.address and company.partner_id.address[0].country_id and company.partner_id.address[0].country_id.name ]] + [[ company.partner_id.address and company.partner_id.address[0].phone ]] + [[ company.partner_id.address and company.partner_id.address[0].email ]] + + + + Cash Receipt Voucher [[ (voucher.type == 'rec_voucher' or removeParentNode('para')) and '' ]] + Cash Payment Voucher [[ (voucher.type == 'pay_voucher' or removeParentNode('para')) and '' ]] + Bank Receipt Voucher [[ (voucher.type == 'bank_rec_voucher' or removeParentNode('para')) and '' ]] + Bank Payment Voucher [[ (voucher.type == 'bank_pay_voucher' or removeParentNode('para')) and '' ]] + + + + + + + No. + + + [[ voucher.number ]] + + + + + + + + Dated : + + + [[ time.strftime('%d %B,%Y', time.strptime(voucher.date , '%Y-%m-%d')) or '' ]] + + + + + State : + + + PRO-FORMA [[ ((voucher.state == 'proforma') or removeParentNode('para')) and '' ]] + Draft[[ ((voucher.state == 'draft') or removeParentNode('para')) and '' ]] + Canceled [[ ((voucher.state == 'cancel') or removeParentNode('para')) and '' ]] + Posted [[ ((voucher.state == 'posted') or removeParentNode('para')) and '' ]] + + + + + + + + Ref. : + + + [[ voucher.reference ]] + + + + + + + + + + + + + Particulars + + + Debit + + + Credit + + + + + + + + [[ repeatIn(voucher.move_ids,'move_ids') ]] + + + + [[ (move_ids.partner_id and move_ids.partner_id.name) or '']] : + [[ move_ids.account_id.name ]] + [[ get_ref(voucher.id,move_ids) ]] + + + [[ move_ids.debit ]] + + + [[ move_ids.credit ]] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Through : + + + + + + + + + + + + + + + [[ voucher.narration or '']] + + + + + + + + + + + + + + + On Account of : + + + + + + + + + + + + + + + [[ voucher.name ]] + + + + + + + + + + + + + + + Amount (in words) : + + + + + + + + + + + + + + + [[ convert(voucher.amount,voucher.currency_id.name) ]] + + + + + + + + + + + + + + + + + + + + [[ debit(voucher.move_ids)]] + + + [[ credit(voucher.move_ids) ]] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Receiver's Signature + + + + + + + + + + + + + Authorised Signatory + + + + + + + + diff --git a/addons/account_voucher/report/report_voucher_amount.py b/addons/account_voucher/report/report_voucher_amount.py new file mode 100755 index 00000000000..3b67ff7a9ac --- /dev/null +++ b/addons/account_voucher/report/report_voucher_amount.py @@ -0,0 +1,51 @@ +############################################################################## +# +# Copyright (c) 2005-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 tools import amount_to_text_en + + +class report_voucher_amount(report_sxw.rml_parse): + def __init__(self, cr, uid, name, context): + super(report_voucher_amount, self).__init__(cr, uid, name, context) + self.localcontext.update({ + 'time': time, + 'convert':self.convert + }) + + def convert(self,amount, cur): + amt_en = amount_to_text_en.amount_to_text(amount,'en',cur); + return amt_en + + +report_sxw.report_sxw( + 'report.voucher.cash_amount', + 'account.voucher', + 'addons/account_voucher/report/report_voucher_amount.rml', + parser=report_voucher_amount,header=False +) \ No newline at end of file diff --git a/addons/account_voucher/report/report_voucher_amount.rml b/addons/account_voucher/report/report_voucher_amount.rml new file mode 100755 index 00000000000..8adec4c6712 --- /dev/null +++ b/addons/account_voucher/report/report_voucher_amount.rml @@ -0,0 +1,353 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[ repeatIn(objects,'voucher') ]] + [[ company.name ]] + [[ company.partner_id.address and company.partner_id.address[0].street ]] + [[ company.partner_id.address and company.partner_id.address[0].zip ]] [[ company.partner_id.address and company.partner_id.address[0].city ]] - [[ company.partner_id.address and company.partner_id.address[0].country_id and company.partner_id.address[0].country_id.name ]] + [[ company.partner_id.address and company.partner_id.address[0].phone ]] + [[ company.partner_id.address and company.partner_id.address[0].email ]] + + + + Cash Receipt Voucher [[ (voucher.type == 'rec_voucher' or removeParentNode('para')) and '' ]] + Cash Payment Voucher [[ (voucher.type == 'pay_voucher' or removeParentNode('para')) and '' ]] + Bank Receipt Voucher [[ (voucher.type == 'bank_rec_voucher' or removeParentNode('para')) and '' ]] + Bank Payment Voucher [[ (voucher.type == 'bank_pay_voucher' or removeParentNode('para')) and '' ]] + + + + + + + No. + + + [[ voucher.number ]] + + + + + + + + Dated : + + + [[ time.strftime('%d %B,%Y', time.strptime(voucher.date , '%Y-%m-%d')) or '' ]] + + + + + State : + + + PRO-FORMA [[ ((voucher.state == 'proforma') or removeParentNode('para')) and '' ]] + Draft[[ ((voucher.state == 'draft') or removeParentNode('para')) and '' ]] + Canceled [[ ((voucher.state == 'cancel') or removeParentNode('para')) and '' ]] + Posted [[ ((voucher.state == 'posted') or removeParentNode('para')) and '' ]] + + + + + + + + Ref. : + + + [[ voucher.reference ]] + + + + + Account : + + + [[ voucher.account_id.name ]] + + + + + + + + + + + + + + + + + + + + + + + + + + Particulars + + + Amount + + + + + + + + + + [[ repeatIn(voucher.payment_ids,'payment_ids') ]] + + + + [[ payment_ids.partner_id.name ]] : + [[ payment_ids.account_id.name ]] + [[ payment_ids.ref ]] [[ payment_ids.amount ]] [[ payment_ids.type ]] + + + [[ payment_ids.amount ]] + + + + + + + + + + + + + + + + + + + + + + + + + Through : + + + + + + + + + + [[ voucher.narration or '' ]] + + + + + + + + + + On Account of : + + + + + + + + + + [[ voucher.name ]] + + + + + + + + + + Amount (in words) : + + + + + + + + + + [[ convert(voucher.amount,voucher.currency_id.name) ]] + + + + + + + + + + + + + + + [[ voucher.amount ]] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Receiver's Signature + + + + + + + + + + + + + Authorised Signatory + + + + + + + + diff --git a/addons/account_voucher/report/tax_report.py b/addons/account_voucher/report/tax_report.py new file mode 100755 index 00000000000..7a898753237 --- /dev/null +++ b/addons/account_voucher/report/tax_report.py @@ -0,0 +1,185 @@ +############################################################################## +# +# Copyright (c) 2005-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 +import pooler +from report import report_sxw + +class account_tax_report(report_sxw.rml_parse): + def __init__(self, cr, uid, name, context): + super(account_tax_report, self).__init__(cr, uid, name, context) + self.localcontext.update({ + 'get_invoice': self.getInvoices, + 'add_invoice': self.addInvoice, + 'get_tax': self.getTax, + 'get_tax_detail' : self.getTaxDetail, + 'get_retail' : self.getRetailTax, + 'get_retail_detail' : self.getRetailTaxDetail, + 'get_local_sale' : self.getLocalSale, + 'get_retail_sale' : self.getRetailSale, + 'total_local_sale' : self.getTotalLocalSale, + 'total_local_tax' : self.getTotalLocalTax, + 'total_retail_sale' : self.getTotalRetailSale, + 'total_retail_tax' : self.getTotalRetailTax, + 'time': time, + 'get_period': self.getPeriod, + 'test' : self.testMethod, + + }) + self.local = 0 + self. retail = 0 + + self.tax_tax = {} + self.retail_tax = {} + + self.sale_tax = {} + self.sale_retail = {} + + self.total_local_sale = 0 + self.total_local_tax = 0 + + self.total_retail_sale = 0 + self.total_retail_tax = 0 + + self.invoices = [] + self.flag = False + #end def + + def getPeriod(self, period_id): + return self.pool.get('account.period').browse(self.cr, self.uid, period_id).name + #end def + + def testMethod(self, obj): + print type(obj) == type({}), obj; + if type(obj) == type({}) and not self.flag: + if obj.has_key('form'): + self.flag = True + ids = self.pool.get('account.move.line').search(self.cr, self.uid, [('period_id','=',obj['form']['period_id'])]) + account = self.pool.get('account.move.line').read(self.cr, self.uid,ids,['invoice']) + invoice_ids = [] + for i in account: + if i['invoice'][0]: + if not i['invoice'][0] in invoice_ids: + inv = self.pool.get('account.invoice').browse(self.cr, self.uid,i['invoice'][0]) + if inv.type == 'out_invoice' and inv.state == 'open': + if not i['invoice'][0] in self.invoices: + print '*********************** : ',i['invoice'][0] + self.invoices.append(i['invoice'][0]) + #end if + #end if + #end for + #end if + elif self.flag == False: + self.invoices = self.ids + #end if + #end def + + def getInvoices(self): + print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>',self.invoices; + return self.pool.get('account.invoice').browse(self.cr, self.uid, self.invoices) + #end def + + def addInvoice(self, invoice): + if invoice.retail_tax == 'tax': + self.total_local_sale += invoice.amount_untaxed + self.total_local_tax += invoice.amount_tax + + for tax in invoice.tax_line: + if self.tax_tax.has_key(tax.name): + self.tax_tax[tax.name] += tax.tax_amount + self.sale_tax[tax.name] += tax.base_amount + else: + self.tax_tax[tax.name] = tax.tax_amount + self.sale_tax[tax.name] = tax.base_amount + #end for + elif invoice.retail_tax == 'retail': + self.total_retail_sale += invoice.amount_untaxed + self.total_retail_tax += invoice.amount_tax + self. retail += invoice.amount_total + for tax in invoice.tax_line: + if self.retail_tax.has_key(tax.name): + self.retail_tax[tax.name] += tax.tax_amount + self.sale_retail[tax.name] += tax.base_amount + else: + self.retail_tax[tax.name] = tax.tax_amount + self.sale_retail[tax.name] = tax.base_amount + #end if + #end for + #endif + #end def + + def getTaxDetail(self, tax): + return self.tax_tax[tax]; + + def getTax(self): + tax = [] + for i in self.tax_tax: + tax.append(i) + return tax + #end if + + def getRetailTaxDetail(self, tax): + return self.retail_tax[tax]; + + def getRetailTax(self): + tax = [] + for i in self.retail_tax: + tax.append(i) + return tax + #end if + + def getLocalSale(self, tax): + return self.sale_tax[tax] + #end def + + def getRetailSale(self, tax): + return self.sale_retail[tax] + #end def + + def getTotalLocalSale(self): + return self.total_local_sale + #end def + + def getTotalLocalTax(self): + return self.total_local_tax + #end def + + def getTotalRetailSale(self): + return self.total_retail_sale + #end def + + def getTotalRetailTax(self): + return self.total_retail_tax + #end def +#end class + +report_sxw.report_sxw( + 'report.indianvat.declaration', + 'account.invoice', + 'addons/india/account/report/tax_report.rml', + parser=account_tax_report, +) \ No newline at end of file diff --git a/addons/account_voucher/report/tax_report.rml b/addons/account_voucher/report/tax_report.rml new file mode 100755 index 00000000000..1c7bc40450d --- /dev/null +++ b/addons/account_voucher/report/tax_report.rml @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sales Register for the Month of XXX-2007 + + + + Date : [[time.strftime('%Y-%m-%d')]] at [[ time.strftime('%H:%M:%S') ]] + [[ test(data) ]] [[ test(objects) ]] + + + + Date + + + Invoice + No + + + Party Name + + + S.T.Req No + + + Invoice Amount + + + Tax. Amount + + + + + + + + + + [[repeatIn(get_invoice(),'o') ]] + [[ o.date_invoice ]] [[ add_invoice(o) ]] + + + [[ o.number ]] + + + [[ o.partner_id.name ]] + + + [[ o.partner_id.vat]] + + + [[ o.amount_total ]] [[o.currency_id.code ]] + + + [[ o.amount_tax ]] [[o.currency_id.code ]] + + + + + + + Local Sale Report + + + + Description + + + Invoice Amount + + + Tax Amount + + + + + + + + + + [[ repeatIn(get_tax(),'t') ]] + [[ t ]] + + + [[ get_local_sale(t) ]] [[o.currency_id.code ]] + + + [[ get_tax_detail(t) ]] [[o.currency_id.code ]] + + + + + + + + + + + + TOTAL + + + [[ total_local_sale() ]] [[o.currency_id.code ]] + + + [[ total_local_tax() ]] [[o.currency_id.code ]] + + + + + + + + + + + + Retail Sale Report + + + + Description + + + Invoice Amount + + + Tax Amount + + + + + + + + + + [[ repeatIn(get_retail(),'r') ]] + [[ r ]] + + + [[ get_retail_sale(r) ]] [[o.currency_id.code ]] + + + [[ get_retail_detail(r) ]] [[o.currency_id.code ]] + + + + + + + + + + + + TOTAL + + + [[ total_retail_sale() ]] [[o.currency_id.code ]] + + + [[ total_retail_tax() ]] [[o.currency_id.code ]] + + + + + + + + + + + + For [[ company.name ]] + + + + [[ user.name ]] + + + diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py new file mode 100755 index 00000000000..d3b3343395c --- /dev/null +++ b/addons/account_voucher/voucher.py @@ -0,0 +1,537 @@ +import time +import netsvc +from osv import fields, osv +import ir +import pooler +import mx.DateTime +from mx.DateTime import RelativeDateTime + +from tools import config + + +class account_voucher(osv.osv): + def _get_period(self, cr, uid, context): + periods = self.pool.get('account.period').find(cr, uid) + if periods: + return periods[0] + else: + return False + + def _get_type(self, cr, uid, context={}): + type = context.get('type', 'rec_voucher') + return type + + def _get_reference_type(self, cursor, user, context=None): + return [('none', 'Free Reference')] + + + + def _get_journal(self, cr, uid, context): + type_inv = context.get('type', 'rec_voucher') + type2journal = {'rec_voucher': 'cash', 'bank_rec_voucher': 'cash','pay_voucher': 'cash','bank_pay_voucher': 'cash', 'cont_voucher': 'cash','journal_sale_voucher': 'sale','journal_pur_voucher': 'purchase' } + journal_obj = self.pool.get('account.journal') + res = journal_obj.search(cr, uid, [('type', '=', type2journal.get(type_inv, 'cash'))], limit=1) + if res: + return res[0] + else: + return False + + def _get_currency(self, cr, uid, context): + user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, [uid])[0] + if user.company_id: + return user.company_id.currency_id.id + else: + return pooler.get_pool(cr.dbname).get('res.currency').search(cr, uid, [('rate','=',1.0)])[0] + + _name = 'account.voucher' + _description = 'Accounting Voucher' + _order = "number" + _columns = { + 'name':fields.char('Name', size=256, required=True, readonly=True, states={'draft':[('readonly',False)]}), + 'type': fields.selection([ + ('pay_voucher','Cash Payment Voucher'), + ('bank_pay_voucher','Bank Payment Voucher'), + ('rec_voucher','Cash Receipt Voucher'), + ('bank_rec_voucher','Bank Receipt Voucher'), + ('cont_voucher','Contra Voucher'), + ('journal_sale_vou','Journal Sale Voucher'), + ('journal_pur_voucher','Journal Purchase Voucher'), + ],'Type', readonly=True, select=True), + 'date':fields.date('Date', readonly=True, states={'draft':[('readonly',False)]}), + 'journal_id':fields.many2one('account.journal', 'Journal', required=True, readonly=True, states={'draft':[('readonly',False)]}), + 'account_id':fields.many2one('account.account', 'Account', required=True, readonly=True, states={'draft':[('readonly',False)]}), + 'payment_ids':fields.one2many('account.voucher.line','voucher_id','Voucher Lines', readonly=False, states={'proforma':[('readonly',True)]}), + 'period_id': fields.many2one('account.period', 'Period', required=True, states={'posted':[('readonly',True)]}), + 'narration':fields.text('Narration', readonly=True, states={'draft':[('readonly',False)]}), + 'currency_id': fields.many2one('res.currency', 'Currency', required=True, readonly=True, states={'draft':[('readonly',False)]}), + 'company_id': fields.many2one('res.company', 'Company', required=True), + 'state':fields.selection( + [('draft','Draft'), + ('proforma','Pro-forma'), + ('posted','Posted'), + ('cancel','Cancel') + ], 'State', + readonly=True), + 'amount':fields.float('Amount', readonly=True), +# , states={'draft':[('readonly',False)]} + 'number':fields.char('Number', size=32, readonly=True), + 'reference': fields.char('Voucher Reference', size=64), + 'reference_type': fields.selection(_get_reference_type, 'Reference Type', + required=True), + 'move_id':fields.many2one('account.move', 'Account Entry'), + 'move_ids':fields.many2many('account.move.line', 'voucher_id', 'account_id', 'rel_account_move', 'Real Entry'), + } + +# def get_bank(self, cr, uid, context={}): +# type = context.get('type', 'bank_payment') +# journal = self.pool.get('account.journal') +# if type == 'bank_payment': +# id = journal.search(cr, uid, [('name','ilike','Bank')]) +# return id +# elif type == 'cash_payment': +# id = journal.search(cr, uid, [('name','ilike','Cash')]) +# return id +# +# return 3 + + _defaults = { + #'journal_id':get_bank, + 'state': lambda *a: 'draft', + 'date' : lambda *a: time.strftime('%Y-%m-%d'), + 'period_id': _get_period, + 'type': _get_type, + 'reference_type': lambda *a: 'none', + 'journal_id':_get_journal, + 'company_id': lambda self, cr, uid, context: \ + self.pool.get('res.users').browse(cr, uid, uid, + context=context).company_id.id, + 'currency_id': _get_currency, + + + } + + def _get_analityc_lines(self, cr, uid, id): + inv = self.browse(cr, uid, [id])[0] + cur_obj = self.pool.get('res.currency') + + def onchange_account(self, cr, uid, ids, account_id): + if not account_id: + return {'value':{'amount':False}} + account = self.pool.get('account.account').browse(cr,uid,account_id) + balance=account.balance + return {'value':{'amount':balance}} + + + def onchange_journal(self, cr, uid, ids, journal_id,type): + if not journal_id: + return {'value':{'account_id':False}} + journal = self.pool.get('account.journal') + if journal_id and (type in ('rec_voucher','bank_rec_voucher','journal_pur_voucher')): + account_id = journal.browse(cr, uid, journal_id).default_debit_account_id + return {'value':{'account_id':account_id.id}} + elif journal_id and (type in ('pay_voucher','bank_pay_voucher','journal_sale_vou')) : + account_id = journal.browse(cr, uid, journal_id).default_credit_account_id + return {'value':{'account_id':account_id.id}} + else: + account_id = journal.browse(cr, uid, journal_id).default_credit_account_id + return {'value':{'account_id':account_id.id}} + + + + + def open_voucher(self, cr, uid, ids, context={}): + obj=self.pool.get('account.voucher').browse(cr,uid,ids) + total=0 + for i in obj[0].payment_ids: + total+=i.amount + self.write(cr,uid,ids,{'amount':total}) + self.write(cr, uid, ids, {'state':'proforma'}) + return True + def proforma_voucher(self, cr, uid, ids, context={}): + self.action_move_line_create(cr, uid, ids) + self.action_number(cr, uid, ids) + self.write(cr, uid, ids, {'state':'posted'}) + return True + def cancel_voucher(self,cr,uid,ids,context={}): + self.action_cancel(cr, uid, ids) + self.write(cr, uid, ids, {'state':'cancel'}) + return True + + def action_cancel_draft(self, cr, uid, ids, *args): + self.write(cr, uid, ids, {'state':'draft'}) + return True + + + def unlink(self, cr, uid, ids): + vouchers = self.read(cr, uid, ids, ['state']) + unlink_ids = [] + for t in vouchers: + if t['state'] in ('draft', 'cancel'): + unlink_ids.append(t['id']) + else: + raise osv.except_osv('Invalid action !', 'Cannot delete invoice(s) which are already opened or paid !') + osv.osv.unlink(self, cr, uid, unlink_ids) + return True + + + def _get_analityc_lines(self, cr, uid, id): + inv = self.browse(cr, uid, [id])[0] + cur_obj = self.pool.get('res.currency') + + company_currency = inv.company_id.currency_id.id + if inv.type in ('rec_voucher'): + sign = 1 + else: + sign = -1 + + iml = self.pool.get('account.voucher.line').move_line_get(cr, uid, inv.id) + + for il in iml: + if il['account_analytic_id']: + if inv.type in ('pay_voucher', 'rec_voucher','cont_voucher','bank_pay_voucher','bank_rec_voucher','journal_sale_vou','journal_pur_voucher'): + ref = inv.reference + else: + ref = self._convert_ref(cr, uid, inv.number) + il['analytic_lines'] = [(0,0, { + 'name': il['name'], + 'date': inv['date'], + 'account_id': il['account_analytic_id'], + 'amount': inv['amount'] * sign, + 'partner_id': il['partner_id'] or False, + 'general_account_id': il['account_id'] or False, + 'journal_id': self._get_journal(cr, uid, inv.type), + 'ref': ref, + })] + + return iml + + def action_move_line_create(self, cr, uid, ids, *args): + for inv in self.browse(cr, uid, ids): + if inv.move_id: + continue + company_currency = inv.company_id.currency_id.id + # create the analytical lines + line_ids = self.read(cr, uid, [inv.id], ['payment_ids'])[0]['payment_ids'] + ils = self.pool.get('account.voucher.line').read(cr, uid, line_ids) + # one move line per invoice line + iml = self._get_analityc_lines(cr, uid, inv.id) + # check if taxes are all computed + diff_currency_p = inv.currency_id.id <> company_currency + # create one move line for the total and possibly adjust the other lines amount + total = 0 + if inv.type in ('pay_voucher', 'rec_voucher','cont_voucher','bank_pay_voucher','bank_rec_voucher','journal_sale_vou','journal_pur_voucher'): + ref = inv.reference + else: + ref = self._convert_ref(cr, uid, inv.number) + date = inv.date + total_currency = 0 + for i in iml: + if inv.currency_id.id != company_currency: + i['currency_id'] = inv.currency_id.id + i['amount_currency'] = i['amount'] + + else: + i['amount_currency'] = False + i['currency_id'] = False + i['ref'] = ref + if inv.type in ('rec_voucher','bank_rec_voucher','journal_pur_voucher'): + total += i['amount'] + total_currency += i['amount_currency'] or i['amount'] + i['amount'] = - i['amount'] + else: + total -= i['amount'] + total_currency -= i['amount_currency'] or i['amount'] + acc_id = inv.account_id.id + + name = inv['name'] or '/' + totlines = False + + iml.append({ + 'type': 'dest', + 'name': name, + 'amount': total, + 'account_id': acc_id, + 'amount_currency': diff_currency_p \ + and total_currency or False, + 'currency_id': diff_currency_p \ + and inv.currency_id.id or False, + 'ref': ref + }) + + date = inv.date + inv.amount=total + + + line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x,date, context={})) ,iml) + + journal_id = inv.journal_id.id #self._get_journal(cr, uid, {'type': inv['type']}) + journal = self.pool.get('account.journal').browse(cr, uid, journal_id) + if journal.sequence_id: + name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id) + + move = {'name': name, 'line_id': line, 'journal_id': journal_id} + if inv.period_id: + move['period_id'] = inv.period_id.id + for i in line: + i[2]['period_id'] = inv.period_id.id + move_id = self.pool.get('account.move').create(cr, uid, move) + # make the invoice point to that move + self.write(cr, uid, [inv.id], {'move_id': move_id}) + obj=self.pool.get('account.move').browse(cr,uid,move_id) + for line in obj.line_id : + cr.execute('insert into voucher_id (account_id,rel_account_move) values (%d, %d)',(int(ids[0]),int(line.id))) +# self.pool.get('account.move').post(cr, uid, [move_id]) +# self._log_event(cr, uid, ids) + return True + + + + def line_get_convert(self, cr, uid, x, date, context={}): + return { + 'date':date, + 'date_maturity': x.get('date_maturity', False), + 'partner_id':x.get('partner_id',False), + 'name':x['name'][:64], + 'debit':x['amount']>0 and x['amount'], + 'credit':x['amount']<0 and -x['amount'], + 'account_id':x['account_id'], + 'analytic_lines':x.get('analytic_lines', []), + 'amount_currency':x.get('amount_currency', False), + 'currency_id':x.get('currency_id', False), + 'tax_code_id': x.get('tax_code_id', False), + 'tax_amount': x.get('tax_amount', False), + 'ref':x.get('ref',False) + } + def _convert_ref(self, cr, uid, ref): + return (ref or '').replace('/','') + + + def action_number(self, cr, uid, ids, *args): + cr.execute('SELECT id, type, number, move_id, reference ' \ + 'FROM account_voucher ' \ + 'WHERE id IN ('+','.join(map(str,ids))+')') + for (id, invtype, number, move_id, reference) in cr.fetchall(): + if not number: + number = self.pool.get('ir.sequence').get(cr, uid, + 'account.voucher.' + invtype) + + if type in ('pay_voucher', 'rec_voucher','cont_voucher','bank_pay_voucher','bank_rec_voucher','journal_sale_vou','journal_pur_voucher'): + ref = reference + else: + ref = self._convert_ref(cr, uid, number) + cr.execute('UPDATE account_voucher SET number=%s ' \ + 'WHERE id=%d', (number, id)) + cr.execute('UPDATE account_move_line SET ref=%s ' \ + 'WHERE move_id=%d AND (ref is null OR ref = \'\')', + (ref, move_id)) + cr.execute('UPDATE account_analytic_line SET ref=%s ' \ + 'FROM account_move_line ' \ + 'WHERE account_move_line.move_id = %d ' \ + 'AND account_analytic_line.move_id = account_move_line.id', + (ref, move_id)) + return True + + + + def name_get(self, cr, uid, ids, context={}): + if not len(ids): + return [] + types = { + 'pay_voucher': 'CPV: ', + 'rec_voucher': 'CRV: ', + 'cont_voucher': 'CV: ', + 'bank_pay_voucher': 'BPV: ', + 'bank_rec_voucher': 'BRV: ', + 'journal_sale_vou': 'JSV: ', + 'journal_pur_voucher': 'JPV: ', + + } + return [(r['id'], types[r['type']]+(r['number'] or '')+' '+(r['name'] or '')) for r in self.read(cr, uid, ids, ['type', 'number', 'name'], context, load='_classic_write')] + + def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80): + if not args: + args=[] + if not context: + context={} + ids = [] + if name: + ids = self.search(cr, user, [('number','=',name)]+ args, limit=limit, context=context) + if not ids: + ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context) + return self.name_get(cr, user, ids, context) + + def copy(self, cr, uid, id, default=None, context=None): + if default is None: + default = {} + default = default.copy() + default.update({'state':'draft', 'number':False, 'move_id':False, 'move_ids':False}) + if 'date' not in default: + default['date'] = time.strftime('%Y-%m-%d') + return super(account_voucher, self).copy(cr, uid, id, default, context) + + def action_cancel(self, cr, uid, ids, *args): + account_move_obj = self.pool.get('account.move') + voucher = self.read(cr, uid, ids, ['move_id']) + for i in voucher: + if i['move_id']: + account_move_obj.button_cancel(cr, uid, [i['move_id'][0]]) + # delete the move this invoice was pointing to + # Note that the corresponding move_lines and move_reconciles + # will be automatically deleted too + account_move_obj.unlink(cr, uid, [i['move_id'][0]]) + self.write(cr, uid, ids, {'state':'cancel', 'move_id':False}) +# self._log_event(cr, uid, ids,-1.0, 'Cancel Invoice') + return True + +account_voucher() + +class VoucherLine(osv.osv): + _name = 'account.voucher.line' + _description = 'Voucher Line' + _columns = { + 'voucher_id':fields.many2one('account.voucher', 'Voucher'), + 'name':fields.char('Description', size=256, required=True), + 'account_id':fields.many2one('account.account','Account', required=True), + 'partner_id': fields.many2one('res.partner', 'Partner', change_default=True, required=True, ), + 'amount':fields.float('Amount'), + 'type':fields.selection([('dr','Debit'),('cr','Credit')], 'Type'), + 'ref':fields.char('Ref.', size=32), + 'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account') + } + _defaults = { + 'type': lambda *a: 'cr' + } + def move_line_get(self, cr, uid, voucher_id, context={}): + res = [] + + cur_obj = self.pool.get('res.currency') + inv = self.pool.get('account.voucher').browse(cr, uid, voucher_id) + company_currency = inv.company_id.currency_id.id + cur = inv.currency_id + + for line in inv.payment_ids: + res.append(self.move_line_get_item(cr, uid, line, context)) + return res + + def onchange_partner(self, cr, uid, ids, partner_id, type,type1): + if not partner_id: + return {'value' : {'account_id' : False, 'type' : False ,'amount':False}} + obj = self.pool.get('res.partner') + account_id = False + + if type1 in ('rec_voucher','bank_rec_voucher'): + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + balance=obj.browse(cr,uid,partner_id).credit + type = 'cr' + elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : + account_id = obj.browse(cr, uid, partner_id).property_account_payable + balance=obj.browse(cr,uid,partner_id).debit + type = 'dr' + elif type1 in ('journal_sale_vou') : + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + balance=obj.browse(cr,uid,partner_id).credit + type = 'dr' + + elif type1 in ('journal_pur_vou') : + account_id = obj.browse(cr, uid, partner_id).property_account_payable + balance=obj.browse(cr,uid,partner_id).debit + type = 'cr' + + return { + 'value' : {'account_id' : account_id.id, 'type' : type, 'amount':balance} + } + + def onchange_amount(self, cr, uid, ids,partner_id,amount, type,type1): + if not amount: + return {'value' : {'type' : False}} + obj = self.pool.get('res.partner') + if type1 in ('rec_voucher','bank_rec_voucher'): + if amount < 0 : + account_id = obj.browse(cr, uid, partner_id).property_account_payable + type = 'dr' + else: + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + type = 'cr' + + elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : + if amount < 0 : + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + type = 'cr' + else: + account_id = obj.browse(cr, uid, partner_id).property_account_payable + type = 'dr' + + elif type1 in ('journal_sale_vou') : + if amount < 0 : + account_id = obj.browse(cr, uid, partner_id).property_account_payable + type = 'cr' + else: + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + type = 'dr' + + elif type1 in ('journal_pur_vou') : + if amount< 0 : + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + type = 'dr' + else: + account_id = obj.browse(cr, uid, partner_id).property_account_payable + type = 'cr' + + return { + 'value' : { 'type' : type , 'amount':amount} + } + + + def onchange_type(self, cr, uid, ids,partner_id,amount,type,type1): + if not partner_id: + return {'value' : {'type' : False}} + obj = self.pool.get('res.partner') + + if type1 in ('rec_voucher','bank_rec_voucher'): + if type == 'dr' : + account_id = obj.browse(cr, uid, partner_id).property_account_payable + total=amount*(-1) + else: + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + total=amount*1 + + elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : + if type == 'cr' : + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + amount*=-1 + else: + account_id = obj.browse(cr, uid, partner_id).property_account_payable + amount*=1 + + elif type1 in ('journal_sale_vou') : + if type == 'cr' : + account_id = obj.browse(cr, uid, partner_id).property_account_payable + amount*=-1 + else: + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + amount*=1 + + elif type1 in ('journal_pur_vou') : + if type == 'dr' : + account_id = obj.browse(cr, uid, partner_id).property_account_receivable + amount*=-1 + else: + account_id = obj.browse(cr, uid, partner_id).property_account_payable + amount*=1 + + return { + 'value' : {'type' : type , 'amount':total} + } + + + def move_line_get_item(self, cr, uid, line, context={}): + return { + 'type':'src', + 'name': line.name[:64], + 'amount':line.amount, + 'account_id':line.account_id.id, + 'partner_id':line.partner_id.id or False , + 'account_analytic_id':line.account_analytic_id.id or False, + } +VoucherLine() + diff --git a/addons/account_voucher/voucher_account.py b/addons/account_voucher/voucher_account.py new file mode 100644 index 00000000000..928a546145d --- /dev/null +++ b/addons/account_voucher/voucher_account.py @@ -0,0 +1,125 @@ +import time +import netsvc +from osv import fields, osv +import ir +import pooler +import mx.DateTime +from mx.DateTime import RelativeDateTime + +from tools import config + +class Account(osv.osv): + _inherit = "account.account" + + def __compute(self, cr, uid, ids, field_names, arg, context={}, query=''): + #compute the balance/debit/credit accordingly to the value of field_name for the given account ids + mapping = { + 'balance': "COALESCE(SUM(l.debit) - SUM(l.credit) , 0) as balance ", + 'debit': "COALESCE(SUM(l.debit), 0) as debit ", + 'credit': "COALESCE(SUM(l.credit), 0) as credit " + } + #get all the necessary accounts + ids2 = self._get_children_and_consol(cr, uid, ids, context) + acc_set = ",".join(map(str, ids2)) + #compute for each account the balance/debit/credit from the move lines + accounts = {} + if ids2: + query = self.pool.get('account.move.line')._query_get(cr, uid, + context=context) + cr.execute(("SELECT l.account_id as id, " +\ + ' , '.join(map(lambda x: mapping[x], field_names)) + + "FROM " \ + "account_move_line l " \ + "WHERE " \ + "l.account_id IN (%s) " \ + "AND " + query + " " \ + "GROUP BY l.account_id") % (acc_set, )) + + for res in cr.dictfetchall(): + accounts[res['id']] = res + + #for the asked accounts, get from the dictionnary 'accounts' the value of it + res = {} + for id in ids: + res[id] = self._get_account_values(cr, uid, id, accounts, field_names, context) + for id in ids: + open=self.browse(cr, uid, id, context) + type_id=open.user_type + obj=self.pool.get('account.account.type').browse(cr,uid,type_id.id) + open_balance=open.open_bal + if obj.code in ('cash','asset','expense'): + res[id]['balance']+=open_balance + elif obj.code in ('equity','income','liability'): + total=open_balance*(-1) + res[id]['balance']+=total + else: + res[id]=res[id] + return res + + def _get_account_values(self, cr, uid, id, accounts, field_names, context={}): + res = {}.fromkeys(field_names, 0.0) + browse_rec = self.browse(cr, uid, id) + if browse_rec.type == 'consolidation': + ids2 = self.read(cr, uid, [browse_rec.id], ['child_consol_ids'], context)[0]['child_consol_ids'] + for t in self.search(cr, uid, [('parent_id', 'child_of', [browse_rec.id])]): + if t not in ids2 and t != browse_rec.id: + ids2.append(t) + for i in ids2: + tmp = self._get_account_values(cr, uid, i, accounts, field_names, context) + for a in field_names: + res[a] += tmp[a] + else: + ids2 = self.search(cr, uid, [('parent_id', 'child_of', [browse_rec.id])]) + for i in ids2: + for a in field_names: + res[a] += accounts.get(i, {}).get(a, 0.0) + return res + + def _diff(self, cr, uid, ids, field_name, arg, context={}): + + res={} + dr_total=0.0 + cr_total=0.0 + difference=0.0 + for id in ids: + open=self.browse(cr, uid, id, context) + if open.type1 == 'dr': + dr_total+=open.open_bal + elif open.type1 == 'cr': + cr_total+=open.open_bal + else: + difference=0.0 + difference=dr_total-cr_total + for id in ids: + res[id]=difference + return res + + _columns = { + 'open_bal' : fields.float('Opening Balance',digits=(16,2)), + 'diff' : fields.function(_diff, digits=(16,2),method=True,string='Difference of Opening Bal.'), + 'type1':fields.selection([('dr','Debit'),('cr','Credit'),('none','None')], 'Dr/Cr',store=True), + 'balance': fields.function(__compute, digits=(16,2), method=True, string='Closing Balance', multi='balance'), + 'credit': fields.function(__compute, digits=(16,2), method=True, string='Credit', multi='balance'), + 'debit': fields.function(__compute, digits=(16,2), method=True, string='Debit', multi='balance'), + + + } + + + def onchange_type(self, cr, uid, ids,user_type,type1): + obj=self.pool.get('account.account.type').browse(cr,uid,user_type) + account_type=obj.code + if not account_type: + return {'value' : {}} + if account_type in ('cash','asset','expense'): + type1 = 'dr' + elif account_type in ('equity','income','liability') : + type1 = 'cr' + else: + type1 = 'none' + + return { + 'value' : {'type1' : type1} + } + +Account() diff --git a/addons/account_voucher/voucher_view.xml b/addons/account_voucher/voucher_view.xml new file mode 100755 index 00000000000..5b625f1c267 --- /dev/null +++ b/addons/account_voucher/voucher_view.xml @@ -0,0 +1,295 @@ + + + + + account.voucher.tree + account.voucher + tree + + + + + + + + + + + + + + account.voucher.form + account.voucher + form + +
+ + + + + + + + + + + + + + + + + + + + + + + +