Browse Source

Merge branch '7.0' into 8.0 and updated QA files

pull/20/head
Alexandre Fayolle 10 years ago
parent
commit
5dfe659c7a
  1. 18
      .coveragerc
  2. 56
      .gitignore
  3. 26
      .travis.yml
  4. 661
      LICENSE
  5. 14
      README.md
  6. 24
      account_chart_report/__init__.py
  7. 53
      account_chart_report/__openerp__.py
  8. 15
      account_chart_report/account_report.xml
  9. 78
      account_chart_report/i18n/account_chart_report.pot
  10. 78
      account_chart_report/i18n/fr.po
  11. 23
      account_chart_report/report/__init__.py
  12. 60
      account_chart_report/report/chart_of_accounts.py
  13. 64
      account_chart_report/report/chart_of_accounts.rml
  14. 23
      account_chart_report/wizard/__init__.py
  15. 47
      account_chart_report/wizard/account_report_chart_of_account.py
  16. 41
      account_chart_report/wizard/account_report_chart_of_account.xml
  17. 5
      account_export_csv/__init__.py
  18. 17
      account_export_csv/__openerp__.py
  19. 5
      account_export_csv/wizard/__init__.py
  20. 148
      account_export_csv/wizard/account_export_csv.py
  21. 8
      account_financial_report/__init__.py
  22. BIN
      account_financial_report/i18n/es.mo
  23. 8
      account_financial_report/model/__init__.py
  24. 107
      account_financial_report/model/account_financial_report.py
  25. 11
      account_financial_report/model/res_company.py
  26. 2
      account_financial_report/report/__init__.py
  27. 472
      account_financial_report/report/parser.py
  28. 2
      account_financial_report/wizard/__init__.py
  29. 195
      account_financial_report/wizard/wizard.py
  30. 4
      account_financial_report_horizontal/__init__.py
  31. 6
      account_financial_report_horizontal/report/__init__.py
  32. 24
      account_financial_report_horizontal/report/account_balance_sheet.py
  33. 16
      account_financial_report_horizontal/report/account_profit_loss.py
  34. 27
      account_financial_report_horizontal/report/common_report_header.py
  35. 8
      account_financial_report_horizontal/wizard/__init__.py
  36. 2
      account_financial_report_horizontal/wizard/account_report_balance_sheet.py
  37. 4
      account_financial_report_horizontal/wizard/account_report_common.py
  38. 2
      account_financial_report_horizontal/wizard/account_report_common_account.py
  39. 2
      account_financial_report_horizontal/wizard/account_report_profit_loss.py
  40. 2
      account_financial_report_webkit/__init__.py
  41. 23
      account_financial_report_webkit/__openerp__.py
  42. 31
      account_financial_report_webkit/account_move_line.py
  43. 37
      account_financial_report_webkit/report/aged_partner_balance.py
  44. 154
      account_financial_report_webkit/report/common_balance_reports.py
  45. 182
      account_financial_report_webkit/report/common_partner_balance_reports.py
  46. 127
      account_financial_report_webkit/report/common_partner_reports.py
  47. 219
      account_financial_report_webkit/report/common_reports.py
  48. 99
      account_financial_report_webkit/report/general_ledger.py
  49. 112
      account_financial_report_webkit/report/open_invoices.py
  50. 39
      account_financial_report_webkit/report/partner_balance.py
  51. 96
      account_financial_report_webkit/report/partners_ledger.py
  52. 64
      account_financial_report_webkit/report/print_journal.py
  53. 35
      account_financial_report_webkit/report/trial_balance.py
  54. 56
      account_financial_report_webkit/report/webkit_parser_header_fix.py
  55. 151
      account_financial_report_webkit/wizard/balance_common.py
  56. 52
      account_financial_report_webkit/wizard/general_ledger_wizard.py
  57. 65
      account_financial_report_webkit/wizard/open_invoices_wizard.py
  58. 13
      account_financial_report_webkit/wizard/partner_balance_wizard.py
  59. 50
      account_financial_report_webkit/wizard/partners_ledger_wizard.py
  60. 63
      account_financial_report_webkit/wizard/print_journal.py
  61. 2
      account_financial_report_webkit/wizard/trial_balance_wizard.py
  62. 4
      account_financial_report_webkit_xls/__init__.py
  63. 5
      account_financial_report_webkit_xls/__openerp__.py
  64. 2
      account_financial_report_webkit_xls/report/__init__.py
  65. 201
      account_financial_report_webkit_xls/report/general_ledger_xls.py
  66. 820
      account_financial_report_webkit_xls/report/open_invoices_xls.py
  67. 286
      account_financial_report_webkit_xls/report/partner_ledger_xls.py
  68. 291
      account_financial_report_webkit_xls/report/partners_balance_xls.py
  69. 199
      account_financial_report_webkit_xls/report/trial_balance_xls.py
  70. 9
      account_financial_report_webkit_xls/wizard/general_ledger_wizard.py
  71. 8
      account_financial_report_webkit_xls/wizard/open_invoices_wizard.py
  72. 12
      account_financial_report_webkit_xls/wizard/partners_balance_wizard.py
  73. 8
      account_financial_report_webkit_xls/wizard/partners_ledger_wizard.py
  74. 9
      account_financial_report_webkit_xls/wizard/trial_balance_wizard.py
  75. 5
      account_journal_report_xls/__init__.py
  76. 2
      account_journal_report_xls/__openerp__.py
  77. 28
      account_journal_report_xls/account_journal.py
  78. 6
      account_journal_report_xls/report/__init__.py
  79. 177
      account_journal_report_xls/report/nov_account_journal.py
  80. 191
      account_journal_report_xls/report/nov_account_journal_xls.py
  81. 2
      account_journal_report_xls/wizard/__init__.py
  82. 66
      account_journal_report_xls/wizard/print_journal_wizard.py
  83. 5
      account_move_line_report_xls/__init__.py
  84. 12
      account_move_line_report_xls/account_move_line.py
  85. 216
      account_move_line_report_xls/report/move_line_list_xls.py

18
.coveragerc

@ -0,0 +1,18 @@
# Config file .coveragerc
# adapt the include for your project
[report]
include =
*/OCA/account-financial-reporting/*
omit =
*/tests/*
*__init__.py
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain about null context checking
if context is None:

56
.gitignore

@ -0,0 +1,56 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
# Pycharm
.idea
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Rope
.ropeproject
# Sphinx documentation
docs/_build/
# Backup files
*~
*.swp

26
.travis.yml

@ -0,0 +1,26 @@
language: python
python:
- "2.7"
env:
- VERSION="8.0" ODOO_REPO="odoo/odoo" EXCLUDE="account_financial_report_webkit"
- VERSION="8.0" ODOO_REPO="OCA/OCB"
virtualenv:
system_site_packages: true
install:
- git clone https://github.com/OCA/reporting-engine ${HOME}/reporting-engine -b ${VERSION}
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- sudo wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb -P /tmp/
- sudo dpkg -i /tmp/wkhtmltox-0.12.1_linux-precise-amd64.deb
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly
script:
- travis_run_flake8
- travis_run_tests
after_success:
coveralls

661
LICENSE

@ -0,0 +1,661 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.

14
README.md

@ -0,0 +1,14 @@
[![Build Status](https://travis-ci.org/OCA/account-financial-reporting.svg?branch=8.0)](https://travis-ci.org/OCA/account-financial-reporting)
[![Coverage Status](https://coveralls.io/repos/OCA/account-financial-reporting/badge.png?branch=8.0)](https://coveralls.io/r/OCA/account-financial-reporting?branch=8.0)
OpenERP account financial reports
=================================
This project aims to deal with modules related to financial reports. You'll
find modules that print legal and official reports. This includes, among
others:
* One module based on webkit and totally rewritten by camptocamp, for standard
financial reports.
* Another based on RML completely improved by Vauxoo.

24
account_chart_report/__init__.py

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014 Savoir-faire Linux (<www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from . import report
from . import wizard

53
account_chart_report/__openerp__.py

@ -0,0 +1,53 @@
# -*- encoding: utf-8 -*-
###############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2014 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
{
'name': 'Print chart of accounts',
'version': '1.0',
'category': 'Reports/pdf',
'description': """Print chart of accounts.
This module add the menu Accounting \ ChartsPrint chart of Accounts
and allow to print the selected chart of accounts.
This module is based on the old RML engine report.
Contributors
------------
* Marc Cassuto (marc.cassuto@savoirfairelinux.com)
* Mathieu Benoit (mathieu.benoit@savoirfairelinux.com)
""",
'author': 'Savoir-faire Linux',
'website': 'http://www.savoirfairelinux.com',
'depends': [
'base',
'account',
],
'data': [
'account_report.xml',
'wizard/account_report_chart_of_account.xml',
],
'installable': True,
'auto_install': False,
}

15
account_chart_report/account_report.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
auto="False"
id="account_chart_account"
menu="False"
model="account.account"
name="account.print.chart"
rml="account_chart_report/report/chart_of_accounts.rml"
string="Print chart account"
report_type="pdf"
/>
</data>
</openerp>

78
account_chart_report/i18n/account_chart_report.pot

@ -0,0 +1,78 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_chart_report
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-07-30 18:52+0000\n"
"PO-Revision-Date: 2014-07-30 18:52+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_chart_report
#: report:account.print.chart:0
msgid "Account"
msgstr ""
#. module: account_chart_report
#: report:account.print.chart:0
msgid "Code"
msgstr ""
#. module: account_chart_report
#: model:ir.actions.act_window,name:account_chart_report.action_print_chart_menu
#: model:ir.ui.menu,name:account_chart_report.menu_wizard_print_chart_account
msgid "Print chart of accounts"
msgstr ""
#. module: account_chart_report
#: view:account.print.chart.accounts.report:0
msgid "Print"
msgstr ""
#. module: account_chart_report
#: model:ir.model,name:account_chart_report.model_account_print_chart_accounts_report
msgid "Chart of accounts Report"
msgstr ""
#. module: account_chart_report
#: model:ir.actions.report.xml,name:account_chart_report.account_chart_account
msgid "Print chart account"
msgstr ""
#. module: account_chart_report
#: view:account.print.chart.accounts.report:0
msgid "Cancel"
msgstr ""
#. module: account_chart_report
#: field:account.print.chart.accounts.report,chart_account_id:0
msgid "Chart of Account"
msgstr ""
#. module: account_chart_report
#: report:account.print.chart:0
msgid "Chart of accounts"
msgstr ""
#. module: account_chart_report
#: view:account.print.chart.accounts.report:0
msgid "or"
msgstr ""
#. module: account_chart_report
#: view:account.print.chart.accounts.report:0
msgid "Report Options"
msgstr ""
#. module: account_chart_report
#: help:account.print.chart.accounts.report,chart_account_id:0
msgid "Select Charts of Accounts"
msgstr ""

78
account_chart_report/i18n/fr.po

@ -0,0 +1,78 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_chart_report
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-07-30 18:52+0000\n"
"PO-Revision-Date: 2014-07-30 14:56-0500\n"
"Last-Translator: Marc Cassuto <marc.cassuto@savoirfairelinux.com>\n"
"Language-Team: Savoir-faire Linux\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
"Language: fr\n"
#. module: account_chart_report
#: report:account.print.chart:0
msgid "Account"
msgstr "Compte"
#. module: account_chart_report
#: report:account.print.chart:0
msgid "Code"
msgstr "Code"
#. module: account_chart_report
#: model:ir.actions.act_window,name:account_chart_report.action_print_chart_menu
#: model:ir.ui.menu,name:account_chart_report.menu_wizard_print_chart_account
msgid "Print chart of accounts"
msgstr "Imprimer la charte de comptes"
#. module: account_chart_report
#: view:account.print.chart.accounts.report:0
msgid "Print"
msgstr "Imprimer"
#. module: account_chart_report
#: model:ir.model,name:account_chart_report.model_account_print_chart_accounts_report
msgid "Chart of accounts Report"
msgstr "Charte de comptes"
#. module: account_chart_report
#: model:ir.actions.report.xml,name:account_chart_report.account_chart_account
msgid "Print chart account"
msgstr "Imprimer la charte de comptes"
#. module: account_chart_report
#: view:account.print.chart.accounts.report:0
msgid "Cancel"
msgstr "Annuler"
#. module: account_chart_report
#: field:account.print.chart.accounts.report,chart_account_id:0
msgid "Chart of Account"
msgstr "Charte de comptes"
#. module: account_chart_report
#: report:account.print.chart:0
msgid "Chart of accounts"
msgstr "Charte de comptes"
#. module: account_chart_report
#: view:account.print.chart.accounts.report:0
msgid "or"
msgstr "ou"
#. module: account_chart_report
#: view:account.print.chart.accounts.report:0
msgid "Report Options"
msgstr "Options du rapport"
#. module: account_chart_report
#: help:account.print.chart.accounts.report,chart_account_id:0
msgid "Select Charts of Accounts"
msgstr "Charte de compte à imprimer"

23
account_chart_report/report/__init__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014 Savoir-faire Linux (<www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from . import chart_of_accounts

60
account_chart_report/report/chart_of_accounts.py

@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014 Savoir-faire Linux (<www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from openerp.report import report_sxw
class AccountChar(report_sxw.rml_parse):
_name = 'report.account.print.chart'
def __init__(self, cr, uid, name, context=None):
super(AccountChar, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
"get_lst_account": self._get_lst_account,
"cr": cr,
"uid": uid,
"actual_context": context,
})
def _get_lst_account(self, cr, uid, account_id, context):
account_obj = self.pool['account.account']
actual_account = account_obj.browse(cr, uid, account_id,
context=context)
lst_account = []
self._fill_list_account_with_child(lst_account, actual_account)
return lst_account
def _fill_list_account_with_child(self, lst_account, account):
# no more child
lst_account.append(account)
if not account.child_id:
return
for child in account.child_id:
self._fill_list_account_with_child(lst_account, child)
report_sxw.report_sxw(
'report.account.print.chart',
'account.account',
'account_chart_report/report/chart_of_accounts.rml',
parser=AccountChar,
)

64
account_chart_report/report/chart_of_accounts.rml

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<document filename="Chart of accounts.pdf">
<template title="Account Balance" author="Mathieu Benoit (mathieu.benoit@savoirfairelinux.com)" allowSplitting="1">
<pageTemplate id="first">
<frame id="first" x1="35.0" y1="35.0" width="650" height="772"/>
</pageTemplate>
</template>
<stylesheet>
<blockTableStyle id="Table_Tilte_Table">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="Table2">
<blockValign value="TOP"/>
<blockAlignment value="RIGHT"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,0"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,1" stop="-1,-1"/>
</blockTableStyle>
<initialize>
<paraStyle name="all" alignment="justify"/>
</initialize>
<paraStyle name="P8" fontName="Helvetica"/>
<paraStyle name="P11" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="P12" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="P14" rightIndent="17.0" leftIndent="-0.0" fontName="Helvetica-Bold" fontSize="8.0" leading="10" spaceBefore="0.0" spaceAfter="6.0"/>
<paraStyle name="P15" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="CENTER" spaceBefore="12.0" spaceAfter="6.0"/>
<paraStyle name="P12a" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<images/>
</stylesheet>
<story>
<blockTable colWidths="650.0" style="Table_Tilte_Table">
<tr>
<td>
<para style="P15">Chart of accounts</para>
</td>
</tr>
</blockTable>
<para style="P11">
<font color="white"> </font>
</para>
<para style="P11">
<font color="white"> </font>
</para>
<para style="P11">
<font color="white"> </font>
</para>
<para style="P11">
<font color="white"> </font>
</para>
<blockTable colWidths="70,450" style="Table2" repeatRows="1">
<tr noRowsplits="1">
<td><para style="P12a">Code</para></td>
<td><para style="P12a">Account</para></td>
</tr>
<tr>
<td><para style="P14">[[ repeatIn(get_lst_account(cr, uid, data["form"]["id_account"], actual_context), 'a') ]]<font>[[ (a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Helvetica"})) or removeParentNode('font') ]]</font><i>[[ a['code'] or removeParentNode('tr') ]]</i></para></td>
<td><para style="P14"><font>[[ (a['type']&lt;&gt;'view' and setTag('para','para',{'fontName':"Helvetica"})) or removeParentNode('font') ]]</font><font color="white">[[ '..'*(a['level']-1) ]]</font><font>[[ a['name'] ]]</font> </para></td>
</tr>
</blockTable>
<para style="P11">
<font color="white"> </font>
</para>
</story>
</document>

23
account_chart_report/wizard/__init__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014 Savoir-faire Linux (<www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import account_report_chart_of_account

47
account_chart_report/wizard/account_report_chart_of_account.py

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014 Savoir-faire Linux (<www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, orm
class ChartOfAccountsReport(orm.TransientModel):
_name = 'account.print.chart.accounts.report'
_description = 'Chart of accounts Report'
domain_char_account = [('parent_id', '=', False)]
_columns = {
'chart_account_id': fields.many2one('account.account',
'Chart of Accounts',
help='Select Charts of Accounts',
required=True,
domain=domain_char_account),
}
def print_report(self, cr, uid, ids, data, context=None):
res = self.read(cr, uid, ids, context=context)[0]
account_id = res["chart_account_id"][0]
data["form"] = {"id_account": account_id}
return {
'type': 'ir.actions.report.xml',
'report_name': 'account.print.chart',
'datas': data
}

41
account_chart_report/wizard/account_report_chart_of_account.xml

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="account_report_print_char_accounts_view" model="ir.ui.view">
<field name="name">Print chart of accounts</field>
<field name="model">account.print.chart.accounts.report</field>
<field name="arch" type="xml">
<form string="Report Options" version="7.0">
<group col="4" colspan="4">
<field name="chart_account_id" widget='selection'/>
</group>
<footer>
<button class="oe_highlight" name="print_report" string="Print"
type="object"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_print_chart_menu" model="ir.actions.act_window">
<field name="name">Print chart of accounts</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account.print.chart.accounts.report</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem
icon="STOCK_PRINT"
name="Print chart of accounts"
parent="account.menu_finance_charts"
action="action_print_chart_menu"
id="menu_wizard_print_chart_account"
/>
</data>
</openerp>

5
account_export_csv/__init__.py

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013 Camptocamp SA
# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013
# Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@ -18,4 +19,4 @@
#
##############################################################################
import wizard
from . import wizard

17
account_export_csv/__openerp__.py

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013 Camptocamp SA
# Author Joel Grand-Guillaume and Vincent Renaville
# Copyright 2013 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@ -19,15 +20,16 @@
##############################################################################
{
'name' : 'Account Export CSV',
'version' : '1.1',
'depends' : [
'name': 'Account Export CSV',
'version': '1.1',
'depends': [
'account',
],
'author' : 'Camptocamp',
'author': 'Camptocamp',
'description': """
Add a wizard that allow you to export a csv file based on accounting journal entries
Add a wizard that allow you to export a csv file based on accounting
journal entries
- Trial Balance
- Analytic Balance (with accounts)
@ -35,7 +37,8 @@
You can filter by period
TODO: rearange wizard view with only one button to generate file plus define a selection list to select report type
TODO: rearange wizard view with only one button to generate file plus
define a selection list to select report type
""",
'website': 'http://www.camptocamp.com',
'data': [

5
account_export_csv/wizard/__init__.py

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013 Camptocamp SA
# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013
# Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@ -18,4 +19,4 @@
#
##############################################################################
import account_export_csv
from . import account_export_csv

148
account_export_csv/wizard/account_export_csv.py

@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013 Camptocamp SA
# CSV data formating inspired from http://docs.python.org/2.7/library/csv.html?highlight=csv#examples
# Author Joel Grand-Guillaume and Vincent Renaville Copyright 2013
# Camptocamp SA
# CSV data formating inspired from
# http://docs.python.org/2.7/library/csv.html?highlight=csv#examples
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@ -20,7 +22,6 @@
##############################################################################
import itertools
import time
import tempfile
import StringIO
import cStringIO
@ -34,6 +35,7 @@ from openerp.tools.translate import _
class AccountUnicodeWriter(object):
"""
A CSV writer which will write rows to CSV file "f",
which is encoded in the given encoding.
@ -48,10 +50,11 @@ class AccountUnicodeWriter(object):
self.encoder = codecs.getincrementalencoder(encoding)()
def writerow(self, row):
#we ensure that we do not try to encode none or bool
# we ensure that we do not try to encode none or bool
row = (x or u'' for x in row)
encoded_row = [c.encode("utf-8") if isinstance(c, unicode) else c for c in row]
encoded_row = [
c.encode("utf-8") if isinstance(c, unicode) else c for c in row]
self.writer.writerow(encoded_row)
# Fetch UTF-8 output from the queue ...
@ -68,32 +71,47 @@ class AccountUnicodeWriter(object):
for row in rows:
self.writerow(row)
class AccountCSVExport(orm.TransientModel):
_name = 'account.csv.export'
_description = 'Export Accounting'
_columns = {
'data': fields.binary('CSV',readonly=True),
'company_id': fields.many2one('res.company', 'Company', invisible=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear', required=True),
'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'),
'journal_ids': fields.many2many('account.journal','rel_wizard_journal','wizard_id','journal_id','Journals', help='If empty, use all journals, only used for journal entries'),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear', required=True),
'data': fields.binary('CSV', readonly=True),
'company_id': fields.many2one('res.company', 'Company',
invisible=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear',
required=True),
'periods': fields.many2many(
'account.period', 'rel_wizard_period',
'wizard_id', 'period_id', 'Periods',
help='All periods in the fiscal year if empty'),
'journal_ids': fields.many2many(
'account.journal',
'rel_wizard_journal',
'wizard_id',
'journal_id',
'Journals',
help='If empty, use all journals, only used for journal entries'),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear',
required=True),
'export_filename': fields.char('Export CSV Filename', size=128),
}
def _get_company_default(self, cr, uid, context=None):
comp_obj = self.pool['res.company']
return comp_obj._company_default_get(cr, uid, 'account.fiscalyear', context=context)
return comp_obj._company_default_get(cr, uid, 'account.fiscalyear',
context=context)
def _get_fiscalyear_default(self, cr, uid, context=None):
fiscalyear_obj = self.pool['account.fiscalyear']
context['company_id'] = self._get_company_default(cr, uid, context)
return fiscalyear_obj.find(cr,uid,dt=None,exception=True, context=context)
return fiscalyear_obj.find(cr, uid, dt=None, exception=True,
context=context)
_defaults = {'company_id': _get_company_default,
'fiscalyear_id' : _get_fiscalyear_default,
'export_filename' : 'account_export.csv'}
'fiscalyear_id': _get_fiscalyear_default,
'export_filename': 'account_export.csv'}
def action_manual_export_account(self, cr, uid, ids, context=None):
this = self.browse(cr, uid, ids)[0]
@ -118,7 +136,6 @@ class AccountCSVExport(orm.TransientModel):
'target': 'new',
}
def _get_header_account(self, cr, uid, ids, context=None):
return [_(u'CODE'),
_(u'NAME'),
@ -137,14 +154,17 @@ class AccountCSVExport(orm.TransientModel):
"""
cr.execute("""
select ac.code,ac.name,
sum(debit) as sum_debit,sum(credit) as sum_credit,sum(debit) - sum(credit) as balance
sum(debit) as sum_debit,
sum(credit) as sum_credit,
sum(debit) - sum(credit) as balance
from account_move_line as aml,account_account as ac
where aml.account_id = ac.id
and period_id in %(period_ids)s
group by ac.id,ac.code,ac.name
order by ac.code
""",
{'fiscalyear_id': fiscalyear_id, 'period_ids':tuple(period_range_ids)}
{'fiscalyear_id': fiscalyear_id,
'period_ids': tuple(period_range_ids)}
)
res = cr.fetchall()
@ -155,7 +175,7 @@ class AccountCSVExport(orm.TransientModel):
def action_manual_export_analytic(self, cr, uid, ids, context=None):
this = self.browse(cr, uid, ids)[0]
rows = self.get_data(cr, uid, ids,"analytic", context)
rows = self.get_data(cr, uid, ids, "analytic", context)
file_data = StringIO.StringIO()
try:
writer = AccountUnicodeWriter(file_data)
@ -194,8 +214,12 @@ class AccountCSVExport(orm.TransientModel):
"""
Return list to generate rows of the CSV file
"""
cr.execute(""" select aac.code as analytic_code,aac.name as analytic_name,ac.code,ac.name,
sum(debit) as sum_debit,sum(credit) as sum_credit,sum(debit) - sum(credit) as balance
cr.execute(""" select aac.code as analytic_code,
aac.name as analytic_name,
ac.code,ac.name,
sum(debit) as sum_debit,
sum(credit) as sum_credit,
sum(debit) - sum(credit) as balance
from account_move_line
left outer join account_analytic_account as aac
on (account_move_line.analytic_account_id = aac.id)
@ -205,7 +229,8 @@ class AccountCSVExport(orm.TransientModel):
group by aac.id,aac.code,aac.name,ac.id,ac.code,ac.name
order by aac.code
""",
{'fiscalyear_id': fiscalyear_id, 'period_ids':tuple(period_range_ids)}
{'fiscalyear_id': fiscalyear_id,
'period_ids': tuple(period_range_ids)}
)
res = cr.fetchall()
@ -214,14 +239,15 @@ class AccountCSVExport(orm.TransientModel):
rows.append(list(line))
return rows
def action_manual_export_journal_entries(self, cr, uid, ids, context=None):
"""
Here we use TemporaryFile to avoid full filling the OpenERP worker Memory
We also write the data to the wizard with SQL query as write seams to use
too much memory as well.
Here we use TemporaryFile to avoid full filling the OpenERP worker
Memory
We also write the data to the wizard with SQL query as write seams
to use too much memory as well.
Those improvements permitted to improve the export from a 100k line to 200k lines
Those improvements permitted to improve the export from a 100k line to
200k lines
with default `limit_memory_hard = 805306368` (768MB) with more lines,
you might encounter a MemoryError when trying to download the file even
if it has been generated.
@ -241,7 +267,10 @@ class AccountCSVExport(orm.TransientModel):
file_data.seek(0)
base64.encode(file_data, base64_data)
base64_data.seek(0)
cr.execute("""UPDATE account_csv_export SET data = %s WHERE id = %s""", (base64_data.read(), ids[0]) )
cr.execute("""
UPDATE account_csv_export
SET data = %s
WHERE id = %s""", (base64_data.read(), ids[0]))
return {
'type': 'ir.actions.act_window',
'res_model': 'account.csv.export',
@ -252,9 +281,7 @@ class AccountCSVExport(orm.TransientModel):
'target': 'new',
}
def _get_header_journal_entries(self, cr, uid, ids, context=None):
return [
# Standard Sage export fields
_(u'DATE'),
@ -282,9 +309,9 @@ class AccountCSVExport(orm.TransientModel):
_(u'TAX CODE CODE'),
_(u'TAX CODE NAME'),
_(u'TAX AMOUNT'),
_(u'BANK STATEMENT'),
]
def _get_rows_journal_entries(self, cr, uid, ids,
fiscalyear_id,
period_range_ids,
@ -306,7 +333,6 @@ class AccountCSVExport(orm.TransientModel):
account_move_reconcile.name as full_reconcile,
account_move_line.reconcile_partial_id AS partial_reconcile_id,
account_analytic_account.code AS analytic_account_code,
account_move.name AS entry_number,
account_account.name AS account_name,
account_move_line.debit - account_move_line.credit AS balance,
@ -318,55 +344,73 @@ class AccountCSVExport(orm.TransientModel):
account_fiscalyear.name as fiscal_year,
account_tax_code.code AS aml_tax_code_code,
account_tax_code.name AS aml_tax_code_name,
account_move_line.tax_amount AS aml_tax_amount
account_move_line.tax_amount AS aml_tax_amount,
account_bank_statement.name AS bank_statement
FROM
public.account_move_line
JOIN account_account on (account_account.id=account_move_line.account_id)
JOIN account_period on (account_period.id=account_move_line.period_id)
JOIN account_fiscalyear on (account_fiscalyear.id=account_period.fiscalyear_id)
JOIN account_journal on (account_journal.id = account_move_line.journal_id)
LEFT JOIN res_currency on (res_currency.id=account_move_line.currency_id)
LEFT JOIN account_move_reconcile on (account_move_reconcile.id = account_move_line.reconcile_id)
LEFT JOIN res_partner on (res_partner.id=account_move_line.partner_id)
LEFT JOIN account_move on (account_move.id=account_move_line.move_id)
LEFT JOIN account_tax on (account_tax.id=account_move_line.account_tax_id)
LEFT JOIN account_tax_code on (account_tax_code.id=account_move_line.tax_code_id)
LEFT JOIN account_analytic_account on (account_analytic_account.id=account_move_line.analytic_account_id)
JOIN account_account on
(account_account.id=account_move_line.account_id)
JOIN account_period on
(account_period.id=account_move_line.period_id)
JOIN account_fiscalyear on
(account_fiscalyear.id=account_period.fiscalyear_id)
JOIN account_journal on
(account_journal.id = account_move_line.journal_id)
LEFT JOIN res_currency on
(res_currency.id=account_move_line.currency_id)
LEFT JOIN account_move_reconcile on
(account_move_reconcile.id = account_move_line.reconcile_id)
LEFT JOIN res_partner on
(res_partner.id=account_move_line.partner_id)
LEFT JOIN account_move on
(account_move.id=account_move_line.move_id)
LEFT JOIN account_tax on
(account_tax.id=account_move_line.account_tax_id)
LEFT JOIN account_tax_code on
(account_tax_code.id=account_move_line.tax_code_id)
LEFT JOIN account_analytic_account on
(account_analytic_account.id=account_move_line.analytic_account_id)
LEFT JOIN account_bank_statement on
(account_bank_statement.id=account_move_line.statement_id)
WHERE account_period.id IN %(period_ids)s
AND account_journal.id IN %(journal_ids)s
ORDER BY account_move_line.date
""",
{'period_ids': tuple(period_range_ids), 'journal_ids': tuple(journal_ids)}
{'period_ids': tuple(
period_range_ids), 'journal_ids': tuple(journal_ids)}
)
while 1:
# http://initd.org/psycopg/docs/cursor.html#cursor.fetchmany
# Set cursor.arraysize to minimize network round trips
cr.arraysize=100
cr.arraysize = 100
rows = cr.fetchmany()
if not rows:
break
for row in rows:
yield row
def get_data(self, cr, uid, ids,result_type,context=None):
get_header_func = getattr(self,("_get_header_%s"%(result_type)), None)
get_rows_func = getattr(self,("_get_rows_%s"%(result_type)), None)
def get_data(self, cr, uid, ids, result_type, context=None):
get_header_func = getattr(
self, ("_get_header_%s" % (result_type)), None)
get_rows_func = getattr(self, ("_get_rows_%s" % (result_type)), None)
form = self.browse(cr, uid, ids[0], context=context)
fiscalyear_id = form.fiscalyear_id.id
user_obj = self.pool.get('res.users')
if form.periods:
period_range_ids = [x.id for x in form.periods]
else:
# If not period selected , we take all periods
p_obj = self.pool.get("account.period")
period_range_ids = p_obj.search(cr, uid, [('fiscalyear_id','=',fiscalyear_id)], context=context)
period_range_ids = p_obj.search(
cr, uid, [('fiscalyear_id', '=', fiscalyear_id)],
context=context)
journal_ids = None
if form.journal_ids:
journal_ids = [x.id for x in form.journal_ids]
else:
j_obj = self.pool.get("account.journal")
journal_ids = j_obj.search(cr, uid, [], context=context)
rows = itertools.chain((get_header_func(cr, uid, ids, context=context),),
rows = itertools.chain((get_header_func(cr, uid, ids,
context=context),),
get_rows_func(cr, uid, ids,
fiscalyear_id,
period_range_ids,

8
account_financial_report/__init__.py

@ -3,7 +3,7 @@
# Module Writen to OpenERP, Open Source Management Solution
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
# All Rights Reserved
###############Credits######################################################
# Credits######################################################
# Coded by: Humberto Arocha humberto@openerp.com.ve
# Angelica Barrios angelicaisabelb@gmail.com
# Jordi Esteve <jesteve@zikzakmedia.com>
@ -25,6 +25,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
import model
import report
import wizard
from . import model
from . import report
from . import wizard

BIN
account_financial_report/i18n/es.mo

8
account_financial_report/model/__init__.py

@ -10,8 +10,8 @@
# Audited by: Nhomar Hernandez <nhomar@vauxoo.com>
#############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@ -23,5 +23,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##########################################################################
import account_financial_report
import res_company
from . import account_financial_report
from . import res_company

107
account_financial_report/model/account_financial_report.py

@ -26,10 +26,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
from osv import osv, fields
import pooler
from openerp.osv import osv, fields
import time
from tools.translate import _
from openerp.tools.translate import _
class account_financial_report(osv.osv):
@ -38,45 +37,75 @@ class account_financial_report(osv.osv):
_columns = {
'name': fields.char('Name', size=128, required=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'currency_id': fields.many2one(
'res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
'inf_type': fields.selection(
[('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True),
'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'),
('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True),
'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'),
('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'),
'display_account_level': fields.integer(
'Up to level', help='Display accounts up to this level (0 to show all)'),
'account_ids': fields.many2many(
'account.account', 'afr_account_rel', 'afr_id', 'account_id', 'Root accounts', required=True),
'fiscalyear_id': fields.many2one(
'account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True),
'period_ids': fields.many2many('account.period', 'afr_period_rel', 'afr_id',
'period_id', 'Periods', help='All periods in the fiscal year if empty'),
'currency_id': fields.many2one('res.currency', 'Currency',
help="Currency at which this report \
will be expressed. If not selected \
will be used the one set in the \
company"),
'inf_type': fields.selection([('BS', 'Balance Sheet'),
('IS', 'Income Statement')],
'Type',
required=True),
'columns': fields.selection(
[('one', 'End. Balance'),
('two', 'Debit | Credit'),
('four', 'Initial | Debit | Credit | YTD'),
('five', 'Initial | Debit | Credit | Period | YTD'),
('qtr', "4 QTR's | YTD"),
('thirteen', '12 Months | YTD')], 'Columns', required=True),
'display_account': fields.selection(
[('all', 'All Accounts'),
('bal', 'With Balance'),
('mov', 'With movements'),
('bal_mov', 'With Balance / Movements')], 'Display accounts'),
'display_account_level': fields.integer('Up to level',
help='Display accounts up to \
this level (0 to show all)'),
'account_ids': fields.many2many('account.account', 'afr_account_rel',
'afr_id', 'account_id',
'Root accounts', required=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal year',
help='Fiscal Year for this report',
required=True),
'period_ids': fields.many2many(
'account.period', 'afr_period_rel', 'afr_id', 'period_id',
'Periods', help='All periods in the fiscal year if empty'),
'analytic_ledger': fields.boolean(
'Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'Analytic Ledger',
help="Allows to Generate an Analytic Ledger for accounts with \
moves. Available when Balance Sheet and 'Initial | Debit \
| Credit | YTD' are selected"),
'journal_ledger': fields.boolean(
'journal Ledger', help="Allows to Generate an journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'partner_balance': fields.boolean('Partner Balance', help="Allows to "
"Generate a Partner Balance for accounts with moves. Available when "
"Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'journal Ledger',
help="Allows to Generate an journal Ledger for accounts with \
moves. Available when Balance Sheet and 'Initial | Debit | \
Credit | YTD' are selected"),
'partner_balance': fields.boolean(
'Partner Balance',
help="Allows to Generate a Partner Balance for accounts with \
moves. Available when Balance Sheet and 'Initial | Debit | \
Credit | YTD' are selected"),
'tot_check': fields.boolean(
'Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
'lab_str':
fields.char(
'Description',
'Summarize?',
help='Checking will add a new line at the end of the Report which \
will Summarize Columns in Report'),
'lab_str': fields.char('Description',
help='Description for the Summary',
size=128),
'target_move': fields.selection([('posted', 'All Posted Entries'),
('all', 'All Entries'),
], 'Entries to Include', required=True,
help='Print All Accounting Entries or just Posted Accounting Entries'),
#~ Deprecated fields
'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'),
('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'),
'target_move': fields.selection(
[('posted', 'All Posted Entries'),
('all', 'All Entries'), ],
'Entries to Include', required=True,
help='Print All Accounting Entries or just Posted \
Accounting Entries'),
# ~ Deprecated fields
'filter': fields.selection([('bydate', 'By Date'),
('byperiod', 'By Period'),
('all', 'By Date and Period'),
('none', 'No Filter')],
'Date/Period Filter'),
'date_to': fields.date('End date'),
'date_from': fields.date('Start date'),
}
@ -144,8 +173,10 @@ class account_financial_report(osv.osv):
if columns in ('qtr', 'thirteen'):
p_obj = self.pool.get("account.period")
period_ids = p_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear_id), (
'special', '=', False)], context=context)
period_ids = p_obj.search(cr, uid,
[('fiscalyear_id', '=', fiscalyear_id),
('special', '=', False)],
context=context)
res['value'].update({'period_ids': period_ids})
else:
res['value'].update({'period_ids': []})

11
account_financial_report/model/res_company.py

@ -10,8 +10,8 @@
# Audited by: Nhomar Hernandez <nhomar@vauxoo.com>
#############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@ -23,12 +23,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##########################################################################
from osv import osv
from osv import fields
from tools.translate import _
from openerp.osv import orm, fields
class res_company(osv.osv):
class res_company(orm.Model):
_inherit = 'res.company'
_columns = {
'credit_account_ids': fields.many2many('account.account',
@ -40,4 +38,3 @@ class res_company(osv.osv):
'company_id', 'account_id',
'Debitable Accounts'),
}
res_company()

2
account_financial_report/report/__init__.py

@ -25,4 +25,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
import parser
from . import parser

472
account_financial_report/report/parser.py

@ -26,16 +26,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
import xml
import copy
from operator import itemgetter
import time
import datetime
from report import report_sxw
from tools import config
from tools.translate import _
from osv import osv
from openerp.tools.safe_eval import safe_eval as eval
from openerp.report import report_sxw
from openerp.tools.translate import _
from openerp.osv import osv
class account_balance(report_sxw.rml_parse):
@ -68,14 +62,17 @@ class account_balance(report_sxw.rml_parse):
"""
rc_obj = self.pool.get('res.company')
country_code = rc_obj.browse(self.cr, self.uid,
form['company_id'][0]).partner_id.country_id.code or ''
form['company_id'][0]).partner_id.\
country_id.code or ''
string_vat = rc_obj.browse(self.cr, self.uid,
form['company_id'][0]).partner_id.vat or ''
if string_vat:
if country_code == 'MX':
return '%s' % (string_vat[2:])
elif country_code == 'VE':
return '- %s-%s-%s' % (string_vat[2:3], string_vat[3:11], string_vat[11:12])
return '- %s-%s-%s' % (string_vat[2:3],
string_vat[3:11],
string_vat[11:12])
else:
return string_vat
else:
@ -85,7 +82,7 @@ class account_balance(report_sxw.rml_parse):
"""
Returns the fiscal year text used on the report.
"""
fiscalyear_obj = self.pool.get('account.fiscalyear')
fiscalyear_obj = self.pool['account.fiscalyear']
fiscalyear = None
if form.get('fiscalyear'):
fiscalyear = fiscalyear_obj.browse(
@ -104,7 +101,8 @@ class account_balance(report_sxw.rml_parse):
list, tuple) and form['afr_id'][0] or form['afr_id']
if afr_id:
name = self.pool.get('afr').browse(self.cr, self.uid, afr_id).name
elif form['analytic_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS':
elif form['analytic_ledger'] and form['columns'] == 'four' \
and form['inf_type'] == 'BS':
name = _('Analytic Ledger')
elif form['inf_type'] == 'BS':
name = _('Balance Sheet')
@ -118,41 +116,43 @@ class account_balance(report_sxw.rml_parse):
return day, year and month
'''
if form['filter'] in ['bydate', 'all']:
months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio",
"Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]
mes = months[time.strptime(form['date_to'], "%Y-%m-%d")[1] - 1]
ano = time.strptime(form['date_to'], "%Y-%m-%d")[0]
dia = time.strptime(form['date_to'], "%Y-%m-%d")[2]
return _('From ') + self.formatLang(form['date_from'], date=True) + _(' to ') + self.formatLang(form['date_to'], date=True)
return _('From ') + self.formatLang(form['date_from'], date=True) \
+ _(' to ') + self.formatLang(form['date_to'], date=True)
elif form['filter'] in ['byperiod', 'all']:
aux = []
period_obj = self.pool.get('account.period')
for period in period_obj.browse(self.cr, self.uid, form['periods']):
for period in period_obj.browse(self.cr, self.uid,
form['periods']):
aux.append(period.date_start)
aux.append(period.date_stop)
sorted(aux)
return _('From ') + self.formatLang(aux[0], date=True) + _(' to ') + self.formatLang(aux[-1], date=True)
return _('From ') + self.formatLang(aux[0], date=True) + \
_(' to ') + self.formatLang(aux[-1], date=True)
def get_periods_and_date_text(self, form):
"""
Returns the text with the periods/dates used on the report.
"""
period_obj = self.pool.get('account.period')
periods_str = None
period_obj = self.pool['account.period']
fiscalyear_obj = self.pool['account.fiscalyear']
fiscalyear_id = form[
'fiscalyear'] or fiscalyear_obj.find(self.cr, self.uid)
period_ids = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear_id), ('special', '=', False)])
if form['filter'] in ['byperiod', 'all']:
period_ids = form['periods']
periods_str = ', '.join([period.name or period.code for period in period_obj.browse(
self.cr, self.uid, period_ids)])
periods_str = ', '.join([period.name or period.code
for period in period_obj.browse(self.cr,
self.uid,
period_ids)])
dates_str = None
if form['filter'] in ['bydate', 'all']:
dates_str = self.formatLang(form[
'date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' '
'date_from'], date=True) + ' - ' + \
self.formatLang(form['date_to'],
date=True) + ' '
return {'periods': periods_str, 'date': dates_str}
def special_period(self, periods):
@ -164,20 +164,26 @@ class account_balance(report_sxw.rml_parse):
return False
def exchange_name(self, form):
self.from_currency_id = self.get_company_currency(form['company_id'] and type(form[
'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'])
self.from_currency_id = self.\
get_company_currency(form['company_id']
and type(form['company_id']) in (list, tuple)
and form['company_id'][0]
or form['company_id'])
if not form['currency_id']:
self.to_currency_id = self.from_currency_id
else:
self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (
list, tuple) and form['currency_id'][0] or form['currency_id']
return self.pool.get('res.currency').browse(self.cr, self.uid, self.to_currency_id).name
self.to_currency_id = form['currency_id'] \
and type(form['currency_id']) in (list, tuple) \
and form['currency_id'][0] or form['currency_id']
return self.pool.get('res.currency').browse(self.cr, self.uid,
self.to_currency_id).name
def exchange(self, from_amount):
if self.from_currency_id == self.to_currency_id:
return from_amount
curr_obj = self.pool.get('res.currency')
return curr_obj.compute(self.cr, self.uid, self.from_currency_id, self.to_currency_id, from_amount)
return curr_obj.compute(self.cr, self.uid, self.from_currency_id,
self.to_currency_id, from_amount)
def get_company_currency(self, company_id):
rc_obj = self.pool.get('res.company')
@ -186,12 +192,15 @@ class account_balance(report_sxw.rml_parse):
def get_company_accounts(self, company_id, acc='credit'):
rc_obj = self.pool.get('res.company')
if acc == 'credit':
return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).credit_account_ids]
return [brw.id for brw in rc_obj.browse(
self.cr, self.uid,
company_id).credit_account_ids]
else:
return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).debit_account_ids]
return [brw.id for brw in rc_obj.browse(
self.cr, self.uid,
company_id).debit_account_ids]
def _get_partner_balance(self, account, init_period, ctx=None):
rp_obj = self.pool.get('res.partner')
res = []
ctx = ctx or {}
if account['type'] in ('other', 'liquidity', 'receivable', 'payable'):
@ -199,7 +208,9 @@ class account_balance(report_sxw.rml_parse):
SELECT
CASE
WHEN aml.partner_id IS NOT NULL
THEN (SELECT name FROM res_partner WHERE aml.partner_id = id)
THEN (SELECT name
FROM res_partner
WHERE aml.partner_id = id)
ELSE 'UNKNOWN'
END AS partner_name,
CASE
@ -255,7 +266,8 @@ class account_balance(report_sxw.rml_parse):
SUM(init_dr)-SUM(init_cr) AS balanceinit,
SUM(bal_dr) AS debit,
SUM(bal_cr) AS credit,
SUM(init_dr) - SUM(init_cr) + SUM(bal_dr) - SUM(bal_cr) AS balance
SUM(init_dr) - SUM(init_cr)
+ SUM(bal_dr) - SUM(bal_cr) AS balance
FROM (
SELECT
*
@ -292,29 +304,50 @@ class account_balance(report_sxw.rml_parse):
res = []
if account['type'] in ('other', 'liquidity', 'receivable', 'payable'):
#~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS DEL EJERCICIO
#~ FISCAL, SIN LOS PERIODOS ESPECIALES
# ~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS
# DEL EJERCICIO
# ~ FISCAL, SIN LOS PERIODOS ESPECIALES
periods = ', '.join([str(i) for i in ctx['periods']])
#~ periods = str(tuple(ctx['periods']))
where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % (
periods, account['id'])
# ~ periods = str(tuple(ctx['periods']))
where = """where aml.period_id in (%s)
and aa.id = %s
and aml.state <> 'draft'""" % (periods, account['id'])
if ctx.get('state', 'posted') == 'posted':
where += "AND am.state = 'posted'"
sql_detalle = """select aml.id as id, aj.name as diario, aa.name as descripcion,
(select name from res_partner where aml.partner_id = id) as partner,
aa.code as cuenta, aml.name as name,
sql_detalle = """select aml.id as id,
aj.name as diario,
aa.name as descripcion,
(select name
from res_partner
where aml.partner_id = id) as partner,
aa.code as cuenta,
aml.name as name,
aml.ref as ref,
case when aml.debit is null then 0.00 else aml.debit end as debit,
case when aml.credit is null then 0.00 else aml.credit end as credit,
(select code from account_analytic_account where aml.analytic_account_id = id) as analitica,
aml.date as date, ap.name as periodo,
case when aml.debit is null
then 0.00
else aml.debit
end as debit,
case when aml.credit is null
then 0.00
else aml.credit
end as credit,
(select code
from account_analytic_account
where aml.analytic_account_id = id)
as analitica,
aml.date as date,
ap.name as periodo,
am.name as asiento
from account_move_line aml
inner join account_journal aj on aj.id = aml.journal_id
inner join account_account aa on aa.id = aml.account_id
inner join account_period ap on ap.id = aml.period_id
inner join account_move am on am.id = aml.move_id """ + where +\
""" order by date, am.name"""
inner join account_journal aj
on aj.id = aml.journal_id
inner join account_account aa
on aa.id = aml.account_id
inner join account_period ap
on ap.id = aml.period_id
inner join account_move am
on am.id = aml.move_id """ \
+ where + """ order by date, am.name"""
self.cr.execute(sql_detalle)
resultat = self.cr.dictfetchall()
@ -342,12 +375,14 @@ class account_balance(report_sxw.rml_parse):
am_obj = self.pool.get('account.move')
print 'AM OBJ ', am_obj
if account['type'] in ('other', 'liquidity', 'receivable', 'payable'):
#~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS DEL EJERCICIO
#~ FISCAL, SIN LOS PERIODOS ESPECIALES
# ~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS
# DEL EJERCICIO
# ~ FISCAL, SIN LOS PERIODOS ESPECIALES
periods = ', '.join([str(i) for i in ctx['periods']])
#~ periods = str(tuple(ctx['periods']))
where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % (
periods, account['id'])
# ~ periods = str(tuple(ctx['periods']))
where = """where aml.period_id in (%s)
and aa.id = %s
and aml.state <> 'draft'""" % (periods, account['id'])
if ctx.get('state', 'posted') == 'posted':
where += "AND am.state = 'posted'"
sql_detalle = """SELECT
@ -360,8 +395,8 @@ class account_balance(report_sxw.rml_parse):
inner join account_journal aj on aj.id = aml.journal_id
inner join account_account aa on aa.id = aml.account_id
inner join account_period ap on ap.id = aml.period_id
inner join account_move am on am.id = aml.move_id """ + where +\
""" order by date, am.name"""
inner join account_move am on am.id = aml.move_id """ \
+ where + """ order by date, am.name"""
self.cr.execute(sql_detalle)
resultat = self.cr.dictfetchall()
@ -374,7 +409,8 @@ class account_balance(report_sxw.rml_parse):
'period': det['periodo'],
'obj': am_obj.browse(self.cr, self.uid, det['am_id'])
})
print 'ACCOUNT NAME', am_obj.browse(self.cr, self.uid, det['am_id']).name
print 'ACCOUNT NAME', am_obj.browse(self.cr, self.uid,
det['am_id']).name
return res
def lines(self, form, level=0):
@ -387,15 +423,18 @@ class account_balance(report_sxw.rml_parse):
period_obj = self.pool.get('account.period')
fiscalyear_obj = self.pool.get('account.fiscalyear')
def _get_children_and_consol(cr, uid, ids, level, context={}, change_sign=False):
def _get_children_and_consol(cr, uid, ids, level, context={},
change_sign=False):
aa_obj = self.pool.get('account.account')
ids2 = []
for aa_brw in aa_obj.browse(cr, uid, ids, context):
if aa_brw.child_id and aa_brw.level < level and aa_brw.type != 'consolidation':
if aa_brw.child_id and aa_brw.level < level \
and aa_brw.type != 'consolidation':
if not change_sign:
ids2.append([aa_brw.id, True, False, aa_brw])
ids2 += _get_children_and_consol(cr, uid, [
x.id for x in aa_brw.child_id], level, context, change_sign=change_sign)
ids2 += _get_children_and_consol(
cr, uid, [x.id for x in aa_brw.child_id], level,
context, change_sign=change_sign)
if change_sign:
ids2.append(aa_brw.id)
else:
@ -414,7 +453,9 @@ class account_balance(report_sxw.rml_parse):
ctx_end = ctx
ctx_end['filter'] = form.get('filter', 'all')
ctx_end['fiscalyear'] = fiscalyear.id
#~ ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)])
# ~ ctx_end['periods'] = period_obj.\
# search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),
# ('special','=',False)])
if ctx_end['filter'] not in ['bydate', 'none']:
special = self.special_period(form['periods'])
@ -423,11 +464,16 @@ class account_balance(report_sxw.rml_parse):
if form['filter'] in ['byperiod', 'all']:
if special:
ctx_end['periods'] = period_obj.search(self.cr, self.uid, [(
'id', 'in', form['periods'] or ctx_end.get('periods', False))])
ctx_end['periods'] = period_obj.search(
self.cr, self.uid,
[('id', 'in', form['periods'] or ctx_end.get('periods',
False))])
else:
ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id', 'in', form[
'periods'] or ctx_end.get('periods', False)), ('special', '=', False)])
ctx_end['periods'] = period_obj.search(
self.cr, self.uid,
[('id', 'in', form['periods'] or ctx_end.get('periods',
False)),
('special', '=', False)])
if form['filter'] in ['bydate', 'all', 'none']:
ctx_end['date_from'] = form['date_from']
@ -437,11 +483,19 @@ class account_balance(report_sxw.rml_parse):
def missing_period(ctx_init):
ctx_init['fiscalyear'] = fiscalyear_obj.search(self.cr, self.uid, [('date_stop', '<', fiscalyear.date_start)], order='date_stop') and \
fiscalyear_obj.search(self.cr, self.uid, [(
'date_stop', '<', fiscalyear.date_start)], order='date_stop')[-1] or []
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', ctx_init['fiscalyear']), ('date_stop', '<', fiscalyear.date_start)])
ctx_init['fiscalyear'] = \
fiscalyear_obj.search(self.cr, self.uid,
[('date_stop', '<',
fiscalyear.date_start)],
order='date_stop') \
and fiscalyear_obj.search(self.cr, self.uid,
[('date_stop', '<',
fiscalyear.date_start)],
order='date_stop')[-1] or []
ctx_init['periods'] = period_obj.search(
self.cr, self.uid,
[('fiscalyear_id', '=', ctx_init['fiscalyear']),
('date_stop', '<', fiscalyear.date_start)])
return ctx_init
#######################################################################
# CONTEXT FOR INITIAL BALANCE #
@ -456,22 +510,30 @@ class account_balance(report_sxw.rml_parse):
ctx_init['periods'] = form['periods']
if not ctx_init['periods']:
ctx_init = missing_period(ctx_init.copy())
date_start = min([period.date_start for period in period_obj.browse(
self.cr, self.uid, ctx_init['periods'])])
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('date_stop', '<=', date_start)])
date_start = min([period.date_start for period in period_obj.
browse(self.cr, self.uid,
ctx_init['periods'])])
ctx_init['periods'] = period_obj.search(
self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id),
('date_stop', '<=', date_start)])
elif form['filter'] in ['bydate']:
ctx_init['date_from'] = fiscalyear.date_start
ctx_init['date_to'] = form['date_from']
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('date_stop', '<=', ctx_init['date_to'])])
ctx_init['periods'] = period_obj.search(
self.cr, self.uid,
[('fiscalyear_id', '=', fiscalyear.id),
('date_stop', '<=', ctx_init['date_to'])])
elif form['filter'] == 'none':
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('special', '=', True)])
date_start = min([period.date_start for period in period_obj.browse(
self.cr, self.uid, ctx_init['periods'])])
ctx_init['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('date_start', '<=', date_start), ('special', '=', True)])
ctx_init['periods'] = period_obj.search(
self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id),
('special', '=', True)])
date_start = min([period.date_start for period in period_obj.
browse(self.cr, self.uid,
ctx_init['periods'])])
ctx_init['periods'] = period_obj.search(
self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id),
('date_start', '<=', date_start),
('special', '=', True)])
return ctx_init.copy()
@ -480,24 +542,35 @@ class account_balance(report_sxw.rml_parse):
self.context['state'] = form['target_move'] or 'posted'
self.from_currency_id = self.get_company_currency(form['company_id'] and type(form[
'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'])
self.from_currency_id = self.\
get_company_currency(form['company_id']
and type(form['company_id']) in (list, tuple)
and form['company_id'][0]
or form['company_id'])
if not form['currency_id']:
self.to_currency_id = self.from_currency_id
else:
self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (
list, tuple) and form['currency_id'][0] or form['currency_id']
self.to_currency_id = form['currency_id'] \
and type(form['currency_id']) in (list, tuple) \
and form['currency_id'][0] \
or form['currency_id']
if 'account_list' in form and form['account_list']:
account_ids = form['account_list']
account_list = form['account_list']
del form['account_list']
credit_account_ids = self.get_company_accounts(form['company_id'] and type(form[
'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'], 'credit')
credit_account_ids = self.\
get_company_accounts(form['company_id']
and type(form['company_id']) in (list, tuple)
and form['company_id'][0]
or form['company_id'], 'credit')
debit_account_ids = self.get_company_accounts(form['company_id'] and type(form[
'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id'], 'debit')
debit_account_ids = self.\
get_company_accounts(form['company_id']
and type(form['company_id']) in (list, tuple)
and form['company_id'][0]
or form['company_id'], 'debit')
if form.get('fiscalyear'):
if type(form.get('fiscalyear')) in (list, tuple):
@ -512,14 +585,19 @@ class account_balance(report_sxw.rml_parse):
all_account_ids = _get_children_and_consol(
self.cr, self.uid, account_ids, 100, self.context)
account_ids = _get_children_and_consol(self.cr, self.uid, account_ids, form[
'display_account_level'] and form['display_account_level'] or 100, self.context)
account_ids = _get_children_and_consol(
self.cr, self.uid, account_ids,
form['display_account_level']
and form['display_account_level']
or 100, self.context)
credit_account_ids = _get_children_and_consol(
self.cr, self.uid, credit_account_ids, 100, self.context, change_sign=True)
self.cr, self.uid, credit_account_ids, 100, self.context,
change_sign=True)
debit_account_ids = _get_children_and_consol(
self.cr, self.uid, debit_account_ids, 100, self.context, change_sign=True)
self.cr, self.uid, debit_account_ids, 100, self.context,
change_sign=True)
credit_account_ids = list(set(
credit_account_ids) - set(debit_account_ids))
@ -530,15 +608,19 @@ class account_balance(report_sxw.rml_parse):
tot_check = False
if not form['periods']:
form['periods'] = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)], order='date_start asc')
form['periods'] = period_obj.search(
self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id),
('special', '=', False)],
order='date_start asc')
if not form['periods']:
raise osv.except_osv(_('UserError'), _(
'The Selected Fiscal Year Does not have Regular Periods'))
if form['columns'] == 'qtr':
period_ids = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)], order='date_start asc')
period_ids = period_obj.search(
self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id),
('special', '=', False)],
order='date_start asc')
a = 0
l = []
p = []
@ -557,8 +639,10 @@ class account_balance(report_sxw.rml_parse):
tot_bal4 = 0.0
tot_bal5 = 0.0
elif form['columns'] == 'thirteen':
period_ids = period_obj.search(self.cr, self.uid, [(
'fiscalyear_id', '=', fiscalyear.id), ('special', '=', False)], order='date_start asc')
period_ids = period_obj.search(
self.cr, self.uid, [('fiscalyear_id', '=', fiscalyear.id),
('special', '=', False)],
order='date_start asc')
tot_bal1 = 0.0
tot_bal1 = 0.0
tot_bal2 = 0.0
@ -590,19 +674,21 @@ class account_balance(report_sxw.rml_parse):
# without repeating operations.
###############################################################
account_black_ids = account_obj.search(self.cr, self.uid, (
account_black_ids = account_obj.search(
self.cr, self.uid, (
[('id', 'in', [i[0] for i in all_account_ids]),
('type', 'not in',
('view', 'consolidation'))]))
('type', 'not in', ('view', 'consolidation'))]))
account_not_black_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [
i[0] for i in all_account_ids]), ('type', '=', 'view')]))
account_not_black_ids = account_obj.search(
self.cr, self.uid, ([('id', 'in', [i[0] for i in all_account_ids]),
('type', '=', 'view')]))
acc_cons_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [
i[0] for i in all_account_ids]), ('type', 'in', ('consolidation',))]))
acc_cons_ids = account_obj.search(
self.cr, self.uid, ([('id', 'in', [i[0] for i in all_account_ids]),
('type', 'in', ('consolidation',))]))
account_consol_ids = acc_cons_ids and account_obj._get_children_and_consol(
self.cr, self.uid, acc_cons_ids) or []
account_consol_ids = acc_cons_ids and account_obj.\
_get_children_and_consol(self.cr, self.uid, acc_cons_ids) or []
account_black_ids += account_obj.search(self.cr, self.uid, (
[('id', 'in', account_consol_ids),
@ -612,8 +698,7 @@ class account_balance(report_sxw.rml_parse):
account_black_ids = list(set(account_black_ids))
c_account_not_black_ids = account_obj.search(self.cr, self.uid, ([
('id', 'in',
account_consol_ids),
('id', 'in', account_consol_ids),
('type', '=', 'view')]))
delete_cons = False
if c_account_not_black_ids:
@ -684,7 +769,7 @@ class account_balance(report_sxw.rml_parse):
account_black_init = account_obj.browse(
self.cr, self.uid, account_black_ids, ctx_i)
#~ Black
# ~ Black
dict_black = {}
for i in account_black:
d = i.debit
@ -704,7 +789,7 @@ class account_balance(report_sxw.rml_parse):
for i in account_black_init:
dict_black.get(i.id)['balanceinit'] = i.balance
#~ Not black
# ~ Not black
dict_not_black = {}
for i in account_not_black:
dict_not_black[i.id] = {
@ -716,7 +801,8 @@ class account_balance(report_sxw.rml_parse):
) # It makes a copy because they modify
for acc_id in account_not_black_ids:
acc_childs = dict_not_black.get(acc_id).get('obj').type == 'view' \
acc_childs = dict_not_black.get(acc_id).get('obj').\
type == 'view' \
and dict_not_black.get(acc_id).get('obj').child_id \
or dict_not_black.get(acc_id).get('obj').child_consol_ids
for child_id in acc_childs:
@ -729,8 +815,8 @@ class account_balance(report_sxw.rml_parse):
dict_not_black.get(acc_id)['balance'] += all_account.get(
child_id.id).get('balance')
if form['inf_type'] == 'BS':
dict_not_black.get(acc_id)['balanceinit'] += all_account.get(
child_id.id).get('balanceinit')
dict_not_black.get(acc_id)['balanceinit'] += \
all_account.get(child_id.id).get('balanceinit')
all_account[acc_id] = dict_not_black[acc_id]
if p_act == limit - 1:
@ -753,17 +839,21 @@ class account_balance(report_sxw.rml_parse):
#
# Check if we need to include this level
#
if not form['display_account_level'] or aa_id[3].level <= form['display_account_level']:
if not form['display_account_level'] \
or aa_id[3].level <= form['display_account_level']:
res = {
'id': id,
'type': aa_id[3].type,
'code': aa_id[3].code,
'name': (aa_id[2] and not aa_id[1]) and 'TOTAL %s' % (aa_id[3].name.upper()) or aa_id[3].name,
'name': (aa_id[2] and not aa_id[1])
and 'TOTAL %s' % (aa_id[3].name.upper())
or aa_id[3].name,
'parent_id': aa_id[3].parent_id and aa_id[3].parent_id.id,
'level': aa_id[3].level,
'label': aa_id[1],
'total': aa_id[2],
'change_sign': credit_account_ids and (id in credit_account_ids and -1 or 1) or 1
'change_sign': credit_account_ids
and (id in credit_account_ids and -1 or 1) or 1
}
if form['columns'] == 'qtr':
@ -771,7 +861,12 @@ class account_balance(report_sxw.rml_parse):
if form['inf_type'] == 'IS':
d, c, b = map(z, [
all_account_period.get(pn - 1).get(id).get('debit', 0.0), all_account_period.get(pn - 1).get(id).get('credit', 0.0), all_account_period.get(pn - 1).get(id).get('balance', 0.0)])
all_account_period.get(pn - 1).
get(id).get('debit', 0.0),
all_account_period.get(pn - 1).
get(id).get('credit', 0.0),
all_account_period.get(pn - 1).
get(id).get('balance', 0.0)])
res.update({
'dbr%s' % pn: self.exchange(d),
'cdr%s' % pn: self.exchange(c),
@ -779,7 +874,12 @@ class account_balance(report_sxw.rml_parse):
})
else:
i, d, c = map(z, [
all_account_period.get(pn - 1).get(id).get('balanceinit', 0.0), all_account_period.get(pn - 1).get(id).get('debit', 0.0), all_account_period.get(pn - 1).get(id).get('credit', 0.0)])
all_account_period.get(pn - 1).
get(id).get('balanceinit', 0.0),
all_account_period.get(pn - 1).
get(id).get('debit', 0.0),
all_account_period.get(pn - 1).
get(id).get('credit', 0.0)])
b = z(i + d - c)
res.update({
'dbr%s' % pn: self.exchange(d),
@ -789,7 +889,12 @@ class account_balance(report_sxw.rml_parse):
if form['inf_type'] == 'IS':
d, c, b = map(z, [
all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0), all_account_period.get('all').get(id).get('balance')])
all_account_period.get('all').get(id).
get('debit', 0.0),
all_account_period.get('all').get(id).
get('credit', 0.0),
all_account_period.get('all').get(id).
get('balance')])
res.update({
'dbr5': self.exchange(d),
'cdr5': self.exchange(c),
@ -797,7 +902,12 @@ class account_balance(report_sxw.rml_parse):
})
else:
i, d, c = map(z, [
all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)])
all_account_period.get('all').get(id).
get('balanceinit', 0.0),
all_account_period.get('all').get(id).
get('debit', 0.0),
all_account_period.get('all').get(id).
get('credit', 0.0)])
b = z(i + d - c)
res.update({
'dbr5': self.exchange(d),
@ -811,7 +921,12 @@ class account_balance(report_sxw.rml_parse):
if form['inf_type'] == 'IS':
d, c, b = map(z, [
all_account_period.get(p_num).get(id).get('debit', 0.0), all_account_period.get(p_num).get(id).get('credit', 0.0), all_account_period.get(p_num).get(id).get('balance', 0.0)])
all_account_period.get(p_num).
get(id).get('debit', 0.0),
all_account_period.get(p_num).
get(id).get('credit', 0.0),
all_account_period.get(p_num).
get(id).get('balance', 0.0)])
res.update({
'dbr%s' % pn: self.exchange(d),
'cdr%s' % pn: self.exchange(c),
@ -819,7 +934,12 @@ class account_balance(report_sxw.rml_parse):
})
else:
i, d, c = map(z, [
all_account_period.get(p_num).get(id).get('balanceinit', 0.0), all_account_period.get(p_num).get(id).get('debit', 0.0), all_account_period.get(p_num).get(id).get('credit', 0.0)])
all_account_period.get(p_num).
get(id).get('balanceinit', 0.0),
all_account_period.get(p_num).
get(id).get('debit', 0.0),
all_account_period.get(p_num).
get(id).get('credit', 0.0)])
b = z(i + d - c)
res.update({
'dbr%s' % pn: self.exchange(d),
@ -831,7 +951,12 @@ class account_balance(report_sxw.rml_parse):
if form['inf_type'] == 'IS':
d, c, b = map(z, [
all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0), all_account_period.get('all').get(id).get('balance', 0.0)])
all_account_period.get('all').get(id).
get('debit', 0.0),
all_account_period.get('all').get(id).
get('credit', 0.0),
all_account_period.get('all').get(id).
get('balance', 0.0)])
res.update({
'dbr13': self.exchange(d),
'cdr13': self.exchange(c),
@ -839,7 +964,12 @@ class account_balance(report_sxw.rml_parse):
})
else:
i, d, c = map(z, [
all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)])
all_account_period.get('all').get(id).
get('balanceinit', 0.0),
all_account_period.get('all').get(id).
get('debit', 0.0),
all_account_period.get('all').get(id).
get('credit', 0.0)])
b = z(i + d - c)
res.update({
'dbr13': self.exchange(d),
@ -849,7 +979,12 @@ class account_balance(report_sxw.rml_parse):
else:
i, d, c = map(z, [
all_account_period.get('all').get(id).get('balanceinit', 0.0), all_account_period.get('all').get(id).get('debit', 0.0), all_account_period.get('all').get(id).get('credit', 0.0)])
all_account_period.get('all').get(id).
get('balanceinit', 0.0),
all_account_period.get('all').get(id).
get('debit', 0.0),
all_account_period.get('all').get(id).
get('credit', 0.0)])
b = z(i + d - c)
res.update({
'balanceinit': self.exchange(i),
@ -884,7 +1019,8 @@ class account_balance(report_sxw.rml_parse):
if any(to_test):
to_include = True
elif form['display_account'] == 'bal' and aa_id[3].parent_id:
elif form['display_account'] == 'bal' and aa_id[3].\
parent_id:
# Include accounts with balance
for x in range(pn - 1):
to_test.append(res.get(
@ -892,7 +1028,8 @@ class account_balance(report_sxw.rml_parse):
if any(to_test):
to_include = True
elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
elif form['display_account'] == 'bal_mov' and aa_id[3].\
parent_id:
# Include accounts with balance or movements
for x in range(pn - 1):
to_test.append(res.get(
@ -913,24 +1050,40 @@ class account_balance(report_sxw.rml_parse):
# Include accounts with movements
if abs(d) >= 0.005 or abs(c) >= 0.005:
to_include = True
elif form['display_account'] == 'bal' and aa_id[3].parent_id:
elif form['display_account'] == 'bal' and aa_id[3].\
parent_id:
# Include accounts with balance
if abs(b) >= 0.005:
to_include = True
elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
elif form['display_account'] == 'bal_mov' and aa_id[3].\
parent_id:
# Include accounts with balance or movements
if abs(b) >= 0.005 or abs(d) >= 0.005 or abs(c) >= 0.005:
if abs(b) >= 0.005 \
or abs(d) >= 0.005 \
or abs(c) >= 0.005:
to_include = True
else:
# Include all accounts
to_include = True
#~ ANALYTIC LEDGER
if to_include and form['analytic_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'):
# ~ ANALYTIC LEDGER
if to_include and form['analytic_ledger'] \
and form['columns'] == 'four' \
and form['inf_type'] == 'BS' \
and res['type'] in ('other', 'liquidity',
'receivable', 'payable'):
res['mayor'] = self._get_analytic_ledger(res, ctx=ctx_end)
elif to_include and form['journal_ledger'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'):
elif to_include and form['journal_ledger'] \
and form['columns'] == 'four' \
and form['inf_type'] == 'BS' \
and res['type'] in ('other', 'liquidity',
'receivable', 'payable'):
res['journal'] = self._get_journal_ledger(res, ctx=ctx_end)
elif to_include and form['partner_balance'] and form['columns'] == 'four' and form['inf_type'] == 'BS' and res['type'] in ('other', 'liquidity', 'receivable', 'payable'):
elif to_include and form['partner_balance'] \
and form['columns'] == 'four' \
and form['inf_type'] == 'BS' \
and res['type'] in ('other', 'liquidity',
'receivable', 'payable'):
res['partner'] = self._get_partner_balance(
res, ctx_i['periods'], ctx=ctx_end)
else:
@ -939,9 +1092,11 @@ class account_balance(report_sxw.rml_parse):
if to_include:
result_acc.append(res)
#
# Check whether we must sumarize this line in the report or not
# Check whether we must sumarize this line in the report
# or not
#
if form['tot_check'] and (res['id'] in account_list) and (res['id'] not in tot):
if form['tot_check'] and (res['id'] in account_list) \
and (res['id'] not in tot):
if form['columns'] == 'qtr':
tot_check = True
tot[res['id']] = True
@ -1019,55 +1174,64 @@ class account_balance(report_sxw.rml_parse):
result_acc.append(res2)
return result_acc
report_sxw.report_sxw('report.afr.1cols',
report_sxw.report_sxw(
'report.afr.1cols',
'wizard.report',
'account_financial_report/report/balance_full.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.2cols',
report_sxw.report_sxw(
'report.afr.2cols',
'wizard.report',
'account_financial_report/report/balance_full_2_cols.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.4cols',
report_sxw.report_sxw(
'report.afr.4cols',
'wizard.report',
'account_financial_report/report/balance_full_4_cols.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.analytic.ledger',
report_sxw.report_sxw(
'report.afr.analytic.ledger',
'wizard.report',
'account_financial_report/report/balance_full_4_cols_analytic_ledger.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.partner.balance',
report_sxw.report_sxw(
'report.afr.partner.balance',
'wizard.report',
'account_financial_report/report/balance_full_4_cols_partner_balance.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.journal.ledger',
report_sxw.report_sxw(
'report.afr.journal.ledger',
'wizard.report',
'account_financial_report/report/balance_full_4_cols_journal_ledger.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.5cols',
report_sxw.report_sxw(
'report.afr.5cols',
'wizard.report',
'account_financial_report/report/balance_full_5_cols.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.qtrcols',
report_sxw.report_sxw(
'report.afr.qtrcols',
'wizard.report',
'account_financial_report/report/balance_full_qtr_cols.rml',
parser=account_balance,
header=False)
report_sxw.report_sxw('report.afr.13cols',
report_sxw.report_sxw(
'report.afr.13cols',
'wizard.report',
'account_financial_report/report/balance_full_13_cols.rml',
parser=account_balance,

2
account_financial_report/wizard/__init__.py

@ -25,4 +25,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
import wizard
from . import wizard

195
account_financial_report/wizard/wizard.py

@ -26,43 +26,94 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##############################################################################
from osv import osv, fields
import pooler
from openerp.osv import osv, fields
import time
from tools.translate import _
from openerp.tools.translate import _
class wizard_report(osv.osv_memory):
_name = "wizard.report"
_columns = {
'afr_id': fields.many2one('afr', 'Custom Report', help='If you have already set a Custom Report, Select it Here.'),
'afr_id': fields.many2one(
'afr', 'Custom Report',
help='If you have already set a Custom Report, Select it Here.'),
'company_id': fields.many2one('res.company', 'Company', required=True),
'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
'inf_type': fields.selection([('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True),
'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'), ('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True),
'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'), ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'),
'display_account_level': fields.integer('Up to level', help='Display accounts up to this level (0 to show all)'),
'account_list': fields.many2many('account.account', 'rel_wizard_account', 'account_list', 'account_id', 'Root accounts', required=True),
'fiscalyear': fields.many2one('account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True),
'periods': fields.many2many('account.period', 'rel_wizard_period', 'wizard_id', 'period_id', 'Periods', help='All periods in the fiscal year if empty'),
'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'journal_ledger': fields.boolean('Journal Ledger', help="Allows to Generate an Journal Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'partner_balance': fields.boolean('Partner Balance', help="Allows to "
"Generate a Partner Balance for accounts with moves. Available when "
"Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
'lab_str': fields.char('Description', help='Description for the Summary', size=128),
'target_move': fields.selection([('posted', 'All Posted Entries'),
'currency_id': fields.many2one(
'res.currency', 'Currency',
help="Currency at which this report will be expressed. If not \
selected will be used the one set in the company"),
'inf_type': fields.selection([('BS', 'Balance Sheet'),
('IS', 'Income Statement')],
'Type',
required=True),
'columns': fields.selection(
[('one', 'End. Balance'),
('two', 'Debit | Credit'),
('four', 'Initial | Debit | Credit | YTD'),
('five', 'Initial | Debit | Credit | Period | YTD'),
('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')],
'Columns', required=True),
'display_account': fields.selection(
[('all', 'All Accounts'),
('bal', 'With Balance'),
('mov', 'With movements'),
('bal_mov', 'With Balance / Movements')],
'Display accounts'),
'display_account_level': fields.integer(
'Up to level',
help='Display accounts up to this level (0 to show all)'),
'account_list': fields.many2many('account.account',
'rel_wizard_account',
'account_list',
'account_id',
'Root accounts',
required=True),
'fiscalyear': fields.many2one('account.fiscalyear', 'Fiscal year',
help='Fiscal Year for this report',
required=True),
'periods': fields.many2many(
'account.period', 'rel_wizard_period',
'wizard_id', 'period_id', 'Periods',
help='All periods in the fiscal year if empty'),
'analytic_ledger': fields.boolean(
'Analytic Ledger',
help="Allows to Generate an Analytic Ledger for accounts with \
moves. Available when Balance Sheet and 'Initial | Debit | Credit \
| YTD' are selected"),
'journal_ledger': fields.boolean(
'Journal Ledger',
help="Allows to Generate an Journal Ledger for accounts with \
moves. Available when Balance Sheet and 'Initial | Debit | Credit \
| YTD' are selected"),
'partner_balance': fields.boolean(
'Partner Balance',
help="Allows to Generate a Partner Balance for accounts with \
moves. Available when Balance Sheet and 'Initial | Debit | Credit \
| YTD' are selected"),
'tot_check': fields.boolean('Summarize?',
help='Checking will add a new line at the \
end of the Report which will Summarize \
Columns in Report'),
'lab_str': fields.char('Description',
help='Description for the Summary', size=128),
'target_move': fields.selection(
[('posted', 'All Posted Entries'),
('all', 'All Entries'),
], 'Entries to Include', required=True,
help='Print All Accounting Entries or just Posted Accounting Entries'),
#~ Deprecated fields
'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'),
], 'Entries to Include',
required=True,
help='Print All Accounting Entries or just Posted Accounting \
Entries'),
# ~ Deprecated fields
'filter': fields.selection([('bydate', 'By Date'),
('byperiod', 'By Period'),
('all', 'By Date and Period'),
('none', 'No Filter')],
'Date/Period Filter'),
'date_to': fields.date('End date'),
'date_from': fields.date('Start date'),
}
@ -73,8 +124,10 @@ class wizard_report(osv.osv_memory):
'filter': lambda *a: 'byperiod',
'display_account_level': lambda *a: 0,
'inf_type': lambda *a: 'BS',
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c),
'fiscalyear': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid),
'company_id': lambda self, cr, uid, c: self.pool['res.company'].
_company_default_get(cr, uid, 'account.invoice', context=c),
'fiscalyear': lambda self, cr, uid, c: self.
pool['account.fiscalyear'].find(cr, uid),
'display_account': lambda *a: 'bal_mov',
'columns': lambda *a: 'five',
'target_move': 'posted',
@ -90,14 +143,16 @@ class wizard_report(osv.osv_memory):
return res
def onchange_columns(self, cr, uid, ids, columns, fiscalyear, periods, context=None):
def onchange_columns(self, cr, uid, ids, columns, fiscalyear, periods,
context=None):
if context is None:
context = {}
res = {'value': {}}
p_obj = self.pool.get("account.period")
all_periods = p_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear), (
'special', '=', False)], context=context)
all_periods = p_obj.search(cr, uid,
[('fiscalyear_id', '=', fiscalyear),
('special', '=', False)], context=context)
s = set(periods[0][2])
t = set(all_periods)
go = periods[0][2] and s.issubset(t) or False
@ -114,7 +169,8 @@ class wizard_report(osv.osv_memory):
res['value'].update({'periods': []})
return res
def onchange_analytic_ledger(self, cr, uid, ids, company_id, analytic_ledger, context=None):
def onchange_analytic_ledger(self, cr, uid, ids, company_id,
analytic_ledger, context=None):
if context is None:
context = {}
context['company_id'] = company_id
@ -152,20 +208,26 @@ class wizard_report(osv.osv_memory):
return res
afr_brw = self.pool.get('afr').browse(cr, uid, afr_id, context=context)
res['value'].update({
'currency_id': afr_brw.currency_id and afr_brw.currency_id.id or afr_brw.company_id.currency_id.id})
'currency_id': afr_brw.currency_id
and afr_brw.currency_id.id
or afr_brw.company_id.currency_id.id})
res['value'].update({'inf_type': afr_brw.inf_type or 'BS'})
res['value'].update({'columns': afr_brw.columns or 'five'})
res['value'].update({
'display_account': afr_brw.display_account or 'bal_mov'})
'display_account': afr_brw.display_account
or 'bal_mov'})
res['value'].update({
'display_account_level': afr_brw.display_account_level or 0})
'display_account_level': afr_brw.
display_account_level or 0})
res['value'].update({
'fiscalyear': afr_brw.fiscalyear_id and afr_brw.fiscalyear_id.id})
'fiscalyear': afr_brw.fiscalyear_id
and afr_brw.fiscalyear_id.id})
res['value'].update({'account_list': [
acc.id for acc in afr_brw.account_ids]})
res['value'].update({'periods': [p.id for p in afr_brw.period_ids]})
res['value'].update({
'analytic_ledger': afr_brw.analytic_ledger or False})
'analytic_ledger':
afr_brw.analytic_ledger or False})
res['value'].update({'tot_check': afr_brw.tot_check or False})
res['value'].update({'lab_str': afr_brw.lab_str or _(
'Write a Description for your Summary Total')})
@ -174,15 +236,14 @@ class wizard_report(osv.osv_memory):
def _get_defaults(self, cr, uid, data, context=None):
if context is None:
context = {}
user = pooler.get_pool(cr.dbname).get(
'res.users').browse(cr, uid, uid, context=context)
user = self.pool['res.users'].browse(cr, uid, uid, context=context)
if user.company_id:
company_id = user.company_id.id
else:
company_id = pooler.get_pool(cr.dbname).get(
'res.company').search(cr, uid, [('parent_id', '=', False)])[0]
company_id = self.pool['res.company'].search(
cr, uid, [('parent_id', '=', False)])[0]
data['form']['company_id'] = company_id
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
fiscalyear_obj = self.pool['account.fiscalyear']
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
data['form']['context'] = context
return data['form']
@ -209,9 +270,12 @@ class wizard_report(osv.osv_memory):
res = cr.dictfetchall()
if res:
if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_from'] < res[0]['date_start']):
raise osv.except_osv(_('UserError'), 'Las fechas deben estar entre %s y %s' % (
res[0]['date_start'], res[0]['date_stop']))
if (data['form']['date_to'] > res[0]['date_stop']
or data['form']['date_from'] < res[0]['date_start']):
raise osv.except_osv(_('UserError'),
'Las fechas deben estar entre %s y %s'
% (res[0]['date_start'],
res[0]['date_stop']))
else:
return 'report'
else:
@ -223,14 +287,20 @@ class wizard_report(osv.osv_memory):
ap_obj = self.pool.get('account.period')
fy_id = fy_id and type(fy_id) in (list, tuple) and fy_id[0] or fy_id
if not ids:
#~ No hay periodos
return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id), ('special', '=', False)], order='date_start asc')
# ~ No hay periodos
return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id),
('special', '=', False)],
order='date_start asc')
ap_brws = ap_obj.browse(cr, uid, ids, context=context)
date_start = min([period.date_start for period in ap_brws])
date_stop = max([period.date_stop for period in ap_brws])
return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id), ('special', '=', False), ('date_start', '>=', date_start), ('date_stop', '<=', date_stop)], order='date_start asc')
return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id),
('special', '=', False),
('date_start', '>=', date_start),
('date_stop', '<=', date_stop)],
order='date_start asc')
def print_report(self, cr, uid, ids, data, context=None):
if context is None:
@ -245,8 +315,10 @@ class wizard_report(osv.osv_memory):
del data['form']['date_from']
del data['form']['date_to']
data['form']['periods'] = self.period_span(cr, uid, data[
'form']['periods'], data['form']['fiscalyear'])
data['form']['periods'] = self.period_span(
cr, uid,
data['form']['periods'],
data['form']['fiscalyear'])
elif data['form']['filter'] == 'bydate':
self._check_date(cr, uid, data)
@ -259,13 +331,15 @@ class wizard_report(osv.osv_memory):
self._check_date(cr, uid, data)
lis2 = str(data['form']['periods']).replace(
"[", "(").replace("]", ")")
sqlmm = """select min(p.date_start) as inicio, max(p.date_stop) as fin
sqlmm = """select min(p.date_start) as inicio,
max(p.date_stop) as fin
from account_period p
where p.id in %s""" % lis2
cr.execute(sqlmm)
minmax = cr.dictfetchall()
if minmax:
if (data['form']['date_to'] < minmax[0]['inicio']) or (data['form']['date_from'] > minmax[0]['fin']):
if (data['form']['date_to'] < minmax[0]['inicio']) \
or (data['form']['date_from'] > minmax[0]['fin']):
raise osv.except_osv(_('Error !'), _(
'La interseccion entre el periodo y fecha es vacio'))
@ -274,11 +348,14 @@ class wizard_report(osv.osv_memory):
if data['form']['columns'] == 'two':
name = 'afr.2cols'
if data['form']['columns'] == 'four':
if data['form']['analytic_ledger'] and data['form']['inf_type'] == 'BS':
if data['form']['analytic_ledger'] \
and data['form']['inf_type'] == 'BS':
name = 'afr.analytic.ledger'
elif data['form']['journal_ledger'] and data['form']['inf_type'] == 'BS':
elif data['form']['journal_ledger'] \
and data['form']['inf_type'] == 'BS':
name = 'afr.journal.ledger'
elif data['form']['partner_balance'] and data['form']['inf_type'] == 'BS':
elif data['form']['partner_balance'] \
and data['form']['inf_type'] == 'BS':
name = 'afr.partner.balance'
else:
name = 'afr.4cols'
@ -289,6 +366,8 @@ class wizard_report(osv.osv_memory):
if data['form']['columns'] == 'thirteen':
name = 'afr.13cols'
return {'type': 'ir.actions.report.xml', 'report_name': name, 'datas': data}
return {'type': 'ir.actions.report.xml',
'report_name': name,
'datas': data}
wizard_report()

4
account_financial_report_horizontal/__init__.py

@ -1,2 +1,2 @@
import report
import wizard
from . import report
from . import wizard

6
account_financial_report_horizontal/report/__init__.py

@ -1,3 +1,3 @@
#import account_balance
import account_balance_sheet
import account_profit_loss
# import account_balance
from . import account_balance_sheet
from . import account_profit_loss

24
account_financial_report_horizontal/report/account_balance_sheet.py

@ -24,18 +24,18 @@
import time
import pooler
from report import report_sxw
from openerp.report import report_sxw
from openerp.addons.account_financial_report_horizontal.report import (
account_profit_loss
)
from common_report_header import common_report_header
from tools.translate import _
from openerp.tools.translate import _
class report_balancesheet_horizontal(
report_sxw.rml_parse, common_report_header
):
def __init__(self, cr, uid, name, context=None):
super(report_balancesheet_horizontal, self).__init__(
cr, uid, name, context=context)
@ -69,11 +69,9 @@ class report_balancesheet_horizontal(
def set_context(self, objects, data, ids, report_type=None):
new_ids = ids
if (data['model'] == 'ir.ui.menu'):
new_ids = 'chart_account_id' in data['form'] and data[
'form'
]['chart_account_id'] and [data[
'form'
]['chart_account_id'][0]] or []
new_ids = 'chart_account_id' in data['form'] \
and data['form']['chart_account_id'] \
and [data['form']['chart_account_id'][0]] or []
objects = self.pool.get('account.account').browse(
self.cr, self.uid, new_ids)
lang_dict = self.pool.get('res.users').read(
@ -98,14 +96,13 @@ class report_balancesheet_horizontal(
def get_data(self, data):
cr, uid = self.cr, self.uid
db_pool = pooler.get_pool(self.cr.dbname)
#Getting Profit or Loss Balance from profit and Loss report
# Getting Profit or Loss Balance from profit and Loss report
self.obj_pl.get_data(data)
self.res_bl = self.obj_pl.final_result()
account_pool = db_pool.get('account.account')
currency_pool = db_pool.get('res.currency')
account_pool = self.pool['account.account']
currency_pool = self.pool['res.currency']
types = [
'liability',
@ -124,7 +121,6 @@ class report_balancesheet_horizontal(
ctx['date_to'] = data['form'].get('date_to', False)
ctx['state'] = data['form'].get('target_move', 'all')
cal_list = {}
pl_dict = {}
account_dict = {}
account_id = data['form'].get('chart_account_id', False)
if account_id:
@ -278,5 +274,3 @@ report_sxw.report_sxw(
'account_balance_sheet.rml',
parser=report_balancesheet_horizontal,
header='internal')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

16
account_financial_report_horizontal/report/account_profit_loss.py

@ -22,10 +22,9 @@
##############################################################################
import time
import pooler
from report import report_sxw
from openerp.report import report_sxw
from common_report_header import common_report_header
from tools.translate import _
from openerp.tools.translate import _
class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header):
@ -63,8 +62,8 @@ class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header):
new_ids = ids
if (data['model'] == 'ir.ui.menu'):
new_ids = 'chart_account_id' in data['form'] and data['form'][
'chart_account_id'] and [data['form'][
'chart_account_id'][0]] or []
'chart_account_id'] and [data['form']['chart_account_id'][0]] \
or []
objects = self.pool.get('account.account').browse(
self.cr, self.uid, new_ids)
lang_dict = self.pool.get('res.users').read(
@ -101,10 +100,9 @@ class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header):
}
cr, uid = self.cr, self.uid
db_pool = pooler.get_pool(self.cr.dbname)
account_pool = db_pool.get('account.account')
currency_pool = db_pool.get('res.currency')
account_pool = self.pool['account.account']
currency_pool = self.pool['res.currency']
types = [
'expense',
@ -247,5 +245,3 @@ report_sxw.report_sxw(
'addons/account_financial_report_horizontal/report/'
'account_profit_loss.rml',
parser=report_pl_account_horizontal, header='internal')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

27
account_financial_report_horizontal/report/common_report_header.py

@ -19,8 +19,7 @@
#
##############################################################################
import pooler
from tools.translate import _
from openerp.tools.translate import _
class common_report_header(object):
@ -44,25 +43,25 @@ class common_report_header(object):
def get_start_period(self, data):
if data.get('form', False) and data['form'].get('period_from', False):
return pooler.get_pool(self.cr.dbname).get(
'account.period').browse(self.cr, self.uid, data[
'form']['period_from'][0]).name
return self.pool['account.period'].browse(
self.cr, self.uid,
data['form']['period_from'][0]).name
return ''
def get_end_period(self, data):
if data.get('form', False) and data['form'].get('period_to', False):
return pooler.get_pool(self.cr.dbname).get(
'account.period').browse(self.cr, self.uid, data[
'form']['period_to'][0]).name
return self.pool['account.period'].browse(
self.cr, self.uid,
data['form']['period_to'][0]).name
return ''
def _get_account(self, data):
if data.get('form', False) and data['form'].get(
'chart_account_id', False
):
return pooler.get_pool(self.cr.dbname).get(
'account.account').browse(self.cr, self.uid, data[
'form']['chart_account_id'][0]).name
return self.pool['account.account'].browse(
self.cr, self.uid,
data['form']['chart_account_id'][0]).name
return ''
def _get_sortby(self, data):
@ -80,7 +79,7 @@ class common_report_header(object):
if data.get('form', False) and data['form'].get(
'fiscalyear_id', False
):
return pooler.get_pool(self.cr.dbname).get(
'account.fiscalyear').browse(self.cr, self.uid, data[
'form']['fiscalyear_id'][0]).name
return self.pool['account.fiscalyear'].browse(
self.cr, self.uid,
data['form']['fiscalyear_id'][0]).name
return ''

8
account_financial_report_horizontal/wizard/__init__.py

@ -1,4 +1,4 @@
import account_report_common
import account_report_common_account
import account_report_balance_sheet
import account_report_profit_loss
from . import account_report_common
from . import account_report_common_account
from . import account_report_balance_sheet
from . import account_report_profit_loss

2
account_financial_report_horizontal/wizard/account_report_balance_sheet.py

@ -21,7 +21,7 @@
#
##############################################################################
from osv import orm, fields
from openerp.osv import orm, fields
class account_bs_report(orm.TransientModel):

4
account_financial_report_horizontal/wizard/account_report_common.py

@ -24,8 +24,8 @@
import time
from lxml import etree
from osv import fields, orm
from tools.translate import _
from openerp.osv import fields, orm
from openerp.tools.translate import _
class account_common_report(orm.TransientModel):

2
account_financial_report_horizontal/wizard/account_report_common_account.py

@ -21,7 +21,7 @@
#
##############################################################################
from osv import orm, fields
from openerp.osv import orm, fields
class account_common_account_report(orm.TransientModel):

2
account_financial_report_horizontal/wizard/account_report_profit_loss.py

@ -21,7 +21,7 @@
#
##############################################################################
from osv import orm, fields
from openerp.osv import orm, fields
class account_pl_report(orm.TransientModel):

2
account_financial_report_webkit/__init__.py

@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import account
from . import account
from . import wizard
from . import report
from . import account_move_line

23
account_financial_report_webkit/__openerp__.py

@ -35,7 +35,8 @@ This module adds or replaces the following standard OpenERP financial reports:
Main improvements per report:
-----------------------------
The General ledger: details of all entries posted in your books sorted by account.
The General ledger: details of all entries posted in your books sorted by
account.
* Filter by account is available in the wizard (no need to go to the
Chart of Accounts to do this anymore) or by View account (the report
@ -114,7 +115,8 @@ like the trial balance but add an extra information :
Overdue data are also split by period.
* For each partner following columns will be displayed:
* Total balance (all figures must match with same date partner balance report).
* Total balance (all figures must match with same date partner balance
report).
This column equals the sum of all following columns)
* Due
@ -126,11 +128,11 @@ like the trial balance but add an extra information :
Hypothesis / Contraints of aged partner balance
* Overdues columns will be by default be based on 30 days range fix number of days.
This can be changed by changes the RANGES constraint
* Overdues columns will be by default be based on 30 days range fix number of
days. This can be changed by changes the RANGES constraint
* All data will be displayed in company currency
* When partial payments, the payment must appear in the same colums than the invoice
(Except if multiple payment terms)
* When partial payments, the payment must appear in the same colums than the
invoice (Except if multiple payment terms)
* Data granularity: partner (will not display figures at invoices level)
* The report aggregate data per account with sub-totals
* Initial balance must be calculated the same way that
@ -173,12 +175,11 @@ wkhtmltopdf. The texts are defined inside the report classes.
'category': 'Finance',
'website': 'http://www.camptocamp.com',
'images': [
'images/ledger.png',],
'images/ledger.png', ],
'depends': ['account',
'report_webkit'],
'init_xml': [],
'demo_xml' : [],
'update_xml': ['account_view.xml',
'demo': [],
'data': ['account_view.xml',
'data/financial_webkit_header.xml',
'report/report.xml',
'wizard/wizard.xml',
@ -199,7 +200,7 @@ wkhtmltopdf. The texts are defined inside the report classes.
'tests/partner_balance.yml',
'tests/open_invoices.yml',
'tests/aged_trial_balance.yml'],
#'tests/account_move_line.yml'
# 'tests/account_move_line.yml'
'active': False,
'installable': True,
'application': True,

31
account_financial_report_webkit/account_move_line.py

@ -20,16 +20,18 @@
##############################################################################
from openerp.osv import fields, orm
from openerp.tools.translate import _
class AccountMoveLine(orm.Model):
"""Overriding Account move line in order to add last_rec_date.
Last rec date is the date of the last reconciliation (full or partial) account move line"""
Last rec date is the date of the last reconciliation (full or partial)
account move line"""
_inherit = 'account.move.line'
def init(self, cr):
##We do not want to catch error as if sql is not run it will give invalid data
# We do not want to catch error as if sql is not run it will give
# invalid data
cr.execute("UPDATE account_move_line as acm "
" SET last_rec_date ="
" (SELECT date from account_move_line"
@ -41,14 +43,16 @@ class AccountMoveLine(orm.Model):
cr.execute("UPDATE account_move_line as acm "
" SET last_rec_date ="
" (SELECT date from account_move_line"
" WHERE reconcile_partial_id = acm.reconcile_partial_id"
" WHERE reconcile_partial_id"
" = acm.reconcile_partial_id"
" AND reconcile_partial_id IS NOT NULL"
" ORDER BY date DESC LIMIT 1)"
" WHERE last_rec_date is null;")
def _get_move_line_from_line_rec(self, cr, uid, ids, context=None):
moves = []
for reconcile in self.pool.get('account.move.reconcile').browse(cr, uid, ids, context=context):
for reconcile in self.pool['account.move.reconcile'].browse(
cr, uid, ids, context=context):
for move_line in reconcile.line_partial_ids:
moves.append(move_line.id)
for move_line in reconcile.line_id:
@ -64,8 +68,9 @@ class AccountMoveLine(orm.Model):
rec = line.reconcile_id or line.reconcile_partial_id or False
if rec:
# we use cursor in order to gain some perfs
cursor.execute('SELECT date from account_move_line where'
' reconcile_id = %s OR reconcile_partial_id = %s'
cursor.execute('SELECT date from account_move_line'
' WHERE reconcile_id = %s'
' OR reconcile_partial_id = %s'
' ORDER BY date DESC LIMIT 1 ',
(rec.id, rec.id))
res_set = cursor.fetchone()
@ -74,12 +79,16 @@ class AccountMoveLine(orm.Model):
return res
_columns = {
'last_rec_date': fields.function(_get_last_rec_date,
'last_rec_date': fields.function(
_get_last_rec_date,
method=True,
string='Last reconciliation date',
store={'account.move.line': (lambda self, cr, uid, ids, c={}: ids, ['date'], 20),
'account.move.reconcile': (_get_move_line_from_line_rec, None, 20)},
store={'account.move.line': (lambda self, cr, uid, ids, c={}: ids,
['date'], 20),
'account.move.reconcile': (_get_move_line_from_line_rec,
None, 20)},
type='date',
multi='all',
help="the date of the last reconciliation (full or partial) account move line"),
help="the date of the last reconciliation (full or partial) \
account move line"),
}

37
account_financial_report_webkit/report/aged_partner_balance.py

@ -35,14 +35,15 @@ def make_ranges(top, offset):
:param offset: offset for ranges
:returns: list of sorted ranges tuples in days
eg. [(-100000, 0), (0, offset), (offset, n*offset), ... (top, 100000)]
eg. [(-100000, 0), (0, offset),
(offset, n*offset), ... (top, 100000)]
"""
ranges = [(n, min(n + offset, top)) for n in xrange(0, top, offset)]
ranges.insert(0, (-100000000000, 0))
ranges.append((top, 100000000000))
return ranges
#list of overdue ranges
# list of overdue ranges
RANGES = make_ranges(120, 30)
@ -53,20 +54,22 @@ def make_ranges_titles():
titles.append(_('Older'))
return titles
#list of overdue ranges title
# list of overdue ranges title
RANGES_TITLES = make_ranges_titles()
#list of payable journal types
# list of payable journal types
REC_PAY_TYPE = ('purchase', 'sale')
#list of refund payable type
# list of refund payable type
REFUND_TYPE = ('purchase_refund', 'sale_refund')
INV_TYPE = REC_PAY_TYPE + REFUND_TYPE
class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
"""Compute Aged Partner Balance based on result of Open Invoices"""
def __init__(self, cursor, uid, name, context=None):
"""Constructor, refer to :class:`openerp.report.report_sxw.rml_parse`"""
"""Constructor,
refer to :class:`openerp.report.report_sxw.rml_parse`"""
super(AccountAgedTrialBalanceWebkit, self).__init__(cursor, uid, name,
context=context)
self.pool = pooler.get_pool(self.cr.dbname)
@ -95,7 +98,8 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
('--header-left', header_report_name),
('--header-spacing', '2'),
('--footer-left', footer_date_time),
('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-right',
' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-line',),
],
})
@ -141,9 +145,10 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
data)
if aged_lines:
acc.aged_lines[part_id] = aged_lines
acc.aged_totals = totals = self.compute_totals(acc.aged_lines.values())
acc.aged_totals = totals = self.compute_totals(
acc.aged_lines.values())
acc.aged_percents = self.compute_percents(totals)
#Free some memory
# Free some memory
del(acc.ledger_lines)
return res
@ -265,17 +270,18 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
:returns: delta in days
"""
sale_lines = [x for x in ledger_lines if x['jtype'] in REC_PAY_TYPE and
line['rec_id'] == x['rec_id']]
refund_lines = [x for x in ledger_lines if x['jtype'] in REFUND_TYPE and
line['rec_id'] == x['rec_id']]
sale_lines = [x for x in ledger_lines if x['jtype'] in REC_PAY_TYPE
and line['rec_id'] == x['rec_id']]
refund_lines = [x for x in ledger_lines if x['jtype'] in REFUND_TYPE
and line['rec_id'] == x['rec_id']]
if len(sale_lines) == 1:
reference_line = sale_lines[0]
elif len(refund_lines) == 1:
reference_line = refund_lines[0]
else:
reference_line = line
key = 'date_maturity' if reference_line.get('date_maturity') else 'ldate'
key = 'date_maturity' if reference_line.get(
'date_maturity') else 'ldate'
return self._compute_delay_from_key(key,
reference_line,
end_date)
@ -398,6 +404,7 @@ class AccountAgedTrialBalanceWebkit(PartnersOpenInvoicesWebkit):
HeaderFooterTextWebKitParser(
'report.account.account_aged_trial_balance_webkit',
'account.account',
'addons/account_financial_report_webkit/report/templates/aged_trial_webkit.mako',
'addons/account_financial_report_webkit/report/templates/\
aged_trial_webkit.mako',
parser=AccountAgedTrialBalanceWebkit,
)

154
account_financial_report_webkit/report/common_balance_reports.py

@ -26,7 +26,9 @@ from .common_reports import CommonReportHeaderWebkit
class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
"""Define common helper for balance (trial balance, P&L, BS oriented financial report"""
"""Define common helper for balance (trial balance, P&L, BS oriented
financial report"""
def _get_numbers_display(self, data):
return self._get_form_param('numbers_display', data)
@ -35,7 +37,9 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
def find_key_by_value_in_list(dic, value):
return [key for key, val in dic.iteritems() if value in val][0]
def _get_account_details(self, account_ids, target_move, fiscalyear, main_filter, start, stop, initial_balance_mode, context=None):
def _get_account_details(self, account_ids, target_move, fiscalyear,
main_filter, start, stop, initial_balance_mode,
context=None):
"""
Get details of accounts to display on the report
@param account_ids: ids of accounts to get details
@ -44,21 +48,26 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
@param main_filter: selection filter period / date or none
@param start: start date or start period browse instance
@param stop: stop date or stop period browse instance
@param initial_balance_mode: False: no calculation, 'opening_balance': from the opening period, 'initial_balance': computed from previous year / periods
@return: dict of list containing accounts details, keys are the account ids
@param initial_balance_mode: False: no calculation,
'opening_balance': from the opening period,
'initial_balance': computed from previous year / periods
@return: dict of list containing accounts details, keys are
the account ids
"""
if context is None:
context = {}
account_obj = self.pool.get('account.account')
period_obj = self.pool.get('account.period')
use_period_ids = main_filter in ('filter_no', 'filter_period', 'filter_opening')
use_period_ids = main_filter in (
'filter_no', 'filter_period', 'filter_opening')
if use_period_ids:
if main_filter == 'filter_opening':
period_ids = [start.id]
else:
period_ids = period_obj.build_ctx_periods(self.cursor, self.uid, start.id, stop.id)
period_ids = period_obj.build_ctx_periods(
self.cursor, self.uid, start.id, stop.id)
# never include the opening in the debit / credit amounts
period_ids = self.exclude_opening_periods(period_ids)
@ -66,7 +75,8 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
if initial_balance_mode == 'opening_balance':
init_balance = self._read_opening_balance(account_ids, start)
elif initial_balance_mode:
init_balance = self._compute_initial_balances(account_ids, start, fiscalyear)
init_balance = self._compute_initial_balances(
account_ids, start, fiscalyear)
ctx = context.copy()
ctx.update({'state': target_move,
@ -82,14 +92,16 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
self.cursor,
self.uid,
account_ids,
['type', 'code', 'name', 'debit', 'credit', 'balance', 'parent_id', 'level', 'child_id'],
['type', 'code', 'name', 'debit', 'credit',
'balance', 'parent_id', 'level', 'child_id'],
ctx)
accounts_by_id = {}
for account in accounts:
if init_balance:
# sum for top level views accounts
child_ids = account_obj._get_children_and_consol(self.cursor, self.uid, account['id'], ctx)
child_ids = account_obj._get_children_and_consol(
self.cursor, self.uid, account['id'], ctx)
if child_ids:
child_init_balances = [
init_bal['init_balance']
@ -99,22 +111,30 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
account['init_balance'] = top_init_balance
else:
account.update(init_balance[account['id']])
account['balance'] = account['init_balance'] + account['debit'] - account['credit']
account['balance'] = account['init_balance'] + \
account['debit'] - account['credit']
accounts_by_id[account['id']] = account
return accounts_by_id
def _get_comparison_details(self, data, account_ids, target_move, comparison_filter, index):
def _get_comparison_details(self, data, account_ids, target_move,
comparison_filter, index):
"""
@param data: data of the wizard form
@param account_ids: ids of the accounts to get details
@param comparison_filter: selected filter on the form for the comparison (filter_no, filter_year, filter_period, filter_date)
@param index: index of the fields to get (ie. comp1_fiscalyear_id where 1 is the index)
@param comparison_filter: selected filter on the form for
the comparison (filter_no, filter_year, filter_period,
filter_date)
@param index: index of the fields to get
(ie. comp1_fiscalyear_id where 1 is the index)
@return: dict of account details (key = account id)
"""
fiscalyear = self._get_info(data, "comp%s_fiscalyear_id" % (index,), 'account.fiscalyear')
start_period = self._get_info(data, "comp%s_period_from" % (index,), 'account.period')
stop_period = self._get_info(data, "comp%s_period_to" % (index,), 'account.period')
fiscalyear = self._get_info(
data, "comp%s_fiscalyear_id" % (index,), 'account.fiscalyear')
start_period = self._get_info(
data, "comp%s_period_from" % (index,), 'account.period')
stop_period = self._get_info(
data, "comp%s_period_to" % (index,), 'account.period')
start_date = self._get_form_param("comp%s_date_from" % (index,), data)
stop_date = self._get_form_param("comp%s_date_to" % (index,), data)
init_balance = self.is_initial_balance_enabled(comparison_filter)
@ -124,12 +144,16 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
details_filter = comparison_filter
if comparison_filter != 'filter_no':
start_period, stop_period, start, stop = \
self._get_start_stop_for_filter(comparison_filter, fiscalyear, start_date, stop_date, start_period, stop_period)
self._get_start_stop_for_filter(
comparison_filter, fiscalyear, start_date, stop_date,
start_period, stop_period)
if comparison_filter == 'filter_year':
details_filter = 'filter_no'
initial_balance_mode = init_balance and self._get_initial_balance_mode(start) or False
accounts_by_ids = self._get_account_details(account_ids, target_move, fiscalyear, details_filter,
initial_balance_mode = init_balance \
and self._get_initial_balance_mode(start) or False
accounts_by_ids = self._get_account_details(
account_ids, target_move, fiscalyear, details_filter,
start, stop, initial_balance_mode)
comp_params = {
'comparison_filter': comparison_filter,
@ -146,14 +170,16 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
"""
@param balance: current balance
@param previous_balance: last balance
@return: dict of form {'diff': difference, 'percent_diff': diff in percentage}
@return: dict of form {'diff': difference,
'percent_diff': diff in percentage}
"""
diff = balance - previous_balance
obj_precision = self.pool.get('decimal.precision')
precision = obj_precision.precision_get(self.cursor, self.uid, 'Account')
# round previous balance with account precision to avoid big numbers if previous
# balance is 0.0000001 or a any very small number
precision = obj_precision.precision_get(
self.cursor, self.uid, 'Account')
# round previous balance with account precision to avoid big numbers
# if previous balance is 0.0000001 or a any very small number
if round(previous_balance, precision) == 0:
percent_diff = False
else:
@ -165,13 +191,18 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
"""
@param data: data of the report
@param comparison_number: number of comparisons
@return: list of comparison filters, nb of comparisons used and comparison mode (no_comparison, single, multiple)
@return: list of comparison filters, nb of comparisons used and
comparison mode (no_comparison, single, multiple)
"""
comp_filters = []
for index in range(comparison_number):
comp_filters.append(self._get_form_param("comp%s_filter" % (index,), data, default='filter_no'))
comp_filters.append(
self._get_form_param("comp%s_filter" % (index,), data,
default='filter_no'))
nb_comparisons = len([comp_filter for comp_filter in comp_filters if comp_filter != 'filter_no'])
nb_comparisons = len(
[comp_filter for comp_filter in comp_filters
if comp_filter != 'filter_no'])
if not nb_comparisons:
comparison_mode = 'no_comparison'
elif nb_comparisons > 1:
@ -180,12 +211,14 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
comparison_mode = 'single'
return comp_filters, nb_comparisons, comparison_mode
def _get_start_stop_for_filter(self, main_filter, fiscalyear, start_date, stop_date, start_period, stop_period):
def _get_start_stop_for_filter(self, main_filter, fiscalyear, start_date,
stop_date, start_period, stop_period):
if main_filter in ('filter_no', 'filter_year'):
start_period = self.get_first_fiscalyear_period(fiscalyear)
stop_period = self.get_last_fiscalyear_period(fiscalyear)
elif main_filter == 'filter_opening':
opening_period = self._get_st_fiscalyear_period(fiscalyear, special=True)
opening_period = self._get_st_fiscalyear_period(
fiscalyear, special=True)
start_period = stop_period = opening_period
if main_filter == 'filter_date':
start = start_date
@ -197,11 +230,14 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
return start_period, stop_period, start, stop
def compute_balance_data(self, data, filter_report_type=None):
new_ids = data['form']['account_ids'] or data['form']['chart_account_id']
max_comparison = self._get_form_param('max_comparison', data, default=0)
new_ids = data['form']['account_ids'] or data[
'form']['chart_account_id']
max_comparison = self._get_form_param(
'max_comparison', data, default=0)
main_filter = self._get_form_param('filter', data, default='filter_no')
comp_filters, nb_comparisons, comparison_mode = self._comp_filters(data, max_comparison)
comp_filters, nb_comparisons, comparison_mode = self._comp_filters(
data, max_comparison)
fiscalyear = self.get_fiscalyear_br(data)
@ -214,51 +250,75 @@ class CommonBalanceReportHeaderWebkit(CommonReportHeaderWebkit):
chart_account = self._get_chart_account_id_br(data)
start_period, stop_period, start, stop = \
self._get_start_stop_for_filter(main_filter, fiscalyear, start_date, stop_date, start_period, stop_period)
self._get_start_stop_for_filter(main_filter, fiscalyear,
start_date, stop_date,
start_period, stop_period)
init_balance = self.is_initial_balance_enabled(main_filter)
initial_balance_mode = init_balance and self._get_initial_balance_mode(start) or False
initial_balance_mode = init_balance and self._get_initial_balance_mode(
start) or False
# Retrieving accounts
account_ids = self.get_all_accounts(new_ids, only_type=filter_report_type)
account_ids = self.get_all_accounts(
new_ids, only_type=filter_report_type)
# get details for each accounts, total of debit / credit / balance
accounts_by_ids = self._get_account_details(account_ids, target_move, fiscalyear, main_filter, start, stop, initial_balance_mode)
accounts_by_ids = self._get_account_details(
account_ids, target_move, fiscalyear, main_filter, start, stop,
initial_balance_mode)
comparison_params = []
comp_accounts_by_ids = []
for index in range(max_comparison):
if comp_filters[index] != 'filter_no':
comparison_result, comp_params = self._get_comparison_details(data, account_ids, target_move, comp_filters[index], index)
comparison_result, comp_params = self._get_comparison_details(
data, account_ids, target_move, comp_filters[index], index)
comparison_params.append(comp_params)
comp_accounts_by_ids.append(comparison_result)
to_display = dict.fromkeys(account_ids, True)
objects = []
for account in self.pool.get('account.account').browse(self.cursor, self.uid, account_ids):
for account in self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids):
if not account.parent_id: # hide top level account
continue
if account.type == 'consolidation':
to_display.update(dict([(a.id, False) for a in account.child_consol_ids]))
to_display.update(
dict([(a.id, False) for a in account.child_consol_ids]))
elif account.type == 'view':
to_display.update(dict([(a.id, True) for a in account.child_id]))
to_display.update(
dict([(a.id, True) for a in account.child_id]))
account.debit = accounts_by_ids[account.id]['debit']
account.credit = accounts_by_ids[account.id]['credit']
account.balance = accounts_by_ids[account.id]['balance']
account.init_balance = accounts_by_ids[account.id].get('init_balance', 0.0)
account.init_balance = accounts_by_ids[
account.id].get('init_balance', 0.0)
display_account = False # if any amount is != 0 in comparisons, we have to display the whole account
# if any amount is != 0 in comparisons, we have to display the
# whole account
display_account = False
comp_accounts = []
for comp_account_by_id in comp_accounts_by_ids:
values = comp_account_by_id.get(account.id)
values.update(self._get_diff(account.balance, values['balance']))
display_account = any((values.get('credit', 0.0), values.get('debit', 0.0), values.get('balance', 0.0), values.get('init_balance', 0.0)))
values.update(
self._get_diff(account.balance, values['balance']))
display_account = any((values.get('credit', 0.0),
values.get('debit', 0.0),
values.get('balance', 0.0),
values.get('init_balance', 0.0)))
comp_accounts.append(values)
account.comparisons = comp_accounts
# we have to display the account if a comparison as an amount or if we have an amount in the main column
# we set it as a property to let the data in the report if someone want to use it in a custom report
display_account = display_account or any((account.debit, account.credit, account.balance, account.init_balance))
to_display.update({account.id: display_account and to_display[account.id]})
# we have to display the account if a comparison as an amount or
# if we have an amount in the main column
# we set it as a property to let the data in the report if someone
# want to use it in a custom report
display_account = display_account or any((account.debit,
account.credit,
account.balance,
account.init_balance))
to_display.update(
{account.id: display_account and to_display[account.id]})
objects.append(account)
for account in objects:

182
account_financial_report_webkit/report/common_partner_balance_reports.py

@ -27,11 +27,16 @@ from .common_balance_reports import CommonBalanceReportHeaderWebkit
from .common_partner_reports import CommonPartnersReportHeaderWebkit
class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit, CommonPartnersReportHeaderWebkit):
"""Define common helper for balance (trial balance, P&L, BS oriented financial report"""
class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit,
CommonPartnersReportHeaderWebkit):
def _get_account_partners_details(self, account_by_ids, main_filter, target_move, start,
stop, initial_balance_mode, partner_filter_ids=False):
"""Define common helper for balance (trial balance, P&L,
BS oriented financial report"""
def _get_account_partners_details(self, account_by_ids, main_filter,
target_move, start, stop,
initial_balance_mode,
partner_filter_ids=False):
res = {}
filter_from = False
if main_filter in ('filter_period', 'filter_no', 'filter_opening'):
@ -41,16 +46,19 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit, Co
partners_init_balances_by_ids = {}
for account_id, account_details in account_by_ids.iteritems():
partners_init_balances_by_ids.update(self._get_partners_initial_balances(account_id,
start,
initial_balance_mode,
partners_init_balances_by_ids.update(
self._get_partners_initial_balances(
account_id, start, initial_balance_mode,
partner_filter_ids=partner_filter_ids,
exclude_reconcile=False)) # we'll never exclude reconciled entries in the legal reports
# we'll never exclude reconciled entries in the legal
# reports
exclude_reconcile=False))
opening_mode = 'exclude_opening'
if main_filter == 'filter_opening':
opening_mode = 'include_opening'
# get credit and debit for partner
details = self._get_partners_totals_account(filter_from,
details = self._get_partners_totals_account(
filter_from,
account_id,
start,
stop,
@ -60,32 +68,49 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit, Co
# merge initial balances in partner details
if partners_init_balances_by_ids.get(account_id):
for partner_id, initial_balances in partners_init_balances_by_ids[account_id].iteritems():
for partner_id, initial_balances in \
partners_init_balances_by_ids[account_id].iteritems():
if initial_balances.get('init_balance'):
details[partner_id].update({'init_balance': initial_balances['init_balance']})
details[partner_id].update(
{'init_balance': initial_balances['init_balance']})
# compute balance for the partner
for partner_id, partner_details in details.iteritems():
details[partner_id]['balance'] = details[partner_id].get('init_balance', 0.0) +\
details[partner_id].get('debit', 0.0) -\
details[partner_id]['balance'] = details[partner_id].\
get('init_balance', 0.0) + \
details[partner_id].get('debit', 0.0) - \
details[partner_id].get('credit', 0.0)
res[account_id] = details
return res
def _get_partners_initial_balances(self, account_ids, start_period, initial_balance_mode, partner_filter_ids=None, exclude_reconcile=False):
# we get the initial balance from the opening period (opening_balance) when the opening period is included in the start period and
# when there is at least one entry in the opening period. Otherwise we compute it from previous periods
def _get_partners_initial_balances(self, account_ids, start_period,
initial_balance_mode,
partner_filter_ids=None,
exclude_reconcile=False):
# we get the initial balance from the opening period (opening_balance)
# when the opening period is included in the start period and
# when there is at least one entry in the opening period. Otherwise we
# compute it from previous periods
if initial_balance_mode == 'opening_balance':
opening_period_selected = self.get_included_opening_period(start_period)
res = self._compute_partners_initial_balances(account_ids, start_period, partner_filter_ids, force_period_ids=opening_period_selected, exclude_reconcile=exclude_reconcile)
opening_period_selected = self.get_included_opening_period(
start_period)
res = self._compute_partners_initial_balances(
account_ids, start_period, partner_filter_ids,
force_period_ids=opening_period_selected,
exclude_reconcile=exclude_reconcile)
elif initial_balance_mode == 'initial_balance':
res = self._compute_partners_initial_balances(account_ids, start_period, partner_filter_ids, exclude_reconcile=exclude_reconcile)
res = self._compute_partners_initial_balances(
account_ids, start_period, partner_filter_ids,
exclude_reconcile=exclude_reconcile)
else:
res = {}
return res
def _get_partners_totals_account(self, filter_from, account_id, start, stop, target_move, partner_filter_ids=None, mode='exclude_opening'):
def _get_partners_totals_account(self, filter_from, account_id, start,
stop, target_move,
partner_filter_ids=None,
mode='exclude_opening'):
final_res = defaultdict(dict)
sql_select = """
@ -94,17 +119,20 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit, Co
sum(account_move_line.credit) AS credit
FROM account_move_line"""
sql_joins = ''
sql_where = "WHERE account_move_line.account_id = %(account_id)s AND account_move_line.state = 'valid' "
sql_where = "WHERE account_move_line.account_id = %(account_id)s \
AND account_move_line.state = 'valid' "
method = getattr(self, '_get_query_params_from_' + filter_from + 's')
sql_conditions, search_params = method(start, stop, mode=mode)
sql_where += sql_conditions
if partner_filter_ids:
sql_where += " AND account_move_line.partner_id in %(partner_ids)s"
sql_where += " AND account_move_line.partner_id \
in %(partner_ids)s"
search_params.update({'partner_ids': tuple(partner_filter_ids)})
if target_move == 'posted':
sql_joins += "INNER JOIN account_move ON account_move_line.move_id = account_move.id"
sql_joins += "INNER JOIN account_move \
ON account_move_line.move_id = account_move.id"
sql_where += " AND account_move.state = %(target_move)s"
search_params.update({'target_move': target_move})
@ -128,19 +156,26 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit, Co
filter_type = ('payable',)
return filter_type
def _get_partners_comparison_details(self, data, account_ids, target_move, comparison_filter, index, partner_filter_ids=False):
def _get_partners_comparison_details(self, data, account_ids, target_move,
comparison_filter, index,
partner_filter_ids=False):
"""
@param data: data of the wizard form
@param account_ids: ids of the accounts to get details
@param comparison_filter: selected filter on the form for the comparison (filter_no, filter_year, filter_period, filter_date)
@param index: index of the fields to get (ie. comp1_fiscalyear_id where 1 is the index)
@param comparison_filter: selected filter on the form for
the comparison (filter_no, filter_year, filter_period, filter_date)
@param index: index of the fields to get (ie. comp1_fiscalyear_id
where 1 is the index)
@param partner_filter_ids: list of ids of partners to select
@return: dict of account details (key = account id)
"""
fiscalyear = self._get_info(data, "comp%s_fiscalyear_id" % (index,), 'account.fiscalyear')
start_period = self._get_info(data, "comp%s_period_from" % (index,), 'account.period')
stop_period = self._get_info(data, "comp%s_period_to" % (index,), 'account.period')
fiscalyear = self._get_info(
data, "comp%s_fiscalyear_id" % (index,), 'account.fiscalyear')
start_period = self._get_info(
data, "comp%s_period_from" % (index,), 'account.period')
stop_period = self._get_info(
data, "comp%s_period_to" % (index,), 'account.period')
start_date = self._get_form_param("comp%s_date_from" % (index,), data)
stop_date = self._get_form_param("comp%s_date_to" % (index,), data)
init_balance = self.is_initial_balance_enabled(comparison_filter)
@ -149,22 +184,30 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit, Co
accounts_details_by_ids = defaultdict(dict)
if comparison_filter != 'filter_no':
start_period, stop_period, start, stop = \
self._get_start_stop_for_filter(comparison_filter, fiscalyear, start_date, stop_date, start_period, stop_period)
self._get_start_stop_for_filter(
comparison_filter, fiscalyear, start_date, stop_date,
start_period, stop_period)
details_filter = comparison_filter
if comparison_filter == 'filter_year':
details_filter = 'filter_no'
initial_balance_mode = init_balance and self._get_initial_balance_mode(start) or False
initial_balance_mode = init_balance \
and self._get_initial_balance_mode(start) or False
accounts_by_ids = self._get_account_details(account_ids, target_move, fiscalyear, details_filter, start, stop, initial_balance_mode)
accounts_by_ids = self._get_account_details(
account_ids, target_move, fiscalyear, details_filter, start,
stop, initial_balance_mode)
partner_details_by_ids = self._get_account_partners_details(accounts_by_ids, details_filter,
partner_details_by_ids = self._get_account_partners_details(
accounts_by_ids, details_filter,
target_move, start, stop, initial_balance_mode,
partner_filter_ids=partner_filter_ids)
for account_id in account_ids:
accounts_details_by_ids[account_id]['account'] = accounts_by_ids[account_id]
accounts_details_by_ids[account_id]['partners_amounts'] = partner_details_by_ids[account_id]
accounts_details_by_ids[account_id][
'account'] = accounts_by_ids[account_id]
accounts_details_by_ids[account_id][
'partners_amounts'] = partner_details_by_ids[account_id]
comp_params = {
'comparison_filter': comparison_filter,
@ -177,11 +220,14 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit, Co
return accounts_details_by_ids, comp_params
def compute_partner_balance_data(self, data, filter_report_type=None):
new_ids = data['form']['account_ids'] or data['form']['chart_account_id']
max_comparison = self._get_form_param('max_comparison', data, default=0)
new_ids = data['form']['account_ids'] or data[
'form']['chart_account_id']
max_comparison = self._get_form_param(
'max_comparison', data, default=0)
main_filter = self._get_form_param('filter', data, default='filter_no')
comp_filters, nb_comparisons, comparison_mode = self._comp_filters(data, max_comparison)
comp_filters, nb_comparisons, comparison_mode = self._comp_filters(
data, max_comparison)
fiscalyear = self.get_fiscalyear_br(data)
@ -197,62 +243,78 @@ class CommonPartnerBalanceReportHeaderWebkit(CommonBalanceReportHeaderWebkit, Co
filter_type = self._get_filter_type(result_selection)
start_period, stop_period, start, stop = \
self._get_start_stop_for_filter(main_filter, fiscalyear, start_date, stop_date, start_period, stop_period)
self._get_start_stop_for_filter(
main_filter, fiscalyear, start_date, stop_date, start_period,
stop_period)
initial_balance = self.is_initial_balance_enabled(main_filter)
initial_balance_mode = initial_balance and self._get_initial_balance_mode(start) or False
initial_balance_mode = initial_balance \
and self._get_initial_balance_mode(start) or False
# Retrieving accounts
account_ids = self.get_all_accounts(new_ids, only_type=filter_type,
account_ids = self.get_all_accounts(
new_ids, only_type=filter_type,
filter_report_type=filter_report_type)
# get details for each accounts, total of debit / credit / balance
accounts_by_ids = self._get_account_details(account_ids, target_move, fiscalyear, main_filter, start, stop, initial_balance_mode)
accounts_by_ids = self._get_account_details(
account_ids, target_move, fiscalyear, main_filter, start, stop,
initial_balance_mode)
partner_details_by_ids = self._get_account_partners_details(accounts_by_ids,
main_filter,
target_move,
start,
stop,
initial_balance_mode,
partner_filter_ids=partner_ids)
partner_details_by_ids = self._get_account_partners_details(
accounts_by_ids, main_filter, target_move, start, stop,
initial_balance_mode, partner_filter_ids=partner_ids)
comparison_params = []
comp_accounts_by_ids = []
for index in range(max_comparison):
if comp_filters[index] != 'filter_no':
comparison_result, comp_params = self._get_partners_comparison_details(data, account_ids,
target_move, comp_filters[index],
index, partner_filter_ids=partner_ids)
comparison_result, comp_params = self.\
_get_partners_comparison_details(
data, account_ids,
target_move,
comp_filters[index],
index,
partner_filter_ids=partner_ids)
comparison_params.append(comp_params)
comp_accounts_by_ids.append(comparison_result)
objects = []
for account in self.pool.get('account.account').browse(self.cursor, self.uid, account_ids):
for account in self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids):
if not account.parent_id: # hide top level account
continue
account.debit = accounts_by_ids[account.id]['debit']
account.credit = accounts_by_ids[account.id]['credit']
account.balance = accounts_by_ids[account.id]['balance']
account.init_balance = accounts_by_ids[account.id].get('init_balance', 0.0)
account.init_balance = accounts_by_ids[
account.id].get('init_balance', 0.0)
account.partners_amounts = partner_details_by_ids[account.id]
comp_accounts = []
for comp_account_by_id in comp_accounts_by_ids:
values = comp_account_by_id.get(account.id)
values['account'].update(self._get_diff(account.balance, values['account'].get('balance', 0.0)))
values['account'].update(
self._get_diff(account.balance,
values['account'].get('balance', 0.0)))
comp_accounts.append(values)
for partner_id, partner_values in values['partners_amounts'].copy().iteritems():
base_partner_balance = account.partners_amounts[partner_id]['balance'] if \
for partner_id, partner_values in \
values['partners_amounts'].copy().iteritems():
base_partner_balance = account.partners_amounts[
partner_id]['balance'] if \
account.partners_amounts.get(partner_id) else 0.0
partner_values.update(self._get_diff(base_partner_balance,
partner_values.update(self._get_diff(
base_partner_balance,
partner_values.get('balance', 0.0)))
values['partners_amounts'][partner_id].update(partner_values)
values['partners_amounts'][
partner_id].update(partner_values)
account.comparisons = comp_accounts
all_partner_ids = reduce(add, [comp['partners_amounts'].keys() for comp in comp_accounts],
all_partner_ids = reduce(add, [comp['partners_amounts'].keys()
for comp in comp_accounts],
account.partners_amounts.keys())
account.partners_order = self._order_partners(all_partner_ids)

127
account_financial_report_webkit/report/common_partner_reports.py

@ -30,10 +30,15 @@ from .common_reports import CommonReportHeaderWebkit
class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
"""Define common helper for partner oriented financial report"""
####################Account move line retrieval helper ##########################
def get_partners_move_lines_ids(self, account_id, main_filter, start, stop, target_move,
######################################
# Account move line retrieval helper #
######################################
def get_partners_move_lines_ids(self, account_id, main_filter, start, stop,
target_move,
exclude_reconcile=False,
partner_filter=False):
filter_from = False
@ -42,11 +47,8 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
elif main_filter == 'filter_date':
filter_from = 'date'
if filter_from:
return self._get_partners_move_line_ids(filter_from,
account_id,
start,
stop,
target_move,
return self._get_partners_move_line_ids(
filter_from, account_id, start, stop, target_move,
exclude_reconcile=exclude_reconcile,
partner_filter=partner_filter)
@ -59,8 +61,8 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
and it returns the id of the first period for which `special` is True
in this fiscal year.
It is used for example in the partners reports, where we have to include
the first, and only the first opening period.
It is used for example in the partners reports, where we have to
include the first, and only the first opening period.
:return: browse record of the first special period.
"""
@ -71,16 +73,20 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
# it may so
if not first_entry_id:
return
first_entry = move_line_obj.browse(self.cr, self.uid, first_entry_id[0])
first_entry = move_line_obj.browse(
self.cr, self.uid, first_entry_id[0])
fiscalyear = first_entry.period_id.fiscalyear_id
special_periods = [period for period in fiscalyear.period_ids if period.special]
special_periods = [
period for period in fiscalyear.period_ids if period.special]
# so, we have no opening period on the first year, nothing to return
if not special_periods:
return
return min(special_periods,
key=lambda p: datetime.strptime(p.date_start, DEFAULT_SERVER_DATE_FORMAT))
key=lambda p: datetime.strptime(p.date_start,
DEFAULT_SERVER_DATE_FORMAT))
def _get_period_range_from_start_period(self, start_period, include_opening=False,
def _get_period_range_from_start_period(self, start_period,
include_opening=False,
fiscalyear=False,
stop_at_previous_opening=False):
"""We retrieve all periods before start period"""
@ -95,7 +101,8 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
periods.append(first_special.id)
return periods
def _get_query_params_from_periods(self, period_start, period_stop, mode='exclude_opening'):
def _get_query_params_from_periods(self, period_start, period_stop,
mode='exclude_opening'):
"""
Build the part of the sql "where clause" which filters on the selected
periods.
@ -118,7 +125,8 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
sql_conditions = ""
if periods:
sql_conditions = " AND account_move_line.period_id in %(period_ids)s"
sql_conditions = " AND account_move_line.period_id in \
%(period_ids)s"
return sql_conditions, search_params
@ -138,14 +146,18 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
'date_start': date_start,
'date_stop': date_stop}
sql_conditions = " AND account_move_line.period_id not in %(period_ids)s" \
" AND account_move_line.date between date(%(date_start)s) and date((%(date_stop)s))"
sql_conditions = " AND account_move_line.period_id not \
in %(period_ids)s \
AND account_move_line.date between \
date(%(date_start)s) and date((%(date_stop)s))"
return sql_conditions, search_params
def _get_partners_move_line_ids(self, filter_from, account_id, start, stop,
target_move, opening_mode='exclude_opening',
exclude_reconcile=False, partner_filter=None):
target_move,
opening_mode='exclude_opening',
exclude_reconcile=False,
partner_filter=None):
"""
:param str filter_from: "periods" or "dates"
@ -162,7 +174,8 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
final_res = defaultdict(list)
sql_select = "SELECT account_move_line.id, account_move_line.partner_id FROM account_move_line"
sql_select = "SELECT account_move_line.id, \
account_move_line.partner_id FROM account_move_line"
sql_joins = ''
sql_where = " WHERE account_move_line.account_id = %(account_ids)s " \
" AND account_move_line.state = 'valid' "
@ -174,13 +187,17 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
if exclude_reconcile:
sql_where += (" AND ((account_move_line.reconcile_id IS NULL)"
" OR (account_move_line.reconcile_id IS NOT NULL AND account_move_line.last_rec_date > date(%(date_stop)s)))")
" OR (account_move_line.reconcile_id IS NOT NULL \
AND account_move_line.last_rec_date > \
date(%(date_stop)s)))")
if partner_filter:
sql_where += " AND account_move_line.partner_id in %(partner_ids)s"
sql_where += " AND account_move_line.partner_id \
in %(partner_ids)s"
if target_move == 'posted':
sql_joins += "INNER JOIN account_move ON account_move_line.move_id = account_move.id"
sql_joins += "INNER JOIN account_move \
ON account_move_line.move_id = account_move.id"
sql_where += " AND account_move.state = %(target_move)s"
search_params.update({'target_move': target_move})
@ -197,14 +214,16 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
final_res[row['partner_id']].append(row['id'])
return final_res
def _get_clearance_move_line_ids(self, move_line_ids, date_stop, date_until):
def _get_clearance_move_line_ids(self, move_line_ids, date_stop,
date_until):
if not move_line_ids:
return []
move_line_obj = self.pool.get('account.move.line')
# we do not use orm in order to gain perfo
# In this case I have to test the effective gain over an itteration
# Actually ORM does not allows distinct behavior
sql = "Select distinct reconcile_id from account_move_line where id in %s"
sql = "Select distinct reconcile_id from account_move_line \
where id in %s"
self.cursor.execute(sql, (tuple(move_line_ids),))
rec_ids = self.cursor.fetchall()
if rec_ids:
@ -218,7 +237,9 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
else:
return []
####################Initial Partner Balance helper ########################
##############################################
# Initial Partner Balance helper #
##############################################
def _tree_move_line_ids(self, move_lines_data, key=None):
"""
@ -243,11 +264,16 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
res[account_id][partner_id] = row
return res
def _partners_initial_balance_line_ids(self, account_ids, start_period, partner_filter, exclude_reconcile=False, force_period_ids=False, date_stop=None):
def _partners_initial_balance_line_ids(self, account_ids, start_period,
partner_filter,
exclude_reconcile=False,
force_period_ids=False,
date_stop=None):
# take ALL previous periods
period_ids = force_period_ids \
if force_period_ids \
else self._get_period_range_from_start_period(start_period, fiscalyear=False, include_opening=False)
else self._get_period_range_from_start_period(
start_period, fiscalyear=False, include_opening=False)
if not period_ids:
period_ids = [-1]
@ -264,10 +290,12 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
"AND ml.account_id in %(account_ids)s ")
if exclude_reconcile:
if not date_stop:
raise Exception("Missing \"date_stop\" to compute the open invoices.")
raise Exception(
"Missing \"date_stop\" to compute the open invoices.")
search_param.update({'date_stop': date_stop})
sql += ("AND ((ml.reconcile_id IS NULL)"
"OR (ml.reconcile_id IS NOT NULL AND ml.last_rec_date > date(%(date_stop)s))) ")
sql += ("AND ((ml.reconcile_id IS NULL) "
"OR (ml.reconcile_id IS NOT NULL \
AND ml.last_rec_date > date(%(date_stop)s))) ")
if partner_filter:
sql += "AND ml.partner_id in %(partner_ids)s "
search_param.update({'partner_ids': tuple(partner_filter)})
@ -275,13 +303,18 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
self.cursor.execute(sql, search_param)
return self.cursor.dictfetchall()
def _compute_partners_initial_balances(self, account_ids, start_period, partner_filter=None, exclude_reconcile=False, force_period_ids=False):
def _compute_partners_initial_balances(self, account_ids, start_period,
partner_filter=None,
exclude_reconcile=False,
force_period_ids=False):
"""We compute initial balance.
If form is filtered by date all initial balance are equal to 0
This function will sum pear and apple in currency amount if account as no secondary currency"""
This function will sum pear and apple in currency amount if account
as no secondary currency"""
if isinstance(account_ids, (int, long)):
account_ids = [account_ids]
move_line_ids = self._partners_initial_balance_line_ids(account_ids, start_period, partner_filter,
move_line_ids = self._partners_initial_balance_line_ids(
account_ids, start_period, partner_filter,
exclude_reconcile=exclude_reconcile,
force_period_ids=force_period_ids)
if not move_line_ids:
@ -289,7 +322,9 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
sql = ("SELECT ml.account_id, ml.partner_id,"
" sum(ml.debit) as debit, sum(ml.credit) as credit,"
" sum(ml.debit-ml.credit) as init_balance,"
" CASE WHEN a.currency_id ISNULL THEN 0.0 ELSE sum(ml.amount_currency) END as init_balance_currency, "
" CASE WHEN a.currency_id ISNULL THEN 0.0\
ELSE sum(ml.amount_currency) \
END as init_balance_currency, "
" c.name as currency_name "
"FROM account_move_line ml "
"INNER JOIN account_account a "
@ -298,12 +333,17 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
"ON c.id = a.currency_id "
"WHERE ml.id in %(move_line_ids)s "
"GROUP BY ml.account_id, ml.partner_id, a.currency_id, c.name")
search_param = {'move_line_ids': tuple([move_line['id'] for move_line in move_line_ids])}
search_param = {
'move_line_ids': tuple([move_line['id'] for move_line in
move_line_ids])}
self.cursor.execute(sql, search_param)
res = self.cursor.dictfetchall()
return self._tree_move_line_ids(res)
####################Partner specific helper ################################
############################################################
# Partner specific helper #
############################################################
def _order_partners(self, *args):
"""We get the partner linked to all current accounts that are used.
We also use ensure that partner are ordered by name
@ -316,11 +356,16 @@ class CommonPartnersReportHeaderWebkit(CommonReportHeaderWebkit):
if not partner_ids:
return []
existing_partner_ids = [partner_id for partner_id in partner_ids if partner_id]
existing_partner_ids = [
partner_id for partner_id in partner_ids if partner_id]
if existing_partner_ids:
# We may use orm here as the performance optimization is not that big
sql = ("SELECT name|| ' ' ||CASE WHEN ref IS NOT NULL THEN '('||ref||')' ELSE '' END, id, ref, name"
" FROM res_partner WHERE id IN %s ORDER BY LOWER(name), ref")
# We may use orm here as the performance optimization is not that
# big
sql = ("SELECT name|| ' ' ||CASE WHEN ref IS NOT NULL \
THEN '('||ref||')' \
ELSE '' END, id, ref, name"
" FROM res_partner \
WHERE id IN %s ORDER BY LOWER(name), ref")
self.cursor.execute(sql, (tuple(set(existing_partner_ids)),))
res = self.cursor.fetchall()

219
account_financial_report_webkit/report/common_reports.py

@ -26,15 +26,22 @@ import logging
from openerp.osv import osv
from openerp.tools.translate import _
from openerp.addons.account.report.common_report_header import common_report_header
from openerp.addons.account.report.common_report_header \
import common_report_header
_logger = logging.getLogger('financial.reports.webkit')
MAX_MONSTER_SLICE = 50000
class CommonReportHeaderWebkit(common_report_header):
"""Define common helper for financial report"""
####################From getter helper #####################################
######################################################################
# From getter helper #
######################################################################
def get_start_period_br(self, data):
return self._get_info(data, 'period_from', 'account.period')
@ -112,20 +119,26 @@ class CommonReportHeaderWebkit(common_report_header):
def _get_form_param(self, param, data, default=False):
return data.get('form', {}).get(param, default)
####################Account and account line filter helper #################
#############################################
# Account and account line filter helper #
#############################################
def sort_accounts_with_structure(self, root_account_ids, account_ids, context=None):
def sort_accounts_with_structure(self, root_account_ids, account_ids,
context=None):
"""Sort accounts by code respecting their structure"""
def recursive_sort_by_code(accounts, parent):
sorted_accounts = []
# add all accounts with same parent
level_accounts = [account for account in accounts
if account['parent_id'] and account['parent_id'][0] == parent['id']]
# add consolidation children of parent, as they are logically on the same level
if account['parent_id']
and account['parent_id'][0] == parent['id']]
# add consolidation children of parent, as they are logically on
# the same level
if parent.get('child_consol_ids'):
level_accounts.extend([account for account in accounts
if account['id'] in parent['child_consol_ids']])
if account['id']
in parent['child_consol_ids']])
# stop recursion if no children found
if not level_accounts:
return []
@ -134,14 +147,15 @@ class CommonReportHeaderWebkit(common_report_header):
for level_account in level_accounts:
sorted_accounts.append(level_account['id'])
sorted_accounts.extend(recursive_sort_by_code(accounts, parent=level_account))
sorted_accounts.extend(
recursive_sort_by_code(accounts, parent=level_account))
return sorted_accounts
if not account_ids:
return []
accounts_data = self.pool.get('account.account').read(self.cr, self.uid,
account_ids,
accounts_data = self.pool.get('account.account').read(
self.cr, self.uid, account_ids,
['id', 'parent_id', 'level', 'code', 'child_consol_ids'],
context=context)
@ -151,7 +165,8 @@ class CommonReportHeaderWebkit(common_report_header):
if account_data['id'] in root_account_ids]
for root_account_data in root_accounts_data:
sorted_accounts.append(root_account_data['id'])
sorted_accounts.extend(recursive_sort_by_code(accounts_data, root_account_data))
sorted_accounts.extend(
recursive_sort_by_code(accounts_data, root_account_data))
# fallback to unsorted accounts when sort failed
# sort fails when the levels are miscalculated by account.account
@ -162,11 +177,14 @@ class CommonReportHeaderWebkit(common_report_header):
return sorted_accounts
def get_all_accounts(self, account_ids, exclude_type=None, only_type=None, filter_report_type=None, context=None):
def get_all_accounts(self, account_ids, exclude_type=None, only_type=None,
filter_report_type=None, context=None):
"""Get all account passed in params with their childrens
@param exclude_type: list of types to exclude (view, receivable, payable, consolidation, other)
@param only_type: list of types to filter on (view, receivable, payable, consolidation, other)
@param exclude_type: list of types to exclude (view, receivable,
payable, consolidation, other)
@param only_type: list of types to filter on (view, receivable,
payable, consolidation, other)
@param filter_report_type: list of report type to filter on
"""
context = context or {}
@ -176,9 +194,11 @@ class CommonReportHeaderWebkit(common_report_header):
acc_obj = self.pool.get('account.account')
for account_id in account_ids:
accounts.append(account_id)
accounts += acc_obj._get_children_and_consol(self.cursor, self.uid, account_id, context=context)
accounts += acc_obj._get_children_and_consol(
self.cursor, self.uid, account_id, context=context)
res_ids = list(set(accounts))
res_ids = self.sort_accounts_with_structure(account_ids, res_ids, context=context)
res_ids = self.sort_accounts_with_structure(
account_ids, res_ids, context=context)
if exclude_type or only_type or filter_report_type:
sql_filters = {'ids': tuple(res_ids)}
@ -207,17 +227,22 @@ class CommonReportHeaderWebkit(common_report_header):
res_ids = [res_id for res_id in res_ids if res_id in only_ids]
return res_ids
####################Periods and fiscal years helper #######################
##########################################
# Periods and fiscal years helper #
##########################################
def _get_opening_periods(self):
"""Return the list of all journal that can be use to create opening entries
We actually filter on this instead of opening period as older version of OpenERP
did not have this notion"""
return self.pool.get('account.period').search(self.cursor, self.uid, [('special', '=', True)])
"""Return the list of all journal that can be use to create opening
entries.
We actually filter on this instead of opening period as older version
of OpenERP did not have this notion"""
return self.pool.get('account.period').search(self.cursor, self.uid,
[('special', '=', True)])
def exclude_opening_periods(self, period_ids):
period_obj = self.pool.get('account.period')
return period_obj.search(self.cr, self.uid, [['special', '=', False], ['id', 'in', period_ids]])
return period_obj.search(self.cr, self.uid, [['special', '=', False],
['id', 'in', period_ids]])
def get_included_opening_period(self, period):
"""Return the opening included in normal period we use the assumption
@ -236,12 +261,16 @@ class CommonReportHeaderWebkit(common_report_header):
mv_line_obj = self.pool.get('account.move.line')
if isinstance(period_ids, (int, long)):
period_ids = [period_ids]
return mv_line_obj.search(self.cursor, self.uid, [('period_id', 'in', period_ids)], limit=1) and True or False
return mv_line_obj.search(self.cursor, self.uid,
[('period_id', 'in', period_ids)], limit=1) \
and True or False
def _get_period_range_from_periods(self, start_period, stop_period, mode=None):
def _get_period_range_from_periods(self, start_period, stop_period,
mode=None):
"""
Deprecated. We have to use now the build_ctx_periods of period_obj otherwise we'll have
inconsistencies, because build_ctx_periods does never filter on the the special
Deprecated. We have to use now the build_ctx_periods of period_obj
otherwise we'll have inconsistencies, because build_ctx_periods does
never filter on the the special
"""
period_obj = self.pool.get('account.period')
search_period = [('date_start', '>=', start_period.date_start),
@ -252,8 +281,10 @@ class CommonReportHeaderWebkit(common_report_header):
res = period_obj.search(self.cursor, self.uid, search_period)
return res
def _get_period_range_from_start_period(self, start_period, include_opening=False,
fiscalyear=False, stop_at_previous_opening=False):
def _get_period_range_from_start_period(self, start_period,
include_opening=False,
fiscalyear=False,
stop_at_previous_opening=False):
"""We retrieve all periods before start period"""
opening_period_id = False
past_limit = []
@ -266,20 +297,24 @@ class CommonReportHeaderWebkit(common_report_header):
if fiscalyear:
opening_search.append(('fiscalyear_id', '=', fiscalyear.id))
opening_periods = period_obj.search(self.cursor, self.uid, opening_search,
opening_periods = period_obj.search(self.cursor, self.uid,
opening_search,
order='date_stop desc')
for opening_period in opening_periods:
validation_res = mv_line_obj.search(self.cursor,
self.uid,
[('period_id', '=', opening_period)],
[('period_id', '=',
opening_period)],
limit=1)
if validation_res:
opening_period_id = opening_period
break
if opening_period_id:
#we also look for overlapping periods
opening_period_br = period_obj.browse(self.cursor, self.uid, opening_period_id)
past_limit = [('date_start', '>=', opening_period_br.date_stop)]
# we also look for overlapping periods
opening_period_br = period_obj.browse(
self.cursor, self.uid, opening_period_id)
past_limit = [
('date_start', '>=', opening_period_br.date_stop)]
periods_search = [('date_stop', '<=', start_period.date_stop)]
periods_search += past_limit
@ -303,7 +338,8 @@ class CommonReportHeaderWebkit(common_report_header):
def get_last_fiscalyear_period(self, fiscalyear):
return self._get_st_fiscalyear_period(fiscalyear, order='DESC')
def _get_st_fiscalyear_period(self, fiscalyear, special=False, order='ASC'):
def _get_st_fiscalyear_period(self, fiscalyear, special=False,
order='ASC'):
period_obj = self.pool.get('account.period')
p_id = period_obj.search(self.cursor,
self.uid,
@ -315,9 +351,12 @@ class CommonReportHeaderWebkit(common_report_header):
raise osv.except_osv(_('No period found'), '')
return period_obj.browse(self.cursor, self.uid, p_id[0])
####################Initial Balance helper #################################
###############################
# Initial Balance helper #
###############################
def _compute_init_balance(self, account_id=None, period_ids=None, mode='computed', default_values=False):
def _compute_init_balance(self, account_id=None, period_ids=None,
mode='computed', default_values=False):
if not isinstance(period_ids, list):
period_ids = [period_ids]
res = {}
@ -332,10 +371,11 @@ class CommonReportHeaderWebkit(common_report_header):
" sum(amount_currency) AS curr_balance"
" FROM account_move_line"
" WHERE period_id in %s"
" AND account_id = %s", (tuple(period_ids), account_id))
" AND account_id = %s",
(tuple(period_ids), account_id))
res = self.cursor.dictfetchone()
except Exception, exc:
except Exception:
self.cursor.rollback()
raise
@ -348,7 +388,8 @@ class CommonReportHeaderWebkit(common_report_header):
def _read_opening_balance(self, account_ids, start_period):
""" Read opening balances from the opening balance
"""
opening_period_selected = self.get_included_opening_period(start_period)
opening_period_selected = self.get_included_opening_period(
start_period)
if not opening_period_selected:
raise osv.except_osv(
_('Error'),
@ -358,57 +399,70 @@ class CommonReportHeaderWebkit(common_report_header):
res = {}
for account_id in account_ids:
res[account_id] = self._compute_init_balance(account_id, opening_period_selected, mode='read')
res[account_id] = self._compute_init_balance(
account_id, opening_period_selected, mode='read')
return res
def _compute_initial_balances(self, account_ids, start_period, fiscalyear):
"""We compute initial balance.
If form is filtered by date all initial balance are equal to 0
This function will sum pear and apple in currency amount if account as no secondary currency"""
# if opening period is included in start period we do not need to compute init balance
# we just read it from opening entries
This function will sum pear and apple in currency amount if account as
no secondary currency"""
# if opening period is included in start period we do not need to
# compute init balance we just read it from opening entries
res = {}
# PNL and Balance accounts are not computed the same way look for attached doc
# We include opening period in pnl account in order to see if opening entries
# were created by error on this account
pnl_periods_ids = self._get_period_range_from_start_period(start_period, fiscalyear=fiscalyear,
include_opening=True)
bs_period_ids = self._get_period_range_from_start_period(start_period, include_opening=True,
stop_at_previous_opening=True)
opening_period_selected = self.get_included_opening_period(start_period)
for acc in self.pool.get('account.account').browse(self.cursor, self.uid, account_ids):
# PNL and Balance accounts are not computed the same way look for
# attached doc We include opening period in pnl account in order to see
# if opening entries were created by error on this account
pnl_periods_ids = self._get_period_range_from_start_period(
start_period, fiscalyear=fiscalyear, include_opening=True)
bs_period_ids = self._get_period_range_from_start_period(
start_period, include_opening=True, stop_at_previous_opening=True)
opening_period_selected = self.get_included_opening_period(
start_period)
for acc in self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids):
res[acc.id] = self._compute_init_balance(default_values=True)
if acc.user_type.close_method == 'none':
# we compute the initial balance for close_method == none only when we print a GL
# during the year, when the opening period is not included in the period selection!
# we compute the initial balance for close_method == none only
# when we print a GL during the year, when the opening period
# is not included in the period selection!
if pnl_periods_ids and not opening_period_selected:
res[acc.id] = self._compute_init_balance(acc.id, pnl_periods_ids)
res[acc.id] = self._compute_init_balance(
acc.id, pnl_periods_ids)
else:
res[acc.id] = self._compute_init_balance(acc.id, bs_period_ids)
return res
####################Account move retrieval helper ##########################
def _get_move_ids_from_periods(self, account_id, period_start, period_stop, target_move):
################################################
# Account move retrieval helper #
################################################
def _get_move_ids_from_periods(self, account_id, period_start, period_stop,
target_move):
move_line_obj = self.pool.get('account.move.line')
period_obj = self.pool.get('account.period')
periods = period_obj.build_ctx_periods(self.cursor, self.uid, period_start.id, period_stop.id)
periods = period_obj.build_ctx_periods(
self.cursor, self.uid, period_start.id, period_stop.id)
if not periods:
return []
search = [('period_id', 'in', periods), ('account_id', '=', account_id)]
search = [
('period_id', 'in', periods), ('account_id', '=', account_id)]
if target_move == 'posted':
search += [('move_id.state', '=', 'posted')]
return move_line_obj.search(self.cursor, self.uid, search)
def _get_move_ids_from_dates(self, account_id, date_start, date_stop, target_move, mode='include_opening'):
def _get_move_ids_from_dates(self, account_id, date_start, date_stop,
target_move, mode='include_opening'):
# TODO imporve perfomance by setting opening period as a property
move_line_obj = self.pool.get('account.move.line')
search_period = [('date', '>=', date_start),
('date', '<=', date_stop),
('account_id', '=', account_id)]
# actually not used because OpenERP itself always include the opening when we
# get the periods from january to december
# actually not used because OpenERP itself always include the opening
# when we get the periods from january to december
if mode == 'exclude_opening':
opening = self._get_opening_periods()
if opening:
@ -419,20 +473,28 @@ class CommonReportHeaderWebkit(common_report_header):
return move_line_obj.search(self.cursor, self.uid, search_period)
def get_move_lines_ids(self, account_id, main_filter, start, stop, target_move, mode='include_opening'):
def get_move_lines_ids(self, account_id, main_filter, start, stop,
target_move, mode='include_opening'):
"""Get account move lines base on form data"""
if mode not in ('include_opening', 'exclude_opening'):
raise osv.except_osv(_('Invalid query mode'), _('Must be in include_opening, exclude_opening'))
raise osv.except_osv(
_('Invalid query mode'),
_('Must be in include_opening, exclude_opening'))
if main_filter in ('filter_period', 'filter_no'):
return self._get_move_ids_from_periods(account_id, start, stop, target_move)
return self._get_move_ids_from_periods(account_id, start, stop,
target_move)
elif main_filter == 'filter_date':
return self._get_move_ids_from_dates(account_id, start, stop, target_move)
return self._get_move_ids_from_dates(account_id, start, stop,
target_move)
else:
raise osv.except_osv(_('No valid filter'), _('Please set a valid time filter'))
raise osv.except_osv(
_('No valid filter'), _('Please set a valid time filter'))
def _get_move_line_datas(self, move_line_ids, order='per.special DESC, l.date ASC, per.date_start ASC, m.name ASC'):
def _get_move_line_datas(self, move_line_ids,
order='per.special DESC, l.date ASC, \
per.date_start ASC, m.name ASC'):
# Possible bang if move_line_ids is too long
# We can not slice here as we have to do the sort.
# If slice has to be done it means that we have to reorder in python
@ -475,7 +537,8 @@ SELECT l.id AS id,
FROM account_move_line l
JOIN account_move m on (l.move_id=m.id)
LEFT JOIN res_currency c on (l.currency_id=c.id)
LEFT JOIN account_move_reconcile partialrec on (l.reconcile_partial_id = partialrec.id)
LEFT JOIN account_move_reconcile partialrec
on (l.reconcile_partial_id = partialrec.id)
LEFT JOIN account_move_reconcile fullrec on (l.reconcile_id = fullrec.id)
LEFT JOIN res_partner p on (l.partner_id=p.id)
LEFT JOIN account_invoice i on (m.id =i.move_id)
@ -486,7 +549,7 @@ FROM account_move_line l
try:
self.cursor.execute(monster, (tuple(move_line_ids),))
res = self.cursor.dictfetchall()
except Exception, exc:
except Exception:
self.cursor.rollback()
raise
return res or []
@ -506,14 +569,16 @@ SELECT account_move.id,
AND m2.account_id<>%s limit %s) , ', ')
FROM account_move
JOIN account_move_line on (account_move_line.move_id = account_move.id)
JOIN account_account on (account_move_line.account_id = account_account.id)
JOIN account_move_line
on (account_move_line.move_id = account_move.id)
JOIN account_account
on (account_move_line.account_id = account_account.id)
WHERE move_id in %s"""
try:
self.cursor.execute(sql, (account_id, limit, tuple(move_ids)))
res = self.cursor.fetchall()
except Exception as exc:
except Exception:
self.cursor.rollback()
raise
return res and dict(res) or {}
@ -524,8 +589,10 @@ WHERE move_id in %s"""
return True
def _get_initial_balance_mode(self, start_period):
opening_period_selected = self.get_included_opening_period(start_period)
opening_move_lines = self.periods_contains_move_lines(opening_period_selected)
opening_period_selected = self.get_included_opening_period(
start_period)
opening_move_lines = self.periods_contains_move_lines(
opening_period_selected)
if opening_move_lines:
return 'opening_balance'
else:

99
account_financial_report_webkit/report/general_ledger.py

@ -33,14 +33,18 @@ from .webkit_parser_header_fix import HeaderFooterTextWebKitParser
class GeneralLedgerWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
def __init__(self, cursor, uid, name, context):
super(GeneralLedgerWebkit, self).__init__(cursor, uid, name, context=context)
super(GeneralLedgerWebkit, self).__init__(
cursor, uid, name, context=context)
self.pool = pooler.get_pool(self.cr.dbname)
self.cursor = self.cr
company = self.pool.get('res.users').browse(self.cr, uid, uid, context=context).company_id
header_report_name = ' - '.join((_('GENERAL LEDGER'), company.name, company.currency_id.name))
company = self.pool.get('res.users').browse(
self.cr, uid, uid, context=context).company_id
header_report_name = ' - '.join(
(_('GENERAL LEDGER'), company.name, company.currency_id.name))
footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
footer_date_time = self.formatLang(
str(datetime.today()), date_time=True)
self.localcontext.update({
'cr': cursor,
@ -62,15 +66,17 @@ class GeneralLedgerWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
('--header-left', header_report_name),
('--header-spacing', '2'),
('--footer-left', footer_date_time),
('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-right',
' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-line',),
],
})
def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will be used
by mako template"""
new_ids = data['form']['account_ids'] or data['form']['chart_account_id']
"""Populate a ledger_lines attribute on each browse record that will be
used by mako template"""
new_ids = data['form']['account_ids'] or data[
'form']['chart_account_id']
# Account initial balance memoizer
init_balance_memoizer = {}
@ -99,23 +105,31 @@ class GeneralLedgerWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
stop = stop_period
initial_balance = self.is_initial_balance_enabled(main_filter)
initial_balance_mode = initial_balance and self._get_initial_balance_mode(start) or False
initial_balance_mode = initial_balance \
and self._get_initial_balance_mode(start) or False
# Retrieving accounts
accounts = self.get_all_accounts(new_ids, exclude_type=['view'])
if initial_balance_mode == 'initial_balance':
init_balance_memoizer = self._compute_initial_balances(accounts, start, fiscalyear)
init_balance_memoizer = self._compute_initial_balances(
accounts, start, fiscalyear)
elif initial_balance_mode == 'opening_balance':
init_balance_memoizer = self._read_opening_balance(accounts, start)
ledger_lines_memoizer = self._compute_account_ledger_lines(accounts, init_balance_memoizer,
main_filter, target_move, start, stop)
ledger_lines_memoizer = self._compute_account_ledger_lines(
accounts, init_balance_memoizer, main_filter, target_move, start,
stop)
objects = []
for account in self.pool.get('account.account').browse(self.cursor, self.uid, accounts):
if do_centralize and account.centralized and ledger_lines_memoizer.get(account.id):
account.ledger_lines = self._centralize_lines(main_filter, ledger_lines_memoizer.get(account.id, []))
for account in self.pool.get('account.account').browse(self.cursor,
self.uid,
accounts):
if do_centralize and account.centralized \
and ledger_lines_memoizer.get(account.id):
account.ledger_lines = self._centralize_lines(
main_filter, ledger_lines_memoizer.get(account.id, []))
else:
account.ledger_lines = ledger_lines_memoizer.get(account.id, [])
account.ledger_lines = ledger_lines_memoizer.get(
account.id, [])
account.init_balance = init_balance_memoizer.get(account.id, {})
objects.append(account)
@ -130,17 +144,20 @@ class GeneralLedgerWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
'initial_balance_mode': initial_balance_mode,
})
return super(GeneralLedgerWebkit, self).set_context(objects, data, new_ids,
report_type=report_type)
return super(GeneralLedgerWebkit, self).set_context(
objects, data, new_ids, report_type=report_type)
def _centralize_lines(self, filter, ledger_lines, context=None):
""" Group by period in filter mode 'period' or on one line in filter mode 'date'
ledger_lines parameter is a list of dict built by _get_ledger_lines"""
""" Group by period in filter mode 'period' or on one line in filter
mode 'date' ledger_lines parameter is a list of dict built
by _get_ledger_lines"""
def group_lines(lines):
if not lines:
return {}
sums = reduce(lambda line, memo: dict((key, value + memo[key]) for key, value
in line.iteritems() if key in ('balance', 'debit', 'credit')), lines)
sums = reduce(lambda line, memo:
dict((key, value + memo[key]) for key, value
in line.iteritems() if key in
('balance', 'debit', 'credit')), lines)
res_lines = {
'balance': sums['balance'],
@ -161,32 +178,38 @@ class GeneralLedgerWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
period_obj = self.pool.get('account.period')
# we need to sort the lines per period in order to use groupby
# unique ids of each used period id in lines
period_ids = list(set([line['lperiod_id'] for line in ledger_lines]))
period_ids = list(
set([line['lperiod_id'] for line in ledger_lines]))
# search on account.period in order to sort them by date_start
sorted_period_ids = period_obj.search(self.cr, self.uid,
[('id', 'in', period_ids)],
order='special desc, date_start',
context=context)
sorted_ledger_lines = sorted(ledger_lines, key=lambda x: sorted_period_ids.index(x['lperiod_id']))
for period_id, lines_per_period_iterator in groupby(sorted_ledger_lines, itemgetter('lperiod_id')):
sorted_period_ids = period_obj.search(
self.cr, self.uid, [('id', 'in', period_ids)],
order='special desc, date_start', context=context)
sorted_ledger_lines = sorted(
ledger_lines, key=lambda x: sorted_period_ids.
index(x['lperiod_id']))
for period_id, lines_per_period_iterator in groupby(
sorted_ledger_lines, itemgetter('lperiod_id')):
lines_per_period = list(lines_per_period_iterator)
if not lines_per_period:
continue
group_per_period = group_lines(lines_per_period)
group_per_period.update({
'lperiod_id': period_id,
'period_code': lines_per_period[0]['period_code'], # period code is anyway the same on each line per period
# period code is anyway the same on each line per period
'period_code': lines_per_period[0]['period_code'],
})
centralized_lines.append(group_per_period)
return centralized_lines
def _compute_account_ledger_lines(self, accounts_ids, init_balance_memoizer, main_filter,
def _compute_account_ledger_lines(self, accounts_ids,
init_balance_memoizer, main_filter,
target_move, start, stop):
res = {}
for acc_id in accounts_ids:
move_line_ids = self.get_move_lines_ids(acc_id, main_filter, start, stop, target_move)
move_line_ids = self.get_move_lines_ids(
acc_id, main_filter, start, stop, target_move)
if not move_line_ids:
res[acc_id] = []
continue
@ -199,8 +222,8 @@ class GeneralLedgerWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
if not move_line_ids:
return []
res = self._get_move_line_datas(move_line_ids)
## computing counter part is really heavy in term of ressouces consuption
## looking for a king of SQL to help me improve it
# computing counter part is really heavy in term of ressouces
# consuption looking for a king of SQL to help me improve it
move_ids = [x.get('move_id') for x in res]
counter_parts = self._get_moves_counterparts(move_ids, account_id)
for line in res:
@ -208,7 +231,9 @@ class GeneralLedgerWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
return res
HeaderFooterTextWebKitParser('report.account.account_report_general_ledger_webkit',
HeaderFooterTextWebKitParser(
'report.account.account_report_general_ledger_webkit',
'account.account',
'addons/account_financial_report_webkit/report/templates/account_report_general_ledger.mako',
'addons/account_financial_report_webkit/report/templates/\
account_report_general_ledger.mako',
parser=GeneralLedgerWebkit)

112
account_financial_report_webkit/report/open_invoices.py

@ -43,17 +43,23 @@ def get_mako_template(obj, *args):
report_helper.WebKitHelper.get_mako_template = get_mako_template
class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeaderWebkit):
class PartnersOpenInvoicesWebkit(report_sxw.rml_parse,
CommonPartnersReportHeaderWebkit):
def __init__(self, cursor, uid, name, context):
super(PartnersOpenInvoicesWebkit, self).__init__(cursor, uid, name, context=context)
super(PartnersOpenInvoicesWebkit, self).__init__(
cursor, uid, name, context=context)
self.pool = pooler.get_pool(self.cr.dbname)
self.cursor = self.cr
company = self.pool.get('res.users').browse(self.cr, uid, uid, context=context).company_id
header_report_name = ' - '.join((_('OPEN INVOICES REPORT'), company.name, company.currency_id.name))
company = self.pool.get('res.users').browse(
self.cr, uid, uid, context=context).company_id
header_report_name = ' - '.join((_('OPEN INVOICES REPORT'),
company.name,
company.currency_id.name))
footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
footer_date_time = self.formatLang(
str(datetime.today()), date_time=True)
self.localcontext.update({
'cr': cursor,
@ -73,7 +79,8 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
('--header-left', header_report_name),
('--header-spacing', '2'),
('--footer-left', footer_date_time),
('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-right',
' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-line',),
],
})
@ -85,13 +92,15 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
for part_id, plane_lines in account_br.ledger_lines.items():
account_br.grouped_ledger_lines[part_id] = []
plane_lines.sort(key=itemgetter('currency_code'))
for curr, lines in groupby(plane_lines, key=itemgetter('currency_code')):
for curr, lines in groupby(plane_lines,
key=itemgetter('currency_code')):
tmp = [x for x in lines]
account_br.grouped_ledger_lines[part_id].append((curr, tmp)) # I want to reiter many times
account_br.grouped_ledger_lines[part_id].append(
(curr, tmp)) # I want to reiter many times
def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will be used
by mako template"""
"""Populate a ledger_lines attribute on each browse record that will
be used by mako template"""
new_ids = data['form']['chart_account_id']
# Account initial balance memoizer
init_balance_memoizer = {}
@ -120,7 +129,8 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
if result_selection == 'supplier':
filter_type = ('payable',)
account_ids = self.get_all_accounts(new_ids, exclude_type=['view'], only_type=filter_type)
account_ids = self.get_all_accounts(
new_ids, exclude_type=['view'], only_type=filter_type)
if not account_ids:
raise osv.except_osv(_('Error'), _('No accounts to print.'))
@ -132,26 +142,28 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
else:
start = start_period
stop = stop_period
ledger_lines_memoizer = self._compute_open_transactions_lines(account_ids,
main_filter,
target_move,
start,
stop,
date_until,
ledger_lines_memoizer = self._compute_open_transactions_lines(
account_ids, main_filter, target_move, start, stop, date_until,
partner_filter=partner_ids)
objects = []
for account in self.pool.get('account.account').browse(self.cursor, self.uid, account_ids):
for account in self.pool.get('account.account').browse(self.cursor,
self.uid,
account_ids):
account.ledger_lines = ledger_lines_memoizer.get(account.id, {})
account.init_balance = init_balance_memoizer.get(account.id, {})
## we have to compute partner order based on inital balance
## and ledger line as we may have partner with init bal
## that are not in ledger line and vice versa
# we have to compute partner order based on inital balance
# and ledger line as we may have partner with init bal
# that are not in ledger line and vice versa
ledg_lines_pids = ledger_lines_memoizer.get(account.id, {}).keys()
non_null_init_balances = dict([(ib, amounts) for ib, amounts in account.init_balance.iteritems()
if amounts['init_balance'] or amounts['init_balance_currency']])
non_null_init_balances = dict([
(ib, amounts) for ib, amounts
in account.init_balance.iteritems()
if amounts['init_balance']
or amounts['init_balance_currency']])
init_bal_lines_pids = non_null_init_balances.keys()
account.partners_order = self._order_partners(ledg_lines_pids, init_bal_lines_pids)
account.partners_order = self._order_partners(
ledg_lines_pids, init_bal_lines_pids)
account.ledger_lines = ledger_lines_memoizer.get(account.id, {})
if group_by_currency:
self._group_lines_by_currency(account)
@ -168,13 +180,16 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
'chart_account': chart_account,
})
return super(PartnersOpenInvoicesWebkit, self).set_context(objects, data, new_ids,
report_type=report_type)
return super(PartnersOpenInvoicesWebkit, self).set_context(
objects, data, new_ids, report_type=report_type)
def _compute_open_transactions_lines(self, accounts_ids, main_filter, target_move, start, stop, date_until=False, partner_filter=False):
def _compute_open_transactions_lines(self, accounts_ids, main_filter,
target_move, start, stop,
date_until=False,
partner_filter=False):
res = defaultdict(dict)
## we check if until date and date stop have the same value
# we check if until date and date stop have the same value
if main_filter in ('filter_period', 'filter_no'):
date_stop = stop.date_stop
date_until_match = (date_stop == date_until)
@ -185,7 +200,8 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
else:
raise osv.except_osv(_('Unsuported filter'),
_('Filter has to be in filter date, period, or none'))
_('Filter has to be in filter date, period, \
or none'))
initial_move_lines_per_account = {}
if main_filter in ('filter_period', 'filter_no'):
@ -195,34 +211,38 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
partner_filter,
exclude_reconcile=True,
force_period_ids=False,
date_stop=date_stop), key='id')
date_stop=date_stop),
key='id')
for account_id in accounts_ids:
initial_move_lines_ids_per_partner = initial_move_lines_per_account.get(account_id, {})
initial_move_lines_ids_per_partner = \
initial_move_lines_per_account.get(account_id, {})
# We get the move line ids of the account
move_line_ids_per_partner = self.get_partners_move_lines_ids(account_id,
main_filter,
start,
stop,
target_move,
exclude_reconcile=True,
partner_filter=partner_filter)
move_line_ids_per_partner = self.get_partners_move_lines_ids(
account_id, main_filter, start, stop, target_move,
exclude_reconcile=True, partner_filter=partner_filter)
if not initial_move_lines_ids_per_partner and not move_line_ids_per_partner:
if not initial_move_lines_ids_per_partner \
and not move_line_ids_per_partner:
continue
for partner_id in list(set(initial_move_lines_ids_per_partner.keys() + move_line_ids_per_partner.keys())):
partner_line_ids = (move_line_ids_per_partner.get(partner_id, []) +
for partner_id in list(
set(initial_move_lines_ids_per_partner.keys() +
move_line_ids_per_partner.keys())):
partner_line_ids = (
move_line_ids_per_partner.get(partner_id, []) +
initial_move_lines_ids_per_partner.get(partner_id, []))
clearance_line_ids = []
if date_until and not date_until_match and partner_line_ids:
clearance_line_ids = self._get_clearance_move_line_ids(partner_line_ids, date_stop, date_until)
clearance_line_ids = self._get_clearance_move_line_ids(
partner_line_ids, date_stop, date_until)
partner_line_ids += clearance_line_ids
lines = self._get_move_line_datas(list(set(partner_line_ids)))
for line in lines:
if line['id'] in initial_move_lines_ids_per_partner.get(partner_id, []):
if line['id'] in initial_move_lines_ids_per_partner.\
get(partner_id, []):
line['is_from_previous_periods'] = True
if line['id'] in clearance_line_ids:
line['is_clearance_line'] = True
@ -231,7 +251,9 @@ class PartnersOpenInvoicesWebkit(report_sxw.rml_parse, CommonPartnersReportHeade
return res
HeaderFooterTextWebKitParser('report.account.account_report_open_invoices_webkit',
HeaderFooterTextWebKitParser(
'report.account.account_report_open_invoices_webkit',
'account.account',
'addons/account_financial_report_webkit/report/templates/account_report_open_invoices.mako',
'addons/account_financial_report_webkit/report/templates/\
account_report_open_invoices.mako',
parser=PartnersOpenInvoicesWebkit)

39
account_financial_report_webkit/report/partner_balance.py

@ -25,21 +25,28 @@ from datetime import datetime
from openerp import pooler
from openerp.report import report_sxw
from openerp.tools.translate import _
from .common_partner_balance_reports import CommonPartnerBalanceReportHeaderWebkit
from .common_partner_balance_reports \
import CommonPartnerBalanceReportHeaderWebkit
from .webkit_parser_header_fix import HeaderFooterTextWebKitParser
class PartnerBalanceWebkit(report_sxw.rml_parse, CommonPartnerBalanceReportHeaderWebkit):
class PartnerBalanceWebkit(report_sxw.rml_parse,
CommonPartnerBalanceReportHeaderWebkit):
def __init__(self, cursor, uid, name, context):
super(PartnerBalanceWebkit, self).__init__(cursor, uid, name, context=context)
super(PartnerBalanceWebkit, self).__init__(
cursor, uid, name, context=context)
self.pool = pooler.get_pool(self.cr.dbname)
self.cursor = self.cr
company = self.pool.get('res.users').browse(self.cr, uid, uid, context=context).company_id
header_report_name = ' - '.join((_('PARTNER BALANCE'), company.name, company.currency_id.name))
company = self.pool.get('res.users').browse(
self.cr, uid, uid, context=context).company_id
header_report_name = ' - '.join((_('PARTNER BALANCE'),
company.name,
company.currency_id.name))
footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
footer_date_time = self.formatLang(
str(datetime.today()), date_time=True)
self.localcontext.update({
'cr': cursor,
@ -60,7 +67,8 @@ class PartnerBalanceWebkit(report_sxw.rml_parse, CommonPartnerBalanceReportHeade
('--header-left', header_report_name),
('--header-spacing', '2'),
('--footer-left', footer_date_time),
('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-right',
' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-line',),
],
})
@ -76,15 +84,18 @@ class PartnerBalanceWebkit(report_sxw.rml_parse, CommonPartnerBalanceReportHeade
return 'initial_balance'
def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will be used
by mako template"""
objects, new_ids, context_report_values = self.compute_partner_balance_data(data)
"""Populate a ledger_lines attribute on each browse record that will
be used by mako template"""
objects, new_ids, context_report_values = self.\
compute_partner_balance_data(data)
self.localcontext.update(context_report_values)
return super(PartnerBalanceWebkit, self).set_context(objects, data, new_ids,
report_type=report_type)
return super(PartnerBalanceWebkit, self).set_context(
objects, data, new_ids, report_type=report_type)
HeaderFooterTextWebKitParser('report.account.account_report_partner_balance_webkit',
HeaderFooterTextWebKitParser(
'report.account.account_report_partner_balance_webkit',
'account.account',
'addons/account_financial_report_webkit/report/templates/account_report_partner_balance.mako',
'addons/account_financial_report_webkit/report/templates/\
account_report_partner_balance.mako',
parser=PartnerBalanceWebkit)

96
account_financial_report_webkit/report/partners_ledger.py

@ -30,17 +30,23 @@ from .common_partner_reports import CommonPartnersReportHeaderWebkit
from .webkit_parser_header_fix import HeaderFooterTextWebKitParser
class PartnersLedgerWebkit(report_sxw.rml_parse, CommonPartnersReportHeaderWebkit):
class PartnersLedgerWebkit(report_sxw.rml_parse,
CommonPartnersReportHeaderWebkit):
def __init__(self, cursor, uid, name, context):
super(PartnersLedgerWebkit, self).__init__(cursor, uid, name, context=context)
super(PartnersLedgerWebkit, self).__init__(
cursor, uid, name, context=context)
self.pool = pooler.get_pool(self.cr.dbname)
self.cursor = self.cr
company = self.pool.get('res.users').browse(self.cr, uid, uid, context=context).company_id
header_report_name = ' - '.join((_('PARTNER LEDGER'), company.name, company.currency_id.name))
company = self.pool.get('res.users').browse(
self.cr, uid, uid, context=context).company_id
header_report_name = ' - '.join((_('PARTNER LEDGER'),
company.name,
company.currency_id.name))
footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
footer_date_time = self.formatLang(
str(datetime.today()), date_time=True)
self.localcontext.update({
'cr': cursor,
@ -61,7 +67,8 @@ class PartnersLedgerWebkit(report_sxw.rml_parse, CommonPartnersReportHeaderWebki
('--header-left', header_report_name),
('--header-spacing', '2'),
('--footer-left', footer_date_time),
('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-right',
' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-line',),
],
})
@ -77,8 +84,8 @@ class PartnersLedgerWebkit(report_sxw.rml_parse, CommonPartnersReportHeaderWebki
return 'initial_balance'
def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will be used
by mako template"""
"""Populate a ledger_lines attribute on each browse record that will
be used by mako template"""
new_ids = data['form']['chart_account_id']
# account partner memoizer
@ -118,45 +125,50 @@ class PartnersLedgerWebkit(report_sxw.rml_parse, CommonPartnersReportHeaderWebki
start = start_period
stop = stop_period
# when the opening period is included in the selected range of periods and
# the opening period contains move lines, we must not compute the initial balance from previous periods
# but only display the move lines of the opening period
# we identify them as:
# - 'initial_balance' means compute the sums of move lines from previous periods
# - 'opening_balance' means display the move lines of the opening period
# when the opening period is included in the selected range of periods
# and the opening period contains move lines, we must not compute the
# initial balance from previous periods but only display the move lines
# of the opening period we identify them as:
# - 'initial_balance' means compute the sums of move lines from
# previous periods
# - 'opening_balance' means display the move lines of the opening
# period
init_balance = main_filter in ('filter_no', 'filter_period')
initial_balance_mode = init_balance and self._get_initial_balance_mode(start) or False
initial_balance_mode = init_balance and self._get_initial_balance_mode(
start) or False
initial_balance_lines = {}
if initial_balance_mode == 'initial_balance':
initial_balance_lines = self._compute_partners_initial_balances(accounts,
start_period,
partner_filter=partner_ids,
initial_balance_lines = self._compute_partners_initial_balances(
accounts, start_period, partner_filter=partner_ids,
exclude_reconcile=False)
ledger_lines = self._compute_partner_ledger_lines(accounts,
main_filter,
target_move,
start,
stop,
ledger_lines = self._compute_partner_ledger_lines(
accounts, main_filter, target_move, start, stop,
partner_filter=partner_ids)
objects = []
for account in self.pool.get('account.account').browse(self.cursor, self.uid, accounts):
for account in self.pool.get('account.account').browse(self.cursor,
self.uid,
accounts):
account.ledger_lines = ledger_lines.get(account.id, {})
account.init_balance = initial_balance_lines.get(account.id, {})
## we have to compute partner order based on inital balance
## and ledger line as we may have partner with init bal
## that are not in ledger line and vice versa
# we have to compute partner order based on inital balance
# and ledger line as we may have partner with init bal
# that are not in ledger line and vice versa
ledg_lines_pids = ledger_lines.get(account.id, {}).keys()
if initial_balance_mode:
non_null_init_balances = dict([(ib, amounts) for ib, amounts in account.init_balance.iteritems()
if amounts['init_balance'] or amounts['init_balance_currency']])
non_null_init_balances = dict(
[(ib, amounts) for ib, amounts
in account.init_balance.iteritems()
if amounts['init_balance']
or amounts['init_balance_currency']])
init_bal_lines_pids = non_null_init_balances.keys()
else:
account.init_balance = {}
init_bal_lines_pids = []
account.partners_order = self._order_partners(ledg_lines_pids, init_bal_lines_pids)
account.partners_order = self._order_partners(
ledg_lines_pids, init_bal_lines_pids)
objects.append(account)
self.localcontext.update({
@ -170,20 +182,18 @@ class PartnersLedgerWebkit(report_sxw.rml_parse, CommonPartnersReportHeaderWebki
'initial_balance_mode': initial_balance_mode,
})
return super(PartnersLedgerWebkit, self).set_context(objects, data, new_ids,
report_type=report_type)
return super(PartnersLedgerWebkit, self).set_context(
objects, data, new_ids, report_type=report_type)
def _compute_partner_ledger_lines(self, accounts_ids, main_filter, target_move, start, stop, partner_filter=False):
def _compute_partner_ledger_lines(self, accounts_ids, main_filter,
target_move, start, stop,
partner_filter=False):
res = defaultdict(dict)
for acc_id in accounts_ids:
move_line_ids = self.get_partners_move_lines_ids(acc_id,
main_filter,
start,
stop,
target_move,
exclude_reconcile=False,
partner_filter=partner_filter)
move_line_ids = self.get_partners_move_lines_ids(
acc_id, main_filter, start, stop, target_move,
exclude_reconcile=False, partner_filter=partner_filter)
if not move_line_ids:
continue
for partner_id in move_line_ids:
@ -193,7 +203,9 @@ class PartnersLedgerWebkit(report_sxw.rml_parse, CommonPartnersReportHeaderWebki
return res
HeaderFooterTextWebKitParser('report.account.account_report_partners_ledger_webkit',
HeaderFooterTextWebKitParser(
'report.account.account_report_partners_ledger_webkit',
'account.account',
'addons/account_financial_report_webkit/report/templates/account_report_partners_ledger.mako',
'addons/account_financial_report_webkit/report/templates/\
account_report_partners_ledger.mako',
parser=PartnersLedgerWebkit)

64
account_financial_report_webkit/report/print_journal.py

@ -1,19 +1,20 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# account_financial_report_webkit module for OpenERP, Webkit based extended report financial report
# account_financial_report_webkit module for OpenERP, Webkit based
# extended report financial report
# Copyright (C) 2012 SYLEAM Info Services (<http://www.syleam.fr/>)
# Sebastien LANGE <sebastien.lange@syleam.fr>
#
# This file is a part of account_financial_report_webkit
#
# account_financial_report_webkit is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# account_financial_report_webkit is free software: you can redistribute it
# and/or modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# account_financial_report_webkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# account_financial_report_webkit 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 Affero General Public License for more details.
#
@ -34,17 +35,22 @@ from webkit_parser_header_fix import HeaderFooterTextWebKitParser
class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
def __init__(self, cursor, uid, name, context):
super(PrintJournalWebkit, self).__init__(cursor, uid, name, context=context)
super(PrintJournalWebkit, self).__init__(cursor, uid, name,
context=context)
self.pool = pooler.get_pool(self.cr.dbname)
self.cursor = self.cr
company_obj = self.pool.get('res.company')
company_id = company_obj._company_default_get(self.cr, uid, 'res.users', context=context)
company_id = company_obj._company_default_get(self.cr, uid,
'res.users',
context=context)
company = company_obj.browse(self.cr, uid, company_id, context=context)
header_report_name = ' - '.join((_('JOURNALS'), company.name, company.currency_id.name))
header_report_name = ' - '.join((_('JOURNALS'), company.name,
company.currency_id.name))
footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
footer_date_time = self.formatLang(str(datetime.today()),
date_time=True)
self.localcontext.update({
'cr': cursor,
@ -66,14 +72,15 @@ class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
('--header-left', header_report_name),
('--header-spacing', '2'),
('--footer-left', footer_date_time),
('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-right', ' '.join((_('Page'), '[page]', _('of'),
'[topage]'))),
('--footer-line',),
],
})
def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will be used
by mako template"""
"""Populate a ledger_lines attribute on each browse record that will
be used by mako template"""
# Reading form
main_filter = self._get_form_param('filter', data, default='filter_no')
@ -90,8 +97,10 @@ class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
domain = [('journal_id', 'in', journal_ids)]
if main_filter == 'filter_no':
domain += [
('date', '>=', self.get_first_fiscalyear_period(fiscalyear).date_start),
('date', '<=', self.get_last_fiscalyear_period(fiscalyear).date_stop),
('date', '>=',
self.get_first_fiscalyear_period(fiscalyear).date_start),
('date', '<=',
self.get_last_fiscalyear_period(fiscalyear).date_stop),
]
# computation of move lines
elif main_filter == 'filter_date':
@ -100,7 +109,10 @@ class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
('date', '<=', stop_date),
]
elif main_filter == 'filter_period':
period_ids = account_period_obj.build_ctx_periods(self.cursor, self.uid, start_period.id, stop_period.id)
period_ids = account_period_obj.build_ctx_periods(self.cursor,
self.uid,
start_period.id,
stop_period.id)
domain = [
('period_id', 'in', period_ids),
]
@ -111,7 +123,8 @@ class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
('journal_id', 'in', journal_ids),
('period_id', 'in', period_ids),
])
objects = account_journal_period_obj.browse(self.cursor, self.uid, new_ids)
objects = account_journal_period_obj.browse(self.cursor, self.uid,
new_ids)
# Sort by journal and period
objects.sort(key=lambda a: (a.journal_id.code, a.period_id.date_start))
move_obj = self.pool.get('account.move')
@ -122,8 +135,10 @@ class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
]
if target_move == 'posted':
domain_arg += [('state', '=', 'posted')]
move_ids = move_obj.search(self.cursor, self.uid, domain_arg, order="name")
journal_period.moves = move_obj.browse(self.cursor, self.uid, move_ids)
move_ids = move_obj.search(self.cursor, self.uid, domain_arg,
order="name")
journal_period.moves = move_obj.browse(self.cursor, self.uid,
move_ids)
# Sort account move line by account accountant
for move in journal_period.moves:
move.line_id.sort(key=lambda a: (a.date, a.account_id.code))
@ -137,11 +152,14 @@ class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
'chart_account': chart_account,
})
return super(PrintJournalWebkit, self).set_context(objects, data, new_ids, report_type=report_type)
return super(PrintJournalWebkit, self).set_context(
objects, data, new_ids, report_type=report_type)
HeaderFooterTextWebKitParser('report.account.account_report_print_journal_webkit',
HeaderFooterTextWebKitParser(
'report.account.account_report_print_journal_webkit',
'account.journal.period',
'addons/account_financial_report_webkit/report/templates/account_report_print_journal.mako',
'addons/account_financial_report_webkit/report/templates/\
account_report_print_journal.mako',
parser=PrintJournalWebkit)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

35
account_financial_report_webkit/report/trial_balance.py

@ -33,17 +33,22 @@ def sign(number):
return cmp(number, 0)
class TrialBalanceWebkit(report_sxw.rml_parse, CommonBalanceReportHeaderWebkit):
class TrialBalanceWebkit(report_sxw.rml_parse,
CommonBalanceReportHeaderWebkit):
def __init__(self, cursor, uid, name, context):
super(TrialBalanceWebkit, self).__init__(cursor, uid, name, context=context)
super(TrialBalanceWebkit, self).__init__(cursor, uid, name,
context=context)
self.pool = pooler.get_pool(self.cr.dbname)
self.cursor = self.cr
company = self.pool.get('res.users').browse(self.cr, uid, uid, context=context).company_id
header_report_name = ' - '.join((_('TRIAL BALANCE'), company.name, company.currency_id.name))
company = self.pool.get('res.users').browse(self.cr, uid, uid,
context=context).company_id
header_report_name = ' - '.join((_('TRIAL BALANCE'), company.name,
company.currency_id.name))
footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
footer_date_time = self.formatLang(str(datetime.today()),
date_time=True)
self.localcontext.update({
'cr': cursor,
@ -63,22 +68,26 @@ class TrialBalanceWebkit(report_sxw.rml_parse, CommonBalanceReportHeaderWebkit):
('--header-left', header_report_name),
('--header-spacing', '2'),
('--footer-left', footer_date_time),
('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
('--footer-right', ' '.join((_('Page'), '[page]', _('of'),
'[topage]'))),
('--footer-line',),
],
})
def set_context(self, objects, data, ids, report_type=None):
"""Populate a ledger_lines attribute on each browse record that will be used
by mako template"""
objects, new_ids, context_report_values = self.compute_balance_data(data)
"""Populate a ledger_lines attribute on each browse record that will
be used by mako template"""
objects, new_ids, context_report_values = self.\
compute_balance_data(data)
self.localcontext.update(context_report_values)
return super(TrialBalanceWebkit, self).set_context(objects, data, new_ids,
report_type=report_type)
return super(TrialBalanceWebkit, self).set_context(
objects, data, new_ids, report_type=report_type)
HeaderFooterTextWebKitParser('report.account.account_report_trial_balance_webkit',
HeaderFooterTextWebKitParser(
'report.account.account_report_trial_balance_webkit',
'account.account',
'addons/account_financial_report_webkit/report/templates/account_report_trial_balance.mako',
'addons/account_financial_report_webkit/report/templates/\
account_report_trial_balance.mako',
parser=TrialBalanceWebkit)

56
account_financial_report_webkit/report/webkit_parser_header_fix.py

@ -56,7 +56,8 @@ _logger = logging.getLogger('financial.reports.webkit')
# them in the localcontext with a key 'additional_args'
# for instance:
# header_report_name = _('PARTNER LEDGER')
# footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
# footer_date_time = self.formatLang(str(datetime.today()),
# date_time=True)
# self.localcontext.update({
# 'additional_args': [
# ('--header-font-name', 'Helvetica'),
@ -65,7 +66,8 @@ _logger = logging.getLogger('financial.reports.webkit')
# ('--footer-font-size', '7'),
# ('--header-left', header_report_name),
# ('--footer-left', footer_date_time),
# ('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
# ('--footer-right', ' '.join((_('Page'), '[page]', _('of'),
# '[topage]'))),
# ('--footer-line',),
# ],
# })
@ -82,8 +84,10 @@ def mako_template(text):
This template uses UTF-8 encoding
"""
tmp_lookup = TemplateLookup() # we need it in order to allow inclusion and inheritance
return Template(text, input_encoding='utf-8', output_encoding='utf-8', lookup=tmp_lookup)
tmp_lookup = TemplateLookup(
) # we need it in order to allow inclusion and inheritance
return Template(text, input_encoding='utf-8', output_encoding='utf-8',
lookup=tmp_lookup)
class HeaderFooterTextWebKitParser(webkit_report.WebKitParser):
@ -106,17 +110,29 @@ class HeaderFooterTextWebKitParser(webkit_report.WebKitParser):
command.extend(['--encoding', 'utf-8'])
if webkit_header.margin_top:
command.extend(['--margin-top', str(webkit_header.margin_top).replace(',', '.')])
command.extend(
['--margin-top',
str(webkit_header.margin_top).replace(',', '.')])
if webkit_header.margin_bottom:
command.extend(['--margin-bottom', str(webkit_header.margin_bottom).replace(',', '.')])
command.extend(
['--margin-bottom',
str(webkit_header.margin_bottom).replace(',', '.')])
if webkit_header.margin_left:
command.extend(['--margin-left', str(webkit_header.margin_left).replace(',', '.')])
command.extend(
['--margin-left',
str(webkit_header.margin_left).replace(',', '.')])
if webkit_header.margin_right:
command.extend(['--margin-right', str(webkit_header.margin_right).replace(',', '.')])
command.extend(
['--margin-right',
str(webkit_header.margin_right).replace(',', '.')])
if webkit_header.orientation:
command.extend(['--orientation', str(webkit_header.orientation).replace(',', '.')])
command.extend(
['--orientation',
str(webkit_header.orientation).replace(',', '.')])
if webkit_header.format:
command.extend(['--page-size', str(webkit_header.format).replace(',', '.')])
command.extend(
['--page-size',
str(webkit_header.format).replace(',', '.')])
if parser_instance.localcontext.get('additional_args', False):
for arg in parser_instance.localcontext['additional_args']:
@ -143,10 +159,14 @@ class HeaderFooterTextWebKitParser(webkit_report.WebKitParser):
if not error_message:
error_message = _('No diagnosis message was provided')
else:
error_message = _('The following diagnosis message was provided:\n') + error_message
error_message = _(
'The following diagnosis message was provided:\n') + \
error_message
if status:
raise except_osv(_('Webkit error'),
_("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
_("The command 'wkhtmltopdf' failed with \
error code = %s. Message: %s") %
(status, error_message))
with open(out_filename, 'rb') as pdf_file:
pdf = pdf_file.read()
os.close(fd)
@ -161,7 +181,8 @@ class HeaderFooterTextWebKitParser(webkit_report.WebKitParser):
return pdf
# override needed to keep the attachments' storing procedure
def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None):
def create_single_pdf(self, cursor, uid, ids, data, report_xml,
context=None):
"""generate the PDF"""
if context is None:
@ -184,13 +205,15 @@ class HeaderFooterTextWebKitParser(webkit_report.WebKitParser):
template = False
if report_xml.report_file:
path = addons.get_module_resource(*report_xml.report_file.split(os.path.sep))
path = addons.get_module_resource(
*report_xml.report_file.split(os.path.sep))
if os.path.exists(path):
template = file(path).read()
if not template and report_xml.report_webkit_data:
template = report_xml.report_webkit_data
if not template:
raise except_osv(_('Error!'), _('Webkit Report template not found !'))
raise except_osv(
_('Error!'), _('Webkit Report template not found !'))
header = report_xml.webkit_header.html
if not header and report_xml.header:
@ -204,7 +227,8 @@ class HeaderFooterTextWebKitParser(webkit_report.WebKitParser):
css = ''
translate_call = partial(self.translate_call, parser_instance)
#default_filters=['unicode', 'entity'] can be used to set global filter
# default_filters=['unicode', 'entity'] can be used to set global
# filter
body_mako_tpl = mako_template(template)
helper = WebKitHelper(cursor, uid, report_xml.id, context)
if report_xml.precise_mode:

151
account_financial_report_webkit/wizard/balance_common.py

@ -47,6 +47,7 @@ def previous_year_date(date, nb_prev=1):
class AccountBalanceCommonWizard(orm.TransientModel):
"""Will launch trial balance report and pass required args"""
_inherit = "account.common.account.report"
@ -75,44 +76,59 @@ class AccountBalanceCommonWizard(orm.TransientModel):
def _get_account_ids(self, cr, uid, context=None):
res = False
if context.get('active_model', False) == 'account.account' and context.get('active_ids', False):
if context.get('active_model', False) == 'account.account' \
and context.get('active_ids', False):
res = context['active_ids']
return res
_columns = {
'account_ids': fields.many2many('account.account', string='Filter on accounts',
help="Only selected accounts will be printed. Leave empty to print all accounts."),
'filter': fields.selection([('filter_no', 'No Filters'),
'account_ids': fields.many2many(
'account.account', string='Filter on accounts',
help="Only selected accounts will be printed. Leave empty to \
print all accounts."),
'filter': fields.selection(
[('filter_no', 'No Filters'),
('filter_date', 'Date'),
('filter_period', 'Periods'),
('filter_opening', 'Opening Only')],
"Filter by",
required=True,
help='Filter by date: no opening balance will be displayed. '
'(opening balance can only be computed based on period to be correct).'),
'(opening balance can only be computed based on period to be \
correct).'),
}
for index in range(COMPARISON_LEVEL):
_columns.update(
{"comp%s_filter" % index: fields.selection(COMPARE_SELECTION, string='Compare By', required=True),
"comp%s_fiscalyear_id" % index: fields.many2one('account.fiscalyear', 'Fiscal Year'),
"comp%s_period_from" % index: fields.many2one('account.period', 'Start Period'),
"comp%s_period_to" % index: fields.many2one('account.period', 'End Period'),
"comp%s_date_from" % index: fields.date("Start Date"),
"comp%s_date_to" % index: fields.date("End Date")})
{"comp%s_filter" % index:
fields.selection(
COMPARE_SELECTION, string='Compare By', required=True),
"comp%s_fiscalyear_id" % index:
fields.many2one('account.fiscalyear', 'Fiscal Year'),
"comp%s_period_from" % index:
fields.many2one('account.period', 'Start Period'),
"comp%s_period_to" % index:
fields.many2one('account.period', 'End Period'),
"comp%s_date_from" % index:
fields.date("Start Date"),
"comp%s_date_to" % index:
fields.date("End Date")})
_defaults = {
'account_ids': _get_account_ids,
}
def _check_fiscalyear(self, cr, uid, ids, context=None):
obj = self.read(cr, uid, ids[0], ['fiscalyear_id', 'filter'], context=context)
obj = self.read(
cr, uid, ids[0], ['fiscalyear_id', 'filter'], context=context)
if not obj['fiscalyear_id'] and obj['filter'] == 'filter_no':
return False
return True
_constraints = [
(_check_fiscalyear, 'When no Fiscal year is selected, you must choose to filter by periods or by date.', ['filter']),
(_check_fiscalyear,
'When no Fiscal year is selected, you must choose to filter by \
periods or by date.', ['filter']),
]
def default_get(self, cr, uid, fields, context=None):
@ -128,15 +144,19 @@ class AccountBalanceCommonWizard(orm.TransientModel):
@return: A dictionary which of fields with values.
"""
res = super(AccountBalanceCommonWizard, self).default_get(cr, uid, fields, context=context)
res = super(AccountBalanceCommonWizard, self).default_get(
cr, uid, fields, context=context)
for index in range(self.COMPARISON_LEVEL):
field = "comp%s_filter" % (index,)
if not res.get(field, False):
res[field] = 'filter_no'
return res
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = super(AccountBalanceCommonWizard, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
context=None, toolbar=False, submenu=False):
res = super(AccountBalanceCommonWizard, self).fields_view_get(
cr, uid, view_id, view_type, context=context, toolbar=toolbar,
submenu=submenu)
res['fields'].update(self.fields_get(cr, uid,
allfields=self.DYNAMIC_FIELDS,
@ -161,16 +181,23 @@ class AccountBalanceCommonWizard(orm.TransientModel):
modifiers_and_append(etree.Element(
'field',
{'name': "comp%s_filter" % index,
'on_change': "onchange_comp_filter(%(index)s, filter, comp%(index)s_filter, fiscalyear_id, date_from, date_to)" % {'index': index}}))
'on_change': "onchange_comp_filter(%(index)s, filter,\
comp%(index)s_filter, fiscalyear_id, date_from, date_to)"
% {'index': index}}))
modifiers_and_append(etree.Element(
'field',
{'name': "comp%s_fiscalyear_id" % index,
'attrs':
"{'required': [('comp%(index)s_filter','in',('filter_year','filter_opening'))]," \
" 'invisible': [('comp%(index)s_filter','not in',('filter_year','filter_opening'))]}" % {'index': index}}))
dates_attrs = "{'required': [('comp%(index)s_filter','=','filter_date')], " \
" 'invisible': [('comp%(index)s_filter','!=','filter_date')]}" % {'index': index}
"{'required': [('comp%(index)s_filter','in',\
('filter_year','filter_opening'))],"
" 'invisible': [('comp%(index)s_filter','not in',\
('filter_year','filter_opening'))]}" % {'index': index}}))
dates_attrs = "{'required': [('comp%(index)s_filter','=',\
'filter_date')], " \
" 'invisible': [('comp%(index)s_filter','!=',\
'filter_date')]}" % {
'index': index}
modifiers_and_append(etree.Element(
'separator',
{'string': _('Dates'),
@ -185,8 +212,11 @@ class AccountBalanceCommonWizard(orm.TransientModel):
{'name': "comp%s_date_to" % index,
'attrs': dates_attrs}))
periods_attrs = "{'required': [('comp%(index)s_filter','=','filter_period')]," \
" 'invisible': [('comp%(index)s_filter','!=','filter_period')]}" % {'index': index}
periods_attrs = "{'required': [('comp%(index)s_filter','=',\
'filter_period')]," \
" 'invisible': [('comp%(index)s_filter','!=',\
'filter_period')]}" % {
'index': index}
periods_domain = "[('special', '=', False)]"
modifiers_and_append(etree.Element(
'separator',
@ -209,24 +239,34 @@ class AccountBalanceCommonWizard(orm.TransientModel):
res['arch'] = etree.tostring(eview)
return res
def onchange_filter(self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, context=None):
def onchange_filter(self, cr, uid, ids, filter='filter_no',
fiscalyear_id=False, context=None):
res = {}
if filter == 'filter_no':
res['value'] = {'period_from': False, 'period_to': False, 'date_from': False, 'date_to': False}
res['value'] = {'period_from': False,
'period_to': False,
'date_from': False,
'date_to': False}
if filter == 'filter_date':
if fiscalyear_id:
fyear = self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id, context=context)
fyear = self.pool.get('account.fiscalyear').browse(
cr, uid, fiscalyear_id, context=context)
date_from = fyear.date_start
date_to = fyear.date_stop > time.strftime('%Y-%m-%d') and time.strftime('%Y-%m-%d') or fyear.date_stop
date_to = fyear.date_stop > time.strftime(
'%Y-%m-%d') and time.strftime('%Y-%m-%d') \
or fyear.date_stop
else:
date_from, date_to = time.strftime('%Y-01-01'), time.strftime('%Y-%m-%d')
res['value'] = {'period_from': False, 'period_to': False, 'date_from': date_from, 'date_to': date_to}
date_from, date_to = time.strftime(
'%Y-01-01'), time.strftime('%Y-%m-%d')
res['value'] = {'period_from': False, 'period_to':
False, 'date_from': date_from, 'date_to': date_to}
if filter == 'filter_period' and fiscalyear_id:
start_period = end_period = False
cr.execute('''
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %s
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_start ASC
@ -234,31 +274,41 @@ class AccountBalanceCommonWizard(orm.TransientModel):
UNION ALL
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %s
AND p.date_start < NOW()
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_stop DESC
LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
LIMIT 1) AS period_stop''',
(fiscalyear_id, fiscalyear_id))
periods = [i[0] for i in cr.fetchall()]
if periods:
start_period = end_period = periods[0]
if len(periods) > 1:
end_period = periods[1]
res['value'] = {'period_from': start_period, 'period_to': end_period, 'date_from': False, 'date_to': False}
res['value'] = {'period_from': start_period, 'period_to':
end_period, 'date_from': False, 'date_to': False}
return res
def onchange_comp_filter(self, cr, uid, ids, index, main_filter='filter_no', comp_filter='filter_no', fiscalyear_id=False, start_date=False, stop_date=False, context=None):
def onchange_comp_filter(self, cr, uid, ids, index,
main_filter='filter_no', comp_filter='filter_no',
fiscalyear_id=False, start_date=False,
stop_date=False, context=None):
res = {}
fy_obj = self.pool.get('account.fiscalyear')
last_fiscalyear_id = False
if fiscalyear_id:
fiscalyear = fy_obj.browse(cr, uid, fiscalyear_id, context=context)
last_fiscalyear_ids = fy_obj.search(cr, uid, [('date_stop', '<', fiscalyear.date_start)],
limit=self.COMPARISON_LEVEL, order='date_start desc', context=context)
last_fiscalyear_ids = fy_obj.search(
cr, uid, [('date_stop', '<', fiscalyear.date_start)],
limit=self.COMPARISON_LEVEL, order='date_start desc',
context=context)
if last_fiscalyear_ids:
if len(last_fiscalyear_ids) > index:
last_fiscalyear_id = last_fiscalyear_ids[index] # first element for the comparison 1, second element for the comparison 2
# first element for the comparison 1, second element for
# the comparison 2
last_fiscalyear_id = last_fiscalyear_ids[index]
fy_id_field = "comp%s_fiscalyear_id" % (index,)
period_from_field = "comp%s_period_from" % (index,)
@ -286,19 +336,28 @@ class AccountBalanceCommonWizard(orm.TransientModel):
dates = {}
if main_filter == 'filter_date':
dates = {
'date_start': previous_year_date(start_date, index + 1).strftime('%Y-%m-%d'),
'date_stop': previous_year_date(stop_date, index + 1).strftime('%Y-%m-%d'),
'date_start': previous_year_date(start_date, index + 1).
strftime('%Y-%m-%d'),
'date_stop': previous_year_date(stop_date, index + 1).
strftime('%Y-%m-%d'),
}
elif last_fiscalyear_id:
dates = fy_obj.read(cr, uid, last_fiscalyear_id, ['date_start', 'date_stop'], context=context)
dates = fy_obj.read(
cr, uid, last_fiscalyear_id, ['date_start', 'date_stop'],
context=context)
res['value'] = {fy_id_field: False, period_from_field: False, period_to_field: False, date_from_field: dates.get('date_start', False), date_to_field: dates.get('date_stop', False)}
res['value'] = {fy_id_field: False,
period_from_field: False,
period_to_field: False,
date_from_field: dates.get('date_start', False),
date_to_field: dates.get('date_stop', False)}
if comp_filter == 'filter_period' and last_fiscalyear_id:
start_period = end_period = False
cr.execute('''
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %(fiscalyear)s
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_start ASC
@ -306,12 +365,14 @@ class AccountBalanceCommonWizard(orm.TransientModel):
UNION ALL
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %(fiscalyear)s
AND p.date_start < NOW()
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_stop DESC
LIMIT 1) AS period_stop''', {'fiscalyear': last_fiscalyear_id})
LIMIT 1) AS period_stop''',
{'fiscalyear': last_fiscalyear_id})
periods = [i[0] for i in cr.fetchall()]
if periods and len(periods) > 1:
start_period = end_period = periods[0]

52
account_financial_report_webkit/wizard/general_ledger_wizard.py

@ -25,6 +25,7 @@ from openerp.osv import fields, orm
class AccountReportGeneralLedgerWizard(orm.TransientModel):
"""Will launch general ledger report and pass required args"""
_inherit = "account.common.account.report"
@ -33,7 +34,8 @@ class AccountReportGeneralLedgerWizard(orm.TransientModel):
def _get_account_ids(self, cr, uid, context=None):
res = False
if context.get('active_model', False) == 'account.account' and context.get('active_ids', False):
if context.get('active_model', False) == 'account.account' \
and context.get('active_ids', False):
res = context['active_ids']
return res
@ -41,13 +43,18 @@ class AccountReportGeneralLedgerWizard(orm.TransientModel):
'amount_currency': fields.boolean("With Currency",
help="It adds the currency column"),
'display_account': fields.selection([('bal_all', 'All'),
'display_account': fields.selection(
[('bal_all', 'All'),
('bal_mix', 'With transactions or non zero balance')],
'Display accounts',
required=True),
'account_ids': fields.many2many('account.account', string='Filter on accounts',
help="""Only selected accounts will be printed. Leave empty to print all accounts."""),
'centralize': fields.boolean('Activate Centralization', help='Uncheck to display all the details of centralized accounts.')
'account_ids': fields.many2many(
'account.account', string='Filter on accounts',
help="""Only selected accounts will be printed. Leave empty to
print all accounts."""),
'centralize': fields.boolean(
'Activate Centralization',
help='Uncheck to display all the details of centralized accounts.')
}
_defaults = {
'amount_currency': False,
@ -57,17 +64,21 @@ class AccountReportGeneralLedgerWizard(orm.TransientModel):
}
def _check_fiscalyear(self, cr, uid, ids, context=None):
obj = self.read(cr, uid, ids[0], ['fiscalyear_id', 'filter'], context=context)
obj = self.read(
cr, uid, ids[0], ['fiscalyear_id', 'filter'], context=context)
if not obj['fiscalyear_id'] and obj['filter'] == 'filter_no':
return False
return True
_constraints = [
(_check_fiscalyear, 'When no Fiscal year is selected, you must choose to filter by periods or by date.', ['filter']),
(_check_fiscalyear,
'When no Fiscal year is selected, you must choose to filter by \
periods or by date.', ['filter']),
]
def pre_print_report(self, cr, uid, ids, data, context=None):
data = super(AccountReportGeneralLedgerWizard, self).pre_print_report(cr, uid, ids, data, context)
data = super(AccountReportGeneralLedgerWizard, self).pre_print_report(
cr, uid, ids, data, context)
# will be used to attach the report on the main account
data['ids'] = [data['form']['chart_account_id']]
vals = self.read(cr, uid, ids,
@ -79,7 +90,8 @@ class AccountReportGeneralLedgerWizard(orm.TransientModel):
data['form'].update(vals)
return data
def onchange_filter(self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, context=None):
def onchange_filter(self, cr, uid, ids, filter='filter_no',
fiscalyear_id=False, context=None):
res = {}
if filter == 'filter_no':
res['value'] = {
@ -90,11 +102,15 @@ class AccountReportGeneralLedgerWizard(orm.TransientModel):
}
if filter == 'filter_date':
if fiscalyear_id:
fyear = self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id, context=context)
fyear = self.pool.get('account.fiscalyear').browse(
cr, uid, fiscalyear_id, context=context)
date_from = fyear.date_start
date_to = fyear.date_stop > time.strftime('%Y-%m-%d') and time.strftime('%Y-%m-%d') or fyear.date_stop
date_to = fyear.date_stop > time.strftime(
'%Y-%m-%d') and time.strftime('%Y-%m-%d') \
or fyear.date_stop
else:
date_from, date_to = time.strftime('%Y-01-01'), time.strftime('%Y-%m-%d')
date_from, date_to = time.strftime(
'%Y-01-01'), time.strftime('%Y-%m-%d')
res['value'] = {
'period_from': False,
'period_to': False,
@ -106,7 +122,8 @@ class AccountReportGeneralLedgerWizard(orm.TransientModel):
cr.execute('''
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %s
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_start ASC
@ -114,18 +131,21 @@ class AccountReportGeneralLedgerWizard(orm.TransientModel):
UNION ALL
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %s
AND p.date_start < NOW()
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_stop DESC
LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
LIMIT 1) AS period_stop''',
(fiscalyear_id, fiscalyear_id))
periods = [i[0] for i in cr.fetchall()]
if periods:
start_period = end_period = periods[0]
if len(periods) > 1:
end_period = periods[1]
res['value'] = {'period_from': start_period, 'period_to': end_period, 'date_from': False, 'date_to': False}
res['value'] = {'period_from': start_period, 'period_to':
end_period, 'date_from': False, 'date_to': False}
return res
def _print_report(self, cursor, uid, ids, data, context=None):

65
account_financial_report_webkit/wizard/open_invoices_wizard.py

@ -22,6 +22,7 @@ from openerp.osv import fields, orm
class AccountReportOpenInvoicesWizard(orm.TransientModel):
"""Will launch partner ledger report and pass required args"""
_inherit = "partners.ledger.webkit"
@ -30,20 +31,27 @@ class AccountReportOpenInvoicesWizard(orm.TransientModel):
_columns = {
'group_by_currency': fields.boolean('Group Partner by currency'),
'until_date': fields.date("Clearance date",
'until_date': fields.date(
"Clearance date",
required=True,
help="""The clearance date is essentially a tool used for debtors provisionning calculation.
help="""The clearance date is essentially a tool used for debtors
provisionning calculation.
By default, this date is equal to the the end date (ie: 31/12/2011 if you select fy 2011).
By default, this date is equal to the the end date (ie: 31/12/2011 if you
select fy 2011).
By amending the clearance date, you will be, for instance, able to answer the question : 'based on my last year end debtors open invoices, which invoices are still unpaid today (today is my clearance date)?'
By amending the clearance date, you will be, for instance, able to answer the
question : 'based on my last year end debtors open invoices, which invoices
are still unpaid today (today is my clearance date)?'
""")}
def _check_until_date(self, cr, uid, ids, context=None):
def get_key_id(obj, field):
return obj.get(field) and obj[field][0] or False
obj = self.read(cr, uid, ids[0], ['fiscalyear_id', 'period_to', 'date_to', 'until_date'], context=context)
obj = self.read(cr, uid, ids[0], [
'fiscalyear_id', 'period_to', 'date_to', 'until_date'],
context=context)
min_date = self.default_until_date(cr, uid, ids,
get_key_id(obj, 'fiscalyear_id'),
get_key_id(obj, 'period_to'),
@ -54,51 +62,69 @@ By amending the clearance date, you will be, for instance, able to answer the qu
return True
_constraints = [
(_check_until_date, 'Clearance date must be the very last date of the last period or later.', ['until_date']),
(_check_until_date, 'Clearance date must be the very last date of the \
last period or later.', ['until_date']),
]
def default_until_date(self, cr, uid, ids, fiscalyear_id=False, period_id=False, date_to=False, context=None):
def default_until_date(self, cr, uid, ids, fiscalyear_id=False,
period_id=False, date_to=False, context=None):
res_date = False
# first priority: period or date filters
if period_id:
res_date = self.pool.get('account.period').read(cr, uid, period_id, ['date_stop'], context=context)['date_stop']
res_date = self.pool.get('account.period').read(
cr, uid, period_id, ['date_stop'],
context=context)['date_stop']
elif date_to:
res_date = date_to
elif fiscalyear_id:
res_date = self.pool.get('account.fiscalyear').read(cr, uid, fiscalyear_id, ['date_stop'], context=context)['date_stop']
res_date = self.pool.get('account.fiscalyear').read(
cr, uid, fiscalyear_id, ['date_stop'],
context=context)['date_stop']
return res_date
def onchange_fiscalyear(self, cr, uid, ids, fiscalyear=False, period_id=False, date_to=False, until_date=False, context=None):
def onchange_fiscalyear(self, cr, uid, ids, fiscalyear=False,
period_id=False, date_to=False, until_date=False,
context=None):
res = {'value': {}}
res['value']['until_date'] = self.default_until_date(cr, uid, ids,
res['value']['until_date'] = self.default_until_date(
cr, uid, ids,
fiscalyear_id=fiscalyear,
period_id=period_id,
date_to=date_to,
context=context)
return res
def onchange_date_to(self, cr, uid, ids, fiscalyear=False, period_id=False, date_to=False, until_date=False, context=None):
def onchange_date_to(self, cr, uid, ids, fiscalyear=False, period_id=False,
date_to=False, until_date=False, context=None):
res = {'value': {}}
res['value']['until_date'] = self.default_until_date(cr, uid, ids,
res['value']['until_date'] = self.default_until_date(
cr, uid, ids,
fiscalyear_id=fiscalyear,
period_id=period_id,
date_to=date_to,
context=context)
return res
def onchange_period_to(self, cr, uid, ids, fiscalyear=False, period_id=False, date_to=False, until_date=False, context=None):
def onchange_period_to(self, cr, uid, ids, fiscalyear=False,
period_id=False, date_to=False, until_date=False,
context=None):
res = {'value': {}}
res['value']['until_date'] = self.default_until_date(cr, uid, ids,
res['value']['until_date'] = self.default_until_date(
cr, uid, ids,
fiscalyear_id=fiscalyear,
period_id=period_id,
date_to=date_to,
context=context)
return res
def onchange_filter(self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, context=None):
res = super(AccountReportOpenInvoicesWizard, self).onchange_filter(cr, uid, ids, filter=filter, fiscalyear_id=fiscalyear_id, context=context)
def onchange_filter(self, cr, uid, ids, filter='filter_no',
fiscalyear_id=False, context=None):
res = super(AccountReportOpenInvoicesWizard, self).onchange_filter(
cr, uid, ids, filter=filter, fiscalyear_id=fiscalyear_id,
context=context)
if res.get('value', False):
res['value']['until_date'] = self.default_until_date(cr, uid, ids,
res['value']['until_date'] = self.default_until_date(
cr, uid, ids,
fiscalyear_id=fiscalyear_id,
period_id=res['value'].get('period_to', False),
date_to=res['value'].get('date_to', False),
@ -106,7 +132,8 @@ By amending the clearance date, you will be, for instance, able to answer the qu
return res
def pre_print_report(self, cr, uid, ids, data, context=None):
data = super(AccountReportOpenInvoicesWizard, self).pre_print_report(cr, uid, ids, data, context)
data = super(AccountReportOpenInvoicesWizard, self).pre_print_report(
cr, uid, ids, data, context)
vals = self.read(cr, uid, ids,
['until_date', 'group_by_currency'],
context=context)[0]

13
account_financial_report_webkit/wizard/partner_balance_wizard.py

@ -23,6 +23,7 @@ from openerp.osv import fields, orm
class AccountPartnerBalanceWizard(orm.TransientModel):
"""Will launch partner balance report and pass required args"""
_inherit = "account.common.balance.report"
@ -30,12 +31,15 @@ class AccountPartnerBalanceWizard(orm.TransientModel):
_description = "Partner Balance Report"
_columns = {
'result_selection': fields.selection([('customer', 'Receivable Accounts'),
'result_selection': fields.selection(
[('customer', 'Receivable Accounts'),
('supplier', 'Payable Accounts'),
('customer_supplier', 'Receivable and Payable Accounts')],
"Partner's", required=True),
'partner_ids': fields.many2many('res.partner', string='Filter on partner',
help="Only selected partners will be printed. Leave empty to print all partners."),
'partner_ids': fields.many2many(
'res.partner', string='Filter on partner',
help="Only selected partners will be printed. \
Leave empty to print all partners."),
}
_defaults = {
@ -43,7 +47,8 @@ class AccountPartnerBalanceWizard(orm.TransientModel):
}
def pre_print_report(self, cr, uid, ids, data, context=None):
data = super(AccountPartnerBalanceWizard, self).pre_print_report(cr, uid, ids, data, context)
data = super(AccountPartnerBalanceWizard, self).\
pre_print_report(cr, uid, ids, data, context)
vals = self.read(cr, uid, ids,
['result_selection', 'partner_ids'],
context=context)[0]

50
account_financial_report_webkit/wizard/partners_ledger_wizard.py

@ -24,6 +24,7 @@ from openerp.osv import fields, orm
class AccountReportPartnersLedgerWizard(orm.TransientModel):
"""Will launch partner ledger report and pass required args"""
_inherit = "account.common.partner.report"
@ -33,14 +34,18 @@ class AccountReportPartnersLedgerWizard(orm.TransientModel):
_columns = {
'amount_currency': fields.boolean("With Currency",
help="It adds the currency column"),
'partner_ids': fields.many2many('res.partner', string='Filter on partner',
'partner_ids': fields.many2many(
'res.partner',
string='Filter on partner',
help="Only selected partners will be printed. "
"Leave empty to print all partners."),
'filter': fields.selection([('filter_no', 'No Filters'),
'filter': fields.selection(
[('filter_no', 'No Filters'),
('filter_date', 'Date'),
('filter_period', 'Periods')], "Filter by", required=True,
help='Filter by date: no opening balance will be displayed. '
'(opening balance can only be computed based on period to be correct).'),
'(opening balance can only be computed based on period to be \
correct).'),
}
_defaults = {
'amount_currency': False,
@ -48,7 +53,8 @@ class AccountReportPartnersLedgerWizard(orm.TransientModel):
}
def _check_fiscalyear(self, cr, uid, ids, context=None):
obj = self.read(cr, uid, ids[0], ['fiscalyear_id', 'filter'], context=context)
obj = self.read(
cr, uid, ids[0], ['fiscalyear_id', 'filter'], context=context)
if not obj['fiscalyear_id'] and obj['filter'] == 'filter_no':
return False
return True
@ -60,25 +66,35 @@ class AccountReportPartnersLedgerWizard(orm.TransientModel):
['filter']),
]
def onchange_filter(self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, context=None):
def onchange_filter(self, cr, uid, ids, filter='filter_no',
fiscalyear_id=False, context=None):
res = {}
if filter == 'filter_no':
res['value'] = {'period_from': False, 'period_to': False, 'date_from': False, 'date_to': False}
res['value'] = {'period_from': False,
'period_to': False,
'date_from': False,
'date_to': False}
if filter == 'filter_date':
if fiscalyear_id:
fyear = self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id, context=context)
fyear = self.pool.get('account.fiscalyear').browse(
cr, uid, fiscalyear_id, context=context)
date_from = fyear.date_start
date_to = fyear.date_stop > time.strftime('%Y-%m-%d') and time.strftime('%Y-%m-%d') or fyear.date_stop
date_to = fyear.date_stop > time.strftime(
'%Y-%m-%d') and time.strftime('%Y-%m-%d') \
or fyear.date_stop
else:
date_from, date_to = time.strftime('%Y-01-01'), time.strftime('%Y-%m-%d')
res['value'] = {'period_from': False, 'period_to': False, 'date_from': date_from, 'date_to': date_to}
date_from, date_to = time.strftime(
'%Y-01-01'), time.strftime('%Y-%m-%d')
res['value'] = {'period_from': False, 'period_to':
False, 'date_from': date_from, 'date_to': date_to}
if filter == 'filter_period' and fiscalyear_id:
start_period = end_period = False
cr.execute('''
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %s
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_start ASC
@ -86,22 +102,26 @@ class AccountReportPartnersLedgerWizard(orm.TransientModel):
UNION ALL
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %s
AND p.date_start < NOW()
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_stop DESC
LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
LIMIT 1) AS period_stop''',
(fiscalyear_id, fiscalyear_id))
periods = [i[0] for i in cr.fetchall()]
if periods:
start_period = end_period = periods[0]
if len(periods) > 1:
end_period = periods[1]
res['value'] = {'period_from': start_period, 'period_to': end_period, 'date_from': False, 'date_to': False}
res['value'] = {'period_from': start_period, 'period_to':
end_period, 'date_from': False, 'date_to': False}
return res
def pre_print_report(self, cr, uid, ids, data, context=None):
data = super(AccountReportPartnersLedgerWizard, self).pre_print_report(cr, uid, ids, data, context)
data = super(AccountReportPartnersLedgerWizard, self).pre_print_report(
cr, uid, ids, data, context)
if context is None:
context = {}
# will be used to attach the report on the main account

63
account_financial_report_webkit/wizard/print_journal.py

@ -7,13 +7,13 @@
#
# This file is a part of account_financial_report_webkit
#
# account_financial_report_webkit is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# account_financial_report_webkit is free software: you can redistribute it
# and/or modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# account_financial_report_webkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# account_financial_report_webkit 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 Affero General Public License for more details.
#
@ -24,10 +24,10 @@
from openerp.osv import fields, orm
import time
from lxml import etree
class AccountReportPrintJournalWizard(orm.TransientModel):
"""Will launch print journal report and pass requiered args"""
_inherit = "account.common.account.report"
@ -35,7 +35,8 @@ class AccountReportPrintJournalWizard(orm.TransientModel):
_description = "Journals Report"
_columns = {
'amount_currency': fields.boolean("With Currency", help="It adds the currency column"),
'amount_currency': fields.boolean("With Currency",
help="It adds the currency column"),
}
_defaults = {
@ -45,17 +46,20 @@ class AccountReportPrintJournalWizard(orm.TransientModel):
}
def _check_fiscalyear(self, cr, uid, ids, context=None):
obj = self.read(cr, uid, ids[0], ['fiscalyear_id', 'filter'], context=context)
obj = self.read(cr, uid, ids[0], ['fiscalyear_id', 'filter'],
context=context)
if not obj['fiscalyear_id'] and obj['filter'] == 'filter_no':
return False
return True
_constraints = [
(_check_fiscalyear, 'When no Fiscal year is selected, you must choose to filter by periods or by date.', ['filter']),
(_check_fiscalyear, 'When no Fiscal year is selected, you must choose \
to filter by periods or by date.', ['filter']),
]
def pre_print_report(self, cr, uid, ids, data, context=None):
data = super(AccountReportPrintJournalWizard, self).pre_print_report(cr, uid, ids, data, context)
data = super(AccountReportPrintJournalWizard, self).\
pre_print_report(cr, uid, ids, data, context)
# will be used to attach the report on the main account
data['ids'] = [data['form']['chart_account_id']]
vals = self.read(cr, uid, ids,
@ -66,24 +70,34 @@ class AccountReportPrintJournalWizard(orm.TransientModel):
data['form'].update(vals)
return data
def onchange_filter(self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, context=None):
def onchange_filter(self, cr, uid, ids, filter='filter_no',
fiscalyear_id=False, context=None):
res = {}
if filter == 'filter_no':
res['value'] = {'period_from': False, 'period_to': False, 'date_from': False, 'date_to': False}
res['value'] = {'period_from': False,
'period_to': False,
'date_from': False,
'date_to': False}
if filter == 'filter_date':
if fiscalyear_id:
fyear = self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id, context=context)
fyear = self.pool.get('account.fiscalyear').browse(
cr, uid, fiscalyear_id, context=context)
date_from = fyear.date_start
date_to = fyear.date_stop > time.strftime('%Y-%m-%d') and time.strftime('%Y-%m-%d') or fyear.date_stop
date_to = fyear.date_stop > time.strftime(
'%Y-%m-%d') and time.strftime('%Y-%m-%d') \
or fyear.date_stop
else:
date_from, date_to = time.strftime('%Y-01-01'), time.strftime('%Y-%m-%d')
res['value'] = {'period_from': False, 'period_to': False, 'date_from': date_from, 'date_to': date_to}
date_from, date_to = time.strftime(
'%Y-01-01'), time.strftime('%Y-%m-%d')
res['value'] = {'period_from': False, 'period_to':
False, 'date_from': date_from, 'date_to': date_to}
if filter == 'filter_period' and fiscalyear_id:
start_period = end_period = False
cr.execute('''
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %s
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_start ASC
@ -91,18 +105,21 @@ class AccountReportPrintJournalWizard(orm.TransientModel):
UNION ALL
SELECT * FROM (SELECT p.id
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
LEFT JOIN account_fiscalyear f
ON (p.fiscalyear_id = f.id)
WHERE f.id = %s
AND p.date_start < NOW()
AND COALESCE(p.special, FALSE) = FALSE
ORDER BY p.date_stop DESC
LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
LIMIT 1) AS period_stop''',
(fiscalyear_id, fiscalyear_id))
periods = [i[0] for i in cr.fetchall()]
if periods:
start_period = end_period = periods[0]
if len(periods) > 1:
end_period = periods[1]
res['value'] = {'period_from': start_period, 'period_to': end_period, 'date_from': False, 'date_to': False}
res['value'] = {'period_from': start_period, 'period_to':
end_period, 'date_from': False, 'date_to': False}
return res
def _print_report(self, cursor, uid, ids, data, context=None):
@ -112,7 +129,3 @@ class AccountReportPrintJournalWizard(orm.TransientModel):
return {'type': 'ir.actions.report.xml',
'report_name': 'account.account_report_print_journal_webkit',
'datas': data}
AccountReportPrintJournalWizard()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

2
account_financial_report_webkit/wizard/trial_balance_wizard.py

@ -37,5 +37,3 @@ class AccountTrialBalanceWizard(orm.TransientModel):
return {'type': 'ir.actions.report.xml',
'report_name': 'account.account_report_trial_balance_webkit',
'datas': data}
AccountTrialBalanceWizard()

4
account_financial_report_webkit_xls/__init__.py

@ -25,5 +25,5 @@ try:
from . import report
except ImportError:
import logging
logging.getLogger('openerp.module').warning('report_xls not available in addons path. account_financial_report_webkit_xls will not be usable')
logging.getLogger('openerp.module').warning('''report_xls not available in
addons path. account_financial_report_webkit_xls will not be usable''')

5
account_financial_report_webkit_xls/__openerp__.py

@ -36,9 +36,8 @@
""",
'depends': ['report_xls', 'account_financial_report_webkit'],
'demo_xml': [],
'init_xml': [],
'update_xml' : [
'demo': [],
'data': [
'wizard/general_ledger_wizard_view.xml',
'wizard/trial_balance_wizard_view.xml',
'wizard/partners_ledger_wizard_view.xml',

2
account_financial_report_webkit_xls/report/__init__.py

@ -25,5 +25,3 @@ from . import trial_balance_xls
from . import partners_balance_xls
from . import partner_ledger_xls
from . import open_invoices_xls
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

201
account_financial_report_webkit_xls/report/general_ledger_xls.py

@ -21,15 +21,14 @@
##############################################################################
import xlwt
import time
from datetime import datetime
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell
from openerp.addons.account_financial_report_webkit.report.general_ledger import GeneralLedgerWebkit
from openerp.addons.account_financial_report_webkit.report.general_ledger \
import GeneralLedgerWebkit
from openerp.tools.translate import _
#import logging
#_logger = logging.getLogger(__name__)
# import logging
# _logger = logging.getLogger(__name__)
_column_sizes = [
('date', 12),
@ -47,6 +46,7 @@ _column_sizes = [
('curr_code', 7),
]
class general_ledger_xls(report_xls):
column_sizes = [x[1] for x in _column_sizes]
@ -64,22 +64,29 @@ class general_ledger_xls(report_xls):
ws.footer_str = self.xls_footers['standard']
# cf. account_report_general_ledger.mako
initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')}
initial_balance_text = {'initial_balance': _('Computed'),
'opening_balance': _('Opening Entries'),
False: _('No')}
# Title
cell_style = xlwt.easyxf(_xs['xls_title'])
report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name])
report_name = ' - '.join([_p.report_name.upper(),
_p.company.partner_id.name,
_p.company.currency_id.name])
c_specs = [
('report_name', 1, 0, 'text', report_name),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
# write empty row to define column sizes
c_sizes = self.column_sizes
c_specs = [('empty%s'%i, 1, c_sizes[i], 'text', None) for i in range(0,len(c_sizes))]
c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None)
for i in range(0, len(c_sizes))]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True)
row_pos = self.xls_write_row(
ws, row_pos, row_data, set_column_size=True)
# Header Table
cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all']
@ -88,14 +95,16 @@ class general_ledger_xls(report_xls):
c_specs = [
('coa', 2, 0, 'text', _('Chart of Account')),
('fy', 1, 0, 'text', _('Fiscal Year')),
('df', 3, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')),
('df', 3, 0, 'text', _p.filter_form(data) ==
'filter_date' and _('Dates Filter') or _('Periods Filter')),
('af', 1, 0, 'text', _('Accounts Filter')),
('tm', 2, 0, 'text', _('Target Moves')),
('ib', 2, 0, 'text', _('Initial Balance')),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_center)
cell_format = _xs['borders_all']
cell_style = xlwt.easyxf(cell_format)
@ -116,12 +125,15 @@ class general_ledger_xls(report_xls):
df += _p.stop_period.name if _p.stop_period else u''
c_specs += [
('df', 3, 0, 'text', df),
('af', 1, 0, 'text', _p.accounts(data) and ', '.join([account.code for account in _p.accounts(data)]) or _('All')),
('af', 1, 0, 'text', _p.accounts(data) and ', '.join(
[account.code for account in _p.accounts(data)]) or _('All')),
('tm', 2, 0, 'text', _p.display_target_move(data)),
('ib', 2, 0, 'text', initial_balance_text[_p.initial_balance_mode]),
('ib', 2, 0, 'text', initial_balance_text[
_p.initial_balance_mode]),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_center)
ws.set_horz_split_pos(row_pos)
row_pos += 1
@ -134,87 +146,111 @@ class general_ledger_xls(report_xls):
c_hdr_cell_style = xlwt.easyxf(cell_format)
c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
c_hdr_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
c_hdr_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# Column Initial Balance Row
cell_format = _xs['italic'] + _xs['borders_all']
c_init_cell_style = xlwt.easyxf(cell_format)
c_init_cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
c_init_cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
c_init_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
c_init_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
c_specs = [
('date', 1, 0, 'text', _('Date'), None, c_hdr_cell_style),
('period', 1, 0, 'text', _('Period'), None, c_hdr_cell_style),
('move', 1, 0, 'text', _('Entry'), None, c_hdr_cell_style),
('journal', 1, 0, 'text', _('Journal'), None, c_hdr_cell_style),
('account_code', 1, 0, 'text', _('Account'), None, c_hdr_cell_style),
('account_code', 1, 0, 'text',
_('Account'), None, c_hdr_cell_style),
('partner', 1, 0, 'text', _('Partner'), None, c_hdr_cell_style),
('label', 1, 0, 'text', _('Label'), None, c_hdr_cell_style),
('counterpart', 1, 0, 'text', _('Counterpart'), None, c_hdr_cell_style),
('counterpart', 1, 0, 'text',
_('Counterpart'), None, c_hdr_cell_style),
('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right),
('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style_right),
('cumul_bal', 1, 0, 'text', _('Cumul. Bal.'), None, c_hdr_cell_style_right),
('credit', 1, 0, 'text', _('Credit'),
None, c_hdr_cell_style_right),
('cumul_bal', 1, 0, 'text', _('Cumul. Bal.'),
None, c_hdr_cell_style_right),
]
if _p.amount_currency(data):
c_specs += [
('curr_bal', 1, 0, 'text', _('Curr. Bal.'), None, c_hdr_cell_style_right),
('curr_code', 1, 0, 'text', _('Curr.'), None, c_hdr_cell_style_center),
('curr_bal', 1, 0, 'text', _('Curr. Bal.'),
None, c_hdr_cell_style_right),
('curr_code', 1, 0, 'text', _('Curr.'),
None, c_hdr_cell_style_center),
]
c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
# cell styles for ledger lines
ll_cell_format = _xs['borders_all']
ll_cell_style = xlwt.easyxf(ll_cell_format)
ll_cell_style_right = xlwt.easyxf(ll_cell_format + _xs['right'])
ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs['center'])
ll_cell_style_date = xlwt.easyxf(ll_cell_format + _xs['left'], num_format_str = report_xls.date_format)
ll_cell_style_decimal = xlwt.easyxf(ll_cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
ll_cell_style_date = xlwt.easyxf(
ll_cell_format + _xs['left'],
num_format_str=report_xls.date_format)
ll_cell_style_decimal = xlwt.easyxf(
ll_cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
cnt = 0
for account in objects:
display_initial_balance = account.init_balance and (account.init_balance.get('debit', 0.0) != 0.0 or account.init_balance.get('credit', 0.0) != 0.0)
display_initial_balance = account.init_balance and \
(account.init_balance.get(
'debit', 0.0) != 0.0 or account.
init_balance.get('credit', 0.0) != 0.0)
display_ledger_lines = account.ledger_lines
if _p.display_account_raw(data) == 'all' or (display_ledger_lines or display_initial_balance):
#TO DO : replace cumul amounts by xls formulas
if _p.display_account_raw(data) == 'all' or \
(display_ledger_lines or display_initial_balance):
# TO DO : replace cumul amounts by xls formulas
cnt += 1
cumul_debit = 0.0
cumul_credit = 0.0
cumul_balance = 0.0
cumul_balance_curr = 0.0
c_specs = [
('acc_title', 11, 0, 'text', ' - '.join([account.code, account.name])),
('acc_title', 11, 0, 'text',
' - '.join([account.code, account.name])),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, c_title_cell_style)
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, c_title_cell_style)
row_pos = self.xls_write_row(ws, row_pos, c_hdr_data)
row_start = row_pos
if display_initial_balance:
cumul_debit = account.init_balance.get('debit') or 0.0
cumul_credit = account.init_balance.get('credit') or 0.0
cumul_balance = account.init_balance.get('init_balance') or 0.0
cumul_balance_curr = account.init_balance.get('init_balance_currency') or 0.0
debit_cell = rowcol_to_cell(row_pos, 8)
credit_cell = rowcol_to_cell(row_pos, 9)
bal_formula = debit_cell + '-' + credit_cell
c_specs = [('empty%s' %x, 1, 0, 'text', None) for x in range(6)]
cumul_balance = account.init_balance.get(
'init_balance') or 0.0
cumul_balance_curr = account.init_balance.get(
'init_balance_currency') or 0.0
c_specs = [('empty%s' % x, 1, 0, 'text', None)
for x in range(6)]
c_specs += [
('init_bal', 1, 0, 'text', _('Initial Balance')),
('counterpart', 1, 0, 'text', None),
('debit', 1, 0, 'number', cumul_debit, None, c_init_cell_style_decimal),
('credit', 1, 0, 'number', cumul_credit, None, c_init_cell_style_decimal),
('cumul_bal', 1, 0, 'number', cumul_balance, None, c_init_cell_style_decimal),
('debit', 1, 0, 'number', cumul_debit,
None, c_init_cell_style_decimal),
('credit', 1, 0, 'number', cumul_credit,
None, c_init_cell_style_decimal),
('cumul_bal', 1, 0, 'number', cumul_balance,
None, c_init_cell_style_decimal),
]
if _p.amount_currency(data):
c_specs += [
('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_init_cell_style_decimal),
('curr_bal', 1, 0, 'number', cumul_balance_curr,
None, c_init_cell_style_decimal),
('curr_code', 1, 0, 'text', None),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, c_init_cell_style)
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, c_init_cell_style)
for line in account.ledger_lines:
@ -224,63 +260,88 @@ class general_ledger_xls(report_xls):
cumul_balance += line.get('balance') or 0.0
label_elements = [line.get('lname') or '']
if line.get('invoice_number'):
label_elements.append("(%s)" % (line['invoice_number'],))
label_elements.append(
"(%s)" % (line['invoice_number'],))
label = ' '.join(label_elements)
if line.get('ldate'):
c_specs = [
('ldate', 1, 0, 'date', datetime.strptime(line['ldate'],'%Y-%m-%d'), None, ll_cell_style_date),
('ldate', 1, 0, 'date', datetime.strptime(
line['ldate'], '%Y-%m-%d'), None,
ll_cell_style_date),
]
else:
c_specs = [
('ldate', 1, 0, 'text', None),
]
c_specs += [
('period', 1, 0, 'text', line.get('period_code') or ''),
('period', 1, 0, 'text',
line.get('period_code') or ''),
('move', 1, 0, 'text', line.get('move_name') or ''),
('journal', 1, 0, 'text', line.get('jcode') or ''),
('account_code', 1, 0, 'text', account.code),
('partner', 1, 0, 'text', line.get('partner_name') or ''),
('partner', 1, 0, 'text',
line.get('partner_name') or ''),
('label', 1, 0, 'text', label),
('counterpart', 1, 0, 'text', line.get('counterparts') or ''),
('debit', 1, 0, 'number', line.get('debit', 0.0), None, ll_cell_style_decimal),
('credit', 1, 0, 'number', line.get('credit', 0.0), None, ll_cell_style_decimal),
('cumul_bal', 1, 0, 'number', cumul_balance, None, ll_cell_style_decimal),
('counterpart', 1, 0, 'text',
line.get('counterparts') or ''),
('debit', 1, 0, 'number', line.get('debit', 0.0),
None, ll_cell_style_decimal),
('credit', 1, 0, 'number', line.get('credit', 0.0),
None, ll_cell_style_decimal),
('cumul_bal', 1, 0, 'number', cumul_balance,
None, ll_cell_style_decimal),
]
if _p.amount_currency(data):
c_specs += [
('curr_bal', 1, 0, 'number', line.get('amount_currency') or 0.0, None, ll_cell_style_decimal),
('curr_code', 1, 0, 'text', line.get('currency_code') or '', None, ll_cell_style_center),
('curr_bal', 1, 0, 'number', line.get(
'amount_currency') or 0.0, None,
ll_cell_style_decimal),
('curr_code', 1, 0, 'text', line.get(
'currency_code') or '', None,
ll_cell_style_center),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, ll_cell_style)
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, ll_cell_style)
debit_start = rowcol_to_cell(row_start, 8)
debit_end = rowcol_to_cell(row_pos-1, 8)
debit_end = rowcol_to_cell(row_pos - 1, 8)
debit_formula = 'SUM(' + debit_start + ':' + debit_end + ')'
credit_start = rowcol_to_cell(row_start, 9)
credit_end = rowcol_to_cell(row_pos-1, 9)
credit_end = rowcol_to_cell(row_pos - 1, 9)
credit_formula = 'SUM(' + credit_start + ':' + credit_end + ')'
balance_debit = rowcol_to_cell(row_pos, 8)
balance_credit = rowcol_to_cell(row_pos, 9)
balance_formula = balance_debit + '-' + balance_credit
c_specs = [
('acc_title', 7, 0, 'text', ' - '.join([account.code, account.name])),
('cum_bal', 1, 0, 'text', _('Cumulated Balance on Account'), None, c_hdr_cell_style_right),
('debit', 1, 0, 'number', None, debit_formula, c_hdr_cell_style_decimal),
('credit', 1, 0, 'number', None, credit_formula, c_hdr_cell_style_decimal),
('balance', 1, 0, 'number', None, balance_formula, c_hdr_cell_style_decimal),
('acc_title', 7, 0, 'text',
' - '.join([account.code, account.name])),
('cum_bal', 1, 0, 'text',
_('Cumulated Balance on Account'),
None, c_hdr_cell_style_right),
('debit', 1, 0, 'number', None,
debit_formula, c_hdr_cell_style_decimal),
('credit', 1, 0, 'number', None,
credit_formula, c_hdr_cell_style_decimal),
('balance', 1, 0, 'number', None,
balance_formula, c_hdr_cell_style_decimal),
]
if _p.amount_currency(data):
if account.currency_id:
c_specs += [('curr_bal', 1, 0, 'number', cumul_balance_curr, None, c_hdr_cell_style_decimal)]
c_specs += [('curr_bal', 1, 0, 'number',
cumul_balance_curr, None,
c_hdr_cell_style_decimal)]
else:
c_specs += [('curr_bal', 1, 0, 'text', None)]
c_specs += [('curr_code', 1, 0, 'text', None)]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, c_hdr_cell_style)
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, c_hdr_cell_style)
row_pos += 1
general_ledger_xls('report.account.account_report_general_ledger_xls', 'account.account',
general_ledger_xls('report.account.account_report_general_ledger_xls',
'account.account',
parser=GeneralLedgerWebkit)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

820
account_financial_report_webkit_xls/report/open_invoices_xls.py
File diff suppressed because it is too large
View File

286
account_financial_report_webkit_xls/report/partner_ledger_xls.py

@ -21,15 +21,14 @@
##############################################################################
import xlwt
import time
from datetime import datetime
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell
from openerp.addons.account_financial_report_webkit.report.partners_ledger import PartnersLedgerWebkit
from openerp.addons.account_financial_report_webkit.report.partners_ledger \
import PartnersLedgerWebkit
from openerp.tools.translate import _
#import logging
#_logger = logging.getLogger(__name__)
# import logging
# _logger = logging.getLogger(__name__)
_column_sizes = [
('date', 12),
@ -46,6 +45,7 @@ _column_sizes = [
('curr_code', 7),
]
class partner_ledger_xls(report_xls):
column_sizes = [x[1] for x in _column_sizes]
@ -63,22 +63,29 @@ class partner_ledger_xls(report_xls):
ws.footer_str = self.xls_footers['standard']
# cf. account_report_partner_ledger.mako
initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')}
initial_balance_text = {'initial_balance': _('Computed'),
'opening_balance': _('Opening Entries'),
False: _('No')}
# Title
cell_style = xlwt.easyxf(_xs['xls_title'])
report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name])
report_name = ' - '.join([_p.report_name.upper(),
_p.company.partner_id.name,
_p.company.currency_id.name])
c_specs = [
('report_name', 1, 0, 'text', report_name),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
# write empty row to define column sizes
c_sizes = self.column_sizes
c_specs = [('empty%s'%i, 1, c_sizes[i], 'text', None) for i in range(0,len(c_sizes))]
c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None)
for i in range(0, len(c_sizes))]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True)
row_pos = self.xls_write_row(
ws, row_pos, row_data, set_column_size=True)
# Header Table
nbr_columns = 10
@ -90,14 +97,16 @@ class partner_ledger_xls(report_xls):
c_specs = [
('coa', 2, 0, 'text', _('Chart of Account')),
('fy', 1, 0, 'text', _('Fiscal Year')),
('df', 2, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')),
('df', 2, 0, 'text', _p.filter_form(data) ==
'filter_date' and _('Dates Filter') or _('Periods Filter')),
('af', 1, 0, 'text', _('Accounts Filter')),
('tm', 2, 0, 'text', _('Target Moves')),
('ib', nbr_columns-8, 0, 'text', _('Initial Balance')),
('ib', nbr_columns - 8, 0, 'text', _('Initial Balance')),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_center)
cell_format = _xs['borders_all']
cell_style = xlwt.easyxf(cell_format)
@ -118,20 +127,26 @@ class partner_ledger_xls(report_xls):
df += _p.stop_period.name if _p.stop_period else u''
c_specs += [
('df', 2, 0, 'text', df),
('af', 1, 0, 'text', _('Custom Filter') if _p.partner_ids else _p.display_partner_account(data)),
('af', 1, 0, 'text', _('Custom Filter')
if _p.partner_ids else _p.display_partner_account(data)),
('tm', 2, 0, 'text', _p.display_target_move(data)),
('ib', nbr_columns-8, 0, 'text', initial_balance_text[_p.initial_balance_mode]),
('ib', nbr_columns - 8, 0, 'text',
initial_balance_text[_p.initial_balance_mode]),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_center)
ws.set_horz_split_pos(row_pos)
row_pos += 1
# Account Title Row
cell_format = _xs['xls_title'] + _xs['bold'] + _xs['fill'] + _xs['borders_all']
cell_format = _xs['xls_title'] + _xs['bold'] + \
_xs['fill'] + _xs['borders_all']
account_cell_style = xlwt.easyxf(cell_format)
account_cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
account_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
account_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# Column Title Row
cell_format = _xs['bold']
@ -142,21 +157,22 @@ class partner_ledger_xls(report_xls):
c_hdr_cell_style = xlwt.easyxf(cell_format)
c_hdr_cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
c_hdr_cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
c_hdr_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
# Column Initial Balance Row
cell_format = _xs['italic'] + _xs['borders_all']
c_init_cell_style = xlwt.easyxf(cell_format)
c_init_cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
c_init_cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
c_init_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
c_init_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# Column Cumulated balance Row
cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
c_cumul_cell_style = xlwt.easyxf(cell_format)
c_cumul_cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
c_cumul_cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
c_cumul_cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
c_cumul_cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# Column Partner Row
cell_format = _xs['bold']
@ -171,23 +187,30 @@ class partner_ledger_xls(report_xls):
('label', 1, 0, 'text', _('Label'), None, c_hdr_cell_style),
('rec', 1, 0, 'text', _('Rec.'), None, c_hdr_cell_style),
('debit', 1, 0, 'text', _('Debit'), None, c_hdr_cell_style_right),
('credit', 1, 0, 'text', _('Credit'), None, c_hdr_cell_style_right),
('cumul_bal', 1, 0, 'text', _('Cumul. Bal.'), None, c_hdr_cell_style_right),
('credit', 1, 0, 'text', _('Credit'),
None, c_hdr_cell_style_right),
('cumul_bal', 1, 0, 'text', _('Cumul. Bal.'),
None, c_hdr_cell_style_right),
]
if _p.amount_currency(data):
c_specs += [
('curr_bal', 1, 0, 'text', _('Curr. Bal.'), None, c_hdr_cell_style_right),
('curr_code', 1, 0, 'text', _('Curr.'), None, c_hdr_cell_style_center),
('curr_bal', 1, 0, 'text', _('Curr. Bal.'),
None, c_hdr_cell_style_right),
('curr_code', 1, 0, 'text', _('Curr.'),
None, c_hdr_cell_style_center),
]
c_hdr_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
# cell styles for ledger lines
ll_cell_format = _xs['borders_all']
ll_cell_style = xlwt.easyxf(ll_cell_format)
ll_cell_style_right = xlwt.easyxf(ll_cell_format + _xs['right'])
ll_cell_style_center = xlwt.easyxf(ll_cell_format + _xs['center'])
ll_cell_style_date = xlwt.easyxf(ll_cell_format + _xs['left'], num_format_str = report_xls.date_format)
ll_cell_style_decimal = xlwt.easyxf(ll_cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
ll_cell_style_date = xlwt.easyxf(
ll_cell_format + _xs['left'],
num_format_str=report_xls.date_format)
ll_cell_style_decimal = xlwt.easyxf(
ll_cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
cnt = 0
for account in objects:
@ -200,14 +223,18 @@ class partner_ledger_xls(report_xls):
account_balance_cumul = 0.0
account_balance_cumul_curr = 0.0
c_specs = [
('acc_title', nbr_columns, 0, 'text', ' - '.join([account.code, account.name]), None, account_cell_style),
('acc_title', nbr_columns, 0, 'text',
' - '.join([account.code, account.name]), None,
account_cell_style),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, c_title_cell_style)
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, c_title_cell_style)
row_pos += 1
row_start_account = row_pos
for partner_name, p_id, p_ref, p_name in account.partners_order:
for partner_name, p_id, p_ref, p_name in \
account.partners_order:
total_debit = 0.0
total_credit = 0.0
@ -216,23 +243,33 @@ class partner_ledger_xls(report_xls):
part_cumul_balance = 0.0
part_cumul_balance_curr = 0.0
c_specs = [
('partner_title', nbr_columns, 0, 'text', partner_name or _('No Partner'), None, c_part_cell_style),
('partner_title', nbr_columns, 0, 'text',
partner_name or _('No Partner'), None,
c_part_cell_style),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, c_title_cell_style)
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, c_title_cell_style)
row_pos = self.xls_write_row(ws, row_pos, c_hdr_data)
row_start_partner = row_pos
total_debit = account.init_balance.get(p_id, {}).get('debit') or 0.0
total_credit = account.init_balance.get(p_id, {}).get('credit') or 0.0
total_debit = account.init_balance.get(
p_id, {}).get('debit') or 0.0
total_credit = account.init_balance.get(
p_id, {}).get('credit') or 0.0
init_line = False
if _p.initial_balance_mode and (total_debit or total_credit):
if _p.initial_balance_mode and \
(total_debit or total_credit):
init_line = True
part_cumul_balance = account.init_balance.get(p_id, {}).get('init_balance') or 0.0
part_cumul_balance_curr = account.init_balance.get(p_id, {}).get('init_balance_currency') or 0.0
balance_forward_currency = account.init_balance.get(p_id, {}).get('currency_name') or ''
part_cumul_balance = account.init_balance.get(
p_id, {}).get('init_balance') or 0.0
part_cumul_balance_curr = account.init_balance.get(
p_id, {}).get('init_balance_currency') or 0.0
balance_forward_currency = account.init_balance.get(
p_id, {}).get('currency_name') or ''
cumul_balance += part_cumul_balance
cumul_balance_curr += part_cumul_balance_curr
@ -241,22 +278,31 @@ class partner_ledger_xls(report_xls):
credit_cell = rowcol_to_cell(row_pos, 8)
init_bal_formula = debit_cell + '-' + credit_cell
################## Print row 'Initial Balance' by partner #################
c_specs = [('empty%s' %x, 1, 0, 'text', None) for x in range(5)]
# Print row 'Initial Balance' by partn
c_specs = [('empty%s' % x, 1, 0, 'text', None)
for x in range(5)]
c_specs += [
('init_bal', 1, 0, 'text', _('Initial Balance')),
('rec', 1, 0, 'text', None),
('debit', 1, 0, 'number', total_debit, None, c_init_cell_style_decimal),
('credit', 1, 0, 'number', total_credit, None, c_init_cell_style_decimal),
('cumul_bal', 1, 0, 'number', None, init_bal_formula, c_init_cell_style_decimal),
('debit', 1, 0, 'number', total_debit,
None, c_init_cell_style_decimal),
('credit', 1, 0, 'number', total_credit,
None, c_init_cell_style_decimal),
('cumul_bal', 1, 0, 'number', None,
init_bal_formula, c_init_cell_style_decimal),
]
if _p.amount_currency(data):
c_specs += [
('curr_bal', 1, 0, 'number', part_cumul_balance_curr, None, c_init_cell_style_decimal),
('curr_code', 1, 0, 'text', balance_forward_currency),
('curr_bal', 1, 0, 'number',
part_cumul_balance_curr,
None, c_init_cell_style_decimal),
('curr_code', 1, 0, 'text',
balance_forward_currency),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, c_init_cell_style)
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, c_init_cell_style)
for line in account.ledger_lines.get(p_id, []):
@ -265,101 +311,147 @@ class partner_ledger_xls(report_xls):
label_elements = [line.get('lname') or '']
if line.get('invoice_number'):
label_elements.append("(%s)" % (line['invoice_number'],))
label_elements.append(
"(%s)" % (line['invoice_number'],))
label = ' '.join(label_elements)
cumul_balance += line.get('balance') or 0.0
if init_line or row_pos > row_start_partner:
cumbal_formula = rowcol_to_cell(row_pos-1, 9) + '+'
cumbal_formula = rowcol_to_cell(
row_pos - 1, 9) + '+'
else:
cumbal_formula = ''
debit_cell = rowcol_to_cell(row_pos, 7)
credit_cell = rowcol_to_cell(row_pos, 8)
cumbal_formula += debit_cell + '-' + credit_cell
################## Print row ledger line data #################
# Print row ledger line data #
if line.get('ldate'):
c_specs = [
('ldate', 1, 0, 'date', datetime.strptime(line['ldate'],'%Y-%m-%d'), None, ll_cell_style_date),
('ldate', 1, 0, 'date', datetime.strptime(
line['ldate'], '%Y-%m-%d'), None,
ll_cell_style_date),
]
else:
c_specs = [
('ldate', 1, 0, 'text', None),
]
c_specs += [
('period', 1, 0, 'text', line.get('period_code') or ''),
('move', 1, 0, 'text', line.get('move_name') or ''),
('period', 1, 0, 'text',
line.get('period_code') or ''),
('move', 1, 0, 'text',
line.get('move_name') or ''),
('journal', 1, 0, 'text', line.get('jcode') or ''),
('partner', 1, 0, 'text', line.get('partner_name') or ''),
('partner', 1, 0, 'text',
line.get('partner_name') or ''),
('label', 1, 0, 'text', label),
('rec_name', 1, 0, 'text', line.get('rec_name') or ''),
('debit', 1, 0, 'number', line.get('debit'), None, ll_cell_style_decimal),
('credit', 1, 0, 'number', line.get('credit'), None, ll_cell_style_decimal),
('cumul_bal', 1, 0, 'number', None, cumbal_formula, ll_cell_style_decimal),
('rec_name', 1, 0, 'text',
line.get('rec_name') or ''),
('debit', 1, 0, 'number', line.get('debit'),
None, ll_cell_style_decimal),
('credit', 1, 0, 'number', line.get('credit'),
None, ll_cell_style_decimal),
('cumul_bal', 1, 0, 'number', None,
cumbal_formula, ll_cell_style_decimal),
]
if _p.amount_currency(data):
c_specs += [
('curr_bal', 1, 0, 'number', line.get('amount_currency') or 0.0, None, ll_cell_style_decimal),
('curr_code', 1, 0, 'text', line.get('currency_code') or '', None, ll_cell_style_center),
('curr_bal', 1, 0, 'number', line.get(
'amount_currency') or 0.0, None,
ll_cell_style_decimal),
('curr_code', 1, 0, 'text', line.get(
'currency_code') or '', None,
ll_cell_style_center),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, ll_cell_style)
#end for line
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, ll_cell_style)
# end for line
################## Print row Cumulated Balance by partner #################
# Print row Cumulated Balance by partner #
debit_partner_start = rowcol_to_cell(row_start_partner, 7)
debit_partner_end = rowcol_to_cell(row_pos-1, 7)
debit_partner_total = 'SUM(' + debit_partner_start + ':' + debit_partner_end + ')'
debit_partner_end = rowcol_to_cell(row_pos - 1, 7)
debit_partner_total = 'SUM(' + debit_partner_start + \
':' + debit_partner_end + ')'
credit_partner_start = rowcol_to_cell(row_start_partner, 8)
credit_partner_end = rowcol_to_cell(row_pos-1, 8)
credit_partner_total = 'SUM(' + credit_partner_start + ':' + credit_partner_end + ')'
credit_partner_end = rowcol_to_cell(row_pos - 1, 8)
credit_partner_total = 'SUM(' + credit_partner_start + \
':' + credit_partner_end + ')'
bal_partner_debit = rowcol_to_cell(row_pos, 7)
bal_partner_credit = rowcol_to_cell(row_pos, 8)
bal_partner_total = bal_partner_debit + '-' + bal_partner_credit
bal_partner_total = bal_partner_debit + \
'-' + bal_partner_credit
c_specs = [('empty%s' %x, 1, 0, 'text', None) for x in range(5)]
c_specs = [('empty%s' % x, 1, 0, 'text', None)
for x in range(5)]
c_specs += [
('init_bal', 1, 0, 'text', _('Cumulated balance on Partner')),
('init_bal', 1, 0, 'text',
_('Cumulated balance on Partner')),
('rec', 1, 0, 'text', None),
('debit', 1, 0, 'number', None, debit_partner_total, c_cumul_cell_style_decimal),
('credit', 1, 0, 'number', None, credit_partner_total, c_cumul_cell_style_decimal),
('cumul_bal', 1, 0, 'number', None, bal_partner_total, c_cumul_cell_style_decimal),
('debit', 1, 0, 'number', None,
debit_partner_total, c_cumul_cell_style_decimal),
('credit', 1, 0, 'number', None,
credit_partner_total, c_cumul_cell_style_decimal),
('cumul_bal', 1, 0, 'number', None,
bal_partner_total, c_cumul_cell_style_decimal),
]
if _p.amount_currency(data):
if account.currency_id:
c_specs += [('curr_bal', 1, 0, 'number', cumul_balance_curr or 0.0, None, c_cumul_cell_style_decimal)]
c_specs += [('curr_bal', 1, 0, 'number',
cumul_balance_curr or 0.0, None,
c_cumul_cell_style_decimal)]
else:
c_specs += [('curr_bal', 1, 0, 'text', '-', None, c_cumul_cell_style_right)]
c_specs += [('curr_code', 1, 0, 'text', account.currency_id.name if account.currency_id else u'', None, c_cumul_cell_style_center)]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, c_cumul_cell_style)
c_specs += [('curr_bal', 1, 0, 'text',
'-', None, c_cumul_cell_style_right)]
c_specs += [('curr_code', 1, 0, 'text',
account.currency_id.name if
account.currency_id else u'', None,
c_cumul_cell_style_center)]
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, c_cumul_cell_style)
row_pos += 1
account_total_debit += total_debit
account_total_credit += total_credit
account_balance_cumul += cumul_balance
account_balance_cumul_curr += cumul_balance_curr
################## Print row Cumulated Balance by account #################
c_specs = [('acc_title', 5, 0, 'text', ' - '.join([account.code, account.name])), ]
# Print row Cumulated Balance by account #
c_specs = [
('acc_title', 5, 0, 'text', ' - '.
join([account.code, account.name])), ]
c_specs += [
('label', 1, 0, 'text', _('Cumulated balance on Account')),
('rec', 1, 0, 'text', None),
('debit', 1, 0, 'number', account_total_debit, None, account_cell_style_decimal),
('credit', 1, 0, 'number', account_total_credit, None, account_cell_style_decimal),
('cumul_bal', 1, 0, 'number', account_balance_cumul, None, account_cell_style_decimal),
('debit', 1, 0, 'number', account_total_debit,
None, account_cell_style_decimal),
('credit', 1, 0, 'number', account_total_credit,
None, account_cell_style_decimal),
('cumul_bal', 1, 0, 'number', account_balance_cumul,
None, account_cell_style_decimal),
]
if _p.amount_currency(data):
if account.currency_id:
c_specs += [('curr_bal', 1, 0, 'number', account_balance_cumul_curr or 0.0, None, account_cell_style_decimal)]
c_specs += [('curr_bal', 1, 0, 'number',
account_balance_cumul_curr or 0.0, None,
account_cell_style_decimal)]
else:
c_specs += [('curr_bal', 1, 0, 'text', '-', None, account_cell_style_right)]
c_specs += [('curr_code', 1, 0, 'text', account.currency_id.name if account.currency_id else u'', None, account_cell_style)]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, account_cell_style)
c_specs += [('curr_bal', 1, 0, 'text',
'-', None, account_cell_style_right)]
c_specs += [('curr_code', 1, 0, 'text',
account.currency_id.name if
account.currency_id else u'', None,
account_cell_style)]
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, account_cell_style)
row_pos += 2
partner_ledger_xls('report.account.account_report_partner_ledger_xls', 'account.account',
partner_ledger_xls('report.account.account_report_partner_ledger_xls',
'account.account',
parser=PartnersLedgerWebkit)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

291
account_financial_report_webkit_xls/report/partners_balance_xls.py

@ -21,36 +21,42 @@
##############################################################################
import xlwt
import time
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell
from openerp.addons.account_financial_report_webkit.report.partner_balance import PartnerBalanceWebkit
from openerp.addons.account_financial_report_webkit.report.partner_balance \
import PartnerBalanceWebkit
from openerp.tools.translate import _
#import logging
#_logger = logging.getLogger(__name__)
# import logging
# _logger = logging.getLogger(__name__)
def display_line(all_comparison_lines):
return any([line.get('balance') for line in all_comparison_lines])
class partners_balance_xls(report_xls):
column_sizes = [12,40,25,17,17,17,17,17]
column_sizes = [12, 40, 25, 17, 17, 17, 17, 17]
def print_title(self, ws, _p, row_position, xlwt,_xs):
def print_title(self, ws, _p, row_position, xlwt, _xs):
cell_style = xlwt.easyxf(_xs['xls_title'])
report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name])
report_name = ' - '.join([_p.report_name.upper(),
_p.company.partner_id.name,
_p.company.currency_id.name])
c_specs = [
('report_name', 1, 0, 'text', report_name),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_position = self.xls_write_row(ws, row_position, row_data, row_style=cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style)
return row_position
def print_empty_row(self, ws, row_position):
c_sizes = self.column_sizes
c_specs = [('empty%s'%i, 1, c_sizes[i], 'text', None) for i in range(0,len(c_sizes))]
c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None)
for i in range(0, len(c_sizes))]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_position = self.xls_write_row(ws, row_position, row_data, set_column_size=True)
row_position = self.xls_write_row(
ws, row_position, row_data, set_column_size=True)
return row_position
def print_header_titles(self, ws, _p, data, row_position, xlwt, _xs):
@ -60,24 +66,35 @@ class partners_balance_xls(report_xls):
c_specs = [
('fy', 1, 0, 'text', _('Fiscal Year'), None, cell_style_center),
('af', 1, 0, 'text', _('Accounts Filter'), None, cell_style_center),
('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter'), None, cell_style_center),
('pf', 1, 0, 'text', _('Partners Filter'), None, cell_style_center),
('af', 1, 0, 'text', _('Accounts Filter'),
None, cell_style_center),
('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _(
'Dates Filter') or _('Periods Filter'), None,
cell_style_center),
('pf', 1, 0, 'text', _('Partners Filter'),
None, cell_style_center),
('tm', 1, 0, 'text', _('Target Moves'), None, cell_style_center),
('ib', 1, 0, 'text', _('Initial Balance'), None, cell_style_center),
('coa', 1, 0, 'text', _('Chart of Account'), None, cell_style_center),
('ib', 1, 0, 'text', _('Initial Balance'),
None, cell_style_center),
('coa', 1, 0, 'text', _('Chart of Account'),
None, cell_style_center),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_position = self.xls_write_row(ws, row_position, row_data, row_style=cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style)
return row_position
def print_header_data(self, ws, _p, data, row_position, xlwt, _xs, initial_balance_text):
def print_header_data(self, ws, _p, data, row_position, xlwt, _xs,
initial_balance_text):
cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format)
cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
c_specs = [
('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-', None, cell_style_center),
('af', 1, 0, 'text', _p.accounts(data) and ', '.join([account.code for account in _p.accounts(data)]) or _('All'), None, cell_style_center),
('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-',
None, cell_style_center),
('af', 1, 0, 'text', _p.accounts(data) and ', '.join(
[account.code for account in _p.accounts(data)]) or _('All'),
None, cell_style_center),
]
df = _('From') + ': '
if _p.filter_form(data) == 'filter_date':
@ -91,38 +108,56 @@ class partners_balance_xls(report_xls):
df += _p.stop_period.name if _p.stop_period else u''
c_specs += [
('df', 1, 0, 'text', df, None, cell_style_center),
('tm', 1, 0, 'text', _p.display_partner_account(data), None, cell_style_center),
('pf', 1, 0, 'text', _p.display_target_move(data), None, cell_style_center),
('ib', 1, 0, 'text', initial_balance_text[_p.initial_balance_mode], None, cell_style_center),
('coa', 1, 0, 'text', _p.chart_account.name, None, cell_style_center),
('tm', 1, 0, 'text', _p.display_partner_account(
data), None, cell_style_center),
('pf', 1, 0, 'text', _p.display_target_move(
data), None, cell_style_center),
('ib', 1, 0, 'text', initial_balance_text[
_p.initial_balance_mode], None, cell_style_center),
('coa', 1, 0, 'text', _p.chart_account.name,
None, cell_style_center),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_position = self.xls_write_row(ws, row_position, row_data, row_style=cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style)
return row_position
def print_comparison_header(self, _xs, xlwt, row_position, _p, ws, initial_balance_text ):
def print_comparison_header(self, _xs, xlwt, row_position, _p, ws,
initial_balance_text):
cell_format_ct = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all']
cell_style_ct = xlwt.easyxf(cell_format_ct)
c_specs = [('ct', 7, 0, 'text', _('Comparisons'))]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_position = self.xls_write_row(ws, row_position, row_data, row_style=cell_style_ct)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style_ct)
cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style_center = xlwt.easyxf(cell_format)
for index, params in enumerate(_p.comp_params):
c_specs = [('c', 2, 0, 'text', _('Comparison') + str(index + 1) + ' (C' + str(index + 1) + ')')]
c_specs = [
('c', 2, 0, 'text', _('Comparison') + str(index + 1) +
' (C' + str(index + 1) + ')')]
if params['comparison_filter'] == 'filter_date':
c_specs += [('f', 2, 0, 'text', _('Dates Filter') + ': ' + _p.formatLang(params['start'], date=True) + ' - ' + _p.formatLang(params['stop'], date=True))]
c_specs += [('f', 2, 0, 'text', _('Dates Filter') + ': ' +
_p.formatLang(params['start'], date=True) + ' - '
+ _p.formatLang(params['stop'], date=True))]
elif params['comparison_filter'] == 'filter_period':
c_specs += [('f', 2, 0, 'text', _('Periods Filter') + ': ' + params['start'].name + ' - ' + params['stop'].name)]
c_specs += [('f', 2, 0, 'text', _('Periods Filter') +
': ' + params['start'].name + ' - ' +
params['stop'].name)]
else:
c_specs += [('f', 2, 0, 'text', _('Fiscal Year') + ': ' + params['fiscalyear'].name)]
c_specs += [('ib', 2, 0, 'text', _('Initial Balance') + ': ' + initial_balance_text[params['initial_balance_mode']])]
c_specs += [('f', 2, 0, 'text', _('Fiscal Year') +
': ' + params['fiscalyear'].name)]
c_specs += [('ib', 2, 0, 'text', _('Initial Balance') +
': ' +
initial_balance_text[params['initial_balance_mode']])]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_position = self.xls_write_row(ws, row_position, row_data, row_style=cell_style_center)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style_center)
return row_position
def print_account_header(self, ws, _p, _xs, xlwt, row_position):
cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_format = _xs['bold'] + _xs['fill'] + \
_xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format)
cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
@ -136,59 +171,87 @@ class partners_balance_xls(report_xls):
]
if _p.comparison_mode == 'no_comparison':
if _p.initial_balance_mode:
c_specs += [('init_bal', 1, 0, 'text', _('Initial Balance'), None, cell_style_right)]
c_specs += [('init_bal', 1, 0, 'text',
_('Initial Balance'), None, cell_style_right)]
c_specs += [
('debit', 1, 0, 'text', _('Debit'), None, cell_style_right),
('credit', 1, 0, 'text', _('Credit'), None, cell_style_right),
]
if _p.comparison_mode == 'no_comparison' or not _p.fiscalyear:
c_specs += [('balance', 1, 0, 'text', _('Balance'), None, cell_style_right)]
c_specs += [('balance', 1, 0, 'text',
_('Balance'), None, cell_style_right)]
else:
c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') % _p.fiscalyear.name, None, cell_style_right)]
c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') %
_p.fiscalyear.name, None, cell_style_right)]
if _p.comparison_mode in ('single', 'multiple'):
for index in range(_p.nb_comparison):
if _p.comp_params[index]['comparison_filter'] == 'filter_year' and _p.comp_params[index].get('fiscalyear', False):
c_specs += [('balance_%s' %index, 1, 0, 'text', _('Balance %s') % _p.comp_params[index]['fiscalyear'].name, None, cell_style_right)]
if _p.comp_params[index][
'comparison_filter'] == 'filter_year' \
and _p.comp_params[index].get('fiscalyear', False):
c_specs += [('balance_%s' % index, 1, 0, 'text',
_('Balance %s') %
_p.comp_params[index]['fiscalyear'].name,
None, cell_style_right)]
else:
c_specs += [('balance_%s' %index, 1, 0, 'text', _('Balance C%s') % (index + 1), None, cell_style_right)]
c_specs += [('balance_%s' % index, 1, 0, 'text',
_('Balance C%s') % (index + 1), None,
cell_style_right)]
if _p.comparison_mode == 'single':
c_specs += [
('diff', 1, 0, 'text', _('Difference'), None, cell_style_right),
('diff_percent', 1, 0, 'text', _('% Difference'), None, cell_style_center),
('diff', 1, 0, 'text', _('Difference'),
None, cell_style_right),
('diff_percent', 1, 0, 'text',
_('% Difference'), None, cell_style_center),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_position = self.xls_write_row(ws, row_position, row_data, row_style=cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, row_style=cell_style)
return row_position
def print_row_code_account(self, ws, current_account, row_position, _xs, xlwt):
cell_format = _xs['xls_title'] + _xs['bold'] + _xs['fill'] + _xs['borders_all']
def print_row_code_account(self, ws, current_account, row_position, _xs,
xlwt):
cell_format = _xs['xls_title'] + _xs['bold'] + \
_xs['fill'] + _xs['borders_all']
cell_style = xlwt.easyxf(cell_format)
c_specs = [ ('acc_title', 7, 0, 'text', ' - '.join([current_account.code, current_account.name])), ]
c_specs = [
('acc_title', 7, 0, 'text', ' - '.join([current_account.code,
current_account.name])), ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_position = self.xls_write_row(ws, row_position, row_data, cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, cell_style)
return row_position
def print_account_totals(self, _xs, xlwt, ws, row_start_account, row_position, current_account,_p):
cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all'] + _xs['wrap'] + _xs['top']
def print_account_totals(self, _xs, xlwt, ws, row_start_account,
row_position, current_account, _p):
cell_format = _xs['bold'] + _xs['fill'] + \
_xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format)
cell_style_decimal = xlwt.easyxf(cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
cell_style_decimal = xlwt.easyxf(
cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
c_specs = [
('acc_title', 2, 0, 'text', current_account.name),
('code', 1, 0, 'text', current_account.code),
]
for column in range(3,7):
if (_p.comparison_mode == 'single' and column == 6): #in case of one single comparison, the column 6 will contain percentages
total_diff = rowcol_to_cell(row_position, column-1)
total_balance = rowcol_to_cell(row_position, column-2)
account_formula = 'Round('+ total_diff + '/' + total_balance + '*100;0)'
for column in range(3, 7):
# in case of one single comparison, the column 6 will contain
# percentages
if (_p.comparison_mode == 'single' and column == 6):
total_diff = rowcol_to_cell(row_position, column - 1)
total_balance = rowcol_to_cell(row_position, column - 2)
account_formula = 'Round(' + total_diff + \
'/' + total_balance + '*100;0)'
else:
account_start = rowcol_to_cell(row_start_account, column)
account_end = rowcol_to_cell(row_position -1, column)
account_formula = 'Round(SUM(' + account_start + ':' + account_end + ');2)'
c_specs += [('total%s' %column, 1, 0, 'text', None, account_formula, None, cell_style_decimal)]
account_end = rowcol_to_cell(row_position - 1, column)
account_formula = 'Round(SUM(' + \
account_start + ':' + account_end + ');2)'
c_specs += [('total%s' % column, 1, 0, 'text', None,
account_formula, None, cell_style_decimal)]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_position = self.xls_write_row(ws, row_position, row_data, cell_style)
row_position = self.xls_write_row(
ws, row_position, row_data, cell_style)
return row_position + 1
def generate_xls_report(self, _p, _xs, data, objects, wb):
@ -207,16 +270,22 @@ class partners_balance_xls(report_xls):
row_pos = self.print_title(ws, _p, row_pos, xlwt, _xs)
# Print empty row to define column sizes
row_pos = self.print_empty_row(ws, row_pos)
# Print Header Table titles (Fiscal Year - Accounts Filter - Periods Filter...)
# Print Header Table titles (Fiscal Year - Accounts Filter - Periods
# Filter...)
row_pos = self.print_header_titles(ws, _p, data, row_pos, xlwt, _xs)
initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')} # cf. account_report_partner_balance.mako
initial_balance_text = {
'initial_balance': _('Computed'),
'opening_balance': _('Opening Entries'),
False: _('No')} # cf. account_report_partner_balance.mako
# Print Header Table data
row_pos = self.print_header_data(ws, _p, data, row_pos, xlwt, _xs, initial_balance_text)
row_pos = self.print_header_data(
ws, _p, data, row_pos, xlwt, _xs, initial_balance_text)
# Print comparison header table
if _p.comparison_mode in ('single', 'multiple'):
row_pos += 1
row_pos = self.print_comparison_header(_xs, xlwt, row_pos, _p, ws, initial_balance_text)
row_pos = self.print_comparison_header(
_xs, xlwt, row_pos, _p, ws, initial_balance_text)
# Freeze the line
ws.set_horz_split_pos(row_pos)
@ -224,9 +293,9 @@ class partners_balance_xls(report_xls):
# cell styles for account data
regular_cell_format = _xs['borders_all']
regular_cell_style = xlwt.easyxf(regular_cell_format)
regular_cell_style_center = xlwt.easyxf(regular_cell_format + _xs['center'])
regular_cell_style_decimal = xlwt.easyxf(regular_cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
regular_cell_style_pct = xlwt.easyxf(regular_cell_format + _xs['center'], num_format_str = '0')
regular_cell_style_decimal = xlwt.easyxf(
regular_cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
row_pos += 1
for current_account in objects:
@ -239,7 +308,8 @@ class partners_balance_xls(report_xls):
comparisons = current_account.comparisons
# in multiple columns mode, we do not want to print accounts without any rows
# in multiple columns mode, we do not want to print accounts
# without any rows
if _p.comparison_mode in ('single', 'multiple'):
all_comparison_lines = [comp['partners_amounts'][partner_id[1]]
for partner_id in partners_order
@ -255,19 +325,28 @@ class partners_balance_xls(report_xls):
comparison_total[i] = {'balance': 0.0}
# print row: Code - Account name
row_pos = self.print_row_code_account(ws, current_account, row_pos, _xs, xlwt)
row_pos = self.print_row_code_account(
ws, current_account, row_pos, _xs, xlwt)
row_account_start = row_pos
# Print row: Titles "Account/Partner Name-Code/ref-Initial Balance-Debit-Credit-Balance" or "Account/Partner Name-Code/ref-Balance Year-Balance Year2-Balance C2-Balance C3"
# Print row: Titles "Account/Partner Name-Code/ref-Initial
# Balance-Debit-Credit-Balance" or "Account/Partner
# Name-Code/ref-Balance Year-Balance Year2-Balance C2-Balance C3"
row_pos = self.print_account_header(ws, _p, _xs, xlwt, row_pos)
for (partner_code_name, partner_id, partner_ref, partner_name) in partners_order:
for (partner_code_name, partner_id, partner_ref, partner_name) \
in partners_order:
partner = current_partner_amounts.get(partner_id, {})
# in single mode, we have to display all the partners even if their balance is 0.0 because the initial balance should match with the previous year closings
# in multiple columns mode, we do not want to print partners which have a balance at 0.0 in each comparison column
# in single mode, we have to display all the partners even if
# their balance is 0.0 because the initial balance should match
# with the previous year closings
# in multiple columns mode, we do not want to print partners
# which have a balance at 0.0 in each comparison column
if _p.comparison_mode in ('single', 'multiple'):
all_comparison_lines = [comp['partners_amounts'][partner_id]
all_comparison_lines = [comp['partners_amounts']
[partner_id]
for comp in comparisons
if comp['partners_amounts'].get(partner_id)]
if comp['partners_amounts'].
get(partner_id)]
if not display_line(all_comparison_lines):
continue
@ -277,8 +356,11 @@ class partners_balance_xls(report_xls):
else:
account_span = _p.initial_balance_mode and 2 or 3
c_specs = [('acc_title', account_span, 0, 'text', partner_name if partner_name else _('Unallocated'))]
c_specs += [('partner_ref', 1, 0, 'text', partner_ref if partner_ref else '')]
c_specs = [('acc_title', account_span, 0, 'text',
partner_name if partner_name else
_('Unallocated'))]
c_specs += [('partner_ref', 1, 0, 'text',
partner_ref if partner_ref else '')]
if _p.comparison_mode == 'no_comparison':
bal_formula = ''
if _p.initial_balance_mode:
@ -286,20 +368,27 @@ class partners_balance_xls(report_xls):
bal_formula = init_bal_cell + '+'
debit_col = 4
c_specs += [
('init_bal', 1, 0, 'number', partner.get('init_balance', 0.0), None, regular_cell_style_decimal),
('init_bal', 1, 0, 'number', partner.get(
'init_balance', 0.0), None,
regular_cell_style_decimal),
]
else:
debit_col = 3
c_specs += [
('debit', 1, 0, 'number', partner.get('debit', 0.0), None, regular_cell_style_decimal),
('credit', 1, 0, 'number', partner.get('credit', 0.0), None, regular_cell_style_decimal),
('debit', 1, 0, 'number', partner.get('debit', 0.0),
None, regular_cell_style_decimal),
('credit', 1, 0, 'number', partner.get('credit', 0.0),
None, regular_cell_style_decimal),
]
debit_cell = rowcol_to_cell(row_pos, debit_col)
credit_cell = rowcol_to_cell(row_pos, debit_col+1)
credit_cell = rowcol_to_cell(row_pos, debit_col + 1)
bal_formula += debit_cell + '-' + credit_cell
c_specs += [('bal', 1, 0, 'number', None, bal_formula, regular_cell_style_decimal),]
c_specs += [('bal', 1, 0, 'number', None,
bal_formula, regular_cell_style_decimal), ]
else:
c_specs += [('bal', 1, 0, 'number', partner.get('balance', 0.0), None, regular_cell_style_decimal),]
c_specs += [('bal', 1, 0, 'number', partner.get('balance',
0.0),
None, regular_cell_style_decimal), ]
if _p.comparison_mode in ('single', 'multiple'):
for i, comp in enumerate(comparisons):
@ -308,21 +397,31 @@ class partners_balance_xls(report_xls):
if comp_partners.get(partner_id):
balance = comp_partners[partner_id]['balance']
diff = comp_partners[partner_id]['diff']
percent_diff = comp_partners[partner_id]['percent_diff']
percent_diff = comp_partners[
partner_id]['percent_diff']
comparison_total[i]['balance'] += balance
c_specs += [('balance_%s' %i, 1, 0, 'number', balance, None, regular_cell_style_decimal), ]
if _p.comparison_mode == 'single': ## no diff in multiple comparisons because it shows too much data
c_specs += [('balance_diff', 1, 0, 'number', diff, None, regular_cell_style_decimal), ]
c_specs += [('balance_%s' % i, 1, 0, 'number',
balance, None,
regular_cell_style_decimal), ]
# no diff in multiple comparisons because it shows too much
# data
if _p.comparison_mode == 'single':
c_specs += [('balance_diff', 1, 0, 'number',
diff, None, regular_cell_style_decimal), ]
if percent_diff is False:
c_specs += [('balance', 1, 0, 'number', diff, None, regular_cell_style_decimal), ]
c_specs += [('balance', 1, 0, 'number',
diff, None, regular_cell_style_decimal), ]
else:
c_specs += [('perc_diff', 1, 0, 'number', int(round(percent_diff))), ]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, regular_cell_style)
row_pos = self.print_account_totals(_xs, xlwt, ws, row_account_start, row_pos, current_account,_p)
partners_balance_xls('report.account.account_report_partner_balance_xls', 'account.account',
c_specs += [('perc_diff', 1, 0, 'number',
int(round(percent_diff))), ]
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, regular_cell_style)
row_pos = self.print_account_totals(
_xs, xlwt, ws, row_account_start, row_pos, current_account, _p)
partners_balance_xls('report.account.account_report_partner_balance_xls',
'account.account',
parser=PartnerBalanceWebkit)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

199
account_financial_report_webkit_xls/report/trial_balance_xls.py

@ -21,17 +21,17 @@
##############################################################################
import xlwt
import time
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell
from openerp.addons.account_financial_report_webkit.report.trial_balance import TrialBalanceWebkit
from openerp.addons.account_financial_report_webkit.report.trial_balance \
import TrialBalanceWebkit
from openerp.tools.translate import _
#import logging
#_logger = logging.getLogger(__name__)
# import logging
# _logger = logging.getLogger(__name__)
class trial_balance_xls(report_xls):
column_sizes = [12,60,17,17,17,17,17,17]
column_sizes = [12, 60, 17, 17, 17, 17, 17, 17]
def generate_xls_report(self, _p, _xs, data, objects, wb):
@ -47,22 +47,29 @@ class trial_balance_xls(report_xls):
ws.footer_str = self.xls_footers['standard']
# cf. account_report_trial_balance.mako
initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')}
initial_balance_text = {'initial_balance': _('Computed'),
'opening_balance': _('Opening Entries'),
False: _('No')}
# Title
cell_style = xlwt.easyxf(_xs['xls_title'])
report_name = ' - '.join([_p.report_name.upper(), _p.company.partner_id.name, _p.company.currency_id.name])
report_name = ' - '.join([_p.report_name.upper(),
_p.company.partner_id.name,
_p.company.currency_id.name])
c_specs = [
('report_name', 1, 0, 'text', report_name),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
# write empty row to define column sizes
c_sizes = self.column_sizes
c_specs = [('empty%s'%i, 1, c_sizes[i], 'text', None) for i in range(0,len(c_sizes))]
c_specs = [('empty%s' % i, 1, c_sizes[i], 'text', None)
for i in range(0, len(c_sizes))]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, set_column_size=True)
row_pos = self.xls_write_row(
ws, row_pos, row_data, set_column_size=True)
# Header Table
cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all']
@ -71,20 +78,25 @@ class trial_balance_xls(report_xls):
c_specs = [
('fy', 1, 0, 'text', _('Fiscal Year')),
('af', 2, 0, 'text', _('Accounts Filter')),
('df', 1, 0, 'text', _p.filter_form(data) == 'filter_date' and _('Dates Filter') or _('Periods Filter')),
('df', 1, 0, 'text', _p.filter_form(data) ==
'filter_date' and _('Dates Filter') or _('Periods Filter')),
('tm', 2, 0, 'text', _('Target Moves'), None, cell_style_center),
('ib', 1, 0, 'text', _('Initial Balance'), None, cell_style_center),
('coa', 1, 0, 'text', _('Chart of Account'), None, cell_style_center),
('ib', 1, 0, 'text', _('Initial Balance'),
None, cell_style_center),
('coa', 1, 0, 'text', _('Chart of Account'),
None, cell_style_center),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
cell_format = _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format)
cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
c_specs = [
('fy', 1, 0, 'text', _p.fiscalyear.name if _p.fiscalyear else '-'),
('af', 2, 0, 'text', _p.accounts(data) and ', '.join([account.code for account in _p.accounts(data)]) or _('All')),
('af', 2, 0, 'text', _p.accounts(data) and ', '.join(
[account.code for account in _p.accounts(data)]) or _('All')),
]
df = _('From') + ': '
if _p.filter_form(data) == 'filter_date':
@ -98,38 +110,58 @@ class trial_balance_xls(report_xls):
df += _p.stop_period.name if _p.stop_period else u''
c_specs += [
('df', 1, 0, 'text', df),
('tm', 2, 0, 'text', _p.display_target_move(data), None, cell_style_center),
('ib', 1, 0, 'text', initial_balance_text[_p.initial_balance_mode], None, cell_style_center),
('coa', 1, 0, 'text', _p.chart_account.name, None, cell_style_center),
('tm', 2, 0, 'text', _p.display_target_move(
data), None, cell_style_center),
('ib', 1, 0, 'text', initial_balance_text[
_p.initial_balance_mode], None, cell_style_center),
('coa', 1, 0, 'text', _p.chart_account.name,
None, cell_style_center),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
# comparison header table
if _p.comparison_mode in ('single', 'multiple'):
row_pos += 1
cell_format_ct = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all']
cell_format_ct = _xs['bold'] + \
_xs['fill_blue'] + _xs['borders_all']
cell_style_ct = xlwt.easyxf(cell_format_ct)
c_specs = [('ct', 8, 0, 'text', _('Comparisons'))]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_ct)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_ct)
cell_style_center = xlwt.easyxf(cell_format)
for index, params in enumerate(_p.comp_params):
c_specs = [('c', 3, 0, 'text', _('Comparison') + str(index + 1) + ' (C' + str(index + 1) + ')')]
c_specs = [
('c', 3, 0, 'text', _('Comparison') + str(index + 1) +
' (C' + str(index + 1) + ')')]
if params['comparison_filter'] == 'filter_date':
c_specs += [('f', 3, 0, 'text', _('Dates Filter') + ': ' + _p.formatLang(params['start'], date=True) + ' - ' + _p.formatLang(params['stop'], date=True))]
c_specs += [('f', 3, 0, 'text', _('Dates Filter') + ': ' +
_p.formatLang(
params['start'], date=True) + ' - ' +
_p.formatLang(params['stop'], date=True))]
elif params['comparison_filter'] == 'filter_period':
c_specs += [('f', 3, 0, 'text', _('Periods Filter') + ': ' + params['start'].name + ' - ' + params['stop'].name)]
c_specs += [('f', 3, 0, 'text', _('Periods Filter') +
': ' + params['start'].name + ' - ' +
params['stop'].name)]
else:
c_specs += [('f', 3, 0, 'text', _('Fiscal Year') + ': ' + params['fiscalyear'].name)]
c_specs += [('ib', 2, 0, 'text', _('Initial Balance') + ': ' + initial_balance_text[params['initial_balance_mode']])]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style_center)
c_specs += [('f', 3, 0, 'text', _('Fiscal Year') +
': ' + params['fiscalyear'].name)]
c_specs += [('ib', 2, 0, 'text', _('Initial Balance') +
': ' +
initial_balance_text[
params['initial_balance_mode']])]
row_data = self.xls_row_template(
c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style_center)
row_pos += 1
# Column Header Row
cell_format = _xs['bold'] + _xs['fill_blue'] + _xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_format = _xs['bold'] + _xs['fill_blue'] + \
_xs['borders_all'] + _xs['wrap'] + _xs['top']
cell_style = xlwt.easyxf(cell_format)
cell_style_right = xlwt.easyxf(cell_format + _xs['right'])
cell_style_center = xlwt.easyxf(cell_format + _xs['center'])
@ -143,46 +175,65 @@ class trial_balance_xls(report_xls):
]
if _p.comparison_mode == 'no_comparison':
if _p.initial_balance_mode:
c_specs += [('init_bal', 1, 0, 'text', _('Initial Balance'), None, cell_style_right)]
c_specs += [('init_bal', 1, 0, 'text',
_('Initial Balance'), None, cell_style_right)]
c_specs += [
('debit', 1, 0, 'text', _('Debit'), None, cell_style_right),
('credit', 1, 0, 'text', _('Credit'), None, cell_style_right),
]
if _p.comparison_mode == 'no_comparison' or not _p.fiscalyear:
c_specs += [('balance', 1, 0, 'text', _('Balance'), None, cell_style_right)]
c_specs += [('balance', 1, 0, 'text',
_('Balance'), None, cell_style_right)]
else:
c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') % _p.fiscalyear.name, None, cell_style_right)]
c_specs += [('balance_fy', 1, 0, 'text', _('Balance %s') %
_p.fiscalyear.name, None, cell_style_right)]
if _p.comparison_mode in ('single', 'multiple'):
for index in range(_p.nb_comparison):
if _p.comp_params[index]['comparison_filter'] == 'filter_year' and _p.comp_params[index].get('fiscalyear', False):
c_specs += [('balance_%s' %index, 1, 0, 'text', _('Balance %s') % _p.comp_params[index]['fiscalyear'].name, None, cell_style_right)]
if _p.comp_params[index][
'comparison_filter'] == 'filter_year' \
and _p.comp_params[index].get('fiscalyear', False):
c_specs += [('balance_%s' % index, 1, 0, 'text',
_('Balance %s') %
_p.comp_params[index]['fiscalyear'].name,
None, cell_style_right)]
else:
c_specs += [('balance_%s' %index, 1, 0, 'text', _('Balance C%s') % (index + 1), None, cell_style_right)]
c_specs += [('balance_%s' % index, 1, 0, 'text',
_('Balance C%s') % (index + 1), None,
cell_style_right)]
if _p.comparison_mode == 'single':
c_specs += [
('diff', 1, 0, 'text', _('Difference'), None, cell_style_right),
('diff_percent', 1, 0, 'text', _('% Difference'), None, cell_style_center),
('diff', 1, 0, 'text', _('Difference'),
None, cell_style_right),
('diff_percent', 1, 0, 'text',
_('% Difference'), None, cell_style_center),
]
c_specs += [('type', 1, 0, 'text', _('Type'), None, cell_style_center)]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
ws.set_horz_split_pos(row_pos)
last_child_consol_ids = []
last_level = False
# cell styles for account data
view_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
view_cell_style = xlwt.easyxf(view_cell_format)
view_cell_style_center = xlwt.easyxf(view_cell_format + _xs['center'])
view_cell_style_decimal = xlwt.easyxf(view_cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
view_cell_style_pct = xlwt.easyxf(view_cell_format + _xs['center'], num_format_str = '0')
view_cell_style_decimal = xlwt.easyxf(
view_cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
view_cell_style_pct = xlwt.easyxf(
view_cell_format + _xs['center'], num_format_str='0')
regular_cell_format = _xs['borders_all']
regular_cell_style = xlwt.easyxf(regular_cell_format)
regular_cell_style_center = xlwt.easyxf(regular_cell_format + _xs['center'])
regular_cell_style_decimal = xlwt.easyxf(regular_cell_format + _xs['right'], num_format_str = report_xls.decimal_format)
regular_cell_style_pct = xlwt.easyxf(regular_cell_format + _xs['center'], num_format_str = '0')
regular_cell_style_center = xlwt.easyxf(
regular_cell_format + _xs['center'])
regular_cell_style_decimal = xlwt.easyxf(
regular_cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
regular_cell_style_pct = xlwt.easyxf(
regular_cell_format + _xs['center'], num_format_str='0')
for current_account in objects:
@ -202,16 +253,12 @@ class trial_balance_xls(report_xls):
comparisons = current_account.comparisons
if current_account.id in last_child_consol_ids:
# current account is a consolidation child of the last account: use the level of last account
level = last_level
level_class = 'account_level_consol'
else:
# current account is a not a consolidation child: use its own level
level = current_account.level or 0
level_class = "account_level_%s" % (level,)
last_child_consol_ids = [child_consol_id.id for child_consol_id in current_account.child_consol_ids]
last_level = current_account.level
if current_account.id not in last_child_consol_ids:
# current account is a not a consolidation child: use its own
# level
last_child_consol_ids = [
child_consol_id.id for child_consol_id in
current_account.child_consol_ids]
c_specs = [
('code', 1, 0, 'text', current_account.code),
@ -227,32 +274,46 @@ class trial_balance_xls(report_xls):
init_cell = rowcol_to_cell(row_pos, 3)
debit_cell = rowcol_to_cell(row_pos, 4)
credit_cell = rowcol_to_cell(row_pos, 5)
bal_formula = init_cell + '+' + debit_cell + '-' + credit_cell
c_specs += [('init_bal', 1, 0, 'number', current_account.init_balance, None, cell_style_decimal)]
bal_formula = init_cell + '+' + \
debit_cell + '-' + credit_cell
c_specs += [('init_bal', 1, 0, 'number',
current_account.init_balance, None,
cell_style_decimal)]
c_specs += [
('debit', 1, 0, 'number', current_account.debit, None, cell_style_decimal),
('credit', 1, 0, 'number', current_account.credit, None, cell_style_decimal),
('debit', 1, 0, 'number', current_account.debit,
None, cell_style_decimal),
('credit', 1, 0, 'number', current_account.credit,
None, cell_style_decimal),
]
c_specs += [('balance', 1, 0, 'number', None, bal_formula, cell_style_decimal)]
c_specs += [('balance', 1, 0, 'number', None,
bal_formula, cell_style_decimal)]
else:
c_specs += [('balance', 1, 0, 'number', current_account.balance, None, cell_style_decimal)]
c_specs += [('balance', 1, 0, 'number',
current_account.balance, None,
cell_style_decimal)]
if _p.comparison_mode in ('single', 'multiple'):
c = 1
for comp_account in comparisons:
c_specs += [('balance_%s' %c, 1, 0, 'number', comp_account['balance'], None, cell_style_decimal)]
c_specs += [('balance_%s' % c, 1, 0, 'number',
comp_account['balance'], None,
cell_style_decimal)]
c += 1
if _p.comparison_mode == 'single':
c_specs += [
('diff', 1, 0, 'number', comp_account['diff'], None, cell_style_decimal),
('diff_percent', 1, 0, 'number', comp_account['percent_diff'] and comp_account['percent_diff'] or 0, None, cell_style_pct),
('diff', 1, 0, 'number', comp_account[
'diff'], None, cell_style_decimal),
('diff_percent', 1, 0, 'number', comp_account[
'percent_diff'] and comp_account['percent_diff']
or 0, None, cell_style_pct),
]
c_specs += [('type', 1, 0, 'text', current_account.type, None, cell_style_center)]
c_specs += [('type', 1, 0, 'text',
current_account.type, None, cell_style_center)]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
trial_balance_xls('report.account.account_report_trial_balance_xls', 'account.account',
trial_balance_xls('report.account.account_report_trial_balance_xls',
'account.account',
parser=TrialBalanceWebkit)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

9
account_financial_report_webkit_xls/wizard/general_ledger_wizard.py

@ -21,8 +21,9 @@
##############################################################################
from openerp.osv import orm
#import logging
#_logger = logging.getLogger(__name__)
# import logging
# _logger = logging.getLogger(__name__)
class general_ledger_webkit_wizard(orm.TransientModel):
_inherit = 'general.ledger.webkit'
@ -39,5 +40,5 @@ class general_ledger_webkit_wizard(orm.TransientModel):
'report_name': 'account.account_report_general_ledger_xls',
'datas': data}
else:
return super(general_ledger_webkit_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(general_ledger_webkit_wizard, self)._print_report(
cr, uid, ids, data, context=context)

8
account_financial_report_webkit_xls/wizard/open_invoices_wizard.py

@ -21,8 +21,9 @@
##############################################################################
from openerp.osv import orm
#import logging
#_logger = logging.getLogger(__name__)
# import logging
# _logger = logging.getLogger(__name__)
class open_invoices_webkit_wizard(orm.TransientModel):
_inherit = 'open.invoices.webkit'
@ -39,4 +40,5 @@ class open_invoices_webkit_wizard(orm.TransientModel):
'report_name': 'account.account_report_open_invoices_xls',
'datas': data}
else:
return super(open_invoices_webkit_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(open_invoices_webkit_wizard, self)._print_report(
cr, uid, ids, data, context=context)

12
account_financial_report_webkit_xls/wizard/partners_balance_wizard.py

@ -21,8 +21,9 @@
##############################################################################
from openerp.osv import orm
#import logging
#_logger = logging.getLogger(__name__)
# import logging
# _logger = logging.getLogger(__name__)
class partner_balance_wizard(orm.TransientModel):
_inherit = 'partner.balance.webkit'
@ -35,9 +36,10 @@ class partner_balance_wizard(orm.TransientModel):
if context.get('xls_export'):
# we update form with display account value
data = self.pre_print_report(cr, uid, ids, data, context=context)
return {'type': 'ir.actions.report.xml',
return {
'type': 'ir.actions.report.xml',
'report_name': 'account.account_report_partner_balance_xls',
'datas': data}
else:
return super(partner_balance_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(partner_balance_wizard, self)._print_report(
cr, uid, ids, data, context=context)

8
account_financial_report_webkit_xls/wizard/partners_ledger_wizard.py

@ -21,8 +21,9 @@
##############################################################################
from openerp.osv import orm
#import logging
#_logger = logging.getLogger(__name__)
# import logging
# _logger = logging.getLogger(__name__)
class partner_ledger_webkit_wizard(orm.TransientModel):
_inherit = 'partners.ledger.webkit'
@ -39,4 +40,5 @@ class partner_ledger_webkit_wizard(orm.TransientModel):
'report_name': 'account.account_report_partner_ledger_xls',
'datas': data}
else:
return super(partner_ledger_webkit_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(partner_ledger_webkit_wizard, self)._print_report(
cr, uid, ids, data, context=context)

9
account_financial_report_webkit_xls/wizard/trial_balance_wizard.py

@ -21,8 +21,9 @@
##############################################################################
from openerp.osv import orm
#import logging
#_logger = logging.getLogger(__name__)
# import logging
# _logger = logging.getLogger(__name__)
class trial_balance_wizard(orm.TransientModel):
_inherit = 'trial.balance.webkit'
@ -39,5 +40,5 @@ class trial_balance_wizard(orm.TransientModel):
'report_name': 'account.account_report_trial_balance_xls',
'datas': data}
else:
return super(trial_balance_wizard, self)._print_report(cr, uid, ids, data, context=context)
return super(trial_balance_wizard, self)._print_report(
cr, uid, ids, data, context=context)

5
account_journal_report_xls/__init__.py

@ -26,6 +26,5 @@ try:
from . import report
except ImportError:
import logging
logging.getLogger('openerp.module').warning('report_xls not available in addons path. account_financial_report_webkit_xls will not be usable')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
logging.getLogger('openerp.module').warning('''report_xls not available in
addons path. account_financial_report_webkit_xls will not be usable''')

2
account_journal_report_xls/__openerp__.py

@ -52,5 +52,3 @@ cf. https://launchpad.net/openerp-reporting-engines
'wizard/print_journal_wizard.xml',
],
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

28
account_journal_report_xls/account_journal.py

@ -21,8 +21,6 @@
##############################################################################
from openerp.osv import orm
from openerp.addons.report_xls.utils import rowcol_to_cell, _render
from openerp.tools.translate import _
class account_journal(orm.Model):
@ -59,17 +57,18 @@ class account_journal(orm.Model):
'credit', # account.move.line,credit
'balance', # debit-credit
'docname', # origin document if any
#'date_maturity', # account.move.line,date_maturity
#'reconcile', # account.move.line,reconcile_id.name
#'reconcile_partial', # account.move.line,reconcile_partial_id.name
#'partner_ref', # res.partner,ref
#'move_ref', # account.move,ref
#'move_id', # account.move,id
#'acc_name', # account.account,name
#'journal', # account.journal,name
#'journal_code', # account.journal,code
#'analytic_account', # account.analytic.account,name
#'analytic_account_code', # account.analytic.account,code
# 'date_maturity', # account.move.line,date_maturity
# 'reconcile', # account.move.line,reconcile_id.name
# 'reconcile_partial',
# account.move.line,reconcile_partial_id.name
# 'partner_ref', # res.partner,ref
# 'move_ref', # account.move,ref
# 'move_id', # account.move,id
# 'acc_name', # account.account,name
# 'journal', # account.journal,name
# 'journal_code', # account.journal,code
# 'analytic_account', # account.analytic.account,name
# 'analytic_account_code', # account.analytic.account,code
]
return res
@ -81,7 +80,8 @@ class account_journal(orm.Model):
my_change = {
'move_name':{
'header': [1, 20, 'text', _render("_('My Move Title')")],
'lines': [1, 0, 'text', _render("l['move_name'] != '/' and l['move_name'] or ('*'+str(l['move_id']))")],
'lines': [1, 0, 'text', _render("l['move_name'] != '/' and
l['move_name'] or ('*'+str(l['move_id']))")],
'totals': [1, 0, 'text', None]},
}
return my_change

6
account_journal_report_xls/report/__init__.py

@ -20,7 +20,5 @@
#
##############################################################################
import nov_account_journal
import nov_account_journal_xls
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
from . import nov_account_journal
from . import nov_account_journal_xls

177
account_journal_report_xls/report/nov_account_journal.py

@ -22,7 +22,7 @@
import time
from openerp.report import report_sxw
from openerp.tools.translate import translate, _
from openerp.tools.translate import translate
import logging
_logger = logging.getLogger(__name__)
@ -32,7 +32,8 @@ _ir_translation_name = 'nov.account.journal.print'
class nov_journal_print(report_sxw.rml_parse):
def set_context(self, objects, data, ids, report_type=None):
#_logger.warn('set_context, objects = %s, data = %s, ids = %s', objects, data, ids)
# _logger.warn('set_context, objects = %s, data = %s,
# ids = %s', objects, data, ids)
super(nov_journal_print, self).set_context(objects, data, ids)
j_obj = self.pool.get('account.journal')
p_obj = self.pool.get('account.period')
@ -42,7 +43,8 @@ class nov_journal_print(report_sxw.rml_parse):
self.move_states = ['posted']
else:
self.move_states = ['draft', 'posted']
self.display_currency = self.localcontext['display_currency'] = data['display_currency']
self.display_currency = self.localcontext[
'display_currency'] = data['display_currency']
self.group_entries = data['group_entries']
self.print_by = data['print_by']
self.report_type = report_type
@ -59,7 +61,8 @@ class nov_journal_print(report_sxw.rml_parse):
objects = []
for jf in journal_fy_ids:
journal = j_obj.browse(self.cr, self.uid, jf[0], self.context)
fiscalyear = fy_obj.browse(self.cr, self.uid, jf[1], self.context)
fiscalyear = fy_obj.browse(
self.cr, self.uid, jf[1], self.context)
objects.append((journal, fiscalyear))
self.localcontext['objects'] = self.objects = objects
@ -82,16 +85,20 @@ class nov_journal_print(report_sxw.rml_parse):
def _(self, src):
lang = self.context.get('lang', 'en_US')
return translate(self.cr, _ir_translation_name, 'report', lang, src) or src
return translate(self.cr, _ir_translation_name, 'report', lang, src) \
or src
def _title(self, object):
return ((self.print_by == 'period' and self._('Period') or self._('Fiscal Year')) + ' ' + object[1].name, object[0].name)
return ((self.print_by == 'period' and self._('Period') or
self._('Fiscal Year')) + ' ' + object[1].name, object[0].name)
def _amount_title(self):
return self.display_currency and (self._('Amount'), self._('Currency')) or (self._('Debit'), self._('Credit'))
return self.display_currency and \
(self._('Amount'), self._('Currency')) or (
self._('Debit'), self._('Credit'))
def _lines(self, object):
j_obj = self.pool.get('account.journal')
j_obj = self.pool['account.journal']
_ = self._
journal = object[0]
journal_id = journal.id
@ -100,75 +107,116 @@ class nov_journal_print(report_sxw.rml_parse):
period_id = period.id
period_ids = [period_id]
# update status period
ids_journal_period = self.pool.get('account.journal.period').search(self.cr, self.uid,
[('journal_id', '=', journal_id), ('period_id', '=', period_id)])
ids_journal_period = self.pool['account.journal.period'].\
search(self.cr, self.uid, [('journal_id', '=', journal_id),
('period_id', '=', period_id)])
if ids_journal_period:
self.cr.execute(
'update account_journal_period set state=%s where journal_id=%s and period_id=%s and state=%s',
'''update account_journal_period set state=%s
where journal_id=%s and period_id=%s and state=%s''',
('printed', journal_id, period_id, 'draft'))
else:
self.pool.get('account.journal.period').create(self.cr, self.uid, {
'name': (journal.code or journal.name) + ':' + (period.name or ''),
self.pool.get('account.journal.period').create(
self.cr, self.uid,
{'name': (journal.code or journal.name) + ':' +
(period.name or ''),
'journal_id': journal.id,
'period_id': period.id,
'state': 'printed',
})
_logger.error("The Entry for Period '%s', Journal '%s' was missing in 'account.journal.period' and has been fixed now !",
_logger.error("""The Entry for Period '%s', Journal '%s' was
missing in 'account.journal.period' and
has been fixed now !""",
period.name, journal.name)
else:
fiscalyear = object[1]
period_ids = [x.id for x in fiscalyear.period_ids]
select_extra, join_extra, where_extra = j_obj._report_xls_query_extra(self.cr, self.uid, self.context)
select_extra, join_extra, where_extra = j_obj._report_xls_query_extra(
self.cr, self.uid, self.context)
# SQL select for performance reasons, as a consequence, there are no field value translations.
# If performance is no issue, you can adapt the _report_xls_template in an inherited module to add field value translations.
# SQL select for performance reasons, as a consequence, there are no
# field value translations.
# If performance is no issue, you can adapt the _report_xls_template in
# an inherited module to add field value translations.
self.cr.execute("SELECT l.move_id AS move_id, l.id AS aml_id, "
"am.name AS move_name, coalesce(am.ref,'') AS move_ref, am.date AS move_date, "
"aa.id AS account_id, aa.code AS acc_code, aa.name AS acc_name, "
"am.name AS move_name, "
"coalesce(am.ref,'') AS move_ref, "
"am.date AS move_date, "
"aa.id AS account_id, aa.code AS acc_code, "
"aa.name AS acc_name, "
"aj.name AS journal, aj.code AS journal_code, "
"coalesce(rp.name,'') AS partner_name, coalesce(rp.ref,'') AS partner_ref, rp.id AS partner_id, "
"coalesce(rp.name,'') AS partner_name, "
"coalesce(rp.ref,'') AS partner_ref, "
"rp.id AS partner_id, "
"coalesce(l.name,'') AS aml_name, "
"l.date_maturity AS date_maturity, "
"coalesce(ap.code, ap.name) AS period, "
"coalesce(atc.code,'') AS tax_code, atc.id AS tax_code_id, coalesce(l.tax_amount,0.0) AS tax_amount, "
"coalesce(l.debit,0.0) AS debit, coalesce(l.credit,0.0) AS credit, "
"coalesce(amr.name,'') AS reconcile, coalesce(amrp.name,'') AS reconcile_partial, "
"ana.name AS an_acc_name, coalesce(ana.code,'') AS an_acc_code, "
"coalesce(atc.code,'') AS tax_code, "
"atc.id AS tax_code_id, "
"coalesce(l.tax_amount,0.0) AS tax_amount, "
"coalesce(l.debit,0.0) AS debit, "
"coalesce(l.credit,0.0) AS credit, "
"coalesce(amr.name,'') AS reconcile, "
"coalesce(amrp.name,'') AS reconcile_partial, "
"ana.name AS an_acc_name, "
"coalesce(ana.code,'') AS an_acc_code, "
"coalesce(l.amount_currency,0.0) AS amount_currency, "
"rc.id AS currency_id, rc.name AS currency_name, rc.symbol AS currency_symbol, "
"coalesce(ai.internal_number,'-') AS inv_number, coalesce(abs.name,'-') AS st_number, coalesce(av.number,'-') AS voucher_number "
"rc.id AS currency_id, rc.name AS currency_name, "
"rc.symbol AS currency_symbol, "
"coalesce(ai.internal_number,'-') AS inv_number, "
"coalesce(abs.name,'-') AS st_number, "
"coalesce(av.number,'-') AS voucher_number "
+ select_extra +
"FROM account_move_line l "
"INNER JOIN account_move am ON l.move_id = am.id "
"INNER JOIN account_account aa ON l.account_id = aa.id "
"INNER JOIN account_journal aj ON l.journal_id = aj.id "
"INNER JOIN account_account aa "
"ON l.account_id = aa.id "
"INNER JOIN account_journal aj "
"ON l.journal_id = aj.id "
"INNER JOIN account_period ap ON l.period_id = ap.id "
"LEFT OUTER JOIN account_invoice ai ON ai.move_id = am.id "
"LEFT OUTER JOIN account_voucher av ON av.move_id = am.id "
"LEFT OUTER JOIN account_bank_statement abs ON l.statement_id = abs.id "
"LEFT OUTER JOIN res_partner rp ON l.partner_id = rp.id "
"LEFT OUTER JOIN account_tax_code atc ON l.tax_code_id = atc.id "
"LEFT OUTER JOIN account_move_reconcile amr ON l.reconcile_id = amr.id "
"LEFT OUTER JOIN account_move_reconcile amrp ON l.reconcile_partial_id = amrp.id "
"LEFT OUTER JOIN account_analytic_account ana ON l.analytic_account_id = ana.id "
"LEFT OUTER JOIN res_currency rc ON l.currency_id = rc.id "
"LEFT OUTER JOIN account_invoice ai "
"ON ai.move_id = am.id "
"LEFT OUTER JOIN account_voucher av "
"ON av.move_id = am.id "
"LEFT OUTER JOIN account_bank_statement abs "
"ON l.statement_id = abs.id "
"LEFT OUTER JOIN res_partner rp "
"ON l.partner_id = rp.id "
"LEFT OUTER JOIN account_tax_code atc "
"ON l.tax_code_id = atc.id "
"LEFT OUTER JOIN account_move_reconcile amr "
"ON l.reconcile_id = amr.id "
"LEFT OUTER JOIN account_move_reconcile amrp "
"ON l.reconcile_partial_id = amrp.id "
"LEFT OUTER JOIN account_analytic_account ana "
"ON l.analytic_account_id = ana.id "
"LEFT OUTER JOIN res_currency rc "
"ON l.currency_id = rc.id "
+ join_extra +
"WHERE l.period_id IN %s AND l.journal_id = %s "
"AND am.state IN %s "
+ where_extra +
"ORDER BY " + self.sort_selection + ", move_date, move_id, acc_code",
(tuple(period_ids), journal_id, tuple(self.move_states)))
"ORDER BY " + self.sort_selection +
", move_date, move_id, acc_code",
(tuple(period_ids), journal_id,
tuple(self.move_states)))
lines = self.cr.dictfetchall()
# add reference of corresponding origin document
if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
[x.update({'docname': (_('Invoice') + ': ' + x['inv_number']) or (_('Voucher') + ': ' + x['voucher_number']) or '-'}) for x in lines]
if journal.type in ('sale', 'sale_refund', 'purchase',
'purchase_refund'):
[x.update({'docname': (_('Invoice') + ': ' + x['inv_number'])
or (_('Voucher') + ': ' + x['voucher_number']) or '-'})
for x in lines]
elif journal.type in ('bank', 'cash'):
[x.update({'docname': (_('Statement') + ': ' + x['st_number']) or (_('Voucher') + ': ' + x['voucher_number']) or '-'}) for x in lines]
[x.update({'docname': (_('Statement') + ': ' + x['st_number'])
or (_('Voucher') + ': ' + x['voucher_number']) or '-'})
for x in lines]
else:
code_string = j_obj._report_xls_document_extra(self.cr, self.uid, self.context)
#_logger.warn('code_string= %s', code_string)
code_string = j_obj._report_xls_document_extra(
self.cr, self.uid, self.context)
# _logger.warn('code_string= %s', code_string)
[x.update({'docname': eval(code_string) or '-'}) for x in lines]
# group lines
@ -180,10 +228,15 @@ class nov_journal_print(report_sxw.rml_parse):
curr_obj = self.pool.get('res.currency')
[x.update({
'amount1': self.formatLang(x['debit'] - x['credit']),
'amount2': self.formatLang(x['amount_currency'], monetary=True, currency_obj=curr_obj.browse(self.cr, self.uid, x['currency_id'])),
'amount2': self.formatLang(
x['amount_currency'], monetary=True,
currency_obj=curr_obj.browse(self.cr,
self.uid, x['currency_id'])),
}) for x in lines]
else:
[x.update({'amount1': self.formatLang(x['debit']), 'amount2': self.formatLang(x['credit'])}) for x in lines]
[x.update({'amount1': self.formatLang(x['debit']),
'amount2': self.formatLang(x['credit'])})
for x in lines]
# insert a flag in every move_line to indicate the end of a move
# this flag will be used to draw a full line between moves
@ -205,8 +258,10 @@ class nov_journal_print(report_sxw.rml_parse):
return lines_in
lines_grouped = {}
for line in lines_in:
key = (line['account_id'], line['tax_code_id'], line['partner_id'])
if not key in lines_grouped:
key = (line['account_id'],
line['tax_code_id'],
line['partner_id'])
if key not in lines_grouped:
lines_grouped[key] = line
else:
lines_grouped[key]['debit'] += line['debit']
@ -245,15 +300,19 @@ class nov_journal_print(report_sxw.rml_parse):
self.cr.execute(
"SELECT distinct tax_code_id FROM account_move_line l "
"INNER JOIN account_move am ON l.move_id = am.id "
"WHERE l.period_id in %s AND l.journal_id=%s AND l.tax_code_id IS NOT NULL AND am.state IN %s",
"WHERE l.period_id in %s AND l.journal_id=%s "
"AND l.tax_code_id IS NOT NULL AND am.state IN %s",
(tuple(period_ids), journal_id, tuple(self.move_states)))
ids = map(lambda x: x[0], self.cr.fetchall())
if ids:
self.cr.execute('SELECT id FROM account_tax_code WHERE id IN %s ORDER BY code', (tuple(ids),))
self.cr.execute(
'SELECT id FROM account_tax_code WHERE id IN %s ORDER BY code',
(tuple(ids),))
tax_code_ids = map(lambda x: x[0], self.cr.fetchall())
else:
tax_code_ids = []
tax_codes = self.pool.get('account.tax.code').browse(self.cr, self.uid, tax_code_ids, self.context)
tax_codes = self.pool.get('account.tax.code').browse(
self.cr, self.uid, tax_code_ids, self.context)
return tax_codes
def _totals(self, field, object, tax_code_id=None):
@ -269,7 +328,8 @@ class nov_journal_print(report_sxw.rml_parse):
"WHERE l.period_id IN %s AND l.journal_id=%s AND am.state IN %s"
if field == 'tax_amount':
select += " AND tax_code_id=%s" % tax_code_id
self.cr.execute(select, (tuple(period_ids), journal_id, tuple(self.move_states)))
self.cr.execute(
select, (tuple(period_ids), journal_id, tuple(self.move_states)))
return self.cr.fetchone()[0] or 0.0
def _sum1(self, object):
@ -284,14 +344,17 @@ class nov_journal_print(report_sxw.rml_parse):
def _sum_vat(self, object, tax_code):
return self._totals('tax_amount', object, tax_code.id)
def formatLang(self, value, digits=None, date=False, date_time=False, grouping=True, monetary=False, dp=False, currency_obj=False):
def formatLang(self, value, digits=None, date=False, date_time=False,
grouping=True, monetary=False, dp=False,
currency_obj=False):
if isinstance(value, (float, int)) and not value:
return ''
else:
return super(nov_journal_print, self).formatLang(value, digits, date, date_time, grouping, monetary, dp, currency_obj)
return super(nov_journal_print, self).formatLang(
value, digits,
date, date_time, grouping, monetary, dp, currency_obj)
report_sxw.report_sxw('report.nov.account.journal.print', 'account.journal',
report_sxw.report_sxw(
'report.nov.account.journal.print', 'account.journal',
'addons/account_journal_report_xls/report/nov_account_journal.rml',
parser=nov_journal_print, header=False)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

191
account_journal_report_xls/report/nov_account_journal_xls.py

@ -21,10 +21,8 @@
##############################################################################
import xlwt
import time
from datetime import datetime
from openerp.osv import orm
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell, _render
from .nov_account_journal import nov_journal_print
@ -36,7 +34,8 @@ _logger = logging.getLogger(__name__)
class account_journal_xls_parser(nov_journal_print):
def __init__(self, cr, uid, name, context):
super(account_journal_xls_parser, self).__init__(cr, uid, name, context=context)
super(account_journal_xls_parser, self).__init__(cr, uid, name,
context=context)
journal_obj = self.pool.get('account.journal')
self.context = context
wanted_list = journal_obj._report_xls_fields(cr, uid, context)
@ -50,8 +49,10 @@ class account_journal_xls_parser(nov_journal_print):
class account_journal_xls(report_xls):
def __init__(self, name, table, rml=False, parser=False, header=True, store=False):
super(account_journal_xls, self).__init__(name, table, rml, parser, header, store)
def __init__(self, name, table, rml=False, parser=False, header=True,
store=False):
super(account_journal_xls, self).__init__(
name, table, rml, parser, header, store)
# Cell Styles
_xs = self.xls_styles
@ -63,24 +64,37 @@ class account_journal_xls(report_xls):
# lines
aml_cell_format = _xs['borders_all']
self.aml_cell_style = xlwt.easyxf(aml_cell_format)
self.aml_cell_style_center = xlwt.easyxf(aml_cell_format + _xs['center'])
self.aml_cell_style_date = xlwt.easyxf(aml_cell_format + _xs['left'], num_format_str=report_xls.date_format)
self.aml_cell_style_decimal = xlwt.easyxf(aml_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)
self.aml_cell_style_center = xlwt.easyxf(
aml_cell_format + _xs['center'])
self.aml_cell_style_date = xlwt.easyxf(
aml_cell_format + _xs['left'],
num_format_str=report_xls.date_format)
self.aml_cell_style_decimal = xlwt.easyxf(
aml_cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# totals
rt_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
self.rt_cell_style = xlwt.easyxf(rt_cell_format)
self.rt_cell_style_right = xlwt.easyxf(rt_cell_format + _xs['right'])
self.rt_cell_style_decimal = xlwt.easyxf(rt_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)
self.rt_cell_style_decimal = xlwt.easyxf(
rt_cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# XLS Template Journal Items
self.col_specs_lines_template = {
'move_name': {
'header': [1, 20, 'text', _render("_('Entry')")],
'lines': [1, 0, 'text', _render("l['move_name'] != '/' and l['move_name'] or ('*'+str(l['move_id']))")],
'lines':
[1, 0, 'text',
_render("l['move_name'] != '/' and l['move_name'] \
or ('*'+str(l['move_id']))")],
'totals': [1, 0, 'text', None]},
'move_date': {
'header': [1, 13, 'text', _render("_('Date')")],
'lines': [1, 0, 'date', _render("datetime.strptime(l['move_date'],'%Y-%m-%d')"), None, self.aml_cell_style_date],
'lines':
[1, 0, 'date',
_render("datetime.strptime(l['move_date'],'%Y-%m-%d')"),
None, self.aml_cell_style_date],
'totals': [1, 0, 'text', None]},
'acc_code': {
'header': [1, 12, 'text', _render("_('Account')")],
@ -124,47 +138,73 @@ class account_journal_xls(report_xls):
'totals': [1, 0, 'text', None]},
'date_maturity': {
'header': [1, 13, 'text', _render("_('Maturity Date')")],
'lines': [1, 0, _render("l['date_maturity'] and 'date' or 'text'"),
_render("l['date_maturity'] and datetime.strptime(l['date_maturity'],'%Y-%m-%d') or None"),
'lines':
[1, 0,
_render("l['date_maturity'] and 'date' or 'text'"),
_render(
"l['date_maturity'] and datetime.\
strptime(l['date_maturity'],'%Y-%m-%d') or None"),
None, self.aml_cell_style_date],
'totals': [1, 0, 'text', None]},
'debit': {
'header': [1, 18, 'text', _render("_('Debit')"), None, self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("l['debit']"), None, self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("debit_formula"), self.rt_cell_style_decimal]},
'header': [1, 18, 'text', _render("_('Debit')"), None,
self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("l['debit']"), None,
self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("debit_formula"),
self.rt_cell_style_decimal]},
'credit': {
'header': [1, 18, 'text', _render("_('Credit')"), None, self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("l['credit']"), None, self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("credit_formula"), self.rt_cell_style_decimal]},
'header': [1, 18, 'text', _render("_('Credit')"), None,
self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("l['credit']"), None,
self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("credit_formula"),
self.rt_cell_style_decimal]},
'balance': {
'header': [1, 18, 'text', _render("_('Balance')"), None, self.rh_cell_style_right],
'lines': [1, 0, 'number', None, _render("bal_formula"), self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("bal_formula"), self.rt_cell_style_decimal]},
'header': [1, 18, 'text', _render("_('Balance')"), None,
self.rh_cell_style_right],
'lines': [1, 0, 'number', None, _render("bal_formula"),
self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("bal_formula"),
self.rt_cell_style_decimal]},
'reconcile': {
'header': [1, 12, 'text', _render("_('Rec.')"), None, self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("l['reconcile']"), None, self.aml_cell_style_center],
'header': [1, 12, 'text', _render("_('Rec.')"), None,
self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("l['reconcile']"), None,
self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
'reconcile_partial': {
'header': [1, 12, 'text', _render("_('Part. Rec.')"), None, self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("l['reconcile_partial']"), None, self.aml_cell_style_center],
'header': [1, 12, 'text', _render("_('Part. Rec.')"), None,
self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("l['reconcile_partial']"),
None, self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
'tax_code': {
'header': [1, 6, 'text', _render("_('VAT')"), None, self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("l['tax_code']"), None, self.aml_cell_style_center],
'header': [1, 6, 'text', _render("_('VAT')"), None,
self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("l['tax_code']"), None,
self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
'tax_amount': {
'header': [1, 18, 'text', _render("_('VAT Amount')"), None, self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("l['tax_amount']"), None, self.aml_cell_style_decimal],
'header': [1, 18, 'text', _render("_('VAT Amount')"), None,
self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("l['tax_amount']"), None,
self.aml_cell_style_decimal],
'totals': [1, 0, 'text', None]},
'amount_currency': {
'header': [1, 18, 'text', _render("_('Am. Currency')"), None, self.rh_cell_style_right],
'lines': [1, 0, _render("l['amount_currency'] and 'number' or 'text'"),
'header': [1, 18, 'text', _render("_('Am. Currency')"), None,
self.rh_cell_style_right],
'lines':
[1, 0,
_render("l['amount_currency'] and 'number' or 'text'"),
_render("l['amount_currency'] or None"),
None, self.aml_cell_style_decimal],
'totals': [1, 0, 'text', None]},
'currency_name': {
'header': [1, 6, 'text', _render("_('Curr.')"), None, self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("l['currency_name']"), None, self.aml_cell_style_center],
'header': [1, 6, 'text', _render("_('Curr.')"), None,
self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("l['currency_name']"), None,
self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
'docname': {
'header': [1, 35, 'text', _render("_('Document')")],
@ -189,8 +229,10 @@ class account_journal_xls(report_xls):
'header': [1, 6, 'text', _render("_('Case')")],
'tax_totals': [1, 0, 'text', _render("t.code")]},
'tax_amount': {
'header': [1, 18, 'text', _render("_('Amount')"), None, self.rh_cell_style_right],
'tax_totals': [1, 0, 'number', _render("sum_vat(o,t)"), None, self.aml_cell_style_decimal]},
'header': [1, 18, 'text', _render("_('Amount')"), None,
self.rh_cell_style_right],
'tax_totals': [1, 0, 'number', _render("sum_vat(o,t)"), None,
self.aml_cell_style_decimal]},
}
def _journal_title(self, o, ws, _p, row_pos, xlwt, _xs):
@ -205,7 +247,8 @@ class account_journal_xls(report_xls):
('report_name', 1, 0, 'text', report_name),
]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
return row_pos + 1
def _journal_lines(self, o, ws, _p, row_pos, xlwt, _xs):
@ -215,9 +258,13 @@ class account_journal_xls(report_xls):
credit_pos = self.credit_pos
# Column headers
c_specs = map(lambda x: self.render(x, self.col_specs_lines_template, 'header', render_space={'_': _p._}), wanted_list)
c_specs = map(lambda x: self.render(
x, self.col_specs_lines_template, 'header',
render_space={'_': _p._}), wanted_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.rh_cell_style,
set_column_size=True)
ws.set_horz_split_pos(row_pos)
# account move lines
@ -229,9 +276,13 @@ class account_journal_xls(report_xls):
debit_cell = rowcol_to_cell(row_pos, debit_pos)
credit_cell = rowcol_to_cell(row_pos, credit_pos)
bal_formula = debit_cell + '-' + credit_cell
c_specs = map(lambda x: self.render(x, self.col_specs_lines_template, 'lines'), wanted_list)
_logger.debug('dummy call - %s', bal_formula)
c_specs = map(
lambda x: self.render(x, self.col_specs_lines_template,
'lines'), wanted_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.aml_cell_style)
if l['draw_line'] and cnt != aml_cnt:
row_pos += 1
@ -239,15 +290,19 @@ class account_journal_xls(report_xls):
debit_start = rowcol_to_cell(aml_start_pos, debit_pos)
debit_stop = rowcol_to_cell(row_pos - 1, debit_pos)
debit_formula = 'SUM(%s:%s)' % (debit_start, debit_stop)
_logger.debug('dummy call - %s', debit_formula)
credit_start = rowcol_to_cell(aml_start_pos, credit_pos)
credit_stop = rowcol_to_cell(row_pos - 1, credit_pos)
credit_formula = 'SUM(%s:%s)' % (credit_start, credit_stop)
_logger.debug('dummy call - %s', credit_formula)
debit_cell = rowcol_to_cell(row_pos, debit_pos)
credit_cell = rowcol_to_cell(row_pos, credit_pos)
bal_formula = debit_cell + '-' + credit_cell
c_specs = map(lambda x: self.render(x, self.col_specs_lines_template, 'totals'), wanted_list)
c_specs = map(lambda x: self.render(
x, self.col_specs_lines_template, 'totals'), wanted_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rt_cell_style_right)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.rt_cell_style_right)
return row_pos + 1
def _journal_vat_summary(self, o, ws, _p, row_pos, xlwt, _xs):
@ -258,7 +313,8 @@ class account_journal_xls(report_xls):
title_cell_style = xlwt.easyxf(_xs['bold'])
c_specs = [('summary_title', 1, 0, 'text', _p._("VAT Declaration"))]
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=title_cell_style) + 1
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=title_cell_style) + 1
wanted_list = self.wanted_list
vat_summary_wanted_list = ['tax_case_name', 'tax_code', 'tax_amount']
@ -267,33 +323,45 @@ class account_journal_xls(report_xls):
cols_number = len(wanted_list)
vat_summary_cols_number = len(vat_summary_wanted_list)
if vat_summary_cols_number > cols_number:
raise orm.except_orm(_('Programming Error!'),
raise orm.except_orm(
_('Programming Error!'),
_("vat_summary_cols_number should be < cols_number !"))
index = 0
for i in range(vat_summary_cols_number):
col = vat_summary_wanted_list[i]
col_size = self.col_specs_lines_template[wanted_list[index]]['header'][1]
templ_col_size = self.col_specs_vat_summary_template[col]['header'][1]
#_logger.warn("col=%s, col_size=%s, templ_col_size=%s", col, col_size, templ_col_size)
col_size = self.col_specs_lines_template[
wanted_list[index]]['header'][1]
templ_col_size = self.col_specs_vat_summary_template[
col]['header'][1]
# _logger.warn("col=%s, col_size=%s, templ_col_size=%s",
# col, col_size, templ_col_size)
col_span = 1
if templ_col_size > col_size:
new_size = col_size
while templ_col_size > new_size:
col_span += 1
index += 1
new_size += self.col_specs_lines_template[wanted_list[index]]['header'][1]
new_size += self.col_specs_lines_template[
wanted_list[index]]['header'][1]
self.col_specs_vat_summary_template[col]['header'][0] = col_span
self.col_specs_vat_summary_template[col]['tax_totals'][0] = col_span
self.col_specs_vat_summary_template[
col]['tax_totals'][0] = col_span
index += 1
c_specs = map(lambda x: self.render(x, self.col_specs_vat_summary_template, 'header'), vat_summary_wanted_list)
c_specs = map(lambda x: self.render(
x, self.col_specs_vat_summary_template, 'header'),
vat_summary_wanted_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.rh_cell_style)
for t in _p.tax_codes(o):
c_specs = map(lambda x: self.render(x, self.col_specs_vat_summary_template, 'tax_totals'), vat_summary_wanted_list)
c_specs = map(lambda x: self.render(
x, self.col_specs_vat_summary_template, 'tax_totals'),
vat_summary_wanted_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.aml_cell_style)
return row_pos
@ -306,14 +374,19 @@ class account_journal_xls(report_xls):
self.col_specs_lines_template.update(_p.template_changes)
self.debit_pos = 'debit' in wanted_list and wanted_list.index('debit')
self.credit_pos = 'credit' in wanted_list and wanted_list.index('credit')
if not (self.credit_pos and self.debit_pos) and 'balance' in wanted_list:
self.credit_pos = 'credit' in wanted_list and wanted_list.index(
'credit')
if not (self.credit_pos and self.debit_pos) and 'balance' \
in wanted_list:
raise orm.except_orm(_('Customisation Error!'),
_("The 'Balance' field is a calculated XLS field requiring the presence of the 'Debit' and 'Credit' fields !"))
_("The 'Balance' field is a calculated XLS \
field requiring the presence of the \
'Debit' and 'Credit' fields !"))
for o in objects:
sheet_name = ' - '.join([o[1].code, o[0].code])[:31].replace('/', '-')
sheet_name = ' - '.join([o[1].code, o[0].code]
)[:31].replace('/', '-')
sheet_name = sheet_name[:31].replace('/', '-')
ws = wb.add_sheet(sheet_name)
ws.panes_frozen = True
@ -333,5 +406,3 @@ class account_journal_xls(report_xls):
account_journal_xls('report.nov.account.journal.xls', 'account.journal.period',
parser=account_journal_xls_parser)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

2
account_journal_report_xls/wizard/__init__.py

@ -21,5 +21,3 @@
##############################################################################
from . import print_journal_wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

66
account_journal_report_xls/wizard/print_journal_wizard.py

@ -22,8 +22,8 @@
from openerp.tools.translate import _
from openerp.osv import orm, fields
from openerp.addons.account.wizard.account_report_common_journal import account_common_journal_report
import time
from openerp.addons.account.wizard.account_report_common_journal \
import account_common_journal_report
import logging
_logger = logging.getLogger(__name__)
@ -33,15 +33,19 @@ class account_print_journal_xls(orm.TransientModel):
_name = 'account.print.journal.xls'
_description = 'Print/Export Journal'
_columns = {
'journal_ids': fields.many2many('account.journal', string='Journals', required=True),
'group_entries': fields.boolean('Group Entries', help="Group entries with same General Account & Tax Code."),
'journal_ids': fields.many2many('account.journal', string='Journals',
required=True),
'group_entries': fields.boolean(
'Group Entries',
help="Group entries with same General Account & Tax Code."),
}
_defaults = {
'group_entries': True,
}
def fields_get(self, cr, uid, fields=None, context=None):
res = super(account_print_journal_xls, self).fields_get(cr, uid, fields, context)
res = super(account_print_journal_xls, self).fields_get(
cr, uid, fields, context)
if context.get('print_by') == 'fiscalyear':
if 'fiscalyear_id' in res:
res['fiscalyear_id']['required'] = True
@ -59,15 +63,18 @@ class account_print_journal_xls(orm.TransientModel):
def fy_period_ids(self, cr, uid, fiscalyear_id):
""" returns all periods from a fiscalyear sorted by date """
fy_period_ids = []
cr.execute('SELECT id, coalesce(special, False) AS special FROM account_period '
'WHERE fiscalyear_id=%s ORDER BY date_start, special DESC',
cr.execute('''
SELECT id, coalesce(special, False) AS special
FROM account_period
WHERE fiscalyear_id=%s ORDER BY date_start, special DESC''',
(fiscalyear_id,))
res = cr.fetchall()
if res:
fy_period_ids = [x[0] for x in res]
return fy_period_ids
def onchange_fiscalyear_id(self, cr, uid, ids, fiscalyear_id=False, context=None):
def onchange_fiscalyear_id(self, cr, uid, ids, fiscalyear_id=False,
context=None):
res = {'value': {}}
if context.get('print_by') == 'fiscalyear':
# get period_from/to with opening/close periods
@ -77,9 +84,13 @@ class account_print_journal_xls(orm.TransientModel):
res['value']['period_to'] = fy_period_ids[-1]
return res
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
""" skip account.common.journal.report,fields_view_get (adds domain filter on journal type) """
return super(account_common_journal_report, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
context=None, toolbar=False, submenu=False):
""" skip account.common.journal.report,fields_view_get
(adds domain filter on journal type) """
return super(account_common_journal_report, self).\
fields_view_get(cr, uid, view_id, view_type, context, toolbar,
submenu)
def xls_export(self, cr, uid, ids, context=None):
return self.print_report(cr, uid, ids, context=context)
@ -98,10 +109,14 @@ class account_print_journal_xls(orm.TransientModel):
else:
period_from = wiz_form.period_from
period_to = wiz_form.period_to
cr.execute("SELECT id, coalesce(special, False) AS special FROM account_period ap "
"WHERE ap.date_start>=%s AND ap.date_stop<=%s AND company_id=%s "
"ORDER BY date_start, special DESC",
(period_from.date_start, period_to.date_stop, company_id))
cr.execute("""
SELECT id, coalesce(special, False) AS special
FROM account_period ap
WHERE ap.date_start>=%s AND ap.date_stop<=%s AND company_id=%s
ORDER BY date_start, special DESC""",
(period_from.date_start,
period_to.date_stop,
company_id))
wiz_period_ids = map(lambda x: x[0], cr.fetchall())
wiz_journal_ids = [j.id for j in wiz_form.journal_ids]
@ -129,31 +144,40 @@ class account_print_journal_xls(orm.TransientModel):
journal_fy_ids = []
for journal_id in wiz_journal_ids:
aml_ids = move_obj.search(cr, uid,
[('journal_id', '=', journal_id), ('period_id', 'in', wiz_period_ids), ('state', 'in', move_states)],
[('journal_id', '=', journal_id),
('period_id', 'in', wiz_period_ids),
('state', 'in', move_states)],
limit=1)
if aml_ids:
journal_fy_ids.append((journal_id, fiscalyear_id))
if not journal_fy_ids:
raise orm.except_orm(_('No Data Available'), _('No records found for your selection!'))
raise orm.except_orm(
_('No Data Available'),
_('No records found for your selection!'))
datas.update({
'ids': [x[0] for x in journal_fy_ids],
'journal_fy_ids': journal_fy_ids,
})
else:
# perform account.move.line query in stead of 'account.journal.period' since this table is not always reliable
# perform account.move.line query in stead of
# 'account.journal.period' since this table is not always reliable
journal_period_ids = []
for journal_id in wiz_journal_ids:
period_ids = []
for period_id in wiz_period_ids:
aml_ids = move_obj.search(cr, uid,
[('journal_id', '=', journal_id), ('period_id', '=', period_id), ('state', 'in', move_states)],
[('journal_id', '=', journal_id),
('period_id', '=', period_id),
('state', 'in', move_states)],
limit=1)
if aml_ids:
period_ids.append(period_id)
if period_ids:
journal_period_ids.append((journal_id, period_ids))
if not journal_period_ids:
raise orm.except_orm(_('No Data Available'), _('No records found for your selection!'))
raise orm.except_orm(
_('No Data Available'),
_('No records found for your selection!'))
datas.update({
'ids': [x[0] for x in journal_period_ids],
'journal_period_ids': journal_period_ids,
@ -168,5 +192,3 @@ class account_print_journal_xls(orm.TransientModel):
'type': 'ir.actions.report.xml',
'report_name': 'nov.account.journal.print',
'datas': datas}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

5
account_move_line_report_xls/__init__.py

@ -25,5 +25,6 @@ try:
from . import report
except ImportError:
import logging
logging.getLogger('openerp.module').warning('report_xls not available in addons path. account_financial_report_webkit_xls will not be usable')
logging.getLogger('openerp.module').\
warning('''report_xls not available in addons path.
account_financial_report_webkit_xls will not be usable''')

12
account_move_line_report_xls/account_move_line.py

@ -21,8 +21,6 @@
##############################################################################
from openerp.osv import orm
from openerp.addons.report_xls.utils import rowcol_to_cell, _render
from openerp.tools.translate import _
class account_move_line(orm.Model):
@ -34,11 +32,11 @@ class account_move_line(orm.Model):
'move', 'name', 'date', 'journal', 'period', 'partner', 'account',
'date_maturity', 'debit', 'credit', 'balance',
'reconcile', 'reconcile_partial', 'analytic_account',
#'ref', 'partner_ref', 'tax_code', 'tax_amount', 'amount_residual',
#'amount_currency', 'currency_name', 'company_currency',
#'amount_residual_currency',
#'product', 'product_ref', 'product_uom', 'quantity',
#'statement', 'invoice', 'narration', 'blocked',
# 'ref', 'partner_ref', 'tax_code', 'tax_amount',
# 'amount_residual', 'amount_currency', 'currency_name',
# 'company_currency', 'amount_residual_currency',
# 'product', 'product_ref', 'product_uom', 'quantity',
# 'statement', 'invoice', 'narration', 'blocked',
]
# Change/Add Template entries

216
account_move_line_report_xls/report/move_line_list_xls.py

@ -21,14 +21,12 @@
##############################################################################
import xlwt
import time
from datetime import datetime
from openerp.osv import orm
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls
from openerp.addons.report_xls.utils import rowcol_to_cell, _render
from openerp.tools.translate import translate, _
from openerp import pooler
import logging
_logger = logging.getLogger(__name__)
@ -38,7 +36,8 @@ _ir_translation_name = 'move.line.list.xls'
class move_line_xls_parser(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(move_line_xls_parser, self).__init__(cr, uid, name, context=context)
super(move_line_xls_parser, self).__init__(
cr, uid, name, context=context)
move_obj = self.pool.get('account.move.line')
self.context = context
wanted_list = move_obj._report_xls_fields(cr, uid, context)
@ -52,13 +51,16 @@ class move_line_xls_parser(report_sxw.rml_parse):
def _(self, src):
lang = self.context.get('lang', 'en_US')
return translate(self.cr, _ir_translation_name, 'report', lang, src) or src
return translate(self.cr, _ir_translation_name, 'report', lang, src) \
or src
class move_line_xls(report_xls):
def __init__(self, name, table, rml=False, parser=False, header=True, store=False):
super(move_line_xls, self).__init__(name, table, rml, parser, header, store)
def __init__(self, name, table, rml=False, parser=False, header=True,
store=False):
super(move_line_xls, self).__init__(
name, table, rml, parser, header, store)
# Cell Styles
_xs = self.xls_styles
@ -70,14 +72,21 @@ class move_line_xls(report_xls):
# lines
aml_cell_format = _xs['borders_all']
self.aml_cell_style = xlwt.easyxf(aml_cell_format)
self.aml_cell_style_center = xlwt.easyxf(aml_cell_format + _xs['center'])
self.aml_cell_style_date = xlwt.easyxf(aml_cell_format + _xs['left'], num_format_str=report_xls.date_format)
self.aml_cell_style_decimal = xlwt.easyxf(aml_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)
self.aml_cell_style_center = xlwt.easyxf(
aml_cell_format + _xs['center'])
self.aml_cell_style_date = xlwt.easyxf(
aml_cell_format + _xs['left'],
num_format_str=report_xls.date_format)
self.aml_cell_style_decimal = xlwt.easyxf(
aml_cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# totals
rt_cell_format = _xs['bold'] + _xs['fill'] + _xs['borders_all']
self.rt_cell_style = xlwt.easyxf(rt_cell_format)
self.rt_cell_style_right = xlwt.easyxf(rt_cell_format + _xs['right'])
self.rt_cell_style_decimal = xlwt.easyxf(rt_cell_format + _xs['right'], num_format_str=report_xls.decimal_format)
self.rt_cell_style_decimal = xlwt.easyxf(
rt_cell_format + _xs['right'],
num_format_str=report_xls.decimal_format)
# XLS Template
self.col_specs_template = {
@ -95,19 +104,27 @@ class move_line_xls(report_xls):
'totals': [1, 0, 'text', None]},
'date': {
'header': [1, 13, 'text', _render("_('Effective Date')")],
'lines': [1, 0, 'date', _render("datetime.strptime(line.date,'%Y-%m-%d')"), None, self.aml_cell_style_date],
'lines': [1, 0, 'date',
_render("datetime.strptime(line.date,'%Y-%m-%d')"),
None, self.aml_cell_style_date],
'totals': [1, 0, 'text', None]},
'period': {
'header': [1, 12, 'text', _render("_('Period')")],
'lines': [1, 0, 'text', _render("line.period_id.code or line.period_id.name")],
'lines':
[1, 0, 'text',
_render("line.period_id.code or line.period_id.name")],
'totals': [1, 0, 'text', None]},
'partner': {
'header': [1, 36, 'text', _render("_('Partner')")],
'lines': [1, 0, 'text', _render("line.partner_id and line.partner_id.name or ''")],
'lines':
[1, 0, 'text',
_render("line.partner_id and line.partner_id.name or ''")],
'totals': [1, 0, 'text', None]},
'partner_ref': {
'header': [1, 36, 'text', _render("_('Partner Reference')")],
'lines': [1, 0, 'text', _render("line.partner_id and line.partner_id.ref or ''")],
'lines':
[1, 0, 'text',
_render("line.partner_id and line.partner_id.ref or ''")],
'totals': [1, 0, 'text', None]},
'account': {
'header': [1, 12, 'text', _render("_('Account')")],
@ -115,47 +132,78 @@ class move_line_xls(report_xls):
'totals': [1, 0, 'text', None]},
'date_maturity': {
'header': [1, 13, 'text', _render("_('Maturity Date')")],
'lines': [1, 0, _render("line.date_maturity.val and 'date' or 'text'"),
_render("line.date_maturity.val and datetime.strptime(line.date_maturity,'%Y-%m-%d') or None"),
'lines':
[1, 0,
_render("line.date_maturity.val and 'date' or 'text'"),
_render(
"line.date_maturity.val \
and datetime.strptime(line.date_maturity,'%Y-%m-%d') \
or None"),
None, self.aml_cell_style_date],
'totals': [1, 0, 'text', None]},
'debit': {
'header': [1, 18, 'text', _render("_('Debit')"), None, self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("line.debit"), None, self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("debit_formula"), self.rt_cell_style_decimal]},
'header': [1, 18, 'text', _render("_('Debit')"), None,
self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("line.debit"), None,
self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("debit_formula"),
self.rt_cell_style_decimal]},
'credit': {
'header': [1, 18, 'text', _render("_('Credit')"), None, self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("line.credit"), None, self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("credit_formula"), self.rt_cell_style_decimal]},
'header': [1, 18, 'text', _render("_('Credit')"), None,
self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("line.credit"), None,
self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("credit_formula"),
self.rt_cell_style_decimal]},
'balance': {
'header': [1, 18, 'text', _render("_('Balance')"), None, self.rh_cell_style_right],
'lines': [1, 0, 'number', None, _render("bal_formula"), self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("bal_formula"), self.rt_cell_style_decimal]},
'header': [1, 18, 'text', _render("_('Balance')"), None,
self.rh_cell_style_right],
'lines': [1, 0, 'number', None, _render("bal_formula"),
self.aml_cell_style_decimal],
'totals': [1, 0, 'number', None, _render("bal_formula"),
self.rt_cell_style_decimal]},
'reconcile': {
'header': [1, 12, 'text', _render("_('Rec.')"), None, self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("line.reconcile_id.name or ''"), None, self.aml_cell_style_center],
'header': [1, 12, 'text', _render("_('Rec.')"), None,
self.rh_cell_style_center],
'lines': [1, 0, 'text',
_render("line.reconcile_id.name or ''"), None,
self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
'reconcile_partial': {
'header': [1, 12, 'text', _render("_('Part. Rec.')"), None, self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("line.reconcile_partial_id.name or ''"), None, self.aml_cell_style_center],
'header': [1, 12, 'text', _render("_('Part. Rec.')"), None,
self.rh_cell_style_center],
'lines': [1, 0, 'text',
_render("line.reconcile_partial_id.name or ''"),
None, self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
'tax_code': {
'header': [1, 12, 'text', _render("_('Tax Code')"), None, self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("line.tax_code_id.code or ''"), None, self.aml_cell_style_center],
'header': [1, 12, 'text', _render("_('Tax Code')"), None,
self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("line.tax_code_id.code or ''"),
None, self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
'tax_amount': {
'header': [1, 18, 'text', _render("_('Tax/Base Amount')"), None, self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("line.tax_amount"), None, self.aml_cell_style_decimal],
'header': [1, 18, 'text', _render("_('Tax/Base Amount')"),
None, self.rh_cell_style_right],
'lines': [1, 0, 'number', _render("line.tax_amount"), None,
self.aml_cell_style_decimal],
'totals': [1, 0, 'text', None]},
'amount_currency': {
'header': [1, 18, 'text', _render("_('Am. Currency')"), None, self.rh_cell_style_right],
'lines': [1, 0, _render("line.amount_currency and 'number' or 'text'"),
'header': [1, 18, 'text', _render("_('Am. Currency')"), None,
self.rh_cell_style_right],
'lines':
[1, 0,
_render("line.amount_currency and 'number' or 'text'"),
_render("line.amount_currency or None"),
None, self.aml_cell_style_decimal],
'totals': [1, 0, 'text', None]},
'currency_name': {
'header': [1, 6, 'text', _render("_('Curr.')"), None, self.rh_cell_style_center],
'lines': [1, 0, 'text', _render("line.currency_id and line.currency_id.name or ''"), None, self.aml_cell_style_center],
'header': [1, 6, 'text', _render("_('Curr.')"), None,
self.rh_cell_style_center],
'lines':
[1, 0, 'text',
_render("line.currency_id and line.currency_id.name or ''"),
None, self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
'journal': {
'header': [1, 12, 'text', _render("_('Journal')")],
@ -163,11 +211,14 @@ class move_line_xls(report_xls):
'totals': [1, 0, 'text', None]},
'company_currency': {
'header': [1, 10, 'text', _render("_('Comp. Curr.')")],
'lines': [1, 0, 'text', _render("line.company_id.currency_id.name or ''"), None, self.aml_cell_style_center],
'lines': [1, 0, 'text',
_render("line.company_id.currency_id.name or ''"),
None, self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
'analytic_account': {
'header': [1, 36, 'text', _render("_('Analytic Account')")],
'lines': [1, 0, 'text', _render("line.analytic_account_id.code or ''")],
'lines': [1, 0, 'text',
_render("line.analytic_account_id.code or ''")],
'totals': [1, 0, 'text', None]},
'product': {
'header': [1, 36, 'text', _render("_('Product')")],
@ -175,44 +226,64 @@ class move_line_xls(report_xls):
'totals': [1, 0, 'text', None]},
'product_ref': {
'header': [1, 36, 'text', _render("_('Product Reference')")],
'lines': [1, 0, 'text', _render("line.product_id.default_code or ''")],
'lines': [1, 0, 'text',
_render("line.product_id.default_code or ''")],
'totals': [1, 0, 'text', None]},
'product_uom': {
'header': [1, 20, 'text', _render("_('Unit of Measure')")],
'lines': [1, 0, 'text', _render("line.product_uom_id.name or ''")],
'lines': [1, 0, 'text',
_render("line.product_uom_id.name or ''")],
'totals': [1, 0, 'text', None]},
'quantity': {
'header': [1, 8, 'text', _render("_('Qty')"), None, self.rh_cell_style_right],
'lines': [1, 0, _render("line.quantity and 'number' or 'text'"),
_render("line.quantity or None"), None, self.aml_cell_style_decimal],
'header': [1, 8, 'text', _render("_('Qty')"), None,
self.rh_cell_style_right],
'lines': [1, 0,
_render("line.quantity and 'number' or 'text'"),
_render("line.quantity or None"), None,
self.aml_cell_style_decimal],
'totals': [1, 0, 'text', None]},
'statement': {
'header': [1, 20, 'text', _render("_('Statement')")],
'lines': [1, 0, 'text', _render("line.statement_id and line.statement_id.name or ''")],
'lines':
[1, 0, 'text',
_render("line.statement_id and line.statement_id.name or ''")
],
'totals': [1, 0, 'text', None]},
'invoice': {
'header': [1, 20, 'text', _render("_('Invoice')")],
'lines': [1, 0, 'text', _render("line.invoice and line.invoice.number or ''")],
'lines':
[1, 0, 'text',
_render("line.invoice and line.invoice.number or ''")],
'totals': [1, 0, 'text', None]},
'amount_residual': {
'header': [1, 18, 'text', _render("_('Residual Amount')"), None, self.rh_cell_style_right],
'lines': [1, 0, _render("line.amount_residual and 'number' or 'text'"),
'header': [1, 18, 'text', _render("_('Residual Amount')"),
None, self.rh_cell_style_right],
'lines':
[1, 0,
_render("line.amount_residual and 'number' or 'text'"),
_render("line.amount_residual or None"),
None, self.aml_cell_style_decimal],
'totals': [1, 0, 'text', None]},
'amount_residual_currency': {
'header': [1, 18, 'text', _render("_('Res. Am. in Curr.')"), None, self.rh_cell_style_right],
'lines': [1, 0, _render("line.amount_residual_currency and 'number' or 'text'"),
'header': [1, 18, 'text', _render("_('Res. Am. in Curr.')"),
None, self.rh_cell_style_right],
'lines':
[1, 0,
_render(
"line.amount_residual_currency and 'number' or 'text'"),
_render("line.amount_residual_currency or None"),
None, self.aml_cell_style_decimal],
'totals': [1, 0, 'text', None]},
'narration': {
'header': [1, 42, 'text', _render("_('Notes')")],
'lines': [1, 0, 'text', _render("line.move_id.narration or ''")],
'lines': [1, 0, 'text',
_render("line.move_id.narration or ''")],
'totals': [1, 0, 'text', None]},
'blocked': {
'header': [1, 4, 'text', _('Lit.'), None, self.rh_cell_style_right],
'lines': [1, 0, 'text', _render("line.blocked and 'x' or ''"), None, self.aml_cell_style_center],
'header': [1, 4, 'text', _('Lit.'),
None, self.rh_cell_style_right],
'lines': [1, 0, 'text', _render("line.blocked and 'x' or ''"),
None, self.aml_cell_style_center],
'totals': [1, 0, 'text', None]},
}
@ -225,10 +296,12 @@ class move_line_xls(report_xls):
debit_pos = 'debit' in wanted_list and wanted_list.index('debit')
credit_pos = 'credit' in wanted_list and wanted_list.index('credit')
if not (credit_pos and debit_pos) and 'balance' in wanted_list:
raise orm.except_orm(_('Customisation Error!'),
_("The 'Balance' field is a calculated XLS field requiring the presence of the 'Debit' and 'Credit' fields !"))
raise orm.except_orm(
_('Customisation Error!'),
_("The 'Balance' field is a calculated XLS field requiring \
the presence of the 'Debit' and 'Credit' fields !"))
#report_name = objects[0]._description or objects[0]._name
# report_name = objects[0]._description or objects[0]._name
report_name = _("Journal Items")
ws = wb.add_sheet(report_name[:31])
ws.panes_frozen = True
@ -247,13 +320,18 @@ class move_line_xls(report_xls):
('report_name', 1, 0, 'text', report_name),
]
row_data = self.xls_row_template(c_specs, ['report_name'])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=cell_style)
row_pos += 1
# Column headers
c_specs = map(lambda x: self.render(x, self.col_specs_template, 'header', render_space={'_': _p._}), wanted_list)
c_specs = map(lambda x: self.render(
x, self.col_specs_template, 'header', render_space={'_': _p._}),
wanted_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rh_cell_style, set_column_size=True)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.rh_cell_style,
set_column_size=True)
ws.set_horz_split_pos(row_pos)
# account move lines
@ -261,27 +339,35 @@ class move_line_xls(report_xls):
debit_cell = rowcol_to_cell(row_pos, debit_pos)
credit_cell = rowcol_to_cell(row_pos, credit_pos)
bal_formula = debit_cell + '-' + credit_cell
c_specs = map(lambda x: self.render(x, self.col_specs_template, 'lines'), wanted_list)
_logger.debug('dummy call - %s', bal_formula)
c_specs = map(
lambda x: self.render(x, self.col_specs_template, 'lines'),
wanted_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.aml_cell_style)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.aml_cell_style)
# Totals
aml_cnt = len(objects)
debit_start = rowcol_to_cell(row_pos - aml_cnt, debit_pos)
debit_stop = rowcol_to_cell(row_pos - 1, debit_pos)
debit_formula = 'SUM(%s:%s)' % (debit_start, debit_stop)
_logger.debug('dummy call - %s', debit_formula)
credit_start = rowcol_to_cell(row_pos - aml_cnt, credit_pos)
credit_stop = rowcol_to_cell(row_pos - 1, credit_pos)
credit_formula = 'SUM(%s:%s)' % (credit_start, credit_stop)
_logger.debug('dummy call - %s', credit_formula)
debit_cell = rowcol_to_cell(row_pos, debit_pos)
credit_cell = rowcol_to_cell(row_pos, credit_pos)
bal_formula = debit_cell + '-' + credit_cell
c_specs = map(lambda x: self.render(x, self.col_specs_template, 'totals'), wanted_list)
_logger.debug('dummy call - %s', bal_formula)
c_specs = map(
lambda x: self.render(x, self.col_specs_template, 'totals'),
wanted_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(ws, row_pos, row_data, row_style=self.rt_cell_style_right)
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.rt_cell_style_right)
move_line_xls('report.move.line.list.xls',
'account.move.line',
parser=move_line_xls_parser)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Loading…
Cancel
Save