Initial commit : Reprise de la branche 10 d'Odoo depuis github
This commit is contained in:
commit
135b177ce6
34
.gitignore
vendored
Normal file
34
.gitignore
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
# sphinx build directories
|
||||
_build/
|
||||
|
||||
# dotfiles
|
||||
.*
|
||||
!.gitignore
|
||||
!.mailmap
|
||||
# compiled python files
|
||||
*.py[co]
|
||||
# setup.py egg_info
|
||||
*.egg-info
|
||||
# emacs backup files
|
||||
*~
|
||||
# hg stuff
|
||||
*.orig
|
||||
status
|
||||
# odoo filestore
|
||||
odoo/filestore
|
||||
# maintenance migration scripts
|
||||
odoo/addons/base/maintenance
|
||||
|
||||
# generated for windows installer?
|
||||
install/win32/*.bat
|
||||
install/win32/meta.py
|
||||
|
||||
# various virtualenv
|
||||
/bin/
|
||||
/build/
|
||||
/dist/
|
||||
/include/
|
||||
/lib/
|
||||
/man/
|
||||
/share/
|
||||
/src/
|
14
CONTRIBUTING.md
Normal file
14
CONTRIBUTING.md
Normal file
@ -0,0 +1,14 @@
|
||||
Contributing to Odoo
|
||||
====================
|
||||
|
||||
[Full contribution guidelines](https://github.com/odoo/odoo/wiki/Contributing)
|
||||
|
||||
TL;DR
|
||||
|
||||
* If you [make a pull request](https://github.com/odoo/odoo/wiki/Contributing#making-pull-requests),
|
||||
do not create an issue! Use the PR description for that
|
||||
* Issues are handled with a much lower priority than pull requests
|
||||
* Use this [template](https://github.com/odoo/odoo/tree/10.0/.github/ISSUE_TEMPLATE.md)
|
||||
when reporting issues. Please search for duplicates first!
|
||||
* Pull requests must be made against the [correct version](https://github.com/odoo/odoo/wiki/Contributing#against-which-version-should-i-submit-a-patch)
|
||||
* There are restrictions on the kind of [changes allowed in stable series](https://github.com/odoo/odoo/wiki/Contributing#what-does-stable-mean)
|
15
COPYRIGHT
Normal file
15
COPYRIGHT
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
Most of the files are
|
||||
|
||||
Copyright (c) 2004-2015 Odoo S.A.
|
||||
|
||||
Many files also contain contributions from third
|
||||
parties. In this case the original copyright of
|
||||
the contributions can be traced through the
|
||||
history of the source version control system.
|
||||
|
||||
When that is not the case, the files contain a prominent
|
||||
notice stating the original copyright and applicable
|
||||
license, or come with their own dedicated COPYRIGHT
|
||||
and/or LICENSE file.
|
||||
|
859
LICENSE
Normal file
859
LICENSE
Normal file
@ -0,0 +1,859 @@
|
||||
|
||||
For copyright information, please see the COPYRIGHT file.
|
||||
|
||||
Odoo is published under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3
|
||||
(LGPLv3), as included below. Since the LGPL is a set of additional
|
||||
permissions on top of the GPL, the text of the GPL is included at the
|
||||
bottom as well.
|
||||
|
||||
Some external libraries and contributions bundled with Odoo may be published
|
||||
under other GPL-compatible licenses. For these, please refer to the relevant
|
||||
source files and/or license files, in the source code tree.
|
||||
|
||||
**************************************************************************
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 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.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser 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
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
||||
**************************************************************************
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 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 General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is 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. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
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.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
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 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. Use with the GNU Affero General Public License.
|
||||
|
||||
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 Affero 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 special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 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 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 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 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU 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 the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
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 GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
||||
|
||||
**************************************************************************
|
46
MANIFEST.in
Normal file
46
MANIFEST.in
Normal file
@ -0,0 +1,46 @@
|
||||
include requirements.txt
|
||||
include LICENSE
|
||||
include README.md
|
||||
recursive-include odoo *.css
|
||||
recursive-include odoo *.csv
|
||||
recursive-include odoo *.doc
|
||||
recursive-include odoo *.docx
|
||||
recursive-include odoo *.eml
|
||||
recursive-include odoo *.eot
|
||||
recursive-include odoo *.gif
|
||||
recursive-include odoo *.html
|
||||
recursive-include odoo *.ico
|
||||
recursive-include odoo *.jpeg
|
||||
recursive-include odoo *.jpg
|
||||
recursive-include odoo *.js
|
||||
recursive-include odoo *.less
|
||||
recursive-include odoo *.md
|
||||
recursive-include odoo *.mp3
|
||||
recursive-include odoo *.ogg
|
||||
recursive-include odoo *.ods
|
||||
recursive-include odoo *.odt
|
||||
recursive-include odoo *.otf
|
||||
recursive-include odoo *.pdf
|
||||
recursive-include odoo *.png
|
||||
recursive-include odoo *.po
|
||||
recursive-include odoo *.rml
|
||||
recursive-include odoo *.rng
|
||||
recursive-include odoo *.rst
|
||||
recursive-include odoo *.sass
|
||||
recursive-include odoo *.sql
|
||||
recursive-include odoo *.svg
|
||||
recursive-include odoo *.template
|
||||
recursive-include odoo *.txt
|
||||
recursive-include odoo *.ttf
|
||||
recursive-include odoo *.woff
|
||||
recursive-include odoo *.woff2
|
||||
recursive-include odoo *.wsdl
|
||||
recursive-include odoo *.xls
|
||||
recursive-include odoo *.xsd
|
||||
recursive-include odoo *.xsl
|
||||
recursive-include odoo *.xlsx
|
||||
recursive-include odoo *.xml
|
||||
recursive-include odoo *.yml
|
||||
recursive-include odoo *.zip
|
||||
recursive-exclude * *.py[co]
|
||||
recursive-exclude * *.hg*
|
9
Makefile
Normal file
9
Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
# NOTE: please keep your version of sass up to date: sudo gem update
|
||||
.PHONY: watch css
|
||||
SASS_FILES=$(wildcard addons/*/static/src/css/*.sass openerp/addons/*/static/src/css/*.sass)
|
||||
CSS_FILES=$(patsubst %.sass,%.css,${SASS_FILES})
|
||||
css: ${CSS_FILES}
|
||||
%.css: %.sass
|
||||
sass -t expanded --compass --unix-newlines --sourcemap=none $< $@
|
||||
watch:
|
||||
sass -t expanded --compass --unix-newlines --sourcemap=none --watch .:.
|
50
README.md
Normal file
50
README.md
Normal file
@ -0,0 +1,50 @@
|
||||
[](http://runbot.odoo.com/runbot)
|
||||
[](http://www.odoo.com/documentation/10.0)
|
||||
[](https://www.odoo.com/forum/help-1)
|
||||
[](http://nightly.odoo.com/)
|
||||
|
||||
Odoo
|
||||
----
|
||||
|
||||
Odoo is a suite of web based open source business apps.
|
||||
|
||||
The main Odoo Apps include an <a href="https://www.odoo.com/page/crm">Open Source CRM</a>,
|
||||
<a href="https://www.odoo.com/page/website-builder">Website Builder</a>,
|
||||
<a href="https://www.odoo.com/page/e-commerce">eCommerce</a>,
|
||||
<a href="https://www.odoo.com/page/warehouse">Warehouse Management</a>,
|
||||
<a href="https://www.odoo.com/page/project-management">Project Management</a>,
|
||||
<a href="https://www.odoo.com/page/accounting">Billing & Accounting</a>,
|
||||
<a href="https://www.odoo.com/page/point-of-sale">Point of Sale</a>,
|
||||
<a href="https://www.odoo.com/page/employees">Human Resources</a>,
|
||||
<a href="https://www.odoo.com/page/lead-automation">Marketing</a>,
|
||||
<a href="https://www.odoo.com/page/manufacturing">Manufacturing</a>,
|
||||
<a href="https://www.odoo.com/page/purchase">Purchase Management</a>,
|
||||
<a href="https://www.odoo.com/#apps">...</a>
|
||||
|
||||
Odoo Apps can be used as stand-alone applications, but they also integrate seamlessly so you get
|
||||
a full-featured <a href="https://www.odoo.com">Open Source ERP</a> when you install several Apps.
|
||||
|
||||
|
||||
Getting started with Odoo
|
||||
-------------------------
|
||||
For a standard installation please follow the <a href="https://www.odoo.com/documentation/10.0/setup/install.html">Setup instructions</a>
|
||||
from the documentation.
|
||||
|
||||
If you are a developer you may type the following command at your terminal:
|
||||
|
||||
wget -O- https://raw.githubusercontent.com/odoo/odoo/10.0/setup/setup_dev.py | python
|
||||
|
||||
Then follow <a href="https://www.odoo.com/documentation/10.0/tutorials.html">the developer tutorials</a>
|
||||
|
||||
|
||||
For Odoo employees
|
||||
------------------
|
||||
|
||||
To add the odoo-dev remote use this command:
|
||||
|
||||
$ ./setup/setup_dev.py setup_git_dev
|
||||
|
||||
To fetch odoo merge pull requests refs use this command:
|
||||
|
||||
$ ./setup/setup_dev.py setup_git_review
|
||||
|
68
addons/account/README.md
Normal file
68
addons/account/README.md
Normal file
@ -0,0 +1,68 @@
|
||||
Odoo Accounting
|
||||
---------------
|
||||
|
||||
The Odoo <a href="https://www.odoo.com/page/accounting">Open Source Accounting</a> app allows a better way to
|
||||
collaborate with your accountants, your customers and control your suppliers.
|
||||
|
||||
Activate features on demand, from integrated analytic accounting to budget,
|
||||
assets and multiple companies consolidation.
|
||||
|
||||
A Smart User Interface
|
||||
----------------------
|
||||
|
||||
Record transactions in a few clicks and easily manage all financial activities
|
||||
in one place. Odoo's user interface is designed with productivity in mind.
|
||||
|
||||
A Better Way To Work – Together
|
||||
-------------------------------
|
||||
|
||||
Share access to your latest business numbers with your team and your accountant
|
||||
– so everyone is up to speed. From work, home or on the go.
|
||||
|
||||
Connect Your Bank Accounts
|
||||
--------------------------
|
||||
|
||||
Import your bank statements and reconcile them in just a few clicks. Prepare
|
||||
payment orders based on your supplier invoices and payment terms.
|
||||
|
||||
Electronic invoicing and automated follow-ups
|
||||
---------------------------------------------
|
||||
|
||||
Create and send professional invoices & get paid online. Get rid of the stress
|
||||
of having to constantly remind your debtors. Simply set-up and automate
|
||||
follow-ups to get paid quickly.
|
||||
|
||||
Sales Integration
|
||||
-----------------
|
||||
|
||||
Automatically create invoices from sales orders, delivery orders or base them
|
||||
on time and material. Re-invoice expenses on projects to your customer in just
|
||||
a few clicks.
|
||||
|
||||
|
||||
Purchase Integration
|
||||
--------------------
|
||||
|
||||
Control supplier invocies based on purchase orders. Get real-time inventory
|
||||
valuation reports automatically posted in your accounts.
|
||||
|
||||
Multi-Level Analytic Accounting
|
||||
-------------------------------
|
||||
|
||||
Integrate your analytic accounting operations with timesheets, projects,
|
||||
invoices, expenses, etc. No need to record transactions, all analytic entries
|
||||
are posted automatically following your business rules.
|
||||
|
||||
Everything you need to grow
|
||||
---------------------------
|
||||
|
||||
Manage your assets, track expenses, control budgets, multi-level analytic
|
||||
accounting; Odoo has all the features you need to sustain all your business
|
||||
activities.
|
||||
|
||||
Scale With Your Organization
|
||||
----------------------------
|
||||
|
||||
Odoo supports multiple currencies, multiple users with different access rights,
|
||||
multiple companies with real time consolidation and unlimited analytic plans.
|
||||
|
42
addons/account/__init__.py
Normal file
42
addons/account/__init__.py
Normal file
@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import models
|
||||
|
||||
import wizard
|
||||
import report
|
||||
|
||||
from odoo import api, SUPERUSER_ID
|
||||
|
||||
|
||||
def _auto_install_l10n(cr, registry):
|
||||
#check the country of the main company (only) and eventually load some module needed in that country
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
country_code = env.user.company_id.country_id.code
|
||||
if country_code:
|
||||
#auto install localization module(s) if available
|
||||
module_list = []
|
||||
if country_code in ['BJ', 'BF', 'CM', 'CF', 'KM', 'CG', 'CI', 'GA', 'GN', 'GW', 'GQ', 'ML', 'NE', 'CD', 'SN', 'TD', 'TG']:
|
||||
#countries using OHADA Chart of Accounts
|
||||
module_list.append('l10n_syscohada')
|
||||
elif country_code == 'GB':
|
||||
module_list.append('l10n_uk')
|
||||
else:
|
||||
if env['ir.module.module'].search([('name', '=', 'l10n_' + country_code.lower())]):
|
||||
module_list.append('l10n_' + country_code.lower())
|
||||
else:
|
||||
module_list.append('l10n_generic_coa')
|
||||
if country_code == 'US':
|
||||
module_list.append('account_plaid')
|
||||
module_list.append('account_check_printing')
|
||||
if country_code in ['US', 'AU', 'NZ', 'CA', 'CO', 'EC', 'ES', 'FR', 'IN', 'MX', 'UK']:
|
||||
module_list.append('account_yodlee')
|
||||
|
||||
#european countries will be using SEPA
|
||||
europe = env.ref('base.europe', raise_if_not_found=False)
|
||||
if europe:
|
||||
europe_country_codes = [x.code for x in europe.country_ids]
|
||||
if country_code in europe_country_codes:
|
||||
module_list.append('account_sepa')
|
||||
module_ids = env['ir.module.module'].search([('name', 'in', module_list), ('state', '=', 'uninstalled')])
|
||||
module_ids.sudo().button_install()
|
80
addons/account/__manifest__.py
Normal file
80
addons/account/__manifest__.py
Normal file
@ -0,0 +1,80 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name' : 'Invoicing',
|
||||
'version' : '1.1',
|
||||
'summary': 'Send Invoices and Track Payments',
|
||||
'sequence': 30,
|
||||
'description': """
|
||||
Invoicing & Payments
|
||||
====================
|
||||
The specific and easy-to-use Invoicing system in Odoo allows you to keep track of your accounting, even when you are not an accountant. It provides an easy way to follow up on your vendors and customers.
|
||||
|
||||
You could use this simplified accounting in case you work with an (external) account to keep your books, and you still want to keep track of payments. This module also offers you an easy method of registering payments, without having to encode complete abstracts of account.
|
||||
""",
|
||||
'category': 'Accounting',
|
||||
'website': 'https://www.odoo.com/page/billing',
|
||||
'images' : ['images/accounts.jpeg','images/bank_statement.jpeg','images/cash_register.jpeg','images/chart_of_accounts.jpeg','images/customer_invoice.jpeg','images/journal_entries.jpeg'],
|
||||
'depends' : ['base_setup', 'product', 'analytic', 'report', 'web_planner'],
|
||||
'data': [
|
||||
'security/account_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'data/data_account_type.xml',
|
||||
'data/account_data.xml',
|
||||
'views/account_menuitem.xml',
|
||||
'views/account_payment_view.xml',
|
||||
'wizard/account_reconcile_view.xml',
|
||||
'wizard/account_unreconcile_view.xml',
|
||||
'wizard/account_move_reversal_view.xml',
|
||||
'views/account_view.xml',
|
||||
'views/account_report.xml',
|
||||
'wizard/account_invoice_refund_view.xml',
|
||||
'wizard/account_validate_move_view.xml',
|
||||
'wizard/account_invoice_state_view.xml',
|
||||
'wizard/pos_box.xml',
|
||||
'views/account_end_fy.xml',
|
||||
'views/account_invoice_view.xml',
|
||||
'data/invoice_action_data.xml',
|
||||
'views/partner_view.xml',
|
||||
'views/product_view.xml',
|
||||
'views/account_analytic_view.xml',
|
||||
'views/res_config_view.xml',
|
||||
'views/account_tip_data.xml',
|
||||
'views/account.xml',
|
||||
'views/report_invoice.xml',
|
||||
'report/account_invoice_report_view.xml',
|
||||
'report/inherited_layouts.xml',
|
||||
'views/account_journal_dashboard_view.xml',
|
||||
'views/report_overdue.xml',
|
||||
'views/web_planner_data.xml',
|
||||
'views/report_overdue.xml',
|
||||
'wizard/account_report_common_view.xml',
|
||||
'wizard/account_report_print_journal_view.xml',
|
||||
'views/report_journal.xml',
|
||||
'wizard/account_report_partner_ledger_view.xml',
|
||||
'views/report_partnerledger.xml',
|
||||
'wizard/account_report_general_ledger_view.xml',
|
||||
'views/report_generalledger.xml',
|
||||
'wizard/account_report_trial_balance_view.xml',
|
||||
'views/report_trialbalance.xml',
|
||||
'views/account_financial_report_data.xml',
|
||||
'wizard/account_financial_report_view.xml',
|
||||
'views/report_financial.xml',
|
||||
'wizard/account_report_aged_partner_balance_view.xml',
|
||||
'views/report_agedpartnerbalance.xml',
|
||||
'views/tax_adjustments.xml',
|
||||
'wizard/wizard_tax_adjustments_view.xml',
|
||||
],
|
||||
'demo': [
|
||||
'demo/account_demo.xml',
|
||||
],
|
||||
'qweb': [
|
||||
"static/src/xml/account_reconciliation.xml",
|
||||
"static/src/xml/account_payment.xml",
|
||||
"static/src/xml/account_report_backend.xml",
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
'auto_install': False,
|
||||
'post_init_hook': '_auto_install_l10n',
|
||||
}
|
164
addons/account/data/account_data.xml
Normal file
164
addons/account/data/account_data.xml
Normal file
@ -0,0 +1,164 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
|
||||
<!-- TAGS FOR CASH FLOW STATEMENT -->
|
||||
|
||||
<record id="account_tag_operating" model="account.account.tag">
|
||||
<field name="name">Operating Activities</field>
|
||||
<field name="applicability">accounts</field>
|
||||
</record>
|
||||
<record id="account_tag_financing" model="account.account.tag">
|
||||
<field name="name">Financing Activities</field>
|
||||
<field name="applicability">accounts</field>
|
||||
</record>
|
||||
<record id="account_tag_investing" model="account.account.tag">
|
||||
<field name="name">Investing & Extraordinary Activities</field>
|
||||
<field name="applicability">accounts</field>
|
||||
</record>
|
||||
|
||||
<!--
|
||||
Payment term
|
||||
-->
|
||||
<record id="account_payment_term_immediate" model="account.payment.term">
|
||||
<field name="name">Immediate Payment</field>
|
||||
<field name="note">Payment term: Immediate Payment</field>
|
||||
</record>
|
||||
|
||||
<record id="account_payment_term_15days" model="account.payment.term">
|
||||
<field name="name">15 Days</field>
|
||||
<field name="note">Payment term: 15 Days</field>
|
||||
<field name="line_ids" eval="[(0, 0, {'value': 'balance', 'value_amount': 0.0, 'sequence': 500, 'days': 15, 'option': 'day_after_invoice_date'})]"/>
|
||||
</record>
|
||||
|
||||
<record forcecreate="True" id="decimal_payment" model="decimal.precision">
|
||||
<field name="name">Payment Terms</field>
|
||||
<field name="digits">6</field>
|
||||
</record>
|
||||
|
||||
<record id="account_payment_term_net" model="account.payment.term">
|
||||
<field name="name">30 Net Days</field>
|
||||
<field name="note">Payment term: 30 Net Days</field>
|
||||
<field name="line_ids" eval="[(0, 0, {'value': 'balance', 'value_amount': 0.0, 'sequence': 500, 'days': 30, 'option': 'day_after_invoice_date'})]"/>
|
||||
</record>
|
||||
|
||||
<!--
|
||||
Account Statement Sequences
|
||||
-->
|
||||
<record id="sequence_reconcile_seq" model="ir.sequence">
|
||||
<field name="name">Account reconcile sequence</field>
|
||||
<field name="code">account.reconcile</field>
|
||||
<field name="prefix">A</field>
|
||||
<field eval="1" name="number_next"/>
|
||||
<field eval="1" name="number_increment"/>
|
||||
<field eval="False" name="company_id"/>
|
||||
</record>
|
||||
<!--
|
||||
Invoice requests (deprecated)
|
||||
-->
|
||||
<record id="req_link_invoice" model="res.request.link">
|
||||
<field name="name">Invoice</field>
|
||||
<field name="object">account.invoice</field>
|
||||
</record>
|
||||
|
||||
<!-- Account-related subtypes for messaging / Chatter -->
|
||||
<record id="mt_invoice_validated" model="mail.message.subtype">
|
||||
<field name="name">Validated</field>
|
||||
<field name="res_model">account.invoice</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="description">Invoice validated</field>
|
||||
</record>
|
||||
<record id="mt_invoice_paid" model="mail.message.subtype">
|
||||
<field name="name">Paid</field>
|
||||
<field name="res_model">account.invoice</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="description">Invoice paid</field>
|
||||
</record>
|
||||
<record id="mt_invoice_created" model="mail.message.subtype">
|
||||
<field name="name">Invoice Created</field>
|
||||
<field name="res_model">account.invoice</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="hidden" eval="True"/>
|
||||
<field name="description">Invoice Created</field>
|
||||
</record>
|
||||
|
||||
<!-- Payment methods -->
|
||||
<record id="account_payment_method_manual_in" model="account.payment.method">
|
||||
<field name="name">Manual</field>
|
||||
<field name="code">manual</field>
|
||||
<field name="payment_type">inbound</field>
|
||||
</record>
|
||||
<record id="account_payment_method_manual_out" model="account.payment.method">
|
||||
<field name="name">Manual</field>
|
||||
<field name="code">manual</field>
|
||||
<field name="payment_type">outbound</field>
|
||||
</record>
|
||||
|
||||
<!-- Payment sequences -->
|
||||
<record id="sequence_payment_customer_invoice" model="ir.sequence">
|
||||
<field name="name">Payments customer invoices sequence</field>
|
||||
<field name="code">account.payment.customer.invoice</field>
|
||||
<field name="prefix">CUST.IN/%(range_year)s/</field>
|
||||
<field eval="1" name="number_next"/>
|
||||
<field eval="1" name="number_increment"/>
|
||||
<field eval="True" name="use_date_range"/>
|
||||
<field eval="False" name="company_id"/>
|
||||
<field name="padding">4</field>
|
||||
</record>
|
||||
<record id="sequence_payment_customer_refund" model="ir.sequence">
|
||||
<field name="name">Payments customer refunds sequence</field>
|
||||
<field name="code">account.payment.customer.refund</field>
|
||||
<field name="prefix">CUST.OUT/%(range_year)s/</field>
|
||||
<field eval="1" name="number_next"/>
|
||||
<field eval="1" name="number_increment"/>
|
||||
<field eval="True" name="use_date_range"/>
|
||||
<field eval="False" name="company_id"/>
|
||||
<field name="padding">4</field>
|
||||
</record>
|
||||
<record id="sequence_payment_supplier_invoice" model="ir.sequence">
|
||||
<field name="name">Payments supplier invoices sequence</field>
|
||||
<field name="code">account.payment.supplier.invoice</field>
|
||||
<field name="prefix">SUPP.OUT/%(range_year)s/</field>
|
||||
<field eval="1" name="number_next"/>
|
||||
<field eval="1" name="number_increment"/>
|
||||
<field eval="True" name="use_date_range"/>
|
||||
<field eval="False" name="company_id"/>
|
||||
<field name="padding">4</field>
|
||||
</record>
|
||||
<record id="sequence_payment_supplier_refund" model="ir.sequence">
|
||||
<field name="name">Payments supplier refunds sequence</field>
|
||||
<field name="code">account.payment.supplier.refund</field>
|
||||
<field name="prefix">SUPP.IN/%(range_year)s/</field>
|
||||
<field eval="1" name="number_next"/>
|
||||
<field eval="1" name="number_increment"/>
|
||||
<field eval="True" name="use_date_range"/>
|
||||
<field eval="False" name="company_id"/>
|
||||
<field name="padding">4</field>
|
||||
</record>
|
||||
<record id="sequence_payment_transfer" model="ir.sequence">
|
||||
<field name="name">Payments transfer sequence</field>
|
||||
<field name="code">account.payment.transfer</field>
|
||||
<field name="prefix">TRANS/%(range_year)s/</field>
|
||||
<field eval="1" name="number_next"/>
|
||||
<field eval="1" name="number_increment"/>
|
||||
<field eval="True" name="use_date_range"/>
|
||||
<field eval="False" name="company_id"/>
|
||||
<field name="padding">4</field>
|
||||
</record>
|
||||
|
||||
<!-- Account Tax Group -->
|
||||
<record id="tax_group_taxes" model="account.tax.group">
|
||||
<field name="name">Taxes</field>
|
||||
<field name="sequence">0</field>
|
||||
</record>
|
||||
|
||||
<!-- Partner Trust Property -->
|
||||
<record forcecreate="True" id="default_followup_trust" model="ir.property">
|
||||
<field name="name">Followup Trust Property</field>
|
||||
<field name="fields_id" search="[('model', '=', 'res.partner'), ('name', '=', 'trust')]"/>
|
||||
<field name="value">normal</field>
|
||||
<field name="type">selection</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
85
addons/account/data/data_account_type.xml
Normal file
85
addons/account/data/data_account_type.xml
Normal file
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
<!-- account.account.type -->
|
||||
<record model="account.account.type" id="data_account_type_receivable">
|
||||
<field name="name">Receivable</field>
|
||||
<field name="type">receivable</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_payable">
|
||||
<field name="name">Payable</field>
|
||||
<field name="type">payable</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_liquidity">
|
||||
<field name="name">Bank and Cash</field>
|
||||
<field name="type">liquidity</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_credit_card">
|
||||
<field name="name">Credit Card</field>
|
||||
<field name="type">liquidity</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_current_assets">
|
||||
<field name="name">Current Assets</field>
|
||||
<field name="type">other</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_non_current_assets">
|
||||
<field name="name">Non-current Assets</field>
|
||||
<field name="type">other</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_prepayments">
|
||||
<field name="name">Prepayments</field>
|
||||
<field name="type">other</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_fixed_assets">
|
||||
<field name="name">Fixed Assets</field>
|
||||
<field name="type">other</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_current_liabilities">
|
||||
<field name="name">Current Liabilities</field>
|
||||
<field name="type">other</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_non_current_liabilities">
|
||||
<field name="name">Non-current Liabilities</field>
|
||||
<field name="type">other</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_equity">
|
||||
<field name="name">Equity</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_unaffected_earnings">
|
||||
<field name="name">Current Year Earnings</field>
|
||||
<field name="include_initial_balance" eval="True"/>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_other_income">
|
||||
<field name="name">Other Income</field>
|
||||
<field name="type">other</field>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_revenue">
|
||||
<field name="name">Income</field>
|
||||
<field name="type">other</field>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_depreciation">
|
||||
<field name="name">Depreciation</field>
|
||||
<field name="type">other</field>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_expenses">
|
||||
<field name="name">Expenses</field>
|
||||
<field name="type">other</field>
|
||||
</record>
|
||||
<record model="account.account.type" id="data_account_type_direct_costs">
|
||||
<field name="name">Cost of Revenue</field>
|
||||
<field name="type">other</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
138
addons/account/data/invoice_action_data.xml
Normal file
138
addons/account/data/invoice_action_data.xml
Normal file
@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" ?>
|
||||
<odoo>
|
||||
|
||||
<!-- Mail template are declared in a NOUPDATE block
|
||||
so users can freely customize/delete them -->
|
||||
<data noupdate="1">
|
||||
<!--Email template -->
|
||||
<record id="email_template_edi_invoice" model="mail.template">
|
||||
<field name="name">Invoice - Send by Email</field>
|
||||
<field name="email_from">${(object.user_id.email and '%s <%s>' % (object.user_id.name, object.user_id.email) or '')|safe}</field>
|
||||
<field name="subject">${object.company_id.name} Invoice (Ref ${object.number or 'n/a'})</field>
|
||||
<field name="partner_to">${object.partner_id.id}</field>
|
||||
<field name="model_id" ref="account.model_account_invoice"/>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
<field name="report_template" ref="account_invoices"/>
|
||||
<field name="report_name">Invoice_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''}</field>
|
||||
<field name="lang">${object.partner_id.lang}</field>
|
||||
<field name="body_html"><![CDATA[
|
||||
<p>Dear ${object.partner_id.name}
|
||||
% set access_action = object.get_access_action()
|
||||
% set access_url = access_action['type'] == 'ir.actions.act_url' and access_action['url'] or '/report/pdf/account.report_invoice/' + str(object.id)
|
||||
% set is_online = access_action and access_action['type'] == 'ir.actions.act_url'
|
||||
|
||||
% if object.partner_id.parent_id:
|
||||
(<i>${object.partner_id.parent_id.name}</i>)
|
||||
% endif
|
||||
,</p>
|
||||
<p>Here is your invoice <strong>${object.number}</strong>
|
||||
% if object.origin:
|
||||
(with reference: ${object.origin} )
|
||||
% endif
|
||||
amounting in <strong>${object.amount_total} ${object.currency_id.name}</strong>
|
||||
from ${object.company_id.name}.
|
||||
</p>
|
||||
|
||||
% if is_online:
|
||||
<br/><br/>
|
||||
<center>
|
||||
<a href="${access_url}" style="background-color: #1abc9c; padding: 20px; text-decoration: none; color: #fff; border-radius: 5px; font-size: 16px;" class="o_default_snippet_text">View Invoice</a>
|
||||
</center>
|
||||
% endif
|
||||
<br/><br/>
|
||||
|
||||
% if object.state=='paid':
|
||||
<p>This invoice is already paid.</p>
|
||||
% else:
|
||||
<p>Please remit payment at your earliest convenience.</p>
|
||||
% endif
|
||||
|
||||
<p>Thank you,</p>
|
||||
% if object.user_id and object.user_id.signature:
|
||||
${object.user_id.signature | safe}
|
||||
% endif
|
||||
]]></field>
|
||||
</record>
|
||||
|
||||
<!--Default Notification Email template for invoices-->
|
||||
<record id="account.mail_template_data_notification_email_account_invoice" model="mail.template">
|
||||
<field name="name">Invoice Notification Email</field>
|
||||
<field name="subject">${object.subject}</field>
|
||||
<field name="model_id" ref="mail.model_mail_message"/>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
<field name="body_html"><![CDATA[<html>
|
||||
<head></head>
|
||||
% set record = ctx.get('record')
|
||||
% set company = record and record.company_id or user.company_id
|
||||
<body style="margin: 0; padding: 0;">
|
||||
<table border="0" width="100%" cellpadding="0" bgcolor="#ededed" style="padding: 20px; background-color: #ededed; border-collapse:separate;" summary="o_mail_notification">
|
||||
<tbody>
|
||||
|
||||
<!-- HEADER -->
|
||||
<tr>
|
||||
<td align="center" style="min-width: 590px;">
|
||||
<table width="590" border="0" cellpadding="0" bgcolor="#875A7B" style="min-width: 590px; background-color: rgb(135,90,123); padding: 20px; border-collapse:separate;">
|
||||
<tr>
|
||||
<td valign="middle">
|
||||
<span style="font-size:20px; color:white; font-weight: bold;">
|
||||
Invoice ${object.record_name}
|
||||
</span>
|
||||
</td>
|
||||
<td valign="middle" align="right">
|
||||
<img src="/logo.png?company=${company.id}" style="padding: 0px; margin: 0px; height: auto; width: 80px;" alt="${company.name}">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- CONTENT -->
|
||||
<tr>
|
||||
<td align="center" style="min-width: 590px;">
|
||||
<table width="590" border="0" cellpadding="0" bgcolor="#ffffff" style="min-width: 590px; background-color: rgb(255, 255, 255); padding: 20px; border-collapse:separate;">
|
||||
<tbody>
|
||||
<td valign="top" style="font-family:Arial,Helvetica,sans-serif; color: #555; font-size: 14px;">
|
||||
${object.body | safe}
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- FOOTER -->
|
||||
<tr>
|
||||
<td align="center" style="min-width: 590px;">
|
||||
<table width="590" border="0" cellpadding="0" bgcolor="#875A7B" style="min-width: 590px; background-color: rgb(135,90,123); padding: 20px; border-collapse:separate;">
|
||||
<tr>
|
||||
<td valign="middle" align="left" style="color: #fff; padding-top: 10px; padding-bottom: 10px; font-size: 12px;">
|
||||
${company.name}<br/>
|
||||
${company.phone or ''}
|
||||
</td>
|
||||
<td valign="middle" align="right" style="color: #fff; padding-top: 10px; padding-bottom: 10px; font-size: 12px;">
|
||||
% if company.email:
|
||||
<a href="mailto:${company.email}" style="text-decoration:none; color: white;">${company.email}</a><br/>
|
||||
% endif
|
||||
% if company.website:
|
||||
<a href="${company.website}" style="text-decoration:none; color: white;">
|
||||
${company.website}
|
||||
</a>
|
||||
% endif
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
Powered by <a href="https://www.odoo.com">Odoo</a>.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
]]></field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
70
addons/account/demo/account_bank_statement.yml
Normal file
70
addons/account/demo/account_bank_statement.yml
Normal file
@ -0,0 +1,70 @@
|
||||
-
|
||||
Create demo bank statement
|
||||
-
|
||||
!python {model: ir.model.data, id: False} : |
|
||||
default_company = self.env['res.company']._company_default_get('account.journal')
|
||||
journal = self.env['account.journal'].search([('type', '=', 'bank'), ('company_id', '=', default_company.id)], limit=1)
|
||||
import time
|
||||
if journal:
|
||||
vals = {
|
||||
'name': 'demo_bank_statement_1',
|
||||
'journal_id': journal.id,
|
||||
'date': time.strftime('%Y')+'-01-01',
|
||||
'name': "BNK/2014/001",
|
||||
'balance_end_real': '8998.2',
|
||||
'balance_start': 5103.0
|
||||
}
|
||||
self._update('account.bank.statement', 'account', vals, 'demo_bank_statement_1')
|
||||
vals = {
|
||||
'ref': '',
|
||||
'statement_id': ref('account.demo_bank_statement_1'),
|
||||
'sequence': 1,
|
||||
'name': "SAJ/2014/002 and SAJ/2014/003",
|
||||
'journal_id': journal.id,
|
||||
'amount': 1175.0,
|
||||
'date': time.strftime('%Y')+'-01-01',
|
||||
'partner_id': ref('base.res_partner_2'),
|
||||
}
|
||||
self._update('account.bank.statement.line', 'account', vals, 'demo_bank_statement_line_1')
|
||||
vals = {
|
||||
'ref': '',
|
||||
'statement_id': ref('account.demo_bank_statement_1'),
|
||||
'sequence': 2,
|
||||
'name': "Bank fees",
|
||||
'journal_id': journal.id,
|
||||
'amount': -32.58,
|
||||
'date': time.strftime('%Y')+'-01-01',
|
||||
}
|
||||
self._update('account.bank.statement.line', 'account', vals, 'demo_bank_statement_line_2')
|
||||
vals = {
|
||||
'ref': '',
|
||||
'statement_id': ref('account.demo_bank_statement_1'),
|
||||
'sequence': 3,
|
||||
'name': "Prepayment",
|
||||
'journal_id': journal.id,
|
||||
'amount': 650.0,
|
||||
'date': time.strftime('%Y')+'-01-01',
|
||||
'partner_id': ref('base.res_partner_12'),
|
||||
}
|
||||
self._update('account.bank.statement.line', 'account', vals, 'demo_bank_statement_line_3')
|
||||
vals = {
|
||||
'ref': '',
|
||||
'statement_id': ref('account.demo_bank_statement_1'),
|
||||
'sequence': 4,
|
||||
'name': "First 2000 € of SAJ/2014/001",
|
||||
'journal_id': journal.id,
|
||||
'amount': 2000.0,
|
||||
'date': time.strftime('%Y')+'-01-01',
|
||||
'partner_id': ref('base.res_partner_12'),
|
||||
}
|
||||
self._update('account.bank.statement.line', 'account', vals, 'demo_bank_statement_line_4')
|
||||
vals = {
|
||||
'ref': '',
|
||||
'statement_id': ref('account.demo_bank_statement_1'),
|
||||
'sequence': 5,
|
||||
'name': "Last Year Interests",
|
||||
'journal_id': journal.id,
|
||||
'amount': 102.78,
|
||||
'date': time.strftime('%Y')+'-01-01',
|
||||
}
|
||||
self._update('account.bank.statement.line', 'account', vals, 'demo_bank_statement_line_5')
|
56
addons/account/demo/account_demo.xml
Normal file
56
addons/account/demo/account_demo.xml
Normal file
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<!-- TAGS FOR RETRIEVING THE DEMO ACCOUNTS -->
|
||||
|
||||
<record id="demo_capital_account" model="account.account.tag">
|
||||
<field name="name">Demo Capital Account</field>
|
||||
</record>
|
||||
<record id="demo_stock_account" model="account.account.tag">
|
||||
<field name="name">Demo Stock Account</field>
|
||||
</record>
|
||||
<record id="demo_sale_of_land_account" model="account.account.tag">
|
||||
<field name="name">Demo Sale of Land Account</field>
|
||||
</record>
|
||||
<record id="demo_ceo_wages_account" model="account.account.tag">
|
||||
<field name="name">Demo CEO Wages Account</field>
|
||||
</record>
|
||||
<record id="demo_coffee_machine_account" model="account.account.tag">
|
||||
<field name="name">Demo Coffe Machine Account</field>
|
||||
</record>
|
||||
<!-- Payment Term -->
|
||||
|
||||
<record id="account_payment_term" model="account.payment.term">
|
||||
<field name="name">End of Following Month</field>
|
||||
<field name="note">Payment term: End of Following Month</field>
|
||||
<field name="line_ids" eval="[(0, 0, {'value': 'balance', 'value_amount': 0.0, 'sequence': 500, 'days': 0, 'option': 'last_day_following_month'})]"/>
|
||||
</record>
|
||||
|
||||
<record id="account_payment_term_advance" model="account.payment.term">
|
||||
<field name="name">30% Advance End of Following Month</field>
|
||||
<field name="note">Payment term: 30% Advance End of Following Month</field>
|
||||
<field name="line_ids" eval="[(0, 0, {'value': 'percent', 'value_amount': 30.0, 'sequence': 400, 'days': 0, 'option': 'day_after_invoice_date'}),
|
||||
(0, 0, {'value': 'balance', 'value_amount': 0.0, 'sequence': 500, 'days': 0, 'option': 'last_day_following_month'})]"/>
|
||||
</record>
|
||||
|
||||
<record id="base.user_demo" model="res.users">
|
||||
<field name="groups_id" eval="[(4,ref('account.group_account_user'))]"/>
|
||||
</record>
|
||||
|
||||
<!-- Add payment term on some demo partners -->
|
||||
<record id="base.res_partner_2" model="res.partner">
|
||||
<field name="property_payment_term_id" ref="account.account_payment_term_net"/>
|
||||
</record>
|
||||
<record id="base.res_partner_12" model="res.partner">
|
||||
<field name="property_payment_term_id" ref="account_payment_term"/>
|
||||
<field name="property_supplier_payment_term_id" ref="account_payment_term"/>
|
||||
</record>
|
||||
<record id="base.res_partner_4" model="res.partner">
|
||||
<field name="property_supplier_payment_term_id" ref="account.account_payment_term_net"/>
|
||||
</record>
|
||||
<record id="base.res_partner_1" model="res.partner">
|
||||
<field name="property_supplier_payment_term_id" ref="account_payment_term"/>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
165
addons/account/demo/account_invoice_demo.yml
Normal file
165
addons/account/demo/account_invoice_demo.yml
Normal file
@ -0,0 +1,165 @@
|
||||
-
|
||||
Set the context for customer invoices because the 'type' field is readonly in invoice form views, so it value won't be considered by the yaml import
|
||||
-
|
||||
!record {model: account.invoice, id: demo_invoice_1}:
|
||||
partner_id: base.res_partner_12
|
||||
user_id: base.user_demo
|
||||
reference_type: none
|
||||
payment_term_id: account.account_payment_term
|
||||
type: 'out_invoice'
|
||||
date_invoice: !eval time.strftime('%Y-%m')+'-01'
|
||||
invoice_line_ids:
|
||||
- product_id: product.consu_delivery_02
|
||||
price_unit: 642.0
|
||||
quantity: 5
|
||||
- product_id: product.consu_delivery_03
|
||||
price_unit: 280.0
|
||||
quantity: 5.0
|
||||
-
|
||||
!python {model: account.invoice, id: demo_invoice_1}:
|
||||
self.action_invoice_open()
|
||||
-
|
||||
!record {model: account.invoice, id: demo_invoice_2}:
|
||||
partner_id: base.res_partner_2
|
||||
type: 'out_invoice'
|
||||
date_invoice: !eval time.strftime('%Y-%m')+'-08'
|
||||
invoice_line_ids:
|
||||
- product_id: product.consu_delivery_03
|
||||
price_unit: 50.0
|
||||
quantity: 3
|
||||
- product_id: product.consu_delivery_01
|
||||
price_unit: 25
|
||||
quantity: 20
|
||||
-
|
||||
!python {model: account.invoice, id: demo_invoice_2}:
|
||||
self.action_invoice_open()
|
||||
-
|
||||
!record {model: account.invoice, id: demo_invoice_3}:
|
||||
partner_id: base.res_partner_2
|
||||
type: 'out_invoice'
|
||||
date_invoice: !eval time.strftime('%Y-%m')+'-08'
|
||||
invoice_line_ids:
|
||||
- product_id: product.consu_delivery_01
|
||||
price_unit: 90.0
|
||||
quantity: 5
|
||||
- product_id: product.consu_delivery_03
|
||||
price_unit: 15.0
|
||||
quantity: 5.0
|
||||
-
|
||||
!python {model: account.invoice, id: demo_invoice_3}:
|
||||
self.action_invoice_open()
|
||||
-
|
||||
Set the context for supplier bills because the 'type' field is readonly in invoice form views, so it value won't be considered by the yaml import
|
||||
-
|
||||
!context
|
||||
type: 'in_invoice'
|
||||
-
|
||||
!record {model: account.invoice, id: demo_invoice_0}:
|
||||
partner_id: base.res_partner_12
|
||||
user_id: base.user_demo
|
||||
reference_type: none
|
||||
payment_term_id: account.account_payment_term
|
||||
type: 'in_invoice'
|
||||
date_invoice: !eval time.strftime('%Y-%m')+'-01'
|
||||
invoice_line_ids:
|
||||
- price_unit: 10.0
|
||||
quantity: 1.0
|
||||
product_id: product.product_delivery_01
|
||||
uom_id: product.product_uom_unit
|
||||
- price_unit: 4.0
|
||||
quantity: 1.0
|
||||
product_id: product.product_order_01
|
||||
uom_id: product.product_uom_unit
|
||||
-
|
||||
!record {model: account.invoice, id: demo_invoice_january_wages}:
|
||||
partner_id: base.res_partner_12
|
||||
type: 'in_invoice'
|
||||
date_invoice: !eval time.strftime('%Y-%m')+'-01'
|
||||
-
|
||||
!python {model: ir.model.data, id: False} : |
|
||||
line_vals = {
|
||||
'invoice_id': ref('demo_invoice_january_wages'),
|
||||
'name': "CEO wages",
|
||||
'price_unit': 10000,
|
||||
}
|
||||
default_company = self.env['res.company']._company_default_get('account.account')
|
||||
account = self.env['account.account'].search([('tag_ids', 'in', [ref('account.demo_ceo_wages_account')]), ('company_id', '=', default_company.id)], limit=1)
|
||||
if not account:
|
||||
account = self.env['account.account'].search([('user_type_id', '=', ref('account.data_account_type_expenses')), ('company_id', '=', default_company.id)], limit=1)
|
||||
if account:
|
||||
line_vals['account_id'] = account.id
|
||||
self._update('account.invoice.line', 'account', line_vals, 'ceo_wages_line')
|
||||
self.env['account.invoice'].browse(ref('demo_invoice_january_wages')).action_invoice_open()
|
||||
-
|
||||
!record {model: account.invoice, id: demo_invoice_equipment_purchase}:
|
||||
partner_id: base.res_partner_1
|
||||
type: 'in_invoice'
|
||||
date_invoice: !eval time.strftime('%Y-%m')+'-15'
|
||||
-
|
||||
!python {model: ir.model.data, id: False} : |
|
||||
line_vals = {
|
||||
'invoice_id': ref('demo_invoice_equipment_purchase'),
|
||||
'name': "Coffee Machine with huge 'employee\'s performances boosting perk'",
|
||||
'price_unit': 4999.99,
|
||||
}
|
||||
account_default_company = self.env['res.company']._company_default_get('account.account')
|
||||
account_id = self.env['account.account'].search([('tag_ids', 'in', [ref('account.demo_coffee_machine_account')]), ('company_id', '=', account_default_company.id)], limit=1).id
|
||||
if not account_id:
|
||||
account_id = self.env['account.account'].search([('user_type_id', '=', ref('account.data_account_type_expenses')), ('company_id', '=', account_default_company.id)], limit=1).id
|
||||
if account_id:
|
||||
line_vals['account_id'] = account_id
|
||||
tax_default_company = self.env['res.company']._company_default_get('account.tax')
|
||||
tax_id = self.env['account.tax'].search([('type_tax_use', '=', 'purchase'), ('amount', '>', 0), ('company_id', '=', tax_default_company.id)], limit=1).id
|
||||
if tax_id:
|
||||
line_vals['invoice_line_tax_ids'] = [(6, 0, [tax_id])]
|
||||
self._update('account.invoice.line', 'account', line_vals, 'coffee_machine_line')
|
||||
self.env['account.invoice'].browse(ref('demo_invoice_equipment_purchase'))._onchange_invoice_line_ids()
|
||||
self.env['account.invoice'].browse(ref('demo_invoice_equipment_purchase')).action_invoice_open()
|
||||
|
||||
-
|
||||
!python {model: account.bank.statement.line, id: False} : |
|
||||
default_company = self.env['res.company']._company_default_get('account.account')
|
||||
account = self.env['account.account'].search([
|
||||
('user_type_id', '=', ref('account.data_account_type_revenue')),
|
||||
('tag_ids', 'in', [ref('account.account_tag_financing')]),
|
||||
('company_id', '=', default_company.id)], limit=1)
|
||||
line = self.env.ref('account.demo_bank_statement_line_5')
|
||||
if not line.journal_entry_ids and account:
|
||||
line.write({'account_id': account.id})
|
||||
line.fast_counterpart_creation()
|
||||
-
|
||||
!python {model: ir.model.data, id: False} : |
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
default_company = self.env['res.company']._company_default_get('account.journal')
|
||||
vals = {
|
||||
'journal_id': self.env['account.journal'].search([('type', '=', 'general'), ('company_id', '=', default_company.id)], limit=1).id,
|
||||
'date': datetime.now().replace(day=1,month=1) - relativedelta(days=1),
|
||||
'ref': 'Company Creation',
|
||||
}
|
||||
self._update('account.move', 'account', vals, 'demo_opening_move')
|
||||
-
|
||||
!python {model: ir.model.data, id: False} : |
|
||||
journal_default_company = self.env['res.company']._company_default_get('account.journal')
|
||||
bank_journal = self.env['account.journal'].search([('type', '=', 'bank'), ('company_id', '=', journal_default_company.id)], limit=1)
|
||||
if bank_journal:
|
||||
bank_account_id = bank_journal.default_debit_account_id.id
|
||||
account_default_company = self.env['res.company']._company_default_get('account.account')
|
||||
fixed_asset_account_id = self.env['account.account'].search([('user_type_id', 'in', (ref('account.data_account_type_fixed_assets'),ref('account.data_account_type_current_assets'))), ('company_id', '=', account_default_company.id)], limit=1).id
|
||||
equity_account_id = self.env['account.account'].search([('user_type_id', '=', ref('account.data_account_type_equity')), ('tag_ids', 'in', [ref('account.demo_capital_account')]), ('company_id', '=', account_default_company.id)], limit=1).id
|
||||
if bank_account_id and fixed_asset_account_id and equity_account_id:
|
||||
self.with_context({'check_move_validity': False})._update('account.move.line', 'account', {
|
||||
'move_id': ref('account.demo_opening_move'),
|
||||
'name': 'Opening Entry',
|
||||
'debit': 5103,
|
||||
'account_id': bank_account_id}, 'opening_line_1')
|
||||
self.with_context({'check_move_validity': False})._update('account.move.line', 'account', {
|
||||
'move_id': ref('account.demo_opening_move'),
|
||||
'name': 'Opening Entry',
|
||||
'debit': 13447,
|
||||
'account_id': fixed_asset_account_id}, 'opening_line_2')
|
||||
self.with_context({'check_move_validity': False})._update('account.move.line', 'account', {
|
||||
'move_id': ref('account.demo_opening_move'),
|
||||
'name': 'Opening Entry',
|
||||
'credit': 18550,
|
||||
'account_id': equity_account_id}, 'opening_line_3')
|
37
addons/account/demo/account_statement_operations.yml
Normal file
37
addons/account/demo/account_statement_operations.yml
Normal file
@ -0,0 +1,37 @@
|
||||
-
|
||||
!python {model: ir.model.data, id: False} : |
|
||||
account_id = self.env['account.account'].search([('user_type_id', '=', ref('account.data_account_type_expenses')), ('tag_ids', '=', ref('account_tag_operating'))], limit=1).id
|
||||
vals = {
|
||||
'name': "Discount For Early Payment",
|
||||
'label': 'Discount',
|
||||
'amount_type': 'percentage',
|
||||
'amount': -7,
|
||||
}
|
||||
if account_id:
|
||||
vals['account_id'] = account_id
|
||||
self._update(cr, uid, 'account.reconcile.model', 'account', vals, 'account_reconcile_model_1')
|
||||
-
|
||||
!python {model: ir.model.data, id: False} : |
|
||||
account_id = self.env['account.account'].search([('user_type_id', '=', ref('account.data_account_type_expenses')), ('tag_ids', '=', ref('account_tag_operating'))], limit=1).id
|
||||
vals = {
|
||||
'name': "Bank Fees",
|
||||
'label': 'Bank Fees',
|
||||
'amount_type': 'percentage',
|
||||
'amount': 100.0,
|
||||
}
|
||||
if account_id:
|
||||
vals['account_id'] = account_id
|
||||
self._update(cr, uid, 'account.reconcile.model', 'account', vals, 'account_reconcile_model_2')
|
||||
-
|
||||
!python {model: ir.model.data, id: False} : |
|
||||
account_id = self.env['account.account'].search([('user_type_id', '=', ref('account.data_account_type_revenue')), ('tag_ids', '=', ref('account_tag_operating'))], limit=1).id
|
||||
vals = {
|
||||
'name': "Profit / Loss",
|
||||
'label': 'Profit / Loss',
|
||||
'amount_type': 'percentage',
|
||||
'amount': 100.0,
|
||||
}
|
||||
if account_id:
|
||||
vals['account_id'] = account_id
|
||||
self._update(cr, uid, 'account.reconcile.model', 'account', vals, 'account_reconcile_model_3')
|
||||
-
|
BIN
addons/account/doc/account_anglo_saxon.ods
Normal file
BIN
addons/account/doc/account_anglo_saxon.ods
Normal file
Binary file not shown.
BIN
addons/account/doc/account_anglo_saxon.pdf
Normal file
BIN
addons/account/doc/account_anglo_saxon.pdf
Normal file
Binary file not shown.
10053
addons/account/i18n/account.pot
Normal file
10053
addons/account/i18n/account.pot
Normal file
File diff suppressed because it is too large
Load Diff
10449
addons/account/i18n/af.po
Normal file
10449
addons/account/i18n/af.po
Normal file
File diff suppressed because it is too large
Load Diff
11194
addons/account/i18n/ar.po
Normal file
11194
addons/account/i18n/ar.po
Normal file
File diff suppressed because it is too large
Load Diff
10771
addons/account/i18n/bg.po
Normal file
10771
addons/account/i18n/bg.po
Normal file
File diff suppressed because it is too large
Load Diff
10728
addons/account/i18n/bs.po
Normal file
10728
addons/account/i18n/bs.po
Normal file
File diff suppressed because it is too large
Load Diff
11351
addons/account/i18n/ca.po
Normal file
11351
addons/account/i18n/ca.po
Normal file
File diff suppressed because it is too large
Load Diff
10868
addons/account/i18n/cs.po
Normal file
10868
addons/account/i18n/cs.po
Normal file
File diff suppressed because it is too large
Load Diff
11270
addons/account/i18n/da.po
Normal file
11270
addons/account/i18n/da.po
Normal file
File diff suppressed because it is too large
Load Diff
11398
addons/account/i18n/de.po
Normal file
11398
addons/account/i18n/de.po
Normal file
File diff suppressed because it is too large
Load Diff
11035
addons/account/i18n/el.po
Normal file
11035
addons/account/i18n/el.po
Normal file
File diff suppressed because it is too large
Load Diff
5292
addons/account/i18n/en_GB.po
Normal file
5292
addons/account/i18n/en_GB.po
Normal file
File diff suppressed because it is too large
Load Diff
11372
addons/account/i18n/es.po
Normal file
11372
addons/account/i18n/es.po
Normal file
File diff suppressed because it is too large
Load Diff
3652
addons/account/i18n/es_AR.po
Normal file
3652
addons/account/i18n/es_AR.po
Normal file
File diff suppressed because it is too large
Load Diff
4948
addons/account/i18n/es_BO.po
Normal file
4948
addons/account/i18n/es_BO.po
Normal file
File diff suppressed because it is too large
Load Diff
5552
addons/account/i18n/es_CL.po
Normal file
5552
addons/account/i18n/es_CL.po
Normal file
File diff suppressed because it is too large
Load Diff
2242
addons/account/i18n/es_CR.po
Normal file
2242
addons/account/i18n/es_CR.po
Normal file
File diff suppressed because it is too large
Load Diff
10063
addons/account/i18n/es_EC.po
Normal file
10063
addons/account/i18n/es_EC.po
Normal file
File diff suppressed because it is too large
Load Diff
34
addons/account/i18n/es_MX.po
Normal file
34
addons/account/i18n/es_MX.po
Normal file
@ -0,0 +1,34 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * account
|
||||
#
|
||||
# Translators:
|
||||
# Jesús Alan Ramos Rodríguez <alan.ramos@jarsa.com.mx>, 2017
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 10.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2017-05-26 08:44+0000\n"
|
||||
"PO-Revision-Date: 2017-05-26 08:44+0000\n"
|
||||
"Last-Translator: Jesús Alan Ramos Rodríguez <alan.ramos@jarsa.com.mx>, 2017\n"
|
||||
"Language-Team: Spanish (https://www.transifex.com/odoo/teams/41243/es/)\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Language: es\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.ui.view,arch_db:account.report_invoice_document
|
||||
msgid "TIN:"
|
||||
msgstr "RFC:"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.ui.view,arch_db:account.account_planner
|
||||
msgid "Tax ID"
|
||||
msgstr "RFC"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.ui.view,arch_db:account.account_planner
|
||||
msgid "Your company's legal name, tax ID, address, and logo."
|
||||
msgstr "Su razón social, RFC, dirección y logo."
|
3770
addons/account/i18n/es_PE.po
Normal file
3770
addons/account/i18n/es_PE.po
Normal file
File diff suppressed because it is too large
Load Diff
2020
addons/account/i18n/es_PY.po
Normal file
2020
addons/account/i18n/es_PY.po
Normal file
File diff suppressed because it is too large
Load Diff
10959
addons/account/i18n/et.po
Normal file
10959
addons/account/i18n/et.po
Normal file
File diff suppressed because it is too large
Load Diff
10553
addons/account/i18n/eu.po
Normal file
10553
addons/account/i18n/eu.po
Normal file
File diff suppressed because it is too large
Load Diff
10615
addons/account/i18n/fa.po
Normal file
10615
addons/account/i18n/fa.po
Normal file
File diff suppressed because it is too large
Load Diff
10914
addons/account/i18n/fi.po
Normal file
10914
addons/account/i18n/fi.po
Normal file
File diff suppressed because it is too large
Load Diff
11427
addons/account/i18n/fr.po
Normal file
11427
addons/account/i18n/fr.po
Normal file
File diff suppressed because it is too large
Load Diff
249
addons/account/i18n/fr_BE.po
Normal file
249
addons/account/i18n/fr_BE.po
Normal file
@ -0,0 +1,249 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * account
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 10.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2016-11-14 15:53+0000\n"
|
||||
"PO-Revision-Date: 2016-12-15 11:40+0100\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"Language: fr_BE\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
"X-Generator: Poedit 1.8.11\n"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,help:account.field_account_tax_refund_account_id
|
||||
#: model:ir.model.fields,help:account.field_account_tax_template_refund_account_id
|
||||
msgid ""
|
||||
"Account that will be set on invoice tax lines for refunds. Leave empty to "
|
||||
"use the expense account."
|
||||
msgstr ""
|
||||
"Compte utilisé sur les lignes de taxes des notes de crédit. Laissez vide "
|
||||
"pour utiliser le compte de dépense."
|
||||
|
||||
#. module: account
|
||||
#: model:ir.ui.view,arch_db:account.invoice_supplier_form
|
||||
msgid "Ask Refund"
|
||||
msgstr "Demander une notes de crédit"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,help:account.field_account_invoice_partner_bank_id
|
||||
msgid ""
|
||||
"Bank Account Number to which the invoice will be paid. A Company bank "
|
||||
"account if this is a Customer Invoice or Vendor Refund, otherwise a Partner "
|
||||
"bank account number."
|
||||
msgstr ""
|
||||
"Numéro de compte bancaire sur lequel la facture doit être payée. Un compte "
|
||||
"bancaire de la société si c'est une facture client ou une note de crédit "
|
||||
"fournisseur, sinon le numéro de compte bancaire du fournisseur."
|
||||
|
||||
#. module: account
|
||||
#: model:ir.ui.view,arch_db:account.account_journal_dashboard_kanban_view
|
||||
msgid "Bill Refund"
|
||||
msgstr "Note de crédit fournisseur"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.filters,name:account.filter_invoice_refund
|
||||
msgid "By Refund"
|
||||
msgstr "Par note de crédit"
|
||||
|
||||
#. module: account
|
||||
#: selection:account.invoice.refund,filter_refund:0
|
||||
msgid "Cancel: create refund and reconcile"
|
||||
msgstr "Annuler : créer la note de crédit et lettrer"
|
||||
|
||||
#. module: account
|
||||
#: code:addons/account/wizard/account_invoice_refund.py:54
|
||||
#, python-format
|
||||
msgid "Cannot refund draft/proforma/cancelled invoice."
|
||||
msgstr ""
|
||||
"Impossible de faire une note de crédit pour une facture draft/proforma/"
|
||||
"annulée."
|
||||
|
||||
#. module: account
|
||||
#: code:addons/account/wizard/account_invoice_refund.py:56
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Cannot refund invoice which is already reconciled, invoice should be "
|
||||
"unreconciled first. You can only refund this invoice."
|
||||
msgstr ""
|
||||
"Ne peut pas faire une note de crédit sur une facture qui est déjà lettrée, "
|
||||
"la facture devrait d'abord être délettrée. Vous pouvez faire un avoir "
|
||||
"seulement sur cette facture."
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,help:account.field_account_journal_refund_sequence
|
||||
msgid ""
|
||||
"Check this box if you don't want to share the same sequence for invoices and "
|
||||
"refunds made from this journal"
|
||||
msgstr ""
|
||||
"Cochez cette case si vous ne souhaitez pas partager une même numérotation "
|
||||
"pour les factures et notes de crédit de ce journal"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.ui.view,arch_db:account.view_account_invoice_refund
|
||||
msgid "Create Refund"
|
||||
msgstr "Créer une note de crédit"
|
||||
|
||||
#. module: account
|
||||
#: selection:account.invoice.refund,filter_refund:0
|
||||
msgid "Create a draft refund"
|
||||
msgstr "Créer une note de crédit en brouillon"
|
||||
|
||||
#. module: account
|
||||
#: selection:account.invoice,type:0 selection:account.invoice.report,type:0
|
||||
#: code:addons/account/models/account_payment.py:488
|
||||
#, python-format
|
||||
msgid "Customer Refund"
|
||||
msgstr "Note de crédit client"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,field_description:account.field_account_journal_refund_sequence
|
||||
msgid "Dedicated Refund Sequence"
|
||||
msgstr "Séquence dédiée aux notes de crédit"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.ui.view,arch_db:account.invoice_form
|
||||
#: model:ir.ui.view,arch_db:account.invoice_supplier_form
|
||||
msgid "Draft Refund"
|
||||
msgstr "Note de crédit brouillon"
|
||||
|
||||
#. module: account
|
||||
#: code:addons/account/models/account_invoice.py:906
|
||||
#, python-format
|
||||
msgid ""
|
||||
"Duplicated vendor reference detected. You probably encoded twice the same "
|
||||
"vendor bill/refund."
|
||||
msgstr ""
|
||||
"Doublon de référence fournisseur détecté. Vous avez probablement saisi deux "
|
||||
"fois la même facture/la même note de crédit fournisseur."
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model,name:account.model_account_invoice_refund
|
||||
msgid "Invoice Refund"
|
||||
msgstr "Note de crédit"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,field_description:account.field_account_invoice_refund_invoice_id
|
||||
msgid "Invoice for which this invoice is the refund"
|
||||
msgstr "Facture source de cet note de crédit\t."
|
||||
|
||||
#. module: account
|
||||
#: code:addons/account/wizard/account_invoice_refund.py:114
|
||||
#, python-format
|
||||
msgid "Invoice refund"
|
||||
msgstr "Note de crédit"
|
||||
|
||||
#. module: account
|
||||
#: selection:account.invoice.refund,filter_refund:0
|
||||
msgid "Modify: create refund, reconcile and create a new draft invoice"
|
||||
msgstr ""
|
||||
"Modifier : créer une note de crédit, le lettrer et créer une nouvelle "
|
||||
"facture en brouillon"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.actions.act_window,help:account.action_move_journal_line
|
||||
msgid ""
|
||||
"Odoo automatically creates one journal entry per accounting\n"
|
||||
" document: invoice, refund, vendor payment, bank statements,\n"
|
||||
" etc. So, you should record journal entries manually only/"
|
||||
"mainly\n"
|
||||
" for miscellaneous operations."
|
||||
msgstr ""
|
||||
"Odoo crée automatiquement une écriture par document comptable : facture, "
|
||||
"note de crédit, paiement fournisseur, relevés bancaires, etc. Donc, vous "
|
||||
"devriez enregistrer des écritures manuelles seulement/principalement pour "
|
||||
"des opérations diverses."
|
||||
|
||||
#. module: account
|
||||
#: code:addons/account/models/account_move.py:140
|
||||
#, python-format
|
||||
msgid "Please define a sequence for the refunds"
|
||||
msgstr "Spécifiez une séquence pour les notes de crédit"
|
||||
|
||||
#. module: account
|
||||
#: code:addons/account/models/account_invoice.py:958
|
||||
#: model:ir.ui.view,arch_db:account.account_journal_dashboard_kanban_view
|
||||
#: model:ir.ui.view,arch_db:account.invoice_form
|
||||
#: model:ir.ui.view,arch_db:account.invoice_supplier_form
|
||||
#: model:ir.ui.view,arch_db:account.report_invoice_document
|
||||
#: model:ir.ui.view,arch_db:account.view_account_invoice_report_search
|
||||
#, python-format
|
||||
msgid "Refund"
|
||||
msgstr "Note de crédit"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,field_description:account.field_account_invoice_refund_date_invoice
|
||||
msgid "Refund Date"
|
||||
msgstr "Date de la note de crédit"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,field_description:account.field_account_journal_refund_sequence_id
|
||||
msgid "Refund Entry Sequence"
|
||||
msgstr "Séquence d'écriture de note de crédit"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.actions.act_window,name:account.action_account_invoice_refund
|
||||
#: model:ir.ui.view,arch_db:account.invoice_form
|
||||
msgid "Refund Invoice"
|
||||
msgstr "Note de crédit"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,field_description:account.field_account_invoice_refund_filter_refund
|
||||
msgid "Refund Method"
|
||||
msgstr "\t"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,help:account.field_account_invoice_refund_filter_refund
|
||||
msgid ""
|
||||
"Refund base on this type. You can not Modify and Cancel if the invoice is "
|
||||
"already reconciled"
|
||||
msgstr ""
|
||||
"Base de note de crédit sur ce type. Vous ne pouvez pas modifier et annuler "
|
||||
"si la facture est déjà lettrée"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.ui.view,arch_db:account.account_journal_dashboard_kanban_view
|
||||
#: model:ir.ui.view,arch_db:account.view_account_invoice_filter
|
||||
msgid "Refunds"
|
||||
msgstr "Notes\t de crédit"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,field_description:account.field_account_tax_refund_account_id
|
||||
#: model:ir.model.fields,field_description:account.field_account_tax_template_refund_account_id
|
||||
msgid "Tax Account on Refunds"
|
||||
msgstr "Compte de taxe pour les notes de crédit"
|
||||
|
||||
#. module: account
|
||||
#: model:ir.model.fields,help:account.field_account_journal_refund_sequence_id
|
||||
msgid ""
|
||||
"This field contains the information related to the numbering of the refund "
|
||||
"entries of this journal."
|
||||
msgstr ""
|
||||
"Ce champ contient les informations relatives à la numérotation des entrées "
|
||||
"de note de crédit de ce journal."
|
||||
|
||||
#. module: account
|
||||
#: selection:account.invoice,type:0 selection:account.invoice.report,type:0
|
||||
#: code:addons/account/models/account_invoice.py:959
|
||||
#: code:addons/account/models/account_payment.py:491
|
||||
#: model:ir.ui.view,arch_db:account.report_invoice_document
|
||||
#, python-format
|
||||
msgid "Vendor Refund"
|
||||
msgstr "Note de crédit fournisseur"
|
||||
|
||||
#. module: account
|
||||
#: code:addons/account/models/account_invoice.py:449
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You cannot delete an invoice which is not draft or cancelled. You should "
|
||||
"refund it instead."
|
||||
msgstr ""
|
||||
"Impossible de supprimer une facture qui n'est ni en brouillon ni annulée. "
|
||||
"Vous pouvez par contre créer une note de crédit."
|
2346
addons/account/i18n/fr_CA.po
Normal file
2346
addons/account/i18n/fr_CA.po
Normal file
File diff suppressed because it is too large
Load Diff
10416
addons/account/i18n/gl.po
Normal file
10416
addons/account/i18n/gl.po
Normal file
File diff suppressed because it is too large
Load Diff
10532
addons/account/i18n/gu.po
Normal file
10532
addons/account/i18n/gu.po
Normal file
File diff suppressed because it is too large
Load Diff
10684
addons/account/i18n/he.po
Normal file
10684
addons/account/i18n/he.po
Normal file
File diff suppressed because it is too large
Load Diff
11154
addons/account/i18n/hr.po
Normal file
11154
addons/account/i18n/hr.po
Normal file
File diff suppressed because it is too large
Load Diff
11375
addons/account/i18n/hu.po
Normal file
11375
addons/account/i18n/hu.po
Normal file
File diff suppressed because it is too large
Load Diff
10528
addons/account/i18n/hy.po
Normal file
10528
addons/account/i18n/hy.po
Normal file
File diff suppressed because it is too large
Load Diff
11314
addons/account/i18n/id.po
Normal file
11314
addons/account/i18n/id.po
Normal file
File diff suppressed because it is too large
Load Diff
10527
addons/account/i18n/is.po
Normal file
10527
addons/account/i18n/is.po
Normal file
File diff suppressed because it is too large
Load Diff
11244
addons/account/i18n/it.po
Normal file
11244
addons/account/i18n/it.po
Normal file
File diff suppressed because it is too large
Load Diff
10602
addons/account/i18n/ja.po
Normal file
10602
addons/account/i18n/ja.po
Normal file
File diff suppressed because it is too large
Load Diff
10552
addons/account/i18n/ka.po
Normal file
10552
addons/account/i18n/ka.po
Normal file
File diff suppressed because it is too large
Load Diff
10704
addons/account/i18n/kab.po
Normal file
10704
addons/account/i18n/kab.po
Normal file
File diff suppressed because it is too large
Load Diff
10529
addons/account/i18n/km.po
Normal file
10529
addons/account/i18n/km.po
Normal file
File diff suppressed because it is too large
Load Diff
10578
addons/account/i18n/ko.po
Normal file
10578
addons/account/i18n/ko.po
Normal file
File diff suppressed because it is too large
Load Diff
10587
addons/account/i18n/lo.po
Normal file
10587
addons/account/i18n/lo.po
Normal file
File diff suppressed because it is too large
Load Diff
11077
addons/account/i18n/lt.po
Normal file
11077
addons/account/i18n/lt.po
Normal file
File diff suppressed because it is too large
Load Diff
10567
addons/account/i18n/lv.po
Normal file
10567
addons/account/i18n/lv.po
Normal file
File diff suppressed because it is too large
Load Diff
10714
addons/account/i18n/mk.po
Normal file
10714
addons/account/i18n/mk.po
Normal file
File diff suppressed because it is too large
Load Diff
11262
addons/account/i18n/mn.po
Normal file
11262
addons/account/i18n/mn.po
Normal file
File diff suppressed because it is too large
Load Diff
10522
addons/account/i18n/mt.po
Normal file
10522
addons/account/i18n/mt.po
Normal file
File diff suppressed because it is too large
Load Diff
10532
addons/account/i18n/my.po
Normal file
10532
addons/account/i18n/my.po
Normal file
File diff suppressed because it is too large
Load Diff
10674
addons/account/i18n/nb.po
Normal file
10674
addons/account/i18n/nb.po
Normal file
File diff suppressed because it is too large
Load Diff
10527
addons/account/i18n/ne.po
Normal file
10527
addons/account/i18n/ne.po
Normal file
File diff suppressed because it is too large
Load Diff
11367
addons/account/i18n/nl.po
Normal file
11367
addons/account/i18n/nl.po
Normal file
File diff suppressed because it is too large
Load Diff
3344
addons/account/i18n/nl_BE.po
Normal file
3344
addons/account/i18n/nl_BE.po
Normal file
File diff suppressed because it is too large
Load Diff
11227
addons/account/i18n/pl.po
Normal file
11227
addons/account/i18n/pl.po
Normal file
File diff suppressed because it is too large
Load Diff
11236
addons/account/i18n/pt.po
Normal file
11236
addons/account/i18n/pt.po
Normal file
File diff suppressed because it is too large
Load Diff
11363
addons/account/i18n/pt_BR.po
Normal file
11363
addons/account/i18n/pt_BR.po
Normal file
File diff suppressed because it is too large
Load Diff
10994
addons/account/i18n/ro.po
Normal file
10994
addons/account/i18n/ro.po
Normal file
File diff suppressed because it is too large
Load Diff
11311
addons/account/i18n/ru.po
Normal file
11311
addons/account/i18n/ru.po
Normal file
File diff suppressed because it is too large
Load Diff
11118
addons/account/i18n/sk.po
Normal file
11118
addons/account/i18n/sk.po
Normal file
File diff suppressed because it is too large
Load Diff
10608
addons/account/i18n/sl.po
Normal file
10608
addons/account/i18n/sl.po
Normal file
File diff suppressed because it is too large
Load Diff
10652
addons/account/i18n/sq.po
Normal file
10652
addons/account/i18n/sq.po
Normal file
File diff suppressed because it is too large
Load Diff
10546
addons/account/i18n/sr.po
Normal file
10546
addons/account/i18n/sr.po
Normal file
File diff suppressed because it is too large
Load Diff
10405
addons/account/i18n/sr@latin.po
Normal file
10405
addons/account/i18n/sr@latin.po
Normal file
File diff suppressed because it is too large
Load Diff
10750
addons/account/i18n/sv.po
Normal file
10750
addons/account/i18n/sv.po
Normal file
File diff suppressed because it is too large
Load Diff
10583
addons/account/i18n/th.po
Normal file
10583
addons/account/i18n/th.po
Normal file
File diff suppressed because it is too large
Load Diff
11276
addons/account/i18n/tr.po
Normal file
11276
addons/account/i18n/tr.po
Normal file
File diff suppressed because it is too large
Load Diff
11343
addons/account/i18n/uk.po
Normal file
11343
addons/account/i18n/uk.po
Normal file
File diff suppressed because it is too large
Load Diff
10711
addons/account/i18n/vi.po
Normal file
10711
addons/account/i18n/vi.po
Normal file
File diff suppressed because it is too large
Load Diff
10806
addons/account/i18n/zh_CN.po
Normal file
10806
addons/account/i18n/zh_CN.po
Normal file
File diff suppressed because it is too large
Load Diff
10767
addons/account/i18n/zh_TW.po
Normal file
10767
addons/account/i18n/zh_TW.po
Normal file
File diff suppressed because it is too large
Load Diff
15
addons/account/models/__init__.py
Normal file
15
addons/account/models/__init__.py
Normal file
@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import partner
|
||||
import account
|
||||
import account_payment
|
||||
import account_invoice
|
||||
import account_bank_statement
|
||||
import account_move
|
||||
import chart_template
|
||||
import account_analytic_line
|
||||
import account_journal_dashboard
|
||||
import product
|
||||
import company
|
||||
import res_config
|
||||
import web_planner
|
878
addons/account/models/account.py
Normal file
878
addons/account/models/account.py
Normal file
@ -0,0 +1,878 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import time
|
||||
import math
|
||||
|
||||
from odoo.osv import expression
|
||||
from odoo.tools.float_utils import float_round as round
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class AccountAccountType(models.Model):
|
||||
_name = "account.account.type"
|
||||
_description = "Account Type"
|
||||
|
||||
name = fields.Char(string='Account Type', required=True, translate=True)
|
||||
include_initial_balance = fields.Boolean(string="Bring Accounts Balance Forward", help="Used in reports to know if we should consider journal items from the beginning of time instead of from the fiscal year only. Account types that should be reset to zero at each new fiscal year (like expenses, revenue..) should not have this option set.")
|
||||
type = fields.Selection([
|
||||
('other', 'Regular'),
|
||||
('receivable', 'Receivable'),
|
||||
('payable', 'Payable'),
|
||||
('liquidity', 'Liquidity'),
|
||||
], required=True, default='other',
|
||||
help="The 'Internal Type' is used for features available on "\
|
||||
"different types of accounts: liquidity type is for cash or bank accounts"\
|
||||
", payable/receivable is for vendor/customer accounts.")
|
||||
note = fields.Text(string='Description')
|
||||
|
||||
|
||||
class AccountAccountTag(models.Model):
|
||||
_name = 'account.account.tag'
|
||||
_description = 'Account Tag'
|
||||
|
||||
name = fields.Char(required=True)
|
||||
applicability = fields.Selection([('accounts', 'Accounts'), ('taxes', 'Taxes')], required=True, default='accounts')
|
||||
color = fields.Integer('Color Index')
|
||||
|
||||
#----------------------------------------------------------
|
||||
# Accounts
|
||||
#----------------------------------------------------------
|
||||
|
||||
|
||||
class AccountAccount(models.Model):
|
||||
_name = "account.account"
|
||||
_description = "Account"
|
||||
_order = "code"
|
||||
|
||||
#@api.multi
|
||||
#def _compute_has_unreconciled_entries(self):
|
||||
# print "ici dedans"
|
||||
# account_ids = self.ids
|
||||
# for account in self:
|
||||
# # Avoid useless work if has_unreconciled_entries is not relevant for this account
|
||||
# if account.deprecated or not account.reconcile:
|
||||
# account.has_unreconciled_entries = False
|
||||
# account_ids = account_ids - account
|
||||
# if account_ids:
|
||||
# res = dict.fromkeys([x.id for x in account_ids], False)
|
||||
# self.env.cr.execute(
|
||||
# """ SELECT s.account_id FROM(
|
||||
# SELECT
|
||||
# a.id as account_id, a.last_time_entries_checked AS last_time_entries_checked,
|
||||
# MAX(l.write_date) AS max_date
|
||||
# FROM
|
||||
# account_move_line l
|
||||
# RIGHT JOIN account_account a ON (a.id = l.account_id)
|
||||
# WHERE
|
||||
# a.id in %s
|
||||
# AND EXISTS (
|
||||
# SELECT 1
|
||||
# FROM account_move_line l
|
||||
# WHERE l.account_id = a.id
|
||||
# AND l.amount_residual > 0
|
||||
# )
|
||||
# AND EXISTS (
|
||||
# SELECT 1
|
||||
# FROM account_move_line l
|
||||
# WHERE l.account_id = a.id
|
||||
# AND l.amount_residual < 0
|
||||
# )
|
||||
# GROUP BY a.id, a.last_time_entries_checked
|
||||
# ) as s
|
||||
# WHERE (last_time_entries_checked IS NULL OR max_date > last_time_entries_checked)
|
||||
# """ % (account_ids,))
|
||||
# res.update(self.env.cr.dictfetchall())
|
||||
# for account in self.browse(res.keys()):
|
||||
# if res[account.id]:
|
||||
# account.has_unreconciled_entries = True
|
||||
|
||||
@api.multi
|
||||
@api.constrains('internal_type', 'reconcile')
|
||||
def _check_reconcile(self):
|
||||
for account in self:
|
||||
if account.internal_type in ('receivable', 'payable') and account.reconcile == False:
|
||||
raise ValidationError(_('You cannot have a receivable/payable account that is not reconciliable. (account code: %s)') % account.code)
|
||||
|
||||
name = fields.Char(required=True, index=True)
|
||||
currency_id = fields.Many2one('res.currency', string='Account Currency',
|
||||
help="Forces all moves for this account to have this account currency.")
|
||||
code = fields.Char(size=64, required=True, index=True)
|
||||
deprecated = fields.Boolean(index=True, default=False)
|
||||
user_type_id = fields.Many2one('account.account.type', string='Type', required=True, oldname="user_type",
|
||||
help="Account Type is used for information purpose, to generate country-specific legal reports, and set the rules to close a fiscal year and generate opening entries.")
|
||||
internal_type = fields.Selection(related='user_type_id.type', string="Internal Type", store=True, readonly=True)
|
||||
#has_unreconciled_entries = fields.Boolean(compute='_compute_has_unreconciled_entries',
|
||||
# help="The account has at least one unreconciled debit and credit since last time the invoices & payments matching was performed.")
|
||||
last_time_entries_checked = fields.Datetime(string='Latest Invoices & Payments Matching Date', readonly=True, copy=False,
|
||||
help='Last time the invoices & payments matching was performed on this account. It is set either if there\'s not at least '\
|
||||
'an unreconciled debit and an unreconciled credit Or if you click the "Done" button.')
|
||||
reconcile = fields.Boolean(string='Allow Reconciliation', default=False,
|
||||
help="Check this box if this account allows invoices & payments matching of journal items.")
|
||||
tax_ids = fields.Many2many('account.tax', 'account_account_tax_default_rel',
|
||||
'account_id', 'tax_id', string='Default Taxes')
|
||||
note = fields.Text('Internal Notes')
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True,
|
||||
default=lambda self: self.env['res.company']._company_default_get('account.account'))
|
||||
tag_ids = fields.Many2many('account.account.tag', 'account_account_account_tag', string='Tags', help="Optional tags you may want to assign for custom reporting")
|
||||
|
||||
_sql_constraints = [
|
||||
('code_company_uniq', 'unique (code,company_id)', 'The code of the account must be unique per company !')
|
||||
]
|
||||
|
||||
@api.model
|
||||
def default_get(self, default_fields):
|
||||
"""If we're creating a new account through a many2one, there are chances that we typed the account code
|
||||
instead of its name. In that case, switch both fields values.
|
||||
"""
|
||||
default_name = self._context.get('default_name')
|
||||
default_code = self._context.get('default_code')
|
||||
if default_name and not default_code:
|
||||
try:
|
||||
default_code = int(default_name)
|
||||
except ValueError:
|
||||
pass
|
||||
if default_code:
|
||||
default_name = False
|
||||
contextual_self = self.with_context(default_name=default_name, default_code=default_code)
|
||||
return super(AccountAccount, contextual_self).default_get(default_fields)
|
||||
|
||||
@api.model
|
||||
def name_search(self, name, args=None, operator='ilike', limit=100):
|
||||
args = args or []
|
||||
domain = []
|
||||
if name:
|
||||
domain = ['|', ('code', '=ilike', name + '%'), ('name', operator, name)]
|
||||
if operator in expression.NEGATIVE_TERM_OPERATORS:
|
||||
domain = ['&', '!'] + domain[1:]
|
||||
accounts = self.search(domain + args, limit=limit)
|
||||
return accounts.name_get()
|
||||
|
||||
@api.onchange('internal_type')
|
||||
def onchange_internal_type(self):
|
||||
if self.internal_type in ('receivable', 'payable'):
|
||||
self.reconcile = True
|
||||
|
||||
@api.multi
|
||||
@api.depends('name', 'code')
|
||||
def name_get(self):
|
||||
result = []
|
||||
for account in self:
|
||||
name = account.code + ' ' + account.name
|
||||
result.append((account.id, name))
|
||||
return result
|
||||
|
||||
@api.one
|
||||
@api.returns('self', lambda value: value.id)
|
||||
def copy(self, default=None):
|
||||
default = dict(default or {})
|
||||
default.setdefault('code', _("%s (copy)") % (self.code or ''))
|
||||
return super(AccountAccount, self).copy(default)
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
# Dont allow changing the company_id when account_move_line already exist
|
||||
if vals.get('company_id', False):
|
||||
move_lines = self.env['account.move.line'].search([('account_id', 'in', self.ids)], limit=1)
|
||||
for account in self:
|
||||
if (account.company_id.id <> vals['company_id']) and move_lines:
|
||||
raise UserError(_('You cannot change the owner company of an account that already contains journal items.'))
|
||||
# If user change the reconcile flag, all aml should be recomputed for that account and this is very costly.
|
||||
# So to prevent some bugs we add a constraint saying that you cannot change the reconcile field if there is any aml existing
|
||||
# for that account.
|
||||
if vals.get('reconcile'):
|
||||
move_lines = self.env['account.move.line'].search([('account_id', 'in', self.ids)], limit=1)
|
||||
if len(move_lines):
|
||||
raise UserError(_('You cannot change the value of the reconciliation on this account as it already has some moves'))
|
||||
return super(AccountAccount, self).write(vals)
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
if self.env['account.move.line'].search([('account_id', 'in', self.ids)], limit=1):
|
||||
raise UserError(_('You cannot do that on an account that contains journal items.'))
|
||||
#Checking whether the account is set as a property to any Partner or not
|
||||
values = ['account.account,%s' % (account_id,) for account_id in self.ids]
|
||||
partner_prop_acc = self.env['ir.property'].search([('value_reference', 'in', values)], limit=1)
|
||||
if partner_prop_acc:
|
||||
raise UserError(_('You cannot remove/deactivate an account which is set on a customer or vendor.'))
|
||||
return super(AccountAccount, self).unlink()
|
||||
|
||||
@api.multi
|
||||
def mark_as_reconciled(self):
|
||||
return self.write({'last_time_entries_checked': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)})
|
||||
|
||||
@api.multi
|
||||
def action_open_reconcile(self):
|
||||
self.ensure_one()
|
||||
# Open reconciliation view for this account
|
||||
if self.internal_type == 'payable':
|
||||
action_context = {'show_mode_selector': False, 'mode': 'suppliers'}
|
||||
elif self.internal_type == 'receivable':
|
||||
action_context = {'show_mode_selector': False, 'mode': 'customers'}
|
||||
else:
|
||||
action_context = {'show_mode_selector': False, 'account_ids': [self.id,]}
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'manual_reconciliation_view',
|
||||
'context': action_context,
|
||||
}
|
||||
|
||||
|
||||
class AccountJournal(models.Model):
|
||||
_name = "account.journal"
|
||||
_description = "Journal"
|
||||
_order = 'sequence, type, code'
|
||||
|
||||
def _default_inbound_payment_methods(self):
|
||||
return self.env.ref('account.account_payment_method_manual_in')
|
||||
|
||||
def _default_outbound_payment_methods(self):
|
||||
return self.env.ref('account.account_payment_method_manual_out')
|
||||
|
||||
name = fields.Char(string='Journal Name', required=True)
|
||||
code = fields.Char(string='Short Code', size=5, required=True, help="The journal entries of this journal will be named using this prefix.")
|
||||
type = fields.Selection([
|
||||
('sale', 'Sale'),
|
||||
('purchase', 'Purchase'),
|
||||
('cash', 'Cash'),
|
||||
('bank', 'Bank'),
|
||||
('general', 'Miscellaneous'),
|
||||
], required=True,
|
||||
help="Select 'Sale' for customer invoices journals.\n"\
|
||||
"Select 'Purchase' for vendor bills journals.\n"\
|
||||
"Select 'Cash' or 'Bank' for journals that are used in customer or vendor payments.\n"\
|
||||
"Select 'General' for miscellaneous operations journals.")
|
||||
type_control_ids = fields.Many2many('account.account.type', 'account_journal_type_rel', 'journal_id', 'type_id', string='Account Types Allowed')
|
||||
account_control_ids = fields.Many2many('account.account', 'account_account_type_rel', 'journal_id', 'account_id', string='Accounts Allowed',
|
||||
domain=[('deprecated', '=', False)])
|
||||
default_credit_account_id = fields.Many2one('account.account', string='Default Credit Account',
|
||||
domain=[('deprecated', '=', False)], help="It acts as a default account for credit amount")
|
||||
default_debit_account_id = fields.Many2one('account.account', string='Default Debit Account',
|
||||
domain=[('deprecated', '=', False)], help="It acts as a default account for debit amount")
|
||||
update_posted = fields.Boolean(string='Allow Cancelling Entries',
|
||||
help="Check this box if you want to allow the cancellation the entries related to this journal or of the invoice related to this journal")
|
||||
group_invoice_lines = fields.Boolean(string='Group Invoice Lines',
|
||||
help="If this box is checked, the system will try to group the accounting lines when generating them from invoices.")
|
||||
sequence_id = fields.Many2one('ir.sequence', string='Entry Sequence',
|
||||
help="This field contains the information related to the numbering of the journal entries of this journal.", required=True, copy=False)
|
||||
refund_sequence_id = fields.Many2one('ir.sequence', string='Refund Entry Sequence',
|
||||
help="This field contains the information related to the numbering of the refund entries of this journal.", copy=False)
|
||||
sequence = fields.Integer(help='Used to order Journals in the dashboard view', default=10)
|
||||
|
||||
#groups_id = fields.Many2many('res.groups', 'account_journal_group_rel', 'journal_id', 'group_id', string='Groups')
|
||||
currency_id = fields.Many2one('res.currency', help='The currency used to enter statement', string="Currency", oldname='currency')
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, index=True, default=lambda self: self.env.user.company_id,
|
||||
help="Company related to this journal")
|
||||
|
||||
refund_sequence = fields.Boolean(string='Dedicated Refund Sequence', help="Check this box if you don't want to share the same sequence for invoices and refunds made from this journal", default=False)
|
||||
|
||||
inbound_payment_method_ids = fields.Many2many('account.payment.method', 'account_journal_inbound_payment_method_rel', 'journal_id', 'inbound_payment_method',
|
||||
domain=[('payment_type', '=', 'inbound')], string='Debit Methods', default=lambda self: self._default_inbound_payment_methods(),
|
||||
help="Means of payment for collecting money. Odoo modules offer various payments handling facilities, "
|
||||
"but you can always use the 'Manual' payment method in order to manage payments outside of the software.")
|
||||
outbound_payment_method_ids = fields.Many2many('account.payment.method', 'account_journal_outbound_payment_method_rel', 'journal_id', 'outbound_payment_method',
|
||||
domain=[('payment_type', '=', 'outbound')], string='Payment Methods', default=lambda self: self._default_outbound_payment_methods(),
|
||||
help="Means of payment for sending money. Odoo modules offer various payments handling facilities, "
|
||||
"but you can always use the 'Manual' payment method in order to manage payments outside of the software.")
|
||||
at_least_one_inbound = fields.Boolean(compute='_methods_compute', store=True)
|
||||
at_least_one_outbound = fields.Boolean(compute='_methods_compute', store=True)
|
||||
profit_account_id = fields.Many2one('account.account', string='Profit Account', domain=[('deprecated', '=', False)], help="Used to register a profit when the ending balance of a cash register differs from what the system computes")
|
||||
loss_account_id = fields.Many2one('account.account', string='Loss Account', domain=[('deprecated', '=', False)], help="Used to register a loss when the ending balance of a cash register differs from what the system computes")
|
||||
|
||||
belongs_to_company = fields.Boolean('Belong to the user\'s current company', compute="_belong_to_company", search="_search_company_journals",)
|
||||
|
||||
# Bank journals fields
|
||||
bank_account_id = fields.Many2one('res.partner.bank', string="Bank Account", ondelete='restrict', copy=False)
|
||||
display_on_footer = fields.Boolean("Show in Invoices Footer", help="Display this bank account on the footer of printed documents like invoices and sales orders.")
|
||||
bank_statements_source = fields.Selection([('manual', 'Record Manually')], string='Bank Feeds')
|
||||
bank_acc_number = fields.Char(related='bank_account_id.acc_number')
|
||||
bank_id = fields.Many2one('res.bank', related='bank_account_id.bank_id')
|
||||
|
||||
_sql_constraints = [
|
||||
('code_company_uniq', 'unique (code, name, company_id)', 'The code and name of the journal must be unique per company !'),
|
||||
]
|
||||
|
||||
@api.one
|
||||
@api.constrains('currency_id', 'default_credit_account_id', 'default_debit_account_id')
|
||||
def _check_currency(self):
|
||||
if self.currency_id:
|
||||
if self.default_credit_account_id and not self.default_credit_account_id.currency_id.id == self.currency_id.id:
|
||||
raise ValidationError(_('Configuration error!\nThe currency of the journal should be the same than the default credit account.'))
|
||||
if self.default_debit_account_id and not self.default_debit_account_id.currency_id.id == self.currency_id.id:
|
||||
raise ValidationError(_('Configuration error!\nThe currency of the journal should be the same than the default debit account.'))
|
||||
|
||||
@api.one
|
||||
@api.constrains('type', 'bank_account_id')
|
||||
def _check_bank_account(self):
|
||||
if self.type == 'bank' and self.bank_account_id:
|
||||
if self.bank_account_id.company_id != self.company_id:
|
||||
raise ValidationError(_('The bank account of a bank journal must belong to the same company (%s).') % self.company_id.name)
|
||||
# A bank account can belong to a customer/supplier, in which case their partner_id is the customer/supplier.
|
||||
# Or they are part of a bank journal and their partner_id must be the company's partner_id.
|
||||
if self.bank_account_id.partner_id != self.company_id.partner_id:
|
||||
raise ValidationError(_('The holder of a journal\'s bank account must be the company (%s).') % self.company_id.name)
|
||||
|
||||
@api.onchange('default_debit_account_id')
|
||||
def onchange_debit_account_id(self):
|
||||
if not self.default_credit_account_id:
|
||||
self.default_credit_account_id = self.default_debit_account_id
|
||||
|
||||
@api.onchange('default_credit_account_id')
|
||||
def onchange_credit_account_id(self):
|
||||
if not self.default_debit_account_id:
|
||||
self.default_debit_account_id = self.default_credit_account_id
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
bank_accounts = self.env['res.partner.bank'].browse()
|
||||
for bank_account in self.mapped('bank_account_id'):
|
||||
accounts = self.search([('bank_account_id', '=', bank_account.id)])
|
||||
if accounts <= self:
|
||||
bank_accounts += bank_account
|
||||
ret = super(AccountJournal, self).unlink()
|
||||
bank_accounts.unlink()
|
||||
return ret
|
||||
|
||||
@api.one
|
||||
@api.returns('self', lambda value: value.id)
|
||||
def copy(self, default=None):
|
||||
default = dict(default or {})
|
||||
default.update(
|
||||
code=_("%s (copy)") % (self.code or ''),
|
||||
name=_("%s (copy)") % (self.name or ''))
|
||||
return super(AccountJournal, self).copy(default)
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
for journal in self:
|
||||
if ('company_id' in vals and journal.company_id.id != vals['company_id']):
|
||||
if self.env['account.move'].search([('journal_id', 'in', self.ids)], limit=1):
|
||||
raise UserError(_('This journal already contains items, therefore you cannot modify its company.'))
|
||||
if self.bank_account_id:
|
||||
self.bank_account_id.company_id = vals['company_id']
|
||||
if ('code' in vals and journal.code != vals['code']):
|
||||
if self.env['account.move'].search([('journal_id', 'in', self.ids)], limit=1):
|
||||
raise UserError(_('This journal already contains items, therefore you cannot modify its short name.'))
|
||||
new_prefix = self._get_sequence_prefix(vals['code'], refund=False)
|
||||
journal.sequence_id.write({'prefix': new_prefix})
|
||||
if journal.refund_sequence_id:
|
||||
new_prefix = self._get_sequence_prefix(vals['code'], refund=True)
|
||||
journal.refund_sequence_id.write({'prefix': new_prefix})
|
||||
if 'currency_id' in vals:
|
||||
if not 'default_debit_account_id' in vals and self.default_debit_account_id:
|
||||
self.default_debit_account_id.currency_id = vals['currency_id']
|
||||
if not 'default_credit_account_id' in vals and self.default_credit_account_id:
|
||||
self.default_credit_account_id.currency_id = vals['currency_id']
|
||||
if self.bank_account_id:
|
||||
self.bank_account_id.currency_id = vals['currency_id']
|
||||
if 'bank_acc_number' in vals and not vals.get('bank_acc_number') and journal.bank_account_id:
|
||||
raise UserError(_('You cannot empty the account number once set.\nIf you would like to delete the account number, you can do it from the Bank Accounts list.'))
|
||||
result = super(AccountJournal, self).write(vals)
|
||||
|
||||
# Create the bank_account_id if necessary
|
||||
if 'bank_acc_number' in vals:
|
||||
for journal in self.filtered(lambda r: r.type == 'bank' and not r.bank_account_id):
|
||||
journal.set_bank_account(vals.get('bank_acc_number'), vals.get('bank_id'))
|
||||
# create the relevant refund sequence
|
||||
if vals.get('refund_sequence'):
|
||||
for journal in self.filtered(lambda j: j.type in ('sale', 'purchase') and not j.refund_sequence_id):
|
||||
journal_vals = {
|
||||
'name': journal.name,
|
||||
'company_id': journal.company_id.id,
|
||||
'code': journal.code
|
||||
}
|
||||
journal.refund_sequence_id = self.sudo()._create_sequence(journal_vals, refund=True).id
|
||||
|
||||
return result
|
||||
|
||||
@api.model
|
||||
def _get_sequence_prefix(self, code, refund=False):
|
||||
prefix = code.upper()
|
||||
if refund:
|
||||
prefix = 'R' + prefix
|
||||
return prefix + '/%(range_year)s/'
|
||||
|
||||
@api.model
|
||||
def _create_sequence(self, vals, refund=False):
|
||||
""" Create new no_gap entry sequence for every new Journal"""
|
||||
prefix = self._get_sequence_prefix(vals['code'], refund)
|
||||
seq = {
|
||||
'name': refund and vals['name'] + _(': Refund') or vals['name'],
|
||||
'implementation': 'no_gap',
|
||||
'prefix': prefix,
|
||||
'padding': 4,
|
||||
'number_increment': 1,
|
||||
'use_date_range': True,
|
||||
}
|
||||
if 'company_id' in vals:
|
||||
seq['company_id'] = vals['company_id']
|
||||
return self.env['ir.sequence'].create(seq)
|
||||
|
||||
@api.model
|
||||
def _prepare_liquidity_account(self, name, company, currency_id, type):
|
||||
'''
|
||||
This function prepares the value to use for the creation of the default debit and credit accounts of a
|
||||
liquidity journal (created through the wizard of generating COA from templates for example).
|
||||
|
||||
:param name: name of the bank account
|
||||
:param company: company for which the wizard is running
|
||||
:param currency_id: ID of the currency in wich is the bank account
|
||||
:param type: either 'cash' or 'bank'
|
||||
:return: mapping of field names and values
|
||||
:rtype: dict
|
||||
'''
|
||||
|
||||
# Seek the next available number for the account code
|
||||
code_digits = company.accounts_code_digits or 0
|
||||
if type == 'bank':
|
||||
account_code_prefix = company.bank_account_code_prefix or ''
|
||||
else:
|
||||
account_code_prefix = company.cash_account_code_prefix or company.bank_account_code_prefix or ''
|
||||
for num in xrange(1, 100):
|
||||
new_code = str(account_code_prefix.ljust(code_digits - 1, '0')) + str(num)
|
||||
rec = self.env['account.account'].search([('code', '=', new_code), ('company_id', '=', company.id)], limit=1)
|
||||
if not rec:
|
||||
break
|
||||
else:
|
||||
raise UserError(_('Cannot generate an unused account code.'))
|
||||
|
||||
liquidity_type = self.env.ref('account.data_account_type_liquidity')
|
||||
return {
|
||||
'name': name,
|
||||
'currency_id': currency_id or False,
|
||||
'code': new_code,
|
||||
'user_type_id': liquidity_type and liquidity_type.id or False,
|
||||
'company_id': company.id,
|
||||
}
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
company_id = vals.get('company_id', self.env.user.company_id.id)
|
||||
if vals.get('type') in ('bank', 'cash'):
|
||||
# For convenience, the name can be inferred from account number
|
||||
if not vals.get('name') and 'bank_acc_number' in vals:
|
||||
vals['name'] = vals['bank_acc_number']
|
||||
|
||||
# If no code provided, loop to find next available journal code
|
||||
if not vals.get('code'):
|
||||
journal_code_base = (vals['type'] == 'cash' and 'CSH' or 'BNK')
|
||||
journals = self.env['account.journal'].search([('code', 'like', journal_code_base + '%'), ('company_id', '=', company_id)])
|
||||
for num in xrange(1, 100):
|
||||
# journal_code has a maximal size of 5, hence we can enforce the boundary num < 100
|
||||
journal_code = journal_code_base + str(num)
|
||||
if journal_code not in journals.mapped('code'):
|
||||
vals['code'] = journal_code
|
||||
break
|
||||
else:
|
||||
raise UserError(_("Cannot generate an unused journal code. Please fill the 'Shortcode' field."))
|
||||
|
||||
# Create a default debit/credit account if not given
|
||||
default_account = vals.get('default_debit_account_id') or vals.get('default_credit_account_id')
|
||||
if not default_account:
|
||||
company = self.env['res.company'].browse(company_id)
|
||||
account_vals = self._prepare_liquidity_account(vals.get('name'), company, vals.get('currency_id'), vals.get('type'))
|
||||
default_account = self.env['account.account'].create(account_vals)
|
||||
vals['default_debit_account_id'] = default_account.id
|
||||
vals['default_credit_account_id'] = default_account.id
|
||||
|
||||
# We just need to create the relevant sequences according to the chosen options
|
||||
if not vals.get('sequence_id'):
|
||||
vals.update({'sequence_id': self.sudo()._create_sequence(vals).id})
|
||||
if vals.get('type') in ('sale', 'purchase') and vals.get('refund_sequence') and not vals.get('refund_sequence_id'):
|
||||
vals.update({'refund_sequence_id': self.sudo()._create_sequence(vals, refund=True).id})
|
||||
|
||||
journal = super(AccountJournal, self).create(vals)
|
||||
|
||||
# Create the bank_account_id if necessary
|
||||
if journal.type == 'bank' and not journal.bank_account_id and vals.get('bank_acc_number'):
|
||||
journal.set_bank_account(vals.get('bank_acc_number'), vals.get('bank_id'))
|
||||
|
||||
return journal
|
||||
|
||||
def set_bank_account(self, acc_number, bank_id=None):
|
||||
""" Create a res.partner.bank and set it as value of the field bank_account_id """
|
||||
self.ensure_one()
|
||||
self.bank_account_id = self.env['res.partner.bank'].create({
|
||||
'acc_number': acc_number,
|
||||
'bank_id': bank_id,
|
||||
'company_id': self.company_id.id,
|
||||
'currency_id': self.currency_id.id,
|
||||
'partner_id': self.company_id.partner_id.id,
|
||||
}).id
|
||||
|
||||
@api.multi
|
||||
@api.depends('name', 'currency_id', 'company_id', 'company_id.currency_id')
|
||||
def name_get(self):
|
||||
res = []
|
||||
for journal in self:
|
||||
currency = journal.currency_id or journal.company_id.currency_id
|
||||
name = "%s (%s)" % (journal.name, currency.name)
|
||||
res += [(journal.id, name)]
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||||
args = args or []
|
||||
connector = '|'
|
||||
if operator in expression.NEGATIVE_TERM_OPERATORS:
|
||||
connector = '&'
|
||||
recs = self.search([connector, ('code', operator, name), ('name', operator, name)] + args, limit=limit)
|
||||
return recs.name_get()
|
||||
|
||||
@api.multi
|
||||
@api.depends('company_id')
|
||||
def _belong_to_company(self):
|
||||
for journal in self:
|
||||
journal.belong_to_company = (journal.company_id.id == self.env.user.company_id.id)
|
||||
|
||||
@api.multi
|
||||
def _search_company_journals(self, operator, value):
|
||||
if value:
|
||||
recs = self.search([('company_id', operator, self.env.user.company_id.id)])
|
||||
elif operator == '=':
|
||||
recs = self.search([('company_id', '!=', self.env.user.company_id.id)])
|
||||
else:
|
||||
recs = self.search([('company_id', operator, self.env.user.company_id.id)])
|
||||
return [('id', 'in', [x.id for x in recs])]
|
||||
|
||||
@api.multi
|
||||
@api.depends('inbound_payment_method_ids', 'outbound_payment_method_ids')
|
||||
def _methods_compute(self):
|
||||
for journal in self:
|
||||
journal.at_least_one_inbound = bool(len(journal.inbound_payment_method_ids))
|
||||
journal.at_least_one_outbound = bool(len(journal.outbound_payment_method_ids))
|
||||
|
||||
|
||||
class ResPartnerBank(models.Model):
|
||||
_inherit = "res.partner.bank"
|
||||
|
||||
journal_id = fields.One2many('account.journal', 'bank_account_id', domain=[('type', '=', 'bank')], string='Account Journal', readonly=True,
|
||||
help="The accounting journal corresponding to this bank account.")
|
||||
|
||||
@api.one
|
||||
@api.constrains('journal_id')
|
||||
def _check_journal_id(self):
|
||||
if len(self.journal_id) > 1:
|
||||
raise ValidationError(_('A bank account can only belong to one journal.'))
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
# Tax
|
||||
#----------------------------------------------------------
|
||||
|
||||
class AccountTaxGroup(models.Model):
|
||||
_name = 'account.tax.group'
|
||||
_order = 'sequence asc'
|
||||
|
||||
name = fields.Char(required=True, translate=True)
|
||||
sequence = fields.Integer(default=10)
|
||||
|
||||
class AccountTax(models.Model):
|
||||
_name = 'account.tax'
|
||||
_description = 'Tax'
|
||||
_order = 'sequence,id'
|
||||
|
||||
@api.model
|
||||
def _default_tax_group(self):
|
||||
return self.env['account.tax.group'].search([], limit=1)
|
||||
|
||||
name = fields.Char(string='Tax Name', required=True, translate=True)
|
||||
type_tax_use = fields.Selection([('sale', 'Sales'), ('purchase', 'Purchases'), ('none', 'None')], string='Tax Scope', required=True, default="sale",
|
||||
help="Determines where the tax is selectable. Note : 'None' means a tax can't be used by itself, however it can still be used in a group.")
|
||||
tax_adjustment = fields.Boolean(help='Set this field to true if this tax can be used in the tax adjustment wizard, used to manually fill some data in the tax declaration')
|
||||
amount_type = fields.Selection(default='percent', string="Tax Computation", required=True, oldname='type',
|
||||
selection=[('group', 'Group of Taxes'), ('fixed', 'Fixed'), ('percent', 'Percentage of Price'), ('division', 'Percentage of Price Tax Included')])
|
||||
active = fields.Boolean(default=True, help="Set active to false to hide the tax without removing it.")
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.user.company_id)
|
||||
children_tax_ids = fields.Many2many('account.tax', 'account_tax_filiation_rel', 'parent_tax', 'child_tax', string='Children Taxes')
|
||||
sequence = fields.Integer(required=True, default=1,
|
||||
help="The sequence field is used to define order in which the tax lines are applied.")
|
||||
amount = fields.Float(required=True, digits=(16, 4))
|
||||
account_id = fields.Many2one('account.account', domain=[('deprecated', '=', False)], string='Tax Account', ondelete='restrict',
|
||||
help="Account that will be set on invoice tax lines for invoices. Leave empty to use the expense account.", oldname='account_collected_id')
|
||||
refund_account_id = fields.Many2one('account.account', domain=[('deprecated', '=', False)], string='Tax Account on Refunds', ondelete='restrict',
|
||||
help="Account that will be set on invoice tax lines for refunds. Leave empty to use the expense account.", oldname='account_paid_id')
|
||||
description = fields.Char(string='Label on Invoices', translate=True)
|
||||
price_include = fields.Boolean(string='Included in Price', default=False,
|
||||
help="Check this if the price you use on the product and invoices includes this tax.")
|
||||
include_base_amount = fields.Boolean(string='Affect Base of Subsequent Taxes', default=False,
|
||||
help="If set, taxes which are computed after this one will be computed based on the price tax included.")
|
||||
analytic = fields.Boolean(string="Include in Analytic Cost", help="If set, the amount computed by this tax will be assigned to the same analytic account as the invoice line (if any)")
|
||||
tag_ids = fields.Many2many('account.account.tag', 'account_tax_account_tag', string='Tags', help="Optional tags you may want to assign for custom reporting")
|
||||
tax_group_id = fields.Many2one('account.tax.group', string="Tax Group", default=_default_tax_group, required=True)
|
||||
|
||||
_sql_constraints = [
|
||||
('name_company_uniq', 'unique(name, company_id, type_tax_use)', 'Tax names must be unique !'),
|
||||
]
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
company_id = self.env.user.company_id.id
|
||||
ir_values = self.env['ir.values']
|
||||
supplier_taxes_id = set(ir_values.get_default('product.template', 'supplier_taxes_id', company_id=company_id) or [])
|
||||
deleted_sup_tax = self.filtered(lambda tax: tax.id in supplier_taxes_id)
|
||||
if deleted_sup_tax:
|
||||
ir_values.sudo().set_default('product.template', "supplier_taxes_id", list(supplier_taxes_id - set(deleted_sup_tax.ids)), for_all_users=True, company_id=company_id)
|
||||
taxes_id = set(self.env['ir.values'].get_default('product.template', 'taxes_id', company_id=company_id) or [])
|
||||
deleted_tax = self.filtered(lambda tax: tax.id in taxes_id)
|
||||
if deleted_tax:
|
||||
ir_values.sudo().set_default('product.template', "taxes_id", list(taxes_id - set(deleted_tax.ids)), for_all_users=True, company_id=company_id)
|
||||
return super(AccountTax, self).unlink()
|
||||
|
||||
@api.one
|
||||
@api.constrains('children_tax_ids', 'type_tax_use')
|
||||
def _check_children_scope(self):
|
||||
if not all(child.type_tax_use in ('none', self.type_tax_use) for child in self.children_tax_ids):
|
||||
raise ValidationError(_('The application scope of taxes in a group must be either the same as the group or "None".'))
|
||||
|
||||
@api.one
|
||||
@api.returns('self', lambda value: value.id)
|
||||
def copy(self, default=None):
|
||||
default = dict(default or {}, name=_("%s (Copy)") % self.name)
|
||||
return super(AccountTax, self).copy(default=default)
|
||||
|
||||
@api.model
|
||||
def name_search(self, name, args=None, operator='ilike', limit=80):
|
||||
""" Returns a list of tupples containing id, name, as internally it is called {def name_get}
|
||||
result format: {[(id, name), (id, name), ...]}
|
||||
"""
|
||||
args = args or []
|
||||
if operator in expression.NEGATIVE_TERM_OPERATORS:
|
||||
domain = [('description', operator, name), ('name', operator, name)]
|
||||
else:
|
||||
domain = ['|', ('description', operator, name), ('name', operator, name)]
|
||||
taxes = self.search(expression.AND([domain, args]), limit=limit)
|
||||
return taxes.name_get()
|
||||
|
||||
@api.model
|
||||
def search(self, args, offset=0, limit=None, order=None, count=False):
|
||||
context = self._context or {}
|
||||
|
||||
if context.get('type'):
|
||||
if context.get('type') in ('out_invoice', 'out_refund'):
|
||||
args += [('type_tax_use', '=', 'sale')]
|
||||
elif context.get('type') in ('in_invoice', 'in_refund'):
|
||||
args += [('type_tax_use', '=', 'purchase')]
|
||||
|
||||
if context.get('journal_id'):
|
||||
journal = self.env['account.journal'].browse(context.get('journal_id'))
|
||||
if journal.type in ('sale', 'purchase'):
|
||||
args += [('type_tax_use', '=', journal.type)]
|
||||
|
||||
return super(AccountTax, self).search(args, offset, limit, order, count=count)
|
||||
|
||||
@api.onchange('amount')
|
||||
def onchange_amount(self):
|
||||
if self.amount_type in ('percent', 'division') and self.amount != 0.0 and not self.description:
|
||||
self.description = "{0:.4g}%".format(self.amount)
|
||||
|
||||
@api.onchange('account_id')
|
||||
def onchange_account_id(self):
|
||||
self.refund_account_id = self.account_id
|
||||
|
||||
@api.onchange('price_include')
|
||||
def onchange_price_include(self):
|
||||
if self.price_include:
|
||||
self.include_base_amount = True
|
||||
|
||||
def get_grouping_key(self, invoice_tax_val):
|
||||
""" Returns a string that will be used to group account.invoice.tax sharing the same properties"""
|
||||
self.ensure_one()
|
||||
return str(invoice_tax_val['tax_id']) + '-' + str(invoice_tax_val['account_id']) + '-' + str(invoice_tax_val['account_analytic_id'])
|
||||
|
||||
def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
|
||||
""" Returns the amount of a single tax. base_amount is the actual amount on which the tax is applied, which is
|
||||
price_unit * quantity eventually affected by previous taxes (if tax is include_base_amount XOR price_include)
|
||||
"""
|
||||
self.ensure_one()
|
||||
if self.amount_type == 'fixed':
|
||||
# Use copysign to take into account the sign of the base amount which includes the sign
|
||||
# of the quantity and the sign of the price_unit
|
||||
# Amount is the fixed price for the tax, it can be negative
|
||||
# Base amount included the sign of the quantity and the sign of the unit price and when
|
||||
# a product is returned, it can be done either by changing the sign of quantity or by changing the
|
||||
# sign of the price unit.
|
||||
# When the price unit is equal to 0, the sign of the quantity is absorbed in base_amount then
|
||||
# a "else" case is needed.
|
||||
if base_amount:
|
||||
return math.copysign(quantity, base_amount) * self.amount
|
||||
else:
|
||||
return quantity * self.amount
|
||||
if (self.amount_type == 'percent' and not self.price_include) or (self.amount_type == 'division' and self.price_include):
|
||||
return base_amount * self.amount / 100
|
||||
if self.amount_type == 'percent' and self.price_include:
|
||||
return base_amount - (base_amount / (1 + self.amount / 100))
|
||||
if self.amount_type == 'division' and not self.price_include:
|
||||
return base_amount / (1 - self.amount / 100) - base_amount
|
||||
|
||||
@api.multi
|
||||
def json_friendly_compute_all(self, price_unit, currency_id=None, quantity=1.0, product_id=None, partner_id=None):
|
||||
""" Just converts parameters in browse records and calls for compute_all, because js widgets can't serialize browse records """
|
||||
if currency_id:
|
||||
currency_id = self.env['res.currency'].browse(currency_id)
|
||||
if product_id:
|
||||
product_id = self.env['product.product'].browse(product_id)
|
||||
if partner_id:
|
||||
partner_id = self.env['res.partner'].browse(partner_id)
|
||||
return self.compute_all(price_unit, currency=currency_id, quantity=quantity, product=product_id, partner=partner_id)
|
||||
|
||||
@api.multi
|
||||
def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None):
|
||||
""" Returns all information required to apply taxes (in self + their children in case of a tax goup).
|
||||
We consider the sequence of the parent for group of taxes.
|
||||
Eg. considering letters as taxes and alphabetic order as sequence :
|
||||
[G, B([A, D, F]), E, C] will be computed as [A, D, F, C, E, G]
|
||||
|
||||
RETURN: {
|
||||
'total_excluded': 0.0, # Total without taxes
|
||||
'total_included': 0.0, # Total with taxes
|
||||
'taxes': [{ # One dict for each tax in self and their children
|
||||
'id': int,
|
||||
'name': str,
|
||||
'amount': float,
|
||||
'sequence': int,
|
||||
'account_id': int,
|
||||
'refund_account_id': int,
|
||||
'analytic': boolean,
|
||||
}]
|
||||
} """
|
||||
if len(self) == 0:
|
||||
company_id = self.env.user.company_id
|
||||
else:
|
||||
company_id = self[0].company_id
|
||||
if not currency:
|
||||
currency = company_id.currency_id
|
||||
taxes = []
|
||||
# By default, for each tax, tax amount will first be computed
|
||||
# and rounded at the 'Account' decimal precision for each
|
||||
# PO/SO/invoice line and then these rounded amounts will be
|
||||
# summed, leading to the total amount for that tax. But, if the
|
||||
# company has tax_calculation_rounding_method = round_globally,
|
||||
# we still follow the same method, but we use a much larger
|
||||
# precision when we round the tax amount for each line (we use
|
||||
# the 'Account' decimal precision + 5), and that way it's like
|
||||
# rounding after the sum of the tax amounts of each line
|
||||
prec = currency.decimal_places
|
||||
|
||||
# In some cases, it is necessary to force/prevent the rounding of the tax and the total
|
||||
# amounts. For example, in SO/PO line, we don't want to round the price unit at the
|
||||
# precision of the currency.
|
||||
# The context key 'round' allows to force the standard behavior.
|
||||
round_tax = False if company_id.tax_calculation_rounding_method == 'round_globally' else True
|
||||
round_total = True
|
||||
if 'round' in self.env.context:
|
||||
round_tax = bool(self.env.context['round'])
|
||||
round_total = bool(self.env.context['round'])
|
||||
|
||||
if not round_tax:
|
||||
prec += 5
|
||||
|
||||
base_values = self.env.context.get('base_values')
|
||||
if not base_values:
|
||||
total_excluded = total_included = base = round(price_unit * quantity, prec)
|
||||
else:
|
||||
total_excluded, total_included, base = base_values
|
||||
|
||||
# Sorting key is mandatory in this case. When no key is provided, sorted() will perform a
|
||||
# search. However, the search method is overridden in account.tax in order to add a domain
|
||||
# depending on the context. This domain might filter out some taxes from self, e.g. in the
|
||||
# case of group taxes.
|
||||
for tax in self.sorted(key=lambda r: r.sequence):
|
||||
if tax.amount_type == 'group':
|
||||
children = tax.children_tax_ids.with_context(base_values=(total_excluded, total_included, base))
|
||||
ret = children.compute_all(price_unit, currency, quantity, product, partner)
|
||||
total_excluded = ret['total_excluded']
|
||||
base = ret['base'] if tax.include_base_amount else base
|
||||
total_included = ret['total_included']
|
||||
tax_amount = total_included - total_excluded
|
||||
taxes += ret['taxes']
|
||||
continue
|
||||
|
||||
tax_amount = tax._compute_amount(base, price_unit, quantity, product, partner)
|
||||
if not round_tax:
|
||||
tax_amount = round(tax_amount, prec)
|
||||
else:
|
||||
tax_amount = currency.round(tax_amount)
|
||||
|
||||
if tax.price_include:
|
||||
total_excluded -= tax_amount
|
||||
base -= tax_amount
|
||||
else:
|
||||
total_included += tax_amount
|
||||
|
||||
# Keep base amount used for the current tax
|
||||
tax_base = base
|
||||
|
||||
if tax.include_base_amount:
|
||||
base += tax_amount
|
||||
|
||||
taxes.append({
|
||||
'id': tax.id,
|
||||
'name': tax.with_context(**{'lang': partner.lang} if partner else {}).name,
|
||||
'amount': tax_amount,
|
||||
'base': tax_base,
|
||||
'sequence': tax.sequence,
|
||||
'account_id': tax.account_id.id,
|
||||
'refund_account_id': tax.refund_account_id.id,
|
||||
'analytic': tax.analytic,
|
||||
})
|
||||
|
||||
return {
|
||||
'taxes': sorted(taxes, key=lambda k: k['sequence']),
|
||||
'total_excluded': currency.round(total_excluded) if round_total else total_excluded,
|
||||
'total_included': currency.round(total_included) if round_total else total_included,
|
||||
'base': base,
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _fix_tax_included_price(self, price, prod_taxes, line_taxes):
|
||||
"""Subtract tax amount from price when corresponding "price included" taxes do not apply"""
|
||||
# FIXME get currency in param?
|
||||
incl_tax = prod_taxes.filtered(lambda tax: tax not in line_taxes and tax.price_include)
|
||||
if incl_tax:
|
||||
return incl_tax.compute_all(price)['total_excluded']
|
||||
return price
|
||||
|
||||
@api.model
|
||||
def _fix_tax_included_price_company(self, price, prod_taxes, line_taxes, company_id):
|
||||
if company_id:
|
||||
#To keep the same behavior as in _compute_tax_id
|
||||
prod_taxes = prod_taxes.filtered(lambda tax: tax.company_id == company_id)
|
||||
line_taxes = line_taxes.filtered(lambda tax: tax.company_id == company_id)
|
||||
return self._fix_tax_included_price(price, prod_taxes, line_taxes)
|
||||
|
||||
class AccountReconcileModel(models.Model):
|
||||
_name = "account.reconcile.model"
|
||||
_description = "Preset to create journal entries during a invoices and payments matching"
|
||||
|
||||
name = fields.Char(string='Button Label', required=True)
|
||||
sequence = fields.Integer(required=True, default=10)
|
||||
has_second_line = fields.Boolean(string='Add a second line', default=False)
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.user.company_id)
|
||||
|
||||
account_id = fields.Many2one('account.account', string='Account', ondelete='cascade', domain=[('deprecated', '=', False)])
|
||||
journal_id = fields.Many2one('account.journal', string='Journal', ondelete='cascade', help="This field is ignored in a bank statement reconciliation.")
|
||||
label = fields.Char(string='Journal Item Label')
|
||||
amount_type = fields.Selection([
|
||||
('fixed', 'Fixed'),
|
||||
('percentage', 'Percentage of balance')
|
||||
], required=True, default='percentage')
|
||||
amount = fields.Float(digits=0, required=True, default=100.0, help="Fixed amount will count as a debit if it is negative, as a credit if it is positive.")
|
||||
tax_id = fields.Many2one('account.tax', string='Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'purchase')])
|
||||
analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account', ondelete='set null')
|
||||
|
||||
second_account_id = fields.Many2one('account.account', string='Second Account', ondelete='cascade', domain=[('deprecated', '=', False)])
|
||||
second_journal_id = fields.Many2one('account.journal', string='Second Journal', ondelete='cascade', help="This field is ignored in a bank statement reconciliation.")
|
||||
second_label = fields.Char(string='Second Journal Item Label')
|
||||
second_amount_type = fields.Selection([
|
||||
('fixed', 'Fixed'),
|
||||
('percentage', 'Percentage of amount')
|
||||
], string="Second Amount type",required=True, default='percentage')
|
||||
second_amount = fields.Float(string='Second Amount', digits=0, required=True, default=100.0, help="Fixed amount will count as a debit if it is negative, as a credit if it is positive.")
|
||||
second_tax_id = fields.Many2one('account.tax', string='Second Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'purchase')])
|
||||
second_analytic_account_id = fields.Many2one('account.analytic.account', string='Second Analytic Account', ondelete='set null')
|
||||
|
||||
@api.onchange('name')
|
||||
def onchange_name(self):
|
||||
self.label = self.name
|
59
addons/account/models/account_analytic_line.py
Normal file
59
addons/account/models/account_analytic_line.py
Normal file
@ -0,0 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from math import copysign
|
||||
|
||||
|
||||
class AccountAnalyticLine(models.Model):
|
||||
_inherit = 'account.analytic.line'
|
||||
_description = 'Analytic Line'
|
||||
_order = 'date desc'
|
||||
|
||||
amount = fields.Monetary(currency_field='company_currency_id')
|
||||
product_uom_id = fields.Many2one('product.uom', string='Unit of Measure')
|
||||
product_id = fields.Many2one('product.product', string='Product')
|
||||
general_account_id = fields.Many2one('account.account', string='Financial Account', ondelete='restrict', readonly=True,
|
||||
related='move_id.account_id', store=True, domain=[('deprecated', '=', False)])
|
||||
move_id = fields.Many2one('account.move.line', string='Move Line', ondelete='cascade', index=True)
|
||||
code = fields.Char(size=8)
|
||||
ref = fields.Char(string='Ref.')
|
||||
company_currency_id = fields.Many2one('res.currency', related='company_id.currency_id', readonly=True,
|
||||
help='Utility field to express amount currency')
|
||||
currency_id = fields.Many2one('res.currency', related='move_id.currency_id', string='Account Currency', store=True, help="The related account currency if not equal to the company one.", readonly=True)
|
||||
amount_currency = fields.Monetary(related='move_id.amount_currency', store=True, help="The amount expressed in the related account currency if not equal to the company one.", readonly=True)
|
||||
analytic_amount_currency = fields.Monetary(string='Amount Currency', compute="_get_analytic_amount_currency", help="The amount expressed in the related account currency if not equal to the company one.", readonly=True)
|
||||
partner_id = fields.Many2one('res.partner', related='account_id.partner_id', string='Partner', store=True, readonly=True)
|
||||
|
||||
def _get_analytic_amount_currency(self):
|
||||
for line in self:
|
||||
line.analytic_amount_currency = abs(line.amount_currency) * copysign(1, line.amount)
|
||||
|
||||
@api.v8
|
||||
@api.onchange('product_id', 'product_uom_id', 'unit_amount', 'currency_id')
|
||||
def on_change_unit_amount(self):
|
||||
if not self.product_id:
|
||||
return {}
|
||||
|
||||
result = 0.0
|
||||
prod_accounts = self.product_id.product_tmpl_id._get_product_accounts()
|
||||
unit = self.product_uom_id
|
||||
account = prod_accounts['expense']
|
||||
if not unit or self.product_id.uom_po_id.category_id.id != unit.category_id.id:
|
||||
unit = self.product_id.uom_po_id
|
||||
|
||||
# Compute based on pricetype
|
||||
amount_unit = self.product_id.price_compute('standard_price', uom=unit)[self.product_id.id]
|
||||
amount = amount_unit * self.unit_amount or 0.0
|
||||
result = round(amount, self.currency_id.decimal_places) * -1
|
||||
self.amount = result
|
||||
self.general_account_id = account
|
||||
self.product_uom_id = unit
|
||||
|
||||
@api.model
|
||||
def view_header_get(self, view_id, view_type):
|
||||
context = (self._context or {})
|
||||
header = False
|
||||
if context.get('account_id', False):
|
||||
analytic_account = self.env['account.analytic.account'].search([('id', '=', context['account_id'])], limit=1)
|
||||
header = _('Entries: ') + (analytic_account.name or '')
|
||||
return header
|
1014
addons/account/models/account_bank_statement.py
Normal file
1014
addons/account/models/account_bank_statement.py
Normal file
File diff suppressed because it is too large
Load Diff
1546
addons/account/models/account_invoice.py
Normal file
1546
addons/account/models/account_invoice.py
Normal file
File diff suppressed because it is too large
Load Diff
383
addons/account/models/account_journal_dashboard.py
Normal file
383
addons/account/models/account_journal_dashboard.py
Normal file
@ -0,0 +1,383 @@
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from babel.dates import format_datetime, format_date
|
||||
|
||||
from odoo import models, api, _, fields
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF
|
||||
from odoo.tools.misc import formatLang
|
||||
|
||||
class account_journal(models.Model):
|
||||
_inherit = "account.journal"
|
||||
|
||||
@api.one
|
||||
def _kanban_dashboard(self):
|
||||
self.kanban_dashboard = json.dumps(self.get_journal_dashboard_datas())
|
||||
|
||||
@api.one
|
||||
def _kanban_dashboard_graph(self):
|
||||
if (self.type in ['sale', 'purchase']):
|
||||
self.kanban_dashboard_graph = json.dumps(self.get_bar_graph_datas())
|
||||
elif (self.type in ['cash', 'bank']):
|
||||
self.kanban_dashboard_graph = json.dumps(self.get_line_graph_datas())
|
||||
|
||||
kanban_dashboard = fields.Text(compute='_kanban_dashboard')
|
||||
kanban_dashboard_graph = fields.Text(compute='_kanban_dashboard_graph')
|
||||
show_on_dashboard = fields.Boolean(string='Show journal on dashboard', help="Whether this journal should be displayed on the dashboard or not", default=True)
|
||||
|
||||
@api.multi
|
||||
def toggle_favorite(self):
|
||||
self.write({'show_on_dashboard': False if self.show_on_dashboard else True})
|
||||
return False
|
||||
|
||||
@api.multi
|
||||
def get_line_graph_datas(self):
|
||||
data = []
|
||||
today = datetime.today()
|
||||
last_month = today + timedelta(days=-30)
|
||||
bank_stmt = []
|
||||
# Query to optimize loading of data for bank statement graphs
|
||||
# Return a list containing the latest bank statement balance per day for the
|
||||
# last 30 days for current journal
|
||||
query = """SELECT a.date, a.balance_end
|
||||
FROM account_bank_statement AS a,
|
||||
(SELECT c.date, max(c.id) AS stmt_id
|
||||
FROM account_bank_statement AS c
|
||||
WHERE c.journal_id = %s
|
||||
AND c.date > %s
|
||||
AND c.date <= %s
|
||||
GROUP BY date, id
|
||||
ORDER BY date, id) AS b
|
||||
WHERE a.id = b.stmt_id;"""
|
||||
|
||||
self.env.cr.execute(query, (self.id, last_month, today))
|
||||
bank_stmt = self.env.cr.dictfetchall()
|
||||
|
||||
last_bank_stmt = self.env['account.bank.statement'].search([('journal_id', 'in', self.ids),('date', '<=', last_month.strftime(DF))], order="date desc, id desc", limit=1)
|
||||
start_balance = last_bank_stmt and last_bank_stmt[0].balance_end or 0
|
||||
|
||||
locale = self._context.get('lang') or 'en_US'
|
||||
show_date = last_month
|
||||
#get date in locale format
|
||||
name = format_date(show_date, 'd LLLL Y', locale=locale)
|
||||
short_name = format_date(show_date, 'd MMM', locale=locale)
|
||||
data.append({'x':short_name,'y':start_balance, 'name':name})
|
||||
|
||||
for stmt in bank_stmt:
|
||||
#fill the gap between last data and the new one
|
||||
number_day_to_add = (datetime.strptime(stmt.get('date'), DF) - show_date).days
|
||||
last_balance = data[len(data) - 1]['y']
|
||||
for day in range(0,number_day_to_add + 1):
|
||||
show_date = show_date + timedelta(days=1)
|
||||
#get date in locale format
|
||||
name = format_date(show_date, 'd LLLL Y', locale=locale)
|
||||
short_name = format_date(show_date, 'd MMM', locale=locale)
|
||||
data.append({'x': short_name, 'y':last_balance, 'name': name})
|
||||
#add new stmt value
|
||||
data[len(data) - 1]['y'] = stmt.get('balance_end')
|
||||
|
||||
#continue the graph if the last statement isn't today
|
||||
if show_date != today:
|
||||
number_day_to_add = (today - show_date).days
|
||||
last_balance = data[len(data) - 1]['y']
|
||||
for day in range(0,number_day_to_add):
|
||||
show_date = show_date + timedelta(days=1)
|
||||
#get date in locale format
|
||||
name = format_date(show_date, 'd LLLL Y', locale=locale)
|
||||
short_name = format_date(show_date, 'd MMM', locale=locale)
|
||||
data.append({'x': short_name, 'y':last_balance, 'name': name})
|
||||
|
||||
return [{'values': data, 'area': True}]
|
||||
|
||||
@api.multi
|
||||
def get_bar_graph_datas(self):
|
||||
data = []
|
||||
today = datetime.strptime(fields.Date.context_today(self), DF)
|
||||
data.append({'label': _('Past'), 'value':0.0, 'type': 'past'})
|
||||
day_of_week = int(format_datetime(today, 'e', locale=self._context.get('lang') or 'en_US'))
|
||||
first_day_of_week = today + timedelta(days=-day_of_week+1)
|
||||
for i in range(-1,4):
|
||||
if i==0:
|
||||
label = _('This Week')
|
||||
elif i==3:
|
||||
label = _('Future')
|
||||
else:
|
||||
start_week = first_day_of_week + timedelta(days=i*7)
|
||||
end_week = start_week + timedelta(days=6)
|
||||
if start_week.month == end_week.month:
|
||||
label = str(start_week.day) + '-' +str(end_week.day)+ ' ' + format_date(end_week, 'MMM', locale=self._context.get('lang') or 'en_US')
|
||||
else:
|
||||
label = format_date(start_week, 'd MMM', locale=self._context.get('lang') or 'en_US')+'-'+format_date(end_week, 'd MMM', locale=self._context.get('lang') or 'en_US')
|
||||
data.append({'label':label,'value':0.0, 'type': 'past' if i<0 else 'future'})
|
||||
|
||||
# Build SQL query to find amount aggregated by week
|
||||
select_sql_clause = """SELECT sum(residual_company_signed) as total, min(date) as aggr_date from account_invoice where journal_id = %(journal_id)s and state = 'open'"""
|
||||
query = ''
|
||||
start_date = (first_day_of_week + timedelta(days=-7))
|
||||
for i in range(0,6):
|
||||
if i == 0:
|
||||
query += "("+select_sql_clause+" and date < '"+start_date.strftime(DF)+"')"
|
||||
elif i == 5:
|
||||
query += " UNION ALL ("+select_sql_clause+" and date >= '"+start_date.strftime(DF)+"')"
|
||||
else:
|
||||
next_date = start_date + timedelta(days=7)
|
||||
query += " UNION ALL ("+select_sql_clause+" and date >= '"+start_date.strftime(DF)+"' and date < '"+next_date.strftime(DF)+"')"
|
||||
start_date = next_date
|
||||
|
||||
self.env.cr.execute(query, {'journal_id':self.id})
|
||||
query_results = self.env.cr.dictfetchall()
|
||||
for index in range(0, len(query_results)):
|
||||
if query_results[index].get('aggr_date') != None:
|
||||
data[index]['value'] = query_results[index].get('total')
|
||||
|
||||
return [{'values': data}]
|
||||
|
||||
@api.multi
|
||||
def get_journal_dashboard_datas(self):
|
||||
currency = self.currency_id or self.company_id.currency_id
|
||||
number_to_reconcile = last_balance = account_sum = 0
|
||||
ac_bnk_stmt = []
|
||||
title = ''
|
||||
number_draft = number_waiting = number_late = 0
|
||||
sum_draft = sum_waiting = sum_late = 0.0
|
||||
if self.type in ['bank', 'cash']:
|
||||
last_bank_stmt = self.env['account.bank.statement'].search([('journal_id', 'in', self.ids)], order="date desc, id desc", limit=1)
|
||||
last_balance = last_bank_stmt and last_bank_stmt[0].balance_end or 0
|
||||
#Get the number of items to reconcile for that bank journal
|
||||
self.env.cr.execute("""SELECT COUNT(DISTINCT(statement_line_id))
|
||||
FROM account_move where statement_line_id
|
||||
IN (SELECT line.id
|
||||
FROM account_bank_statement_line AS line
|
||||
LEFT JOIN account_bank_statement AS st
|
||||
ON line.statement_id = st.id
|
||||
WHERE st.journal_id IN %s and st.state = 'open')""", (tuple(self.ids),))
|
||||
already_reconciled = self.env.cr.fetchone()[0]
|
||||
self.env.cr.execute("""SELECT COUNT(line.id)
|
||||
FROM account_bank_statement_line AS line
|
||||
LEFT JOIN account_bank_statement AS st
|
||||
ON line.statement_id = st.id
|
||||
WHERE st.journal_id IN %s and st.state = 'open'""", (tuple(self.ids),))
|
||||
all_lines = self.env.cr.fetchone()[0]
|
||||
number_to_reconcile = all_lines - already_reconciled
|
||||
# optimization to read sum of balance from account_move_line
|
||||
account_ids = tuple(filter(None, [self.default_debit_account_id.id, self.default_credit_account_id.id]))
|
||||
if account_ids:
|
||||
amount_field = 'balance' if (not self.currency_id or self.currency_id == self.company_id.currency_id) else 'amount_currency'
|
||||
query = """SELECT sum(%s) FROM account_move_line WHERE account_id in %%s AND date <= %%s;""" % (amount_field,)
|
||||
self.env.cr.execute(query, (account_ids, fields.Date.today(),))
|
||||
query_results = self.env.cr.dictfetchall()
|
||||
if query_results and query_results[0].get('sum') != None:
|
||||
account_sum = query_results[0].get('sum')
|
||||
#TODO need to check if all invoices are in the same currency than the journal!!!!
|
||||
elif self.type in ['sale', 'purchase']:
|
||||
title = _('Bills to pay') if self.type == 'purchase' else _('Invoices owed to you')
|
||||
# optimization to find total and sum of invoice that are in draft, open state
|
||||
query = """SELECT state, amount_total, currency_id AS currency, type FROM account_invoice WHERE journal_id = %s AND state NOT IN ('paid', 'cancel');"""
|
||||
self.env.cr.execute(query, (self.id,))
|
||||
query_results = self.env.cr.dictfetchall()
|
||||
today = datetime.today()
|
||||
query = """SELECT amount_total, currency_id AS currency, type FROM account_invoice WHERE journal_id = %s AND date < %s AND state = 'open';"""
|
||||
self.env.cr.execute(query, (self.id, today))
|
||||
late_query_results = self.env.cr.dictfetchall()
|
||||
for result in query_results:
|
||||
if result['type'] in ['in_refund', 'out_refund']:
|
||||
factor = -1
|
||||
else:
|
||||
factor = 1
|
||||
cur = self.env['res.currency'].browse(result.get('currency'))
|
||||
if result.get('state') in ['draft', 'proforma', 'proforma2']:
|
||||
number_draft += 1
|
||||
sum_draft += cur.compute(result.get('amount_total'), currency) * factor
|
||||
elif result.get('state') == 'open':
|
||||
number_waiting += 1
|
||||
sum_waiting += cur.compute(result.get('amount_total'), currency) * factor
|
||||
for result in late_query_results:
|
||||
if result['type'] in ['in_refund', 'out_refund']:
|
||||
factor = -1
|
||||
else:
|
||||
factor = 1
|
||||
cur = self.env['res.currency'].browse(result.get('currency'))
|
||||
number_late += 1
|
||||
sum_late += cur.compute(result.get('amount_total'), currency) * factor
|
||||
|
||||
difference = currency.round(last_balance-account_sum) + 0.0
|
||||
return {
|
||||
'number_to_reconcile': number_to_reconcile,
|
||||
'account_balance': formatLang(self.env, currency.round(account_sum) + 0.0, currency_obj=currency),
|
||||
'last_balance': formatLang(self.env, currency.round(last_balance) + 0.0, currency_obj=currency),
|
||||
'difference': formatLang(self.env, difference, currency_obj=currency) if difference else False,
|
||||
'number_draft': number_draft,
|
||||
'number_waiting': number_waiting,
|
||||
'number_late': number_late,
|
||||
'sum_draft': formatLang(self.env, currency.round(sum_draft) + 0.0, currency_obj=currency),
|
||||
'sum_waiting': formatLang(self.env, currency.round(sum_waiting) + 0.0, currency_obj=currency),
|
||||
'sum_late': formatLang(self.env, currency.round(sum_late) + 0.0, currency_obj=currency),
|
||||
'currency_id': currency.id,
|
||||
'bank_statements_source': self.bank_statements_source,
|
||||
'title': title,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def action_create_new(self):
|
||||
ctx = self._context.copy()
|
||||
model = 'account.invoice'
|
||||
if self.type == 'sale':
|
||||
ctx.update({'journal_type': self.type, 'default_type': 'out_invoice', 'type': 'out_invoice', 'default_journal_id': self.id})
|
||||
if ctx.get('refund'):
|
||||
ctx.update({'default_type':'out_refund', 'type':'out_refund'})
|
||||
view_id = self.env.ref('account.invoice_form').id
|
||||
elif self.type == 'purchase':
|
||||
ctx.update({'journal_type': self.type, 'default_type': 'in_invoice', 'type': 'in_invoice', 'default_journal_id': self.id})
|
||||
if ctx.get('refund'):
|
||||
ctx.update({'default_type': 'in_refund', 'type': 'in_refund'})
|
||||
view_id = self.env.ref('account.invoice_supplier_form').id
|
||||
else:
|
||||
ctx.update({'default_journal_id': self.id})
|
||||
view_id = self.env.ref('account.view_move_form').id
|
||||
model = 'account.move'
|
||||
return {
|
||||
'name': _('Create invoice/bill'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': model,
|
||||
'view_id': view_id,
|
||||
'context': ctx,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def create_cash_statement(self):
|
||||
ctx = self._context.copy()
|
||||
ctx.update({'journal_id': self.id, 'default_journal_id': self.id, 'default_journal_type': 'cash'})
|
||||
return {
|
||||
'name': _('Create cash statement'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'account.bank.statement',
|
||||
'context': ctx,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def action_open_reconcile(self):
|
||||
if self.type in ['bank', 'cash']:
|
||||
# Open reconciliation view for bank statements belonging to this journal
|
||||
bank_stmt = self.env['account.bank.statement'].search([('journal_id', 'in', self.ids)])
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'bank_statement_reconciliation_view',
|
||||
'context': {'statement_ids': bank_stmt.ids, 'company_ids': self.mapped('company_id').ids},
|
||||
}
|
||||
else:
|
||||
# Open reconciliation view for customers/suppliers
|
||||
action_context = {'show_mode_selector': False, 'company_ids': self.mapped('company_id').ids}
|
||||
if self.type == 'sale':
|
||||
action_context.update({'mode': 'customers'})
|
||||
elif self.type == 'purchase':
|
||||
action_context.update({'mode': 'suppliers'})
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'manual_reconciliation_view',
|
||||
'context': action_context,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def open_action(self):
|
||||
"""return action based on type for related journals"""
|
||||
action_name = self._context.get('action_name', False)
|
||||
if not action_name:
|
||||
if self.type == 'bank':
|
||||
action_name = 'action_bank_statement_tree'
|
||||
elif self.type == 'cash':
|
||||
action_name = 'action_view_bank_statement_tree'
|
||||
elif self.type == 'sale':
|
||||
action_name = 'action_invoice_tree1'
|
||||
elif self.type == 'purchase':
|
||||
action_name = 'action_invoice_tree2'
|
||||
else:
|
||||
action_name = 'action_move_journal_line'
|
||||
|
||||
_journal_invoice_type_map = {
|
||||
('sale', None): 'out_invoice',
|
||||
('purchase', None): 'in_invoice',
|
||||
('sale', 'refund'): 'out_refund',
|
||||
('purchase', 'refund'): 'in_refund',
|
||||
('bank', None): 'bank',
|
||||
('cash', None): 'cash',
|
||||
('general', None): 'general',
|
||||
}
|
||||
invoice_type = _journal_invoice_type_map[(self.type, self._context.get('invoice_type'))]
|
||||
|
||||
ctx = self._context.copy()
|
||||
ctx.pop('group_by', None)
|
||||
ctx.update({
|
||||
'journal_type': self.type,
|
||||
'default_journal_id': self.id,
|
||||
'search_default_journal_id': self.id,
|
||||
'default_type': invoice_type,
|
||||
'type': invoice_type
|
||||
})
|
||||
|
||||
[action] = self.env.ref('account.%s' % action_name).read()
|
||||
action['context'] = ctx
|
||||
action['domain'] = self._context.get('use_domain', [])
|
||||
if action_name in ['action_bank_statement_tree', 'action_view_bank_statement_tree']:
|
||||
action['views'] = False
|
||||
action['view_id'] = False
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def open_spend_money(self):
|
||||
return self.open_payments_action('outbound')
|
||||
|
||||
@api.multi
|
||||
def open_collect_money(self):
|
||||
return self.open_payments_action('inbound')
|
||||
|
||||
@api.multi
|
||||
def open_transfer_money(self):
|
||||
return self.open_payments_action('transfer')
|
||||
|
||||
@api.multi
|
||||
def open_payments_action(self, payment_type):
|
||||
ctx = self._context.copy()
|
||||
ctx.update({
|
||||
'default_payment_type': payment_type,
|
||||
'default_journal_id': self.id
|
||||
})
|
||||
ctx.pop('group_by', None)
|
||||
action_rec = self.env['ir.model.data'].xmlid_to_object('account.action_account_payments')
|
||||
if action_rec:
|
||||
action = action_rec.read([])[0]
|
||||
action['context'] = ctx
|
||||
action['domain'] = [('journal_id','=',self.id),('payment_type','=',payment_type)]
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def open_action_with_context(self):
|
||||
action_name = self.env.context.get('action_name', False)
|
||||
if not action_name:
|
||||
return False
|
||||
ctx = dict(self.env.context, default_journal_id=self.id)
|
||||
if ctx.get('search_default_journal', False):
|
||||
ctx.update(search_default_journal_id=self.id)
|
||||
ctx.pop('group_by', None)
|
||||
ir_model_obj = self.env['ir.model.data']
|
||||
model, action_id = ir_model_obj.get_object_reference('account', action_name)
|
||||
[action] = self.env[model].browse(action_id).read()
|
||||
action['context'] = ctx
|
||||
if ctx.get('use_domain', False):
|
||||
action['domain'] = ['|', ('journal_id', '=', self.id), ('journal_id', '=', False)]
|
||||
action['name'] += ' for journal ' + self.name
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def create_bank_statement(self):
|
||||
"""return action to create a bank statements. This button should be called only on journals with type =='bank'"""
|
||||
self.bank_statements_source = 'manual'
|
||||
action = self.env.ref('account.action_bank_statement_tree').read()[0]
|
||||
action.update({
|
||||
'views': [[False, 'form']],
|
||||
'context': "{'default_journal_id': " + str(self.id) + "}",
|
||||
})
|
||||
return action
|
1637
addons/account/models/account_move.py
Normal file
1637
addons/account/models/account_move.py
Normal file
File diff suppressed because it is too large
Load Diff
568
addons/account/models/account_payment.py
Normal file
568
addons/account/models/account_payment.py
Normal file
@ -0,0 +1,568 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
MAP_INVOICE_TYPE_PARTNER_TYPE = {
|
||||
'out_invoice': 'customer',
|
||||
'out_refund': 'customer',
|
||||
'in_invoice': 'supplier',
|
||||
'in_refund': 'supplier',
|
||||
}
|
||||
# Since invoice amounts are unsigned, this is how we know if money comes in or goes out
|
||||
MAP_INVOICE_TYPE_PAYMENT_SIGN = {
|
||||
'out_invoice': 1,
|
||||
'in_refund': 1,
|
||||
'in_invoice': -1,
|
||||
'out_refund': -1,
|
||||
}
|
||||
|
||||
class account_payment_method(models.Model):
|
||||
_name = "account.payment.method"
|
||||
_description = "Payment Methods"
|
||||
|
||||
name = fields.Char(required=True, translate=True)
|
||||
code = fields.Char(required=True) # For internal identification
|
||||
payment_type = fields.Selection([('inbound', 'Inbound'), ('outbound', 'Outbound')], required=True)
|
||||
|
||||
|
||||
class account_abstract_payment(models.AbstractModel):
|
||||
_name = "account.abstract.payment"
|
||||
_description = "Contains the logic shared between models which allows to register payments"
|
||||
|
||||
payment_type = fields.Selection([('outbound', 'Send Money'), ('inbound', 'Receive Money')], string='Payment Type', required=True)
|
||||
payment_method_id = fields.Many2one('account.payment.method', string='Payment Method Type', required=True, oldname="payment_method")
|
||||
payment_method_code = fields.Char(related='payment_method_id.code',
|
||||
help="Technical field used to adapt the interface to the payment type selected.", readonly=True)
|
||||
|
||||
partner_type = fields.Selection([('customer', 'Customer'), ('supplier', 'Vendor')])
|
||||
partner_id = fields.Many2one('res.partner', string='Partner')
|
||||
|
||||
amount = fields.Monetary(string='Payment Amount', required=True)
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', required=True, default=lambda self: self.env.user.company_id.currency_id)
|
||||
payment_date = fields.Date(string='Payment Date', default=fields.Date.context_today, required=True, copy=False)
|
||||
communication = fields.Char(string='Memo')
|
||||
journal_id = fields.Many2one('account.journal', string='Payment Journal', required=True, domain=[('type', 'in', ('bank', 'cash'))])
|
||||
company_id = fields.Many2one('res.company', related='journal_id.company_id', string='Company', readonly=True)
|
||||
|
||||
hide_payment_method = fields.Boolean(compute='_compute_hide_payment_method',
|
||||
help="Technical field used to hide the payment method if the selected journal has only one available which is 'manual'")
|
||||
|
||||
@api.one
|
||||
@api.constrains('amount')
|
||||
def _check_amount(self):
|
||||
if not self.amount > 0.0:
|
||||
raise ValidationError(_('The payment amount must be strictly positive.'))
|
||||
|
||||
@api.one
|
||||
@api.depends('payment_type', 'journal_id')
|
||||
def _compute_hide_payment_method(self):
|
||||
if not self.journal_id:
|
||||
self.hide_payment_method = True
|
||||
return
|
||||
journal_payment_methods = self.payment_type == 'inbound' and self.journal_id.inbound_payment_method_ids or self.journal_id.outbound_payment_method_ids
|
||||
self.hide_payment_method = len(journal_payment_methods) == 1 and journal_payment_methods[0].code == 'manual'
|
||||
|
||||
@api.onchange('journal_id')
|
||||
def _onchange_journal(self):
|
||||
if self.journal_id:
|
||||
self.currency_id = self.journal_id.currency_id or self.company_id.currency_id
|
||||
# Set default payment method (we consider the first to be the default one)
|
||||
payment_methods = self.payment_type == 'inbound' and self.journal_id.inbound_payment_method_ids or self.journal_id.outbound_payment_method_ids
|
||||
self.payment_method_id = payment_methods and payment_methods[0] or False
|
||||
# Set payment method domain (restrict to methods enabled for the journal and to selected payment type)
|
||||
payment_type = self.payment_type in ('outbound', 'transfer') and 'outbound' or 'inbound'
|
||||
return {'domain': {'payment_method_id': [('payment_type', '=', payment_type), ('id', 'in', payment_methods.ids)]}}
|
||||
return {}
|
||||
|
||||
def _get_invoices(self):
|
||||
""" Return the invoices of the payment. Must be overridden """
|
||||
raise NotImplementedError
|
||||
|
||||
def _compute_total_invoices_amount(self):
|
||||
""" Compute the sum of the residual of invoices, expressed in the payment currency """
|
||||
payment_currency = self.currency_id or self.journal_id.currency_id or self.journal_id.company_id.currency_id or self.env.user.company_id.currency_id
|
||||
invoices = self._get_invoices()
|
||||
|
||||
if all(inv.currency_id == payment_currency for inv in invoices):
|
||||
total = sum(invoices.mapped('residual_signed'))
|
||||
else:
|
||||
total = 0
|
||||
for inv in invoices:
|
||||
if inv.company_currency_id != payment_currency:
|
||||
total += inv.company_currency_id.with_context(date=self.payment_date).compute(inv.residual_company_signed, payment_currency)
|
||||
else:
|
||||
total += inv.residual_company_signed
|
||||
return abs(total)
|
||||
|
||||
|
||||
class account_register_payments(models.TransientModel):
|
||||
_name = "account.register.payments"
|
||||
_inherit = 'account.abstract.payment'
|
||||
_description = "Register payments on multiple invoices"
|
||||
|
||||
@api.onchange('payment_type')
|
||||
def _onchange_payment_type(self):
|
||||
if self.payment_type:
|
||||
return {'domain': {'payment_method_id': [('payment_type', '=', self.payment_type)]}}
|
||||
|
||||
def _get_invoices(self):
|
||||
return self.env['account.invoice'].browse(self._context.get('active_ids'))
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
rec = super(account_register_payments, self).default_get(fields)
|
||||
context = dict(self._context or {})
|
||||
active_model = context.get('active_model')
|
||||
active_ids = context.get('active_ids')
|
||||
|
||||
# Checks on context parameters
|
||||
if not active_model or not active_ids:
|
||||
raise UserError(_("Programmation error: wizard action executed without active_model or active_ids in context."))
|
||||
if active_model != 'account.invoice':
|
||||
raise UserError(_("Programmation error: the expected model for this action is 'account.invoice'. The provided one is '%d'.") % active_model)
|
||||
|
||||
# Checks on received invoice records
|
||||
invoices = self.env[active_model].browse(active_ids)
|
||||
if any(invoice.state != 'open' for invoice in invoices):
|
||||
raise UserError(_("You can only register payments for open invoices"))
|
||||
if any(inv.commercial_partner_id != invoices[0].commercial_partner_id for inv in invoices):
|
||||
raise UserError(_("In order to pay multiple invoices at once, they must belong to the same commercial partner."))
|
||||
if any(MAP_INVOICE_TYPE_PARTNER_TYPE[inv.type] != MAP_INVOICE_TYPE_PARTNER_TYPE[invoices[0].type] for inv in invoices):
|
||||
raise UserError(_("You cannot mix customer invoices and vendor bills in a single payment."))
|
||||
if any(inv.currency_id != invoices[0].currency_id for inv in invoices):
|
||||
raise UserError(_("In order to pay multiple invoices at once, they must use the same currency."))
|
||||
|
||||
total_amount = sum(inv.residual * MAP_INVOICE_TYPE_PAYMENT_SIGN[inv.type] for inv in invoices)
|
||||
communication = ' '.join([ref for ref in invoices.mapped('reference') if ref])
|
||||
|
||||
rec.update({
|
||||
'amount': abs(total_amount),
|
||||
'currency_id': invoices[0].currency_id.id,
|
||||
'payment_type': total_amount > 0 and 'inbound' or 'outbound',
|
||||
'partner_id': invoices[0].commercial_partner_id.id,
|
||||
'partner_type': MAP_INVOICE_TYPE_PARTNER_TYPE[invoices[0].type],
|
||||
'communication': communication,
|
||||
})
|
||||
return rec
|
||||
|
||||
def get_payment_vals(self):
|
||||
""" Hook for extension """
|
||||
return {
|
||||
'journal_id': self.journal_id.id,
|
||||
'payment_method_id': self.payment_method_id.id,
|
||||
'payment_date': self.payment_date,
|
||||
'communication': self.communication,
|
||||
'invoice_ids': [(4, inv.id, None) for inv in self._get_invoices()],
|
||||
'payment_type': self.payment_type,
|
||||
'amount': self.amount,
|
||||
'currency_id': self.currency_id.id,
|
||||
'partner_id': self.partner_id.id,
|
||||
'partner_type': self.partner_type,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def create_payment(self):
|
||||
payment = self.env['account.payment'].create(self.get_payment_vals())
|
||||
payment.post()
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
|
||||
class account_payment(models.Model):
|
||||
_name = "account.payment"
|
||||
_inherit = 'account.abstract.payment'
|
||||
_description = "Payments"
|
||||
_order = "payment_date desc, name desc"
|
||||
|
||||
@api.one
|
||||
@api.depends('invoice_ids')
|
||||
def _get_has_invoices(self):
|
||||
self.has_invoices = bool(self.invoice_ids)
|
||||
|
||||
@api.one
|
||||
@api.depends('invoice_ids', 'amount', 'payment_date', 'currency_id')
|
||||
def _compute_payment_difference(self):
|
||||
if len(self.invoice_ids) == 0:
|
||||
return
|
||||
if self.invoice_ids[0].type in ['in_invoice', 'out_refund']:
|
||||
self.payment_difference = self.amount - self._compute_total_invoices_amount()
|
||||
else:
|
||||
self.payment_difference = self._compute_total_invoices_amount() - self.amount
|
||||
|
||||
company_id = fields.Many2one(store=True)
|
||||
|
||||
name = fields.Char(readonly=True, copy=False, default="Draft Payment") # The name is attributed upon post()
|
||||
state = fields.Selection([('draft', 'Draft'), ('posted', 'Posted'), ('sent', 'Sent'), ('reconciled', 'Reconciled')], readonly=True, default='draft', copy=False, string="Status")
|
||||
|
||||
payment_type = fields.Selection(selection_add=[('transfer', 'Internal Transfer')])
|
||||
payment_reference = fields.Char(copy=False, readonly=True, help="Reference of the document used to issue this payment. Eg. check number, file name, etc.")
|
||||
move_name = fields.Char(string='Journal Entry Name', readonly=True,
|
||||
default=False, copy=False,
|
||||
help="Technical field holding the number given to the journal entry, automatically set when the statement line is reconciled then stored to set the same number again if the line is cancelled, set to draft and re-processed again.")
|
||||
|
||||
# Money flows from the journal_id's default_debit_account_id or default_credit_account_id to the destination_account_id
|
||||
destination_account_id = fields.Many2one('account.account', compute='_compute_destination_account_id', readonly=True)
|
||||
# For money transfer, money goes from journal_id to a transfer account, then from the transfer account to destination_journal_id
|
||||
destination_journal_id = fields.Many2one('account.journal', string='Transfer To', domain=[('type', 'in', ('bank', 'cash'))])
|
||||
|
||||
invoice_ids = fields.Many2many('account.invoice', 'account_invoice_payment_rel', 'payment_id', 'invoice_id', string="Invoices", copy=False, readonly=True)
|
||||
has_invoices = fields.Boolean(compute="_get_has_invoices", help="Technical field used for usability purposes")
|
||||
payment_difference = fields.Monetary(compute='_compute_payment_difference', readonly=True)
|
||||
payment_difference_handling = fields.Selection([('open', 'Keep open'), ('reconcile', 'Mark invoice as fully paid')], default='open', string="Payment Difference", copy=False)
|
||||
writeoff_account_id = fields.Many2one('account.account', string="Difference Account", domain=[('deprecated', '=', False)], copy=False)
|
||||
|
||||
# FIXME: ondelete='restrict' not working (eg. cancel a bank statement reconciliation with a payment)
|
||||
move_line_ids = fields.One2many('account.move.line', 'payment_id', readonly=True, copy=False, ondelete='restrict')
|
||||
|
||||
def open_payment_matching_screen(self):
|
||||
# Open reconciliation view for customers/suppliers
|
||||
action_context = {'company_ids': [self.company_id.id], 'partner_ids': [self.partner_id.commercial_partner_id.id]}
|
||||
if self.partner_type == 'customer':
|
||||
action_context.update({'mode': 'customers'})
|
||||
elif self.partner_type == 'supplier':
|
||||
action_context.update({'mode': 'suppliers'})
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'manual_reconciliation_view',
|
||||
'context': action_context,
|
||||
}
|
||||
|
||||
@api.one
|
||||
@api.depends('invoice_ids', 'payment_type', 'partner_type', 'partner_id')
|
||||
def _compute_destination_account_id(self):
|
||||
if self.invoice_ids:
|
||||
self.destination_account_id = self.invoice_ids[0].account_id.id
|
||||
elif self.payment_type == 'transfer':
|
||||
if not self.company_id.transfer_account_id.id:
|
||||
raise UserError(_('Transfer account not defined on the company.'))
|
||||
self.destination_account_id = self.company_id.transfer_account_id.id
|
||||
elif self.partner_id:
|
||||
if self.partner_type == 'customer':
|
||||
self.destination_account_id = self.partner_id.property_account_receivable_id.id
|
||||
else:
|
||||
self.destination_account_id = self.partner_id.property_account_payable_id.id
|
||||
|
||||
@api.onchange('partner_type')
|
||||
def _onchange_partner_type(self):
|
||||
# Set partner_id domain
|
||||
if self.partner_type:
|
||||
return {'domain': {'partner_id': [(self.partner_type, '=', True)]}}
|
||||
|
||||
@api.onchange('payment_type')
|
||||
def _onchange_payment_type(self):
|
||||
if not self.invoice_ids:
|
||||
# Set default partner type for the payment type
|
||||
if self.payment_type == 'inbound':
|
||||
self.partner_type = 'customer'
|
||||
elif self.payment_type == 'outbound':
|
||||
self.partner_type = 'supplier'
|
||||
else:
|
||||
self.partner_type = False
|
||||
# Set payment method domain
|
||||
res = self._onchange_journal()
|
||||
if not res.get('domain', {}):
|
||||
res['domain'] = {}
|
||||
res['domain']['journal_id'] = self.payment_type == 'inbound' and [('at_least_one_inbound', '=', True)] or self.payment_type == 'outbound' and [('at_least_one_outbound', '=', True)] or []
|
||||
res['domain']['journal_id'].append(('type', 'in', ('bank', 'cash')))
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
rec = super(account_payment, self).default_get(fields)
|
||||
invoice_defaults = self.resolve_2many_commands('invoice_ids', rec.get('invoice_ids'))
|
||||
if invoice_defaults and len(invoice_defaults) == 1:
|
||||
invoice = invoice_defaults[0]
|
||||
rec['communication'] = invoice['reference'] or invoice['name'] or invoice['number']
|
||||
rec['currency_id'] = invoice['currency_id'][0]
|
||||
rec['payment_type'] = invoice['type'] in ('out_invoice', 'in_refund') and 'inbound' or 'outbound'
|
||||
rec['partner_type'] = MAP_INVOICE_TYPE_PARTNER_TYPE[invoice['type']]
|
||||
rec['partner_id'] = invoice['partner_id'][0]
|
||||
rec['amount'] = invoice['residual']
|
||||
return rec
|
||||
|
||||
def _get_invoices(self):
|
||||
return self.invoice_ids
|
||||
|
||||
@api.multi
|
||||
def button_journal_entries(self):
|
||||
return {
|
||||
'name': _('Journal Items'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'account.move.line',
|
||||
'view_id': False,
|
||||
'type': 'ir.actions.act_window',
|
||||
'domain': [('payment_id', 'in', self.ids)],
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def button_invoices(self):
|
||||
return {
|
||||
'name': _('Paid Invoices'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'account.invoice',
|
||||
'view_id': False,
|
||||
'type': 'ir.actions.act_window',
|
||||
'domain': [('id', 'in', [x.id for x in self.invoice_ids])],
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def button_dummy(self):
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def unreconcile(self):
|
||||
""" Set back the payments in 'posted' or 'sent' state, without deleting the journal entries.
|
||||
Called when cancelling a bank statement line linked to a pre-registered payment.
|
||||
"""
|
||||
for payment in self:
|
||||
if payment.payment_reference:
|
||||
payment.write({'state': 'sent'})
|
||||
else:
|
||||
payment.write({'state': 'posted'})
|
||||
|
||||
@api.multi
|
||||
def cancel(self):
|
||||
for rec in self:
|
||||
for move in rec.move_line_ids.mapped('move_id'):
|
||||
if rec.invoice_ids:
|
||||
move.line_ids.remove_move_reconcile()
|
||||
move.button_cancel()
|
||||
move.unlink()
|
||||
rec.state = 'draft'
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
if any(bool(rec.move_line_ids) for rec in self):
|
||||
raise UserError(_("You can not delete a payment that is already posted"))
|
||||
if any(rec.move_name for rec in self):
|
||||
raise UserError(_('It is not allowed to delete a payment that already created a journal entry since it would create a gap in the numbering. You should create the journal entry again and cancel it thanks to a regular revert.'))
|
||||
return super(account_payment, self).unlink()
|
||||
|
||||
@api.multi
|
||||
def post(self):
|
||||
""" Create the journal items for the payment and update the payment's state to 'posted'.
|
||||
A journal entry is created containing an item in the source liquidity account (selected journal's default_debit or default_credit)
|
||||
and another in the destination reconciliable account (see _compute_destination_account_id).
|
||||
If invoice_ids is not empty, there will be one reconciliable move line per invoice to reconcile with.
|
||||
If the payment is a transfer, a second journal entry is created in the destination journal to receive money from the transfer account.
|
||||
"""
|
||||
for rec in self:
|
||||
|
||||
if rec.state != 'draft':
|
||||
raise UserError(_("Only a draft payment can be posted. Trying to post a payment in state %s.") % rec.state)
|
||||
|
||||
if any(inv.state != 'open' for inv in rec.invoice_ids):
|
||||
raise ValidationError(_("The payment cannot be processed because the invoice is not open!"))
|
||||
|
||||
# Use the right sequence to set the name
|
||||
if rec.payment_type == 'transfer':
|
||||
sequence_code = 'account.payment.transfer'
|
||||
else:
|
||||
if rec.partner_type == 'customer':
|
||||
if rec.payment_type == 'inbound':
|
||||
sequence_code = 'account.payment.customer.invoice'
|
||||
if rec.payment_type == 'outbound':
|
||||
sequence_code = 'account.payment.customer.refund'
|
||||
if rec.partner_type == 'supplier':
|
||||
if rec.payment_type == 'inbound':
|
||||
sequence_code = 'account.payment.supplier.refund'
|
||||
if rec.payment_type == 'outbound':
|
||||
sequence_code = 'account.payment.supplier.invoice'
|
||||
rec.name = self.env['ir.sequence'].with_context(ir_sequence_date=rec.payment_date).next_by_code(sequence_code)
|
||||
if not rec.name and rec.payment_type != 'transfer':
|
||||
raise UserError(_("You have to define a sequence for %s in your company.") % (sequence_code,))
|
||||
|
||||
# Create the journal entry
|
||||
amount = rec.amount * (rec.payment_type in ('outbound', 'transfer') and 1 or -1)
|
||||
move = rec._create_payment_entry(amount)
|
||||
|
||||
# In case of a transfer, the first journal entry created debited the source liquidity account and credited
|
||||
# the transfer account. Now we debit the transfer account and credit the destination liquidity account.
|
||||
if rec.payment_type == 'transfer':
|
||||
transfer_credit_aml = move.line_ids.filtered(lambda r: r.account_id == rec.company_id.transfer_account_id)
|
||||
transfer_debit_aml = rec._create_transfer_entry(amount)
|
||||
(transfer_credit_aml + transfer_debit_aml).reconcile()
|
||||
|
||||
rec.write({'state': 'posted', 'move_name': move.name})
|
||||
|
||||
def _create_payment_entry(self, amount):
|
||||
""" Create a journal entry corresponding to a payment, if the payment references invoice(s) they are reconciled.
|
||||
Return the journal entry.
|
||||
"""
|
||||
aml_obj = self.env['account.move.line'].with_context(check_move_validity=False)
|
||||
invoice_currency = False
|
||||
if self.invoice_ids and all([x.currency_id == self.invoice_ids[0].currency_id for x in self.invoice_ids]):
|
||||
#if all the invoices selected share the same currency, record the paiement in that currency too
|
||||
invoice_currency = self.invoice_ids[0].currency_id
|
||||
debit, credit, amount_currency, currency_id = aml_obj.with_context(date=self.payment_date).compute_amount_fields(amount, self.currency_id, self.company_id.currency_id, invoice_currency)
|
||||
|
||||
move = self.env['account.move'].create(self._get_move_vals())
|
||||
|
||||
#Write line corresponding to invoice payment
|
||||
counterpart_aml_dict = self._get_shared_move_line_vals(debit, credit, amount_currency, move.id, False)
|
||||
counterpart_aml_dict.update(self._get_counterpart_move_line_vals(self.invoice_ids))
|
||||
counterpart_aml_dict.update({'currency_id': currency_id})
|
||||
counterpart_aml = aml_obj.create(counterpart_aml_dict)
|
||||
|
||||
#Reconcile with the invoices
|
||||
if self.payment_difference_handling == 'reconcile' and self.payment_difference:
|
||||
writeoff_line = self._get_shared_move_line_vals(0, 0, 0, move.id, False)
|
||||
amount_currency_wo, currency_id = aml_obj.with_context(date=self.payment_date).compute_amount_fields(self.payment_difference, self.currency_id, self.company_id.currency_id, invoice_currency)[2:]
|
||||
# the writeoff debit and credit must be computed from the invoice residual in company currency
|
||||
# minus the payment amount in company currency, and not from the payment difference in the payment currency
|
||||
# to avoid loss of precision during the currency rate computations. See revision 20935462a0cabeb45480ce70114ff2f4e91eaf79 for a detailed example.
|
||||
total_residual_company_signed = sum(invoice.residual_company_signed for invoice in self.invoice_ids)
|
||||
total_payment_company_signed = self.currency_id.with_context(date=self.payment_date).compute(self.amount, self.company_id.currency_id)
|
||||
if self.invoice_ids[0].type in ['in_invoice', 'out_refund']:
|
||||
amount_wo = total_payment_company_signed - total_residual_company_signed
|
||||
else:
|
||||
amount_wo = total_residual_company_signed - total_payment_company_signed
|
||||
# Align the sign of the secondary currency writeoff amount with the sign of the writeoff
|
||||
# amount in the company currency
|
||||
if amount_wo > 0:
|
||||
debit_wo = amount_wo
|
||||
credit_wo = 0.0
|
||||
amount_currency_wo = abs(amount_currency_wo)
|
||||
else:
|
||||
debit_wo = 0.0
|
||||
credit_wo = -amount_wo
|
||||
amount_currency_wo = -abs(amount_currency_wo)
|
||||
writeoff_line['name'] = _('Counterpart')
|
||||
writeoff_line['account_id'] = self.writeoff_account_id.id
|
||||
writeoff_line['debit'] = debit_wo
|
||||
writeoff_line['credit'] = credit_wo
|
||||
writeoff_line['amount_currency'] = amount_currency_wo
|
||||
writeoff_line['currency_id'] = currency_id
|
||||
writeoff_line = aml_obj.create(writeoff_line)
|
||||
if counterpart_aml['debit']:
|
||||
counterpart_aml['debit'] += credit_wo - debit_wo
|
||||
if counterpart_aml['credit']:
|
||||
counterpart_aml['credit'] += debit_wo - credit_wo
|
||||
counterpart_aml['amount_currency'] -= amount_currency_wo
|
||||
self.invoice_ids.register_payment(counterpart_aml)
|
||||
|
||||
#Write counterpart lines
|
||||
if not self.currency_id != self.company_id.currency_id:
|
||||
amount_currency = 0
|
||||
liquidity_aml_dict = self._get_shared_move_line_vals(credit, debit, -amount_currency, move.id, False)
|
||||
liquidity_aml_dict.update(self._get_liquidity_move_line_vals(-amount))
|
||||
aml_obj.create(liquidity_aml_dict)
|
||||
|
||||
move.post()
|
||||
return move
|
||||
|
||||
def _create_transfer_entry(self, amount):
|
||||
""" Create the journal entry corresponding to the 'incoming money' part of an internal transfer, return the reconciliable move line
|
||||
"""
|
||||
aml_obj = self.env['account.move.line'].with_context(check_move_validity=False)
|
||||
debit, credit, amount_currency, dummy = aml_obj.with_context(date=self.payment_date).compute_amount_fields(amount, self.currency_id, self.company_id.currency_id)
|
||||
amount_currency = self.destination_journal_id.currency_id and self.currency_id.with_context(date=self.payment_date).compute(amount, self.destination_journal_id.currency_id) or 0
|
||||
|
||||
dst_move = self.env['account.move'].create(self._get_move_vals(self.destination_journal_id))
|
||||
|
||||
dst_liquidity_aml_dict = self._get_shared_move_line_vals(debit, credit, amount_currency, dst_move.id)
|
||||
dst_liquidity_aml_dict.update({
|
||||
'name': _('Transfer from %s') % self.journal_id.name,
|
||||
'account_id': self.destination_journal_id.default_credit_account_id.id,
|
||||
'currency_id': self.destination_journal_id.currency_id.id,
|
||||
'payment_id': self.id,
|
||||
'journal_id': self.destination_journal_id.id})
|
||||
aml_obj.create(dst_liquidity_aml_dict)
|
||||
|
||||
transfer_debit_aml_dict = self._get_shared_move_line_vals(credit, debit, 0, dst_move.id)
|
||||
transfer_debit_aml_dict.update({
|
||||
'name': self.name,
|
||||
'payment_id': self.id,
|
||||
'account_id': self.company_id.transfer_account_id.id,
|
||||
'journal_id': self.destination_journal_id.id})
|
||||
if self.currency_id != self.company_id.currency_id:
|
||||
transfer_debit_aml_dict.update({
|
||||
'currency_id': self.currency_id.id,
|
||||
'amount_currency': -self.amount,
|
||||
})
|
||||
transfer_debit_aml = aml_obj.create(transfer_debit_aml_dict)
|
||||
dst_move.post()
|
||||
return transfer_debit_aml
|
||||
|
||||
def _get_move_vals(self, journal=None):
|
||||
""" Return dict to create the payment move
|
||||
"""
|
||||
journal = journal or self.journal_id
|
||||
if not journal.sequence_id:
|
||||
raise UserError(_('Configuration Error !'), _('The journal %s does not have a sequence, please specify one.') % journal.name)
|
||||
if not journal.sequence_id.active:
|
||||
raise UserError(_('Configuration Error !'), _('The sequence of journal %s is deactivated.') % journal.name)
|
||||
name = self.move_name or journal.with_context(ir_sequence_date=self.payment_date).sequence_id.next_by_id()
|
||||
return {
|
||||
'name': name,
|
||||
'date': self.payment_date,
|
||||
'ref': self.communication or '',
|
||||
'company_id': self.company_id.id,
|
||||
'journal_id': journal.id,
|
||||
}
|
||||
|
||||
def _get_shared_move_line_vals(self, debit, credit, amount_currency, move_id, invoice_id=False):
|
||||
""" Returns values common to both move lines (except for debit, credit and amount_currency which are reversed)
|
||||
"""
|
||||
return {
|
||||
'partner_id': self.payment_type in ('inbound', 'outbound') and self.env['res.partner']._find_accounting_partner(self.partner_id).id or False,
|
||||
'invoice_id': invoice_id and invoice_id.id or False,
|
||||
'move_id': move_id,
|
||||
'debit': debit,
|
||||
'credit': credit,
|
||||
'amount_currency': amount_currency or False,
|
||||
}
|
||||
|
||||
def _get_counterpart_move_line_vals(self, invoice=False):
|
||||
if self.payment_type == 'transfer':
|
||||
name = self.name
|
||||
else:
|
||||
name = ''
|
||||
if self.partner_type == 'customer':
|
||||
if self.payment_type == 'inbound':
|
||||
name += _("Customer Payment")
|
||||
elif self.payment_type == 'outbound':
|
||||
name += _("Customer Refund")
|
||||
elif self.partner_type == 'supplier':
|
||||
if self.payment_type == 'inbound':
|
||||
name += _("Vendor Refund")
|
||||
elif self.payment_type == 'outbound':
|
||||
name += _("Vendor Payment")
|
||||
if invoice:
|
||||
name += ': '
|
||||
for inv in invoice:
|
||||
if inv.move_id:
|
||||
name += inv.number + ', '
|
||||
name = name[:len(name)-2]
|
||||
return {
|
||||
'name': name,
|
||||
'account_id': self.destination_account_id.id,
|
||||
'journal_id': self.journal_id.id,
|
||||
'currency_id': self.currency_id != self.company_id.currency_id and self.currency_id.id or False,
|
||||
'payment_id': self.id,
|
||||
}
|
||||
|
||||
def _get_liquidity_move_line_vals(self, amount):
|
||||
name = self.name
|
||||
if self.payment_type == 'transfer':
|
||||
name = _('Transfer to %s') % self.destination_journal_id.name
|
||||
vals = {
|
||||
'name': name,
|
||||
'account_id': self.payment_type in ('outbound','transfer') and self.journal_id.default_debit_account_id.id or self.journal_id.default_credit_account_id.id,
|
||||
'payment_id': self.id,
|
||||
'journal_id': self.journal_id.id,
|
||||
'currency_id': self.currency_id != self.company_id.currency_id and self.currency_id.id or False,
|
||||
}
|
||||
|
||||
# If the journal has a currency specified, the journal item need to be expressed in this currency
|
||||
if self.journal_id.currency_id and self.currency_id != self.journal_id.currency_id:
|
||||
amount = self.currency_id.with_context(date=self.payment_date).compute(amount, self.journal_id.currency_id)
|
||||
debit, credit, amount_currency, dummy = self.env['account.move.line'].with_context(date=self.payment_date).compute_amount_fields(amount, self.journal_id.currency_id, self.company_id.currency_id)
|
||||
vals.update({
|
||||
'amount_currency': amount_currency,
|
||||
'currency_id': self.journal_id.currency_id.id,
|
||||
})
|
||||
|
||||
return vals
|
905
addons/account/models/chart_template.py
Normal file
905
addons/account/models/chart_template.py
Normal file
@ -0,0 +1,905 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo.exceptions import AccessError
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import SUPERUSER_ID
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
def migrate_set_tags_and_taxes_updatable(cr, registry, module):
|
||||
''' This is a utility function used to manually set the flag noupdate to False on tags and account tax templates on localization modules
|
||||
that need migration (for example in case of VAT report improvements)
|
||||
'''
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
xml_record_ids = env['ir.model.data'].search([
|
||||
('model', 'in', ['account.tax.template', 'account.account.tag']),
|
||||
('module', 'like', module)
|
||||
]).ids
|
||||
if xml_record_ids:
|
||||
cr.execute("update ir_model_data set noupdate = 'f' where id in %s", (tuple(xml_record_ids),))
|
||||
|
||||
def migrate_tags_on_taxes(cr, registry):
|
||||
''' This is a utiliy function to help migrate the tags of taxes when the localization has been modified on stable version. If
|
||||
called accordingly in a post_init_hooked function, it will reset the tags set on taxes as per their equivalent template.
|
||||
|
||||
Note: This unusual decision has been made in order to help the improvement of VAT reports on version 9.0, to have them more flexible
|
||||
and working out of the box when people are creating/using new taxes.
|
||||
'''
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
xml_records = env['ir.model.data'].search([
|
||||
('model', '=', 'account.tax.template'),
|
||||
('module', 'like', 'l10n_%')
|
||||
])
|
||||
tax_template_ids = [x['res_id'] for x in xml_records.sudo().read(['res_id'])]
|
||||
for tax_template in env['account.tax.template'].browse(tax_template_ids):
|
||||
tax_id = env['account.tax'].search([
|
||||
('name', '=', tax_template.name),
|
||||
('type_tax_use', '=', tax_template.type_tax_use),
|
||||
('description', '=', tax_template.description)
|
||||
])
|
||||
tax_id.sudo().write({'tag_ids': [(6, 0, tax_template.tag_ids.ids)]})
|
||||
|
||||
def preserve_existing_tags_on_taxes(cr, registry, module):
|
||||
''' This is a utility function used to preserve existing previous tags during upgrade of the module.'''
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
xml_records = env['ir.model.data'].search([('model', '=', 'account.account.tag'), ('module', 'like', module)])
|
||||
if xml_records:
|
||||
cr.execute("update ir_model_data set noupdate = 't' where id in %s", [tuple(xml_records.ids)])
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# Account Templates: Account, Tax, Tax Code and chart. + Wizard
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
|
||||
class AccountAccountTemplate(models.Model):
|
||||
_name = "account.account.template"
|
||||
_description = 'Templates for Accounts'
|
||||
_order = "code"
|
||||
|
||||
name = fields.Char(required=True, index=True)
|
||||
currency_id = fields.Many2one('res.currency', string='Account Currency', help="Forces all moves for this account to have this secondary currency.")
|
||||
code = fields.Char(size=64, required=True, index=True)
|
||||
user_type_id = fields.Many2one('account.account.type', string='Type', required=True, oldname='user_type',
|
||||
help="These types are defined according to your country. The type contains more information "\
|
||||
"about the account and its specificities.")
|
||||
reconcile = fields.Boolean(string='Allow Invoices & payments Matching', default=False,
|
||||
help="Check this option if you want the user to reconcile entries in this account.")
|
||||
note = fields.Text()
|
||||
tax_ids = fields.Many2many('account.tax.template', 'account_account_template_tax_rel', 'account_id', 'tax_id', string='Default Taxes')
|
||||
nocreate = fields.Boolean(string='Optional Create', default=False,
|
||||
help="If checked, the new chart of accounts will not contain this by default.")
|
||||
chart_template_id = fields.Many2one('account.chart.template', string='Chart Template',
|
||||
help="This optional field allow you to link an account template to a specific chart template that may differ from the one its root parent belongs to. This allow you "
|
||||
"to define chart templates that extend another and complete it with few new accounts (You don't need to define the whole structure that is common to both several times).")
|
||||
tag_ids = fields.Many2many('account.account.tag', 'account_account_template_account_tag', string='Account tag', help="Optional tags you may want to assign for custom reporting")
|
||||
|
||||
@api.multi
|
||||
@api.depends('name', 'code')
|
||||
def name_get(self):
|
||||
res = []
|
||||
for record in self:
|
||||
name = record.name
|
||||
if record.code:
|
||||
name = record.code + ' ' + name
|
||||
res.append((record.id, name))
|
||||
return res
|
||||
|
||||
|
||||
class AccountChartTemplate(models.Model):
|
||||
_name = "account.chart.template"
|
||||
_description = "Templates for Account Chart"
|
||||
|
||||
name = fields.Char(required=True)
|
||||
company_id = fields.Many2one('res.company', string='Company')
|
||||
parent_id = fields.Many2one('account.chart.template', string='Parent Chart Template')
|
||||
code_digits = fields.Integer(string='# of Digits', required=True, default=6, help="No. of Digits to use for account code")
|
||||
visible = fields.Boolean(string='Can be Visible?', default=True,
|
||||
help="Set this to False if you don't want this template to be used actively in the wizard that generate Chart of Accounts from "
|
||||
"templates, this is useful when you want to generate accounts of this template only when loading its child template.")
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', required=True)
|
||||
use_anglo_saxon = fields.Boolean(string="Use Anglo-Saxon accounting", default=False)
|
||||
complete_tax_set = fields.Boolean(string='Complete Set of Taxes', default=True,
|
||||
help="This boolean helps you to choose if you want to propose to the user to encode the sale and purchase rates or choose from list "
|
||||
"of taxes. This last choice assumes that the set of tax defined on this template is complete")
|
||||
account_ids = fields.One2many('account.account.template', 'chart_template_id', string='Associated Account Templates')
|
||||
tax_template_ids = fields.One2many('account.tax.template', 'chart_template_id', string='Tax Template List',
|
||||
help='List of all the taxes that have to be installed by the wizard')
|
||||
bank_account_code_prefix = fields.Char(string='Prefix of the bank accounts', oldname="bank_account_code_char")
|
||||
cash_account_code_prefix = fields.Char(string='Prefix of the main cash accounts')
|
||||
transfer_account_id = fields.Many2one('account.account.template', string='Transfer Account', required=True,
|
||||
domain=lambda self: [('reconcile', '=', True), ('user_type_id.id', '=', self.env.ref('account.data_account_type_current_assets').id)],
|
||||
help="Intermediary account used when moving money from a liquidity account to another")
|
||||
income_currency_exchange_account_id = fields.Many2one('account.account.template',
|
||||
string="Gain Exchange Rate Account", domain=[('internal_type', '=', 'other'), ('deprecated', '=', False)])
|
||||
expense_currency_exchange_account_id = fields.Many2one('account.account.template',
|
||||
string="Loss Exchange Rate Account", domain=[('internal_type', '=', 'other'), ('deprecated', '=', False)])
|
||||
property_account_receivable_id = fields.Many2one('account.account.template', string='Receivable Account', oldname="property_account_receivable")
|
||||
property_account_payable_id = fields.Many2one('account.account.template', string='Payable Account', oldname="property_account_payable")
|
||||
property_account_expense_categ_id = fields.Many2one('account.account.template', string='Category of Expense Account', oldname="property_account_expense_categ")
|
||||
property_account_income_categ_id = fields.Many2one('account.account.template', string='Category of Income Account', oldname="property_account_income_categ")
|
||||
property_account_expense_id = fields.Many2one('account.account.template', string='Expense Account on Product Template', oldname="property_account_expense")
|
||||
property_account_income_id = fields.Many2one('account.account.template', string='Income Account on Product Template', oldname="property_account_income")
|
||||
property_stock_account_input_categ_id = fields.Many2one('account.account.template', string="Input Account for Stock Valuation", oldname="property_stock_account_input_categ")
|
||||
property_stock_account_output_categ_id = fields.Many2one('account.account.template', string="Output Account for Stock Valuation", oldname="property_stock_account_output_categ")
|
||||
property_stock_valuation_account_id = fields.Many2one('account.account.template', string="Account Template for Stock Valuation")
|
||||
|
||||
@api.one
|
||||
def try_loading_for_current_company(self):
|
||||
self.ensure_one()
|
||||
company = self.env.user.company_id
|
||||
# If we don't have any chart of account on this company, install this chart of account
|
||||
if not company.chart_template_id:
|
||||
wizard = self.env['wizard.multi.charts.accounts'].create({
|
||||
'company_id': self.env.user.company_id.id,
|
||||
'chart_template_id': self.id,
|
||||
'code_digits': self.code_digits,
|
||||
'transfer_account_id': self.transfer_account_id.id,
|
||||
'currency_id': self.currency_id.id,
|
||||
'bank_account_code_prefix': self.bank_account_code_prefix,
|
||||
'cash_account_code_prefix': self.cash_account_code_prefix,
|
||||
})
|
||||
wizard.onchange_chart_template_id()
|
||||
wizard.execute()
|
||||
|
||||
@api.multi
|
||||
def open_select_template_wizard(self):
|
||||
# Add action to open wizard to select between several templates
|
||||
if not self.company_id.chart_template_id:
|
||||
todo = self.env['ir.actions.todo']
|
||||
action_rec = self.env['ir.model.data'].xmlid_to_object('account.action_wizard_multi_chart')
|
||||
if action_rec:
|
||||
todo.create({'action_id': action_rec.id, 'name': _('Choose Accounting Template'), 'type': 'automatic'})
|
||||
return True
|
||||
|
||||
@api.model
|
||||
def generate_journals(self, acc_template_ref, company, journals_dict=None):
|
||||
"""
|
||||
This method is used for creating journals.
|
||||
|
||||
:param chart_temp_id: Chart Template Id.
|
||||
:param acc_template_ref: Account templates reference.
|
||||
:param company_id: company_id selected from wizard.multi.charts.accounts.
|
||||
:returns: True
|
||||
"""
|
||||
JournalObj = self.env['account.journal']
|
||||
for vals_journal in self._prepare_all_journals(acc_template_ref, company, journals_dict=journals_dict):
|
||||
journal = JournalObj.create(vals_journal)
|
||||
if vals_journal['type'] == 'general' and vals_journal['code'] == _('EXCH'):
|
||||
company.write({'currency_exchange_journal_id': journal.id})
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def _prepare_all_journals(self, acc_template_ref, company, journals_dict=None):
|
||||
def _get_default_account(journal_vals, type='debit'):
|
||||
# Get the default accounts
|
||||
default_account = False
|
||||
if journal['type'] == 'sale':
|
||||
default_account = acc_template_ref.get(self.property_account_income_categ_id.id)
|
||||
elif journal['type'] == 'purchase':
|
||||
default_account = acc_template_ref.get(self.property_account_expense_categ_id.id)
|
||||
elif journal['type'] == 'general' and journal['code'] == _('EXCH'):
|
||||
if type=='credit':
|
||||
default_account = acc_template_ref.get(self.income_currency_exchange_account_id.id)
|
||||
else:
|
||||
default_account = acc_template_ref.get(self.expense_currency_exchange_account_id.id)
|
||||
return default_account
|
||||
|
||||
journals = [{'name': _('Customer Invoices'), 'type': 'sale', 'code': _('INV'), 'favorite': True, 'sequence': 5},
|
||||
{'name': _('Vendor Bills'), 'type': 'purchase', 'code': _('BILL'), 'favorite': True, 'sequence': 6},
|
||||
{'name': _('Miscellaneous Operations'), 'type': 'general', 'code': _('MISC'), 'favorite': False, 'sequence': 7},
|
||||
{'name': _('Exchange Difference'), 'type': 'general', 'code': _('EXCH'), 'favorite': False, 'sequence': 9},]
|
||||
if journals_dict != None:
|
||||
journals.extend(journals_dict)
|
||||
|
||||
self.ensure_one()
|
||||
journal_data = []
|
||||
for journal in journals:
|
||||
vals = {
|
||||
'type': journal['type'],
|
||||
'name': journal['name'],
|
||||
'code': journal['code'],
|
||||
'company_id': company.id,
|
||||
'default_credit_account_id': _get_default_account(journal, 'credit'),
|
||||
'default_debit_account_id': _get_default_account(journal, 'debit'),
|
||||
'show_on_dashboard': journal['favorite'],
|
||||
'sequence': journal['sequence']
|
||||
}
|
||||
journal_data.append(vals)
|
||||
return journal_data
|
||||
|
||||
@api.multi
|
||||
def generate_properties(self, acc_template_ref, company):
|
||||
"""
|
||||
This method used for creating properties.
|
||||
|
||||
:param self: chart templates for which we need to create properties
|
||||
:param acc_template_ref: Mapping between ids of account templates and real accounts created from them
|
||||
:param company_id: company_id selected from wizard.multi.charts.accounts.
|
||||
:returns: True
|
||||
"""
|
||||
self.ensure_one()
|
||||
PropertyObj = self.env['ir.property']
|
||||
todo_list = [
|
||||
('property_account_receivable_id', 'res.partner', 'account.account'),
|
||||
('property_account_payable_id', 'res.partner', 'account.account'),
|
||||
('property_account_expense_categ_id', 'product.category', 'account.account'),
|
||||
('property_account_income_categ_id', 'product.category', 'account.account'),
|
||||
('property_account_expense_id', 'product.template', 'account.account'),
|
||||
('property_account_income_id', 'product.template', 'account.account'),
|
||||
]
|
||||
for record in todo_list:
|
||||
account = getattr(self, record[0])
|
||||
value = account and 'account.account,' + str(acc_template_ref[account.id]) or False
|
||||
if value:
|
||||
field = self.env['ir.model.fields'].search([('name', '=', record[0]), ('model', '=', record[1]), ('relation', '=', record[2])], limit=1)
|
||||
vals = {
|
||||
'name': record[0],
|
||||
'company_id': company.id,
|
||||
'fields_id': field.id,
|
||||
'value': value,
|
||||
}
|
||||
properties = PropertyObj.search([('name', '=', record[0]), ('company_id', '=', company.id)])
|
||||
if properties:
|
||||
#the property exist: modify it
|
||||
properties.write(vals)
|
||||
else:
|
||||
#create the property
|
||||
PropertyObj.create(vals)
|
||||
stock_properties = [
|
||||
'property_stock_account_input_categ_id',
|
||||
'property_stock_account_output_categ_id',
|
||||
'property_stock_valuation_account_id',
|
||||
]
|
||||
for stock_property in stock_properties:
|
||||
account = getattr(self, stock_property)
|
||||
value = account and acc_template_ref[account.id] or False
|
||||
if value:
|
||||
company.write({stock_property: value})
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def _install_template(self, company, code_digits=None, transfer_account_id=None, obj_wizard=None, acc_ref=None, taxes_ref=None):
|
||||
""" Recursively load the template objects and create the real objects from them.
|
||||
|
||||
:param company: company the wizard is running for
|
||||
:param code_digits: number of digits the accounts code should have in the COA
|
||||
:param transfer_account_id: reference to the account template that will be used as intermediary account for transfers between 2 liquidity accounts
|
||||
:param obj_wizard: the current wizard for generating the COA from the templates
|
||||
:param acc_ref: Mapping between ids of account templates and real accounts created from them
|
||||
:param taxes_ref: Mapping between ids of tax templates and real taxes created from them
|
||||
:returns: tuple with a dictionary containing
|
||||
* the mapping between the account template ids and the ids of the real accounts that have been generated
|
||||
from them, as first item,
|
||||
* a similar dictionary for mapping the tax templates and taxes, as second item,
|
||||
:rtype: tuple(dict, dict, dict)
|
||||
"""
|
||||
self.ensure_one()
|
||||
if acc_ref is None:
|
||||
acc_ref = {}
|
||||
if taxes_ref is None:
|
||||
taxes_ref = {}
|
||||
if self.parent_id:
|
||||
tmp1, tmp2 = self.parent_id._install_template(company, code_digits=code_digits, transfer_account_id=transfer_account_id, acc_ref=acc_ref, taxes_ref=taxes_ref)
|
||||
acc_ref.update(tmp1)
|
||||
taxes_ref.update(tmp2)
|
||||
# Ensure, even if individually, that everything is translated according to the company's language.
|
||||
tmp1, tmp2 = self.with_context(lang=company.partner_id.lang)._load_template(company, code_digits=code_digits, transfer_account_id=transfer_account_id, account_ref=acc_ref, taxes_ref=taxes_ref)
|
||||
acc_ref.update(tmp1)
|
||||
taxes_ref.update(tmp2)
|
||||
return acc_ref, taxes_ref
|
||||
|
||||
@api.multi
|
||||
def _load_template(self, company, code_digits=None, transfer_account_id=None, account_ref=None, taxes_ref=None):
|
||||
""" Generate all the objects from the templates
|
||||
|
||||
:param company: company the wizard is running for
|
||||
:param code_digits: number of digits the accounts code should have in the COA
|
||||
:param transfer_account_id: reference to the account template that will be used as intermediary account for transfers between 2 liquidity accounts
|
||||
:param acc_ref: Mapping between ids of account templates and real accounts created from them
|
||||
:param taxes_ref: Mapping between ids of tax templates and real taxes created from them
|
||||
:returns: tuple with a dictionary containing
|
||||
* the mapping between the account template ids and the ids of the real accounts that have been generated
|
||||
from them, as first item,
|
||||
* a similar dictionary for mapping the tax templates and taxes, as second item,
|
||||
:rtype: tuple(dict, dict, dict)
|
||||
"""
|
||||
self.ensure_one()
|
||||
if account_ref is None:
|
||||
account_ref = {}
|
||||
if taxes_ref is None:
|
||||
taxes_ref = {}
|
||||
if not code_digits:
|
||||
code_digits = self.code_digits
|
||||
if not transfer_account_id:
|
||||
transfer_account_id = self.transfer_account_id
|
||||
AccountTaxObj = self.env['account.tax']
|
||||
|
||||
# Generate taxes from templates.
|
||||
generated_tax_res = self.tax_template_ids._generate_tax(company)
|
||||
taxes_ref.update(generated_tax_res['tax_template_to_tax'])
|
||||
|
||||
# Generating Accounts from templates.
|
||||
account_template_ref = self.generate_account(taxes_ref, account_ref, code_digits, company)
|
||||
account_ref.update(account_template_ref)
|
||||
|
||||
# writing account values after creation of accounts
|
||||
company.transfer_account_id = account_template_ref[transfer_account_id.id]
|
||||
for key, value in generated_tax_res['account_dict'].items():
|
||||
if value['refund_account_id'] or value['account_id']:
|
||||
AccountTaxObj.browse(key).write({
|
||||
'refund_account_id': account_ref.get(value['refund_account_id'], False),
|
||||
'account_id': account_ref.get(value['account_id'], False),
|
||||
})
|
||||
|
||||
# Create Journals - Only done for root chart template
|
||||
if not self.parent_id:
|
||||
self.generate_journals(account_ref, company)
|
||||
|
||||
# generate properties function
|
||||
self.generate_properties(account_ref, company)
|
||||
|
||||
# Generate Fiscal Position , Fiscal Position Accounts and Fiscal Position Taxes from templates
|
||||
self.generate_fiscal_position(taxes_ref, account_ref, company)
|
||||
|
||||
# Generate account operation template templates
|
||||
self.generate_account_reconcile_model(taxes_ref, account_ref, company)
|
||||
|
||||
return account_ref, taxes_ref
|
||||
|
||||
@api.multi
|
||||
def create_record_with_xmlid(self, company, template, model, vals):
|
||||
# Create a record for the given model with the given vals and
|
||||
# also create an entry in ir_model_data to have an xmlid for the newly created record
|
||||
# xmlid is the concatenation of company_id and template_xml_id
|
||||
ir_model_data = self.env['ir.model.data']
|
||||
template_xmlid = ir_model_data.search([('model', '=', template._name), ('res_id', '=', template.id)])
|
||||
new_xml_id = str(company.id)+'_'+template_xmlid.name
|
||||
return ir_model_data._update(model, template_xmlid.module, vals, xml_id=new_xml_id, store=True, noupdate=True, mode='init', res_id=False)
|
||||
|
||||
def _get_account_vals(self, company, account_template, code_acc, tax_template_ref):
|
||||
""" This method generates a dictionnary of all the values for the account that will be created.
|
||||
"""
|
||||
self.ensure_one()
|
||||
tax_ids = []
|
||||
for tax in account_template.tax_ids:
|
||||
tax_ids.append(tax_template_ref[tax.id])
|
||||
val = {
|
||||
'name': account_template.name,
|
||||
'currency_id': account_template.currency_id and account_template.currency_id.id or False,
|
||||
'code': code_acc,
|
||||
'user_type_id': account_template.user_type_id and account_template.user_type_id.id or False,
|
||||
'reconcile': account_template.reconcile,
|
||||
'note': account_template.note,
|
||||
'tax_ids': [(6, 0, tax_ids)],
|
||||
'company_id': company.id,
|
||||
'tag_ids': [(6, 0, [t.id for t in account_template.tag_ids])],
|
||||
}
|
||||
return val
|
||||
|
||||
@api.multi
|
||||
def generate_account(self, tax_template_ref, acc_template_ref, code_digits, company):
|
||||
""" This method for generating accounts from templates.
|
||||
|
||||
:param tax_template_ref: Taxes templates reference for write taxes_id in account_account.
|
||||
:param acc_template_ref: dictionary with the mappping between the account templates and the real accounts.
|
||||
:param code_digits: number of digits got from wizard.multi.charts.accounts, this is use for account code.
|
||||
:param company_id: company_id selected from wizard.multi.charts.accounts.
|
||||
:returns: return acc_template_ref for reference purpose.
|
||||
:rtype: dict
|
||||
"""
|
||||
self.ensure_one()
|
||||
account_tmpl_obj = self.env['account.account.template']
|
||||
acc_template = account_tmpl_obj.search([('nocreate', '!=', True), ('chart_template_id', '=', self.id)], order='id')
|
||||
for account_template in acc_template:
|
||||
code_main = account_template.code and len(account_template.code) or 0
|
||||
code_acc = account_template.code or ''
|
||||
if code_main > 0 and code_main <= code_digits:
|
||||
code_acc = str(code_acc) + (str('0'*(code_digits-code_main)))
|
||||
vals = self._get_account_vals(company, account_template, code_acc, tax_template_ref)
|
||||
new_account = self.create_record_with_xmlid(company, account_template, 'account.account', vals)
|
||||
acc_template_ref[account_template.id] = new_account
|
||||
return acc_template_ref
|
||||
|
||||
def _prepare_reconcile_model_vals(self, company, account_reconcile_model, acc_template_ref, tax_template_ref):
|
||||
""" This method generates a dictionnary of all the values for the account.reconcile.model that will be created.
|
||||
"""
|
||||
self.ensure_one()
|
||||
return {
|
||||
'name': account_reconcile_model.name,
|
||||
'sequence': account_reconcile_model.sequence,
|
||||
'has_second_line': account_reconcile_model.has_second_line,
|
||||
'company_id': company.id,
|
||||
'account_id': acc_template_ref[account_reconcile_model.account_id.id],
|
||||
'label': account_reconcile_model.label,
|
||||
'amount_type': account_reconcile_model.amount_type,
|
||||
'amount': account_reconcile_model.amount,
|
||||
'tax_id': account_reconcile_model.tax_id and tax_template_ref[account_reconcile_model.tax_id.id] or False,
|
||||
'second_account_id': account_reconcile_model.second_account_id and acc_template_ref[account_reconcile_model.second_account_id.id] or False,
|
||||
'second_label': account_reconcile_model.second_label,
|
||||
'second_amount_type': account_reconcile_model.second_amount_type,
|
||||
'second_amount': account_reconcile_model.second_amount,
|
||||
'second_tax_id': account_reconcile_model.second_tax_id and tax_template_ref[account_reconcile_model.second_tax_id.id] or False,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def generate_account_reconcile_model(self, tax_template_ref, acc_template_ref, company):
|
||||
""" This method for generating accounts from templates.
|
||||
|
||||
:param tax_template_ref: Taxes templates reference for write taxes_id in account_account.
|
||||
:param acc_template_ref: dictionary with the mappping between the account templates and the real accounts.
|
||||
:param company_id: company_id selected from wizard.multi.charts.accounts.
|
||||
:returns: return new_account_reconcile_model for reference purpose.
|
||||
:rtype: dict
|
||||
"""
|
||||
self.ensure_one()
|
||||
account_reconcile_models = self.env['account.reconcile.model.template'].search([
|
||||
('account_id.chart_template_id', '=', self.id)
|
||||
])
|
||||
for account_reconcile_model in account_reconcile_models:
|
||||
vals = self._prepare_reconcile_model_vals(company, account_reconcile_model, acc_template_ref, tax_template_ref)
|
||||
self.create_record_with_xmlid(company, account_reconcile_model, 'account.reconcile.model', vals)
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def generate_fiscal_position(self, tax_template_ref, acc_template_ref, company):
|
||||
""" This method generate Fiscal Position, Fiscal Position Accounts and Fiscal Position Taxes from templates.
|
||||
|
||||
:param chart_temp_id: Chart Template Id.
|
||||
:param taxes_ids: Taxes templates reference for generating account.fiscal.position.tax.
|
||||
:param acc_template_ref: Account templates reference for generating account.fiscal.position.account.
|
||||
:param company_id: company_id selected from wizard.multi.charts.accounts.
|
||||
:returns: True
|
||||
"""
|
||||
self.ensure_one()
|
||||
positions = self.env['account.fiscal.position.template'].search([('chart_template_id', '=', self.id)])
|
||||
for position in positions:
|
||||
new_fp = self.create_record_with_xmlid(company, position, 'account.fiscal.position', {'company_id': company.id, 'name': position.name, 'note': position.note})
|
||||
for tax in position.tax_ids:
|
||||
self.create_record_with_xmlid(company, tax, 'account.fiscal.position.tax', {
|
||||
'tax_src_id': tax_template_ref[tax.tax_src_id.id],
|
||||
'tax_dest_id': tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False,
|
||||
'position_id': new_fp
|
||||
})
|
||||
for acc in position.account_ids:
|
||||
self.create_record_with_xmlid(company, acc, 'account.fiscal.position.account', {
|
||||
'account_src_id': acc_template_ref[acc.account_src_id.id],
|
||||
'account_dest_id': acc_template_ref[acc.account_dest_id.id],
|
||||
'position_id': new_fp
|
||||
})
|
||||
return True
|
||||
|
||||
|
||||
class AccountTaxTemplate(models.Model):
|
||||
_name = 'account.tax.template'
|
||||
_description = 'Templates for Taxes'
|
||||
_order = 'id'
|
||||
|
||||
chart_template_id = fields.Many2one('account.chart.template', string='Chart Template', required=True)
|
||||
|
||||
name = fields.Char(string='Tax Name', required=True)
|
||||
type_tax_use = fields.Selection([('sale', 'Sales'), ('purchase', 'Purchases'), ('none', 'None')], string='Tax Scope', required=True, default="sale",
|
||||
help="Determines where the tax is selectable. Note : 'None' means a tax can't be used by itself, however it can still be used in a group.")
|
||||
amount_type = fields.Selection(default='percent', string="Tax Computation", required=True,
|
||||
selection=[('group', 'Group of Taxes'), ('fixed', 'Fixed'), ('percent', 'Percentage of Price'), ('division', 'Percentage of Price Tax Included')])
|
||||
active = fields.Boolean(default=True, help="Set active to false to hide the tax without removing it.")
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.user.company_id)
|
||||
children_tax_ids = fields.Many2many('account.tax.template', 'account_tax_template_filiation_rel', 'parent_tax', 'child_tax', string='Children Taxes')
|
||||
sequence = fields.Integer(required=True, default=1,
|
||||
help="The sequence field is used to define order in which the tax lines are applied.")
|
||||
amount = fields.Float(required=True, digits=(16, 4))
|
||||
account_id = fields.Many2one('account.account.template', string='Tax Account', ondelete='restrict',
|
||||
help="Account that will be set on invoice tax lines for invoices. Leave empty to use the expense account.", oldname='account_collected_id')
|
||||
refund_account_id = fields.Many2one('account.account.template', string='Tax Account on Refunds', ondelete='restrict',
|
||||
help="Account that will be set on invoice tax lines for refunds. Leave empty to use the expense account.", oldname='account_paid_id')
|
||||
description = fields.Char(string='Display on Invoices')
|
||||
price_include = fields.Boolean(string='Included in Price', default=False,
|
||||
help="Check this if the price you use on the product and invoices includes this tax.")
|
||||
include_base_amount = fields.Boolean(string='Affect Subsequent Taxes', default=False,
|
||||
help="If set, taxes which are computed after this one will be computed based on the price tax included.")
|
||||
analytic = fields.Boolean(string="Analytic Cost", help="If set, the amount computed by this tax will be assigned to the same analytic account as the invoice line (if any)")
|
||||
tag_ids = fields.Many2many('account.account.tag', string='Account tag', help="Optional tags you may want to assign for custom reporting")
|
||||
tax_group_id = fields.Many2one('account.tax.group', string="Tax Group")
|
||||
tax_adjustment = fields.Boolean(default=False)
|
||||
|
||||
_sql_constraints = [
|
||||
('name_company_uniq', 'unique(name, company_id, type_tax_use)', 'Tax names must be unique !'),
|
||||
]
|
||||
|
||||
@api.multi
|
||||
@api.depends('name', 'description')
|
||||
def name_get(self):
|
||||
res = []
|
||||
for record in self:
|
||||
name = record.description and record.description or record.name
|
||||
res.append((record.id, name))
|
||||
return res
|
||||
|
||||
def _get_tax_vals(self, company):
|
||||
""" This method generates a dictionnary of all the values for the tax that will be created.
|
||||
"""
|
||||
self.ensure_one()
|
||||
val = {
|
||||
'name': self.name,
|
||||
'type_tax_use': self.type_tax_use,
|
||||
'amount_type': self.amount_type,
|
||||
'active': self.active,
|
||||
'company_id': company.id,
|
||||
'sequence': self.sequence,
|
||||
'amount': self.amount,
|
||||
'description': self.description,
|
||||
'price_include': self.price_include,
|
||||
'include_base_amount': self.include_base_amount,
|
||||
'analytic': self.analytic,
|
||||
'tag_ids': [(6, 0, [t.id for t in self.tag_ids])],
|
||||
'tax_adjustment': self.tax_adjustment,
|
||||
}
|
||||
if self.tax_group_id:
|
||||
val['tax_group_id'] = self.tax_group_id.id
|
||||
return val
|
||||
|
||||
@api.multi
|
||||
def _generate_tax(self, company):
|
||||
""" This method generate taxes from templates.
|
||||
|
||||
:param company: the company for which the taxes should be created from templates in self
|
||||
:returns: {
|
||||
'tax_template_to_tax': mapping between tax template and the newly generated taxes corresponding,
|
||||
'account_dict': dictionary containing a to-do list with all the accounts to assign on new taxes
|
||||
}
|
||||
"""
|
||||
todo_dict = {}
|
||||
tax_template_to_tax = {}
|
||||
for tax in self:
|
||||
# Compute children tax ids
|
||||
children_ids = []
|
||||
for child_tax in tax.children_tax_ids:
|
||||
if tax_template_to_tax.get(child_tax.id):
|
||||
children_ids.append(tax_template_to_tax[child_tax.id])
|
||||
vals_tax = tax._get_tax_vals(company)
|
||||
vals_tax['children_tax_ids'] = children_ids and [(6, 0, children_ids)] or []
|
||||
new_tax = self.env['account.chart.template'].create_record_with_xmlid(company, tax, 'account.tax', vals_tax)
|
||||
tax_template_to_tax[tax.id] = new_tax
|
||||
# Since the accounts have not been created yet, we have to wait before filling these fields
|
||||
todo_dict[new_tax] = {
|
||||
'account_id': tax.account_id.id,
|
||||
'refund_account_id': tax.refund_account_id.id,
|
||||
}
|
||||
|
||||
return {
|
||||
'tax_template_to_tax': tax_template_to_tax,
|
||||
'account_dict': todo_dict
|
||||
}
|
||||
|
||||
|
||||
# Fiscal Position Templates
|
||||
|
||||
class AccountFiscalPositionTemplate(models.Model):
|
||||
_name = 'account.fiscal.position.template'
|
||||
_description = 'Template for Fiscal Position'
|
||||
|
||||
name = fields.Char(string='Fiscal Position Template', required=True)
|
||||
chart_template_id = fields.Many2one('account.chart.template', string='Chart Template', required=True)
|
||||
account_ids = fields.One2many('account.fiscal.position.account.template', 'position_id', string='Account Mapping')
|
||||
tax_ids = fields.One2many('account.fiscal.position.tax.template', 'position_id', string='Tax Mapping')
|
||||
note = fields.Text(string='Notes')
|
||||
|
||||
|
||||
class AccountFiscalPositionTaxTemplate(models.Model):
|
||||
_name = 'account.fiscal.position.tax.template'
|
||||
_description = 'Template Tax Fiscal Position'
|
||||
_rec_name = 'position_id'
|
||||
|
||||
position_id = fields.Many2one('account.fiscal.position.template', string='Fiscal Position', required=True, ondelete='cascade')
|
||||
tax_src_id = fields.Many2one('account.tax.template', string='Tax Source', required=True)
|
||||
tax_dest_id = fields.Many2one('account.tax.template', string='Replacement Tax')
|
||||
|
||||
|
||||
class AccountFiscalPositionAccountTemplate(models.Model):
|
||||
_name = 'account.fiscal.position.account.template'
|
||||
_description = 'Template Account Fiscal Mapping'
|
||||
_rec_name = 'position_id'
|
||||
|
||||
position_id = fields.Many2one('account.fiscal.position.template', string='Fiscal Mapping', required=True, ondelete='cascade')
|
||||
account_src_id = fields.Many2one('account.account.template', string='Account Source', required=True)
|
||||
account_dest_id = fields.Many2one('account.account.template', string='Account Destination', required=True)
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Account generation from template wizards
|
||||
# ---------------------------------------------------------
|
||||
|
||||
|
||||
class WizardMultiChartsAccounts(models.TransientModel):
|
||||
"""
|
||||
Create a new account chart for a company.
|
||||
Wizards ask for:
|
||||
* a company
|
||||
* an account chart template
|
||||
* a number of digits for formatting code of non-view accounts
|
||||
* a list of bank accounts owned by the company
|
||||
Then, the wizard:
|
||||
* generates all accounts from the template and assigns them to the right company
|
||||
* generates all taxes and tax codes, changing account assignations
|
||||
* generates all accounting properties and assigns them correctly
|
||||
"""
|
||||
|
||||
_name = 'wizard.multi.charts.accounts'
|
||||
_inherit = 'res.config'
|
||||
|
||||
company_id = fields.Many2one('res.company', string='Company', required=True)
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', help="Currency as per company's country.", required=True)
|
||||
only_one_chart_template = fields.Boolean(string='Only One Chart Template Available')
|
||||
chart_template_id = fields.Many2one('account.chart.template', string='Chart Template', required=True)
|
||||
bank_account_ids = fields.One2many('account.bank.accounts.wizard', 'bank_account_id', string='Cash and Banks', required=True, oldname="bank_accounts_id")
|
||||
bank_account_code_prefix = fields.Char('Bank Accounts Prefix', oldname="bank_account_code_char")
|
||||
cash_account_code_prefix = fields.Char('Cash Accounts Prefix')
|
||||
code_digits = fields.Integer(string='# of Digits', required=True, help="No. of Digits to use for account code")
|
||||
sale_tax_id = fields.Many2one('account.tax.template', string='Default Sales Tax', oldname="sale_tax")
|
||||
purchase_tax_id = fields.Many2one('account.tax.template', string='Default Purchase Tax', oldname="purchase_tax")
|
||||
sale_tax_rate = fields.Float(string='Sales Tax(%)')
|
||||
use_anglo_saxon = fields.Boolean(string='Use Anglo-Saxon Accounting', related='chart_template_id.use_anglo_saxon')
|
||||
transfer_account_id = fields.Many2one('account.account.template', required=True, string='Transfer Account',
|
||||
domain=lambda self: [('reconcile', '=', True), ('user_type_id.id', '=', self.env.ref('account.data_account_type_current_assets').id)],
|
||||
help="Intermediary account used when moving money from a liquidity account to another")
|
||||
purchase_tax_rate = fields.Float(string='Purchase Tax(%)')
|
||||
complete_tax_set = fields.Boolean('Complete Set of Taxes',
|
||||
help="This boolean helps you to choose if you want to propose to the user to encode the sales and purchase rates or use "
|
||||
"the usual m2o fields. This last choice assumes that the set of tax defined for the chosen template is complete")
|
||||
|
||||
@api.model
|
||||
def _get_chart_parent_ids(self, chart_template):
|
||||
""" Returns the IDs of all ancestor charts, including the chart itself.
|
||||
(inverse of child_of operator)
|
||||
|
||||
:param browse_record chart_template: the account.chart.template record
|
||||
:return: the IDS of all ancestor charts, including the chart itself.
|
||||
"""
|
||||
result = [chart_template.id]
|
||||
while chart_template.parent_id:
|
||||
chart_template = chart_template.parent_id
|
||||
result.append(chart_template.id)
|
||||
return result
|
||||
|
||||
@api.onchange('sale_tax_rate')
|
||||
def onchange_tax_rate(self):
|
||||
self.purchase_tax_rate = self.sale_tax_rate or False
|
||||
|
||||
@api.onchange('chart_template_id')
|
||||
def onchange_chart_template_id(self):
|
||||
res = {}
|
||||
tax_templ_obj = self.env['account.tax.template']
|
||||
if self.chart_template_id:
|
||||
currency_id = self.chart_template_id.currency_id and self.chart_template_id.currency_id.id or self.env.user.company_id.currency_id.id
|
||||
self.complete_tax_set = self.chart_template_id.complete_tax_set
|
||||
self.currency_id = currency_id
|
||||
if self.chart_template_id.complete_tax_set:
|
||||
# default tax is given by the lowest sequence. For same sequence we will take the latest created as it will be the case for tax created while isntalling the generic chart of account
|
||||
chart_ids = self._get_chart_parent_ids(self.chart_template_id)
|
||||
base_tax_domain = [('chart_template_id', 'parent_of', chart_ids)]
|
||||
sale_tax_domain = base_tax_domain + [('type_tax_use', '=', 'sale')]
|
||||
purchase_tax_domain = base_tax_domain + [('type_tax_use', '=', 'purchase')]
|
||||
sale_tax = tax_templ_obj.search(sale_tax_domain, order="sequence, id desc", limit=1)
|
||||
purchase_tax = tax_templ_obj.search(purchase_tax_domain, order="sequence, id desc", limit=1)
|
||||
self.sale_tax_id = sale_tax.id
|
||||
self.purchase_tax_id = purchase_tax.id
|
||||
res.setdefault('domain', {})
|
||||
res['domain']['sale_tax_id'] = repr(sale_tax_domain)
|
||||
res['domain']['purchase_tax_id'] = repr(purchase_tax_domain)
|
||||
if self.chart_template_id.transfer_account_id:
|
||||
self.transfer_account_id = self.chart_template_id.transfer_account_id.id
|
||||
if self.chart_template_id.code_digits:
|
||||
self.code_digits = self.chart_template_id.code_digits
|
||||
if self.chart_template_id.bank_account_code_prefix:
|
||||
self.bank_account_code_prefix = self.chart_template_id.bank_account_code_prefix
|
||||
if self.chart_template_id.cash_account_code_prefix:
|
||||
self.cash_account_code_prefix = self.chart_template_id.cash_account_code_prefix
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _get_default_bank_account_ids(self):
|
||||
return [{'acc_name': _('Cash'), 'account_type': 'cash'}, {'acc_name': _('Bank'), 'account_type': 'bank'}]
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
context = self._context or {}
|
||||
res = super(WizardMultiChartsAccounts, self).default_get(fields)
|
||||
tax_templ_obj = self.env['account.tax.template']
|
||||
account_chart_template = self.env['account.chart.template']
|
||||
|
||||
if 'bank_account_ids' in fields:
|
||||
res.update({'bank_account_ids': self._get_default_bank_account_ids()})
|
||||
if 'company_id' in fields:
|
||||
res.update({'company_id': self.env.user.company_id.id})
|
||||
if 'currency_id' in fields:
|
||||
company_id = res.get('company_id') or False
|
||||
if company_id:
|
||||
company = self.env['res.company'].browse(company_id)
|
||||
currency_id = company.on_change_country(company.country_id.id)['value']['currency_id']
|
||||
res.update({'currency_id': currency_id})
|
||||
|
||||
chart_templates = account_chart_template.search([('visible', '=', True)])
|
||||
if chart_templates:
|
||||
#in order to set default chart which was last created set max of ids.
|
||||
chart_id = max(chart_templates.ids)
|
||||
if context.get("default_charts"):
|
||||
model_data = self.env['ir.model.data'].search_read([('model', '=', 'account.chart.template'), ('module', '=', context.get("default_charts"))], ['res_id'])
|
||||
if model_data:
|
||||
chart_id = model_data[0]['res_id']
|
||||
chart = account_chart_template.browse(chart_id)
|
||||
chart_hierarchy_ids = self._get_chart_parent_ids(chart)
|
||||
if 'chart_template_id' in fields:
|
||||
res.update({'only_one_chart_template': len(chart_templates) == 1,
|
||||
'chart_template_id': chart_id})
|
||||
if 'sale_tax_id' in fields:
|
||||
sale_tax = tax_templ_obj.search([('chart_template_id', 'in', chart_hierarchy_ids),
|
||||
('type_tax_use', '=', 'sale')], limit=1, order='sequence')
|
||||
res.update({'sale_tax_id': sale_tax and sale_tax.id or False})
|
||||
if 'purchase_tax_id' in fields:
|
||||
purchase_tax = tax_templ_obj.search([('chart_template_id', 'in', chart_hierarchy_ids),
|
||||
('type_tax_use', '=', 'purchase')], limit=1, order='sequence')
|
||||
res.update({'purchase_tax_id': purchase_tax and purchase_tax.id or False})
|
||||
res.update({
|
||||
'purchase_tax_rate': 15.0,
|
||||
'sale_tax_rate': 15.0,
|
||||
})
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
|
||||
context = self._context or {}
|
||||
res = super(WizardMultiChartsAccounts, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=False)
|
||||
cmp_select = []
|
||||
CompanyObj = self.env['res.company']
|
||||
|
||||
companies = CompanyObj.search([])
|
||||
#display in the widget selection of companies, only the companies that haven't been configured yet (but don't care about the demo chart of accounts)
|
||||
self._cr.execute("SELECT company_id FROM account_account WHERE deprecated = 'f' AND name != 'Chart For Automated Tests' AND name NOT LIKE '%(test)'")
|
||||
configured_cmp = [r[0] for r in self._cr.fetchall()]
|
||||
unconfigured_cmp = list(set(companies.ids) - set(configured_cmp))
|
||||
for field in res['fields']:
|
||||
if field == 'company_id':
|
||||
res['fields'][field]['domain'] = [('id', 'in', unconfigured_cmp)]
|
||||
res['fields'][field]['selection'] = [('', '')]
|
||||
if unconfigured_cmp:
|
||||
cmp_select = [(line.id, line.name) for line in CompanyObj.browse(unconfigured_cmp)]
|
||||
res['fields'][field]['selection'] = cmp_select
|
||||
return res
|
||||
|
||||
@api.one
|
||||
def _create_tax_templates_from_rates(self, company_id):
|
||||
'''
|
||||
This function checks if the chosen chart template is configured as containing a full set of taxes, and if
|
||||
it's not the case, it creates the templates for account.tax object accordingly to the provided sale/purchase rates.
|
||||
Then it saves the new tax templates as default taxes to use for this chart template.
|
||||
|
||||
:param company_id: id of the company for wich the wizard is running
|
||||
:return: True
|
||||
'''
|
||||
obj_tax_temp = self.env['account.tax.template']
|
||||
all_parents = self._get_chart_parent_ids(self.chart_template_id)
|
||||
# create tax templates from purchase_tax_rate and sale_tax_rate fields
|
||||
if not self.chart_template_id.complete_tax_set:
|
||||
value = self.sale_tax_rate
|
||||
ref_taxs = obj_tax_temp.search([('type_tax_use', '=', 'sale'), ('chart_template_id', 'in', all_parents)], order="sequence, id desc", limit=1)
|
||||
ref_taxs.write({'amount': value, 'name': _('Tax %.2f%%') % value, 'description': '%.2f%%' % value})
|
||||
value = self.purchase_tax_rate
|
||||
ref_taxs = obj_tax_temp.search([('type_tax_use', '=', 'purchase'), ('chart_template_id', 'in', all_parents)], order="sequence, id desc", limit=1)
|
||||
ref_taxs.write({'amount': value, 'name': _('Tax %.2f%%') % value, 'description': '%.2f%%' % value})
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def execute(self):
|
||||
'''
|
||||
This function is called at the confirmation of the wizard to generate the COA from the templates. It will read
|
||||
all the provided information to create the accounts, the banks, the journals, the taxes, the
|
||||
accounting properties... accordingly for the chosen company.
|
||||
'''
|
||||
# Ensure everything is translated consitingly to the company's language, not the user's one.
|
||||
self = self.with_context(lang=self.company_id.partner_id.lang)
|
||||
if len(self.env['account.account'].search([('company_id', '=', self.company_id.id)])) > 0:
|
||||
# We are in a case where we already have some accounts existing, meaning that user has probably
|
||||
# created its own accounts and does not need a coa, so skip installation of coa.
|
||||
_logger.info('Could not install chart of account since some accounts already exists for the company (%s)', (self.company_id.id,))
|
||||
return {}
|
||||
if not self.env.user._is_admin():
|
||||
raise AccessError(_("Only administrators can change the settings"))
|
||||
ir_values_obj = self.env['ir.values']
|
||||
company = self.company_id
|
||||
self.company_id.write({'currency_id': self.currency_id.id,
|
||||
'accounts_code_digits': self.code_digits,
|
||||
'anglo_saxon_accounting': self.use_anglo_saxon,
|
||||
'bank_account_code_prefix': self.bank_account_code_prefix,
|
||||
'cash_account_code_prefix': self.cash_account_code_prefix,
|
||||
'chart_template_id': self.chart_template_id.id})
|
||||
|
||||
#set the coa currency to active
|
||||
self.currency_id.write({'active': True})
|
||||
|
||||
# When we install the CoA of first company, set the currency to price types and pricelists
|
||||
if company.id == 1:
|
||||
for reference in ['product.list_price', 'product.standard_price', 'product.list0']:
|
||||
try:
|
||||
tmp2 = self.env.ref(reference).write({'currency_id': self.currency_id.id})
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# If the floats for sale/purchase rates have been filled, create templates from them
|
||||
self._create_tax_templates_from_rates(company.id)
|
||||
|
||||
# Install all the templates objects and generate the real objects
|
||||
acc_template_ref, taxes_ref = self.chart_template_id._install_template(company, code_digits=self.code_digits, transfer_account_id=self.transfer_account_id)
|
||||
|
||||
# write values of default taxes for product as super user
|
||||
if self.sale_tax_id and taxes_ref:
|
||||
ir_values_obj.sudo().set_default('product.template', "taxes_id", [taxes_ref[self.sale_tax_id.id]], for_all_users=True, company_id=company.id)
|
||||
if self.purchase_tax_id and taxes_ref:
|
||||
ir_values_obj.sudo().set_default('product.template', "supplier_taxes_id", [taxes_ref[self.purchase_tax_id.id]], for_all_users=True, company_id=company.id)
|
||||
|
||||
# Create Bank journals
|
||||
self._create_bank_journals_from_o2m(company, acc_template_ref)
|
||||
|
||||
# Create the current year earning account if it wasn't present in the CoA
|
||||
account_obj = self.env['account.account']
|
||||
unaffected_earnings_xml = self.env.ref("account.data_unaffected_earnings")
|
||||
if unaffected_earnings_xml and not account_obj.search([('company_id', '=', company.id), ('user_type_id', '=', unaffected_earnings_xml.id)]):
|
||||
account_obj.create({
|
||||
'code': '999999',
|
||||
'name': _('Undistributed Profits/Losses'),
|
||||
'user_type_id': unaffected_earnings_xml.id,
|
||||
'company_id': company.id,})
|
||||
return {}
|
||||
|
||||
@api.multi
|
||||
def _create_bank_journals_from_o2m(self, company, acc_template_ref):
|
||||
'''
|
||||
This function creates bank journals and its accounts for each line encoded in the field bank_account_ids of the
|
||||
wizard (which is currently only used to create a default bank and cash journal when the CoA is installed).
|
||||
|
||||
:param company: the company for which the wizard is running.
|
||||
:param acc_template_ref: the dictionary containing the mapping between the ids of account templates and the ids
|
||||
of the accounts that have been generated from them.
|
||||
'''
|
||||
self.ensure_one()
|
||||
# Create the journals that will trigger the account.account creation
|
||||
for acc in self.bank_account_ids:
|
||||
self.env['account.journal'].create({
|
||||
'name': acc.acc_name,
|
||||
'type': acc.account_type,
|
||||
'company_id': company.id,
|
||||
'currency_id': acc.currency_id.id,
|
||||
'sequence': 10
|
||||
})
|
||||
|
||||
|
||||
class AccountBankAccountsWizard(models.TransientModel):
|
||||
_name = 'account.bank.accounts.wizard'
|
||||
|
||||
acc_name = fields.Char(string='Account Name.', required=True)
|
||||
bank_account_id = fields.Many2one('wizard.multi.charts.accounts', string='Bank Account', required=True, ondelete='cascade')
|
||||
currency_id = fields.Many2one('res.currency', string='Account Currency',
|
||||
help="Forces all moves for this account to have this secondary currency.")
|
||||
account_type = fields.Selection([('cash', 'Cash'), ('bank', 'Bank')])
|
||||
|
||||
|
||||
class AccountReconcileModelTemplate(models.Model):
|
||||
_name = "account.reconcile.model.template"
|
||||
|
||||
name = fields.Char(string='Button Label', required=True)
|
||||
sequence = fields.Integer(required=True, default=10)
|
||||
has_second_line = fields.Boolean(string='Add a second line', default=False)
|
||||
account_id = fields.Many2one('account.account.template', string='Account', ondelete='cascade', domain=[('deprecated', '=', False)])
|
||||
label = fields.Char(string='Journal Item Label')
|
||||
amount_type = fields.Selection([
|
||||
('fixed', 'Fixed'),
|
||||
('percentage', 'Percentage of balance')
|
||||
], required=True, default='percentage')
|
||||
amount = fields.Float(digits=0, required=True, default=100.0, help="Fixed amount will count as a debit if it is negative, as a credit if it is positive.")
|
||||
tax_id = fields.Many2one('account.tax.template', string='Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'purchase')])
|
||||
second_account_id = fields.Many2one('account.account.template', string='Second Account', ondelete='cascade', domain=[('deprecated', '=', False)])
|
||||
second_label = fields.Char(string='Second Journal Item Label')
|
||||
second_amount_type = fields.Selection([
|
||||
('fixed', 'Fixed'),
|
||||
('percentage', 'Percentage of amount')
|
||||
], string="Second Amount type",required=True, default='percentage')
|
||||
second_amount = fields.Float(string='Second Amount', digits=0, required=True, default=100.0, help="Fixed amount will count as a debit if it is negative, as a credit if it is positive.")
|
||||
second_tax_id = fields.Many2one('account.tax.template', string='Second Tax', ondelete='restrict', domain=[('type_tax_use', '=', 'purchase')])
|
179
addons/account/models/company.py
Normal file
179
addons/account/models/company.py
Normal file
@ -0,0 +1,179 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datetime import timedelta, datetime
|
||||
import calendar
|
||||
import time
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import fields, models, api, _
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
from odoo.tools.misc import DEFAULT_SERVER_DATE_FORMAT
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
#TODO check all the options/fields are in the views (settings + company form view)
|
||||
fiscalyear_last_day = fields.Integer(default=31, required=True)
|
||||
fiscalyear_last_month = fields.Selection([(1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'), (5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'), (9, 'September'), (10, 'October'), (11, 'November'), (12, 'December')], default=12, required=True)
|
||||
period_lock_date = fields.Date(string="Lock Date for Non-Advisers", help="Only users with the 'Adviser' role can edit accounts prior to and inclusive of this date. Use it for period locking inside an open fiscal year, for example.")
|
||||
fiscalyear_lock_date = fields.Date(string="Lock Date", help="No users, including Advisers, can edit accounts prior to and inclusive of this date. Use it for fiscal year locking for example.")
|
||||
transfer_account_id = fields.Many2one('account.account',
|
||||
domain=lambda self: [('reconcile', '=', True), ('user_type_id.id', '=', self.env.ref('account.data_account_type_current_assets').id), ('deprecated', '=', False)], string="Inter-Banks Transfer Account", help="Intermediary account used when moving money from a liquidity account to another")
|
||||
expects_chart_of_accounts = fields.Boolean(string='Expects a Chart of Accounts', default=True)
|
||||
chart_template_id = fields.Many2one('account.chart.template', help='The chart template for the company (if any)')
|
||||
bank_account_code_prefix = fields.Char(string='Prefix of the bank accounts', oldname="bank_account_code_char")
|
||||
cash_account_code_prefix = fields.Char(string='Prefix of the cash accounts')
|
||||
accounts_code_digits = fields.Integer(string='Number of digits in an account code')
|
||||
tax_calculation_rounding_method = fields.Selection([
|
||||
('round_per_line', 'Round per Line'),
|
||||
('round_globally', 'Round Globally'),
|
||||
], default='round_per_line', string='Tax Calculation Rounding Method',
|
||||
help="If you select 'Round per Line' : for each tax, the tax amount will first be computed and rounded for each PO/SO/invoice line and then these rounded amounts will be summed, leading to the total amount for that tax. If you select 'Round Globally': for each tax, the tax amount will be computed for each PO/SO/invoice line, then these amounts will be summed and eventually this total tax amount will be rounded. If you sell with tax included, you should choose 'Round per line' because you certainly want the sum of your tax-included line subtotals to be equal to the total amount with taxes.")
|
||||
currency_exchange_journal_id = fields.Many2one('account.journal', string="Exchange Gain or Loss Journal", domain=[('type', '=', 'general')])
|
||||
income_currency_exchange_account_id = fields.Many2one('account.account', related='currency_exchange_journal_id.default_credit_account_id',
|
||||
string="Gain Exchange Rate Account", domain="[('internal_type', '=', 'other'), ('deprecated', '=', False), ('company_id', '=', id)]")
|
||||
expense_currency_exchange_account_id = fields.Many2one('account.account', related='currency_exchange_journal_id.default_debit_account_id',
|
||||
string="Loss Exchange Rate Account", domain="[('internal_type', '=', 'other'), ('deprecated', '=', False), ('company_id', '=', id)]")
|
||||
anglo_saxon_accounting = fields.Boolean(string="Use anglo-saxon accounting")
|
||||
property_stock_account_input_categ_id = fields.Many2one('account.account', string="Input Account for Stock Valuation", oldname="property_stock_account_input_categ")
|
||||
property_stock_account_output_categ_id = fields.Many2one('account.account', string="Output Account for Stock Valuation", oldname="property_stock_account_output_categ")
|
||||
property_stock_valuation_account_id = fields.Many2one('account.account', string="Account Template for Stock Valuation")
|
||||
bank_journal_ids = fields.One2many('account.journal', 'company_id', domain=[('type', '=', 'bank')], string='Bank Journals')
|
||||
overdue_msg = fields.Text(string='Overdue Payments Message', translate=True,
|
||||
default='''Dear Sir/Madam,
|
||||
|
||||
Our records indicate that some payments on your account are still due. Please find details below.
|
||||
If the amount has already been paid, please disregard this notice. Otherwise, please forward us the total amount stated below.
|
||||
If you have any queries regarding your account, Please contact us.
|
||||
|
||||
Thank you in advance for your cooperation.
|
||||
Best Regards,''')
|
||||
|
||||
@api.multi
|
||||
def _check_lock_dates(self, vals):
|
||||
'''Check the lock dates for the current companies. This can't be done in a api.constrains because we need
|
||||
to perform some comparison between new/old values. This method forces the lock dates to be irreversible.
|
||||
|
||||
* You cannot define stricter conditions on advisors than on users. Then, the lock date on advisor must be set
|
||||
after the lock date for users.
|
||||
* You cannot lock a period that is not finished yet. Then, the lock date for advisors must be set after the
|
||||
last day of the previous month.
|
||||
* The new lock date for advisors must be set after the previous lock date.
|
||||
|
||||
:param vals: The values passed to the write method.
|
||||
'''
|
||||
period_lock_date = vals.get('period_lock_date') and\
|
||||
time.strptime(vals['period_lock_date'], DEFAULT_SERVER_DATE_FORMAT)
|
||||
fiscalyear_lock_date = vals.get('fiscalyear_lock_date') and\
|
||||
time.strptime(vals['fiscalyear_lock_date'], DEFAULT_SERVER_DATE_FORMAT)
|
||||
|
||||
previous_month = datetime.strptime(fields.Date.today(), DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=-1)
|
||||
days_previous_month = calendar.monthrange(previous_month.year, previous_month.month)
|
||||
previous_month = previous_month.replace(day=days_previous_month[1]).timetuple()
|
||||
for company in self:
|
||||
old_fiscalyear_lock_date = company.fiscalyear_lock_date and\
|
||||
time.strptime(company.fiscalyear_lock_date, DEFAULT_SERVER_DATE_FORMAT)
|
||||
|
||||
# The user attempts to remove the lock date for advisors
|
||||
if old_fiscalyear_lock_date and not fiscalyear_lock_date and 'fiscalyear_lock_date' in vals:
|
||||
raise ValidationError(_('The lock date for advisors is irreversible and can\'t be removed.'))
|
||||
|
||||
# The user attempts to set a lock date for advisors prior to the previous one
|
||||
if old_fiscalyear_lock_date and fiscalyear_lock_date and fiscalyear_lock_date < old_fiscalyear_lock_date:
|
||||
raise ValidationError(_('The new lock date for advisors must be set after the previous lock date.'))
|
||||
|
||||
# In case of no new fiscal year in vals, fallback to the oldest
|
||||
if not fiscalyear_lock_date:
|
||||
if old_fiscalyear_lock_date:
|
||||
fiscalyear_lock_date = old_fiscalyear_lock_date
|
||||
else:
|
||||
continue
|
||||
|
||||
# The user attempts to set a lock date for advisors prior to the last day of previous month
|
||||
if fiscalyear_lock_date > previous_month:
|
||||
raise ValidationError(_('You cannot lock a period that is not finished yet. Please make sure that the lock date for advisors is not set after the last day of the previous month.'))
|
||||
|
||||
# In case of no new period lock date in vals, fallback to the one defined in the company
|
||||
if not period_lock_date:
|
||||
if company.period_lock_date:
|
||||
period_lock_date = time.strptime(company.period_lock_date, DEFAULT_SERVER_DATE_FORMAT)
|
||||
else:
|
||||
continue
|
||||
|
||||
# The user attempts to set a lock date for advisors prior to the lock date for users
|
||||
if period_lock_date < fiscalyear_lock_date:
|
||||
raise ValidationError(_('You cannot define stricter conditions on advisors than on users. Please make sure that the lock date on advisor is set before the lock date for users.'))
|
||||
|
||||
@api.multi
|
||||
def compute_fiscalyear_dates(self, date):
|
||||
""" Computes the start and end dates of the fiscalyear where the given 'date' belongs to
|
||||
@param date: a datetime object
|
||||
@returns: a dictionary with date_from and date_to
|
||||
"""
|
||||
self = self[0]
|
||||
last_month = self.fiscalyear_last_month
|
||||
last_day = self.fiscalyear_last_day
|
||||
if (date.month < last_month or (date.month == last_month and date.day <= last_day)):
|
||||
date = date.replace(month=last_month, day=last_day)
|
||||
else:
|
||||
if last_month == 2 and last_day == 29 and (date.year + 1) % 4 != 0:
|
||||
date = date.replace(month=last_month, day=28, year=date.year + 1)
|
||||
else:
|
||||
date = date.replace(month=last_month, day=last_day, year=date.year + 1)
|
||||
date_to = date
|
||||
date_from = date + timedelta(days=1)
|
||||
if date_from.month == 2 and date_from.day == 29:
|
||||
date_from = date_from.replace(day=28, year=date_from.year - 1)
|
||||
else:
|
||||
date_from = date_from.replace(year=date_from.year - 1)
|
||||
return {'date_from': date_from, 'date_to': date_to}
|
||||
|
||||
def get_new_account_code(self, current_code, old_prefix, new_prefix, digits):
|
||||
return new_prefix + current_code.replace(old_prefix, '', 1).lstrip('0').rjust(digits-len(new_prefix), '0')
|
||||
|
||||
def reflect_code_prefix_change(self, old_code, new_code, digits):
|
||||
accounts = self.env['account.account'].search([('code', 'like', old_code), ('internal_type', '=', 'liquidity'),
|
||||
('company_id', '=', self.id)], order='code asc')
|
||||
for account in accounts:
|
||||
if account.code.startswith(old_code):
|
||||
account.write({'code': self.get_new_account_code(account.code, old_code, new_code, digits)})
|
||||
|
||||
def reflect_code_digits_change(self, digits):
|
||||
accounts = self.env['account.account'].search([('company_id', '=', self.id)], order='code asc')
|
||||
for account in accounts:
|
||||
account.write({'code': account.code.rstrip('0').ljust(digits, '0')})
|
||||
|
||||
@api.multi
|
||||
def _validate_fiscalyear_lock(self, values):
|
||||
if values.get('fiscalyear_lock_date'):
|
||||
nb_draft_entries = self.env['account.move'].search([
|
||||
('company_id', 'in', [c.id for c in self]),
|
||||
('state', '=', 'draft'),
|
||||
('date', '<=', values['fiscalyear_lock_date'])])
|
||||
if nb_draft_entries:
|
||||
raise ValidationError(_('There are still unposted entries in the period you want to lock. You should either post or delete them.'))
|
||||
|
||||
@api.multi
|
||||
def write(self, values):
|
||||
#restrict the closing of FY if there are still unposted entries
|
||||
self._validate_fiscalyear_lock(values)
|
||||
|
||||
# Reflect the change on accounts
|
||||
for company in self:
|
||||
digits = values.get('accounts_code_digits') or company.accounts_code_digits
|
||||
if values.get('bank_account_code_prefix') or values.get('accounts_code_digits'):
|
||||
new_bank_code = values.get('bank_account_code_prefix') or company.bank_account_code_prefix
|
||||
company.reflect_code_prefix_change(company.bank_account_code_prefix, new_bank_code, digits)
|
||||
if values.get('cash_account_code_prefix') or values.get('accounts_code_digits'):
|
||||
new_cash_code = values.get('cash_account_code_prefix') or company.cash_account_code_prefix
|
||||
company.reflect_code_prefix_change(company.cash_account_code_prefix, new_cash_code, digits)
|
||||
if values.get('accounts_code_digits'):
|
||||
company.reflect_code_digits_change(digits)
|
||||
|
||||
#forbid the change of currency_id if there are already some accounting entries existing
|
||||
if 'currency_id' in values and values['currency_id'] != company.currency_id.id:
|
||||
if self.env['account.move.line'].search([('company_id', '=', company.id)]):
|
||||
raise UserError(_('You cannot change the currency of the company since some journal items already exist'))
|
||||
|
||||
return super(ResCompany, self).write(values)
|
454
addons/account/models/partner.py
Normal file
454
addons/account/models/partner.py
Normal file
@ -0,0 +1,454 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ast import literal_eval
|
||||
from operator import itemgetter
|
||||
import time
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.addons.base.res.res_partner import WARNING_MESSAGE, WARNING_HELP
|
||||
|
||||
class AccountFiscalPosition(models.Model):
|
||||
_name = 'account.fiscal.position'
|
||||
_description = 'Fiscal Position'
|
||||
_order = 'sequence'
|
||||
|
||||
sequence = fields.Integer()
|
||||
name = fields.Char(string='Fiscal Position', required=True)
|
||||
active = fields.Boolean(default=True,
|
||||
help="By unchecking the active field, you may hide a fiscal position without deleting it.")
|
||||
company_id = fields.Many2one('res.company', string='Company')
|
||||
account_ids = fields.One2many('account.fiscal.position.account', 'position_id', string='Account Mapping', copy=True)
|
||||
tax_ids = fields.One2many('account.fiscal.position.tax', 'position_id', string='Tax Mapping', copy=True)
|
||||
note = fields.Text('Notes', translate=True, help="Legal mentions that have to be printed on the invoices.")
|
||||
auto_apply = fields.Boolean(string='Detect Automatically', help="Apply automatically this fiscal position.")
|
||||
vat_required = fields.Boolean(string='VAT required', help="Apply only if partner has a VAT number.")
|
||||
country_id = fields.Many2one('res.country', string='Country',
|
||||
help="Apply only if delivery or invoicing country match.")
|
||||
country_group_id = fields.Many2one('res.country.group', string='Country Group',
|
||||
help="Apply only if delivery or invocing country match the group.")
|
||||
state_ids = fields.Many2many('res.country.state', string='Federal States')
|
||||
zip_from = fields.Integer(string='Zip Range From', default=0)
|
||||
zip_to = fields.Integer(string='Zip Range To', default=0)
|
||||
# To be used in hiding the 'Federal States' field('attrs' in view side) when selected 'Country' has 0 states.
|
||||
states_count = fields.Integer(compute='_compute_states_count')
|
||||
|
||||
@api.one
|
||||
def _compute_states_count(self):
|
||||
self.states_count = len(self.country_id.state_ids)
|
||||
|
||||
@api.one
|
||||
@api.constrains('zip_from', 'zip_to')
|
||||
def _check_zip(self):
|
||||
if self.zip_from > self.zip_to:
|
||||
raise ValidationError(_('Invalid "Zip Range", please configure it properly.'))
|
||||
return True
|
||||
|
||||
@api.model # noqa
|
||||
def map_tax(self, taxes, product=None, partner=None):
|
||||
result = self.env['account.tax'].browse()
|
||||
for tax in taxes:
|
||||
tax_count = 0
|
||||
for t in self.tax_ids:
|
||||
if t.tax_src_id == tax:
|
||||
tax_count += 1
|
||||
if t.tax_dest_id:
|
||||
result |= t.tax_dest_id
|
||||
if not tax_count:
|
||||
result |= tax
|
||||
return result
|
||||
|
||||
@api.model
|
||||
def map_account(self, account):
|
||||
for pos in self.account_ids:
|
||||
if pos.account_src_id == account:
|
||||
return pos.account_dest_id
|
||||
return account
|
||||
|
||||
@api.model
|
||||
def map_accounts(self, accounts):
|
||||
""" Receive a dictionary having accounts in values and try to replace those accounts accordingly to the fiscal position.
|
||||
"""
|
||||
ref_dict = {}
|
||||
for line in self.account_ids:
|
||||
ref_dict[line.account_src_id] = line.account_dest_id
|
||||
for key, acc in accounts.items():
|
||||
if acc in ref_dict:
|
||||
accounts[key] = ref_dict[acc]
|
||||
return accounts
|
||||
|
||||
@api.onchange('country_id')
|
||||
def _onchange_country_id(self):
|
||||
if self.country_id:
|
||||
self.zip_from = self.zip_to = self.country_group_id = False
|
||||
self.state_ids = [(5,)]
|
||||
self.states_count = len(self.country_id.state_ids)
|
||||
|
||||
@api.onchange('country_group_id')
|
||||
def _onchange_country_group_id(self):
|
||||
if self.country_group_id:
|
||||
self.zip_from = self.zip_to = self.country_id = False
|
||||
self.state_ids = [(5,)]
|
||||
|
||||
@api.model
|
||||
def _get_fpos_by_region(self, country_id=False, state_id=False, zipcode=False, vat_required=False):
|
||||
if not country_id:
|
||||
return False
|
||||
base_domain = [('auto_apply', '=', True), ('vat_required', '=', vat_required)]
|
||||
if self.env.context.get('force_company'):
|
||||
base_domain.append(('company_id', '=', self.env.context.get('force_company')))
|
||||
null_state_dom = state_domain = [('state_ids', '=', False)]
|
||||
null_zip_dom = zip_domain = [('zip_from', '=', 0), ('zip_to', '=', 0)]
|
||||
null_country_dom = [('country_id', '=', False), ('country_group_id', '=', False)]
|
||||
|
||||
if zipcode and zipcode.isdigit():
|
||||
zipcode = int(zipcode)
|
||||
zip_domain = [('zip_from', '<=', zipcode), ('zip_to', '>=', zipcode)]
|
||||
else:
|
||||
zipcode = 0
|
||||
|
||||
if state_id:
|
||||
state_domain = [('state_ids', '=', state_id)]
|
||||
|
||||
domain_country = base_domain + [('country_id', '=', country_id)]
|
||||
domain_group = base_domain + [('country_group_id.country_ids', '=', country_id)]
|
||||
|
||||
# Build domain to search records with exact matching criteria
|
||||
fpos = self.search(domain_country + state_domain + zip_domain, limit=1)
|
||||
# return records that fit the most the criteria, and fallback on less specific fiscal positions if any can be found
|
||||
if not fpos and state_id:
|
||||
fpos = self.search(domain_country + null_state_dom + zip_domain, limit=1)
|
||||
if not fpos and zipcode:
|
||||
fpos = self.search(domain_country + state_domain + null_zip_dom, limit=1)
|
||||
if not fpos and state_id and zipcode:
|
||||
fpos = self.search(domain_country + null_state_dom + null_zip_dom, limit=1)
|
||||
|
||||
# fallback: country group with no state/zip range
|
||||
if not fpos:
|
||||
fpos = self.search(domain_group + null_state_dom + null_zip_dom, limit=1)
|
||||
|
||||
if not fpos:
|
||||
# Fallback on catchall (no country, no group)
|
||||
fpos = self.search(base_domain + null_country_dom, limit=1)
|
||||
return fpos or False
|
||||
|
||||
@api.model
|
||||
def get_fiscal_position(self, partner_id, delivery_id=None):
|
||||
if not partner_id:
|
||||
return False
|
||||
# This can be easily overriden to apply more complex fiscal rules
|
||||
PartnerObj = self.env['res.partner']
|
||||
partner = PartnerObj.browse(partner_id)
|
||||
|
||||
# if no delivery use invoicing
|
||||
if delivery_id:
|
||||
delivery = PartnerObj.browse(delivery_id)
|
||||
else:
|
||||
delivery = partner
|
||||
|
||||
# partner manually set fiscal position always win
|
||||
if delivery.property_account_position_id or partner.property_account_position_id:
|
||||
return delivery.property_account_position_id.id or partner.property_account_position_id.id
|
||||
|
||||
# First search only matching VAT positions
|
||||
vat_required = bool(partner.vat)
|
||||
fp = self._get_fpos_by_region(delivery.country_id.id, delivery.state_id.id, delivery.zip, vat_required)
|
||||
|
||||
# Then if VAT required found no match, try positions that do not require it
|
||||
if not fp and vat_required:
|
||||
fp = self._get_fpos_by_region(delivery.country_id.id, delivery.state_id.id, delivery.zip, False)
|
||||
|
||||
return fp.id if fp else False
|
||||
|
||||
|
||||
class AccountFiscalPositionTax(models.Model):
|
||||
_name = 'account.fiscal.position.tax'
|
||||
_description = 'Taxes Fiscal Position'
|
||||
_rec_name = 'position_id'
|
||||
|
||||
position_id = fields.Many2one('account.fiscal.position', string='Fiscal Position',
|
||||
required=True, ondelete='cascade')
|
||||
tax_src_id = fields.Many2one('account.tax', string='Tax on Product', required=True)
|
||||
tax_dest_id = fields.Many2one('account.tax', string='Tax to Apply')
|
||||
|
||||
_sql_constraints = [
|
||||
('tax_src_dest_uniq',
|
||||
'unique (position_id,tax_src_id,tax_dest_id)',
|
||||
'A tax fiscal position could be defined only once time on same taxes.')
|
||||
]
|
||||
|
||||
|
||||
class AccountFiscalPositionAccount(models.Model):
|
||||
_name = 'account.fiscal.position.account'
|
||||
_description = 'Accounts Fiscal Position'
|
||||
_rec_name = 'position_id'
|
||||
|
||||
position_id = fields.Many2one('account.fiscal.position', string='Fiscal Position',
|
||||
required=True, ondelete='cascade')
|
||||
account_src_id = fields.Many2one('account.account', string='Account on Product',
|
||||
domain=[('deprecated', '=', False)], required=True)
|
||||
account_dest_id = fields.Many2one('account.account', string='Account to Use Instead',
|
||||
domain=[('deprecated', '=', False)], required=True)
|
||||
|
||||
_sql_constraints = [
|
||||
('account_src_dest_uniq',
|
||||
'unique (position_id,account_src_id,account_dest_id)',
|
||||
'An account fiscal position could be defined only once time on same accounts.')
|
||||
]
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_name = 'res.partner'
|
||||
_inherit = 'res.partner'
|
||||
_description = 'Partner'
|
||||
|
||||
@api.multi
|
||||
def _credit_debit_get(self):
|
||||
tables, where_clause, where_params = self.env['account.move.line']._query_get()
|
||||
where_params = [tuple(self.ids)] + where_params
|
||||
if where_clause:
|
||||
where_clause = 'AND ' + where_clause
|
||||
self._cr.execute("""SELECT account_move_line.partner_id, act.type, SUM(account_move_line.amount_residual)
|
||||
FROM account_move_line
|
||||
LEFT JOIN account_account a ON (account_move_line.account_id=a.id)
|
||||
LEFT JOIN account_account_type act ON (a.user_type_id=act.id)
|
||||
WHERE act.type IN ('receivable','payable')
|
||||
AND account_move_line.partner_id IN %s
|
||||
AND account_move_line.reconciled IS FALSE
|
||||
""" + where_clause + """
|
||||
GROUP BY account_move_line.partner_id, act.type
|
||||
""", where_params)
|
||||
for pid, type, val in self._cr.fetchall():
|
||||
partner = self.browse(pid)
|
||||
if type == 'receivable':
|
||||
partner.credit = val
|
||||
elif type == 'payable':
|
||||
partner.debit = -val
|
||||
|
||||
@api.multi
|
||||
def _asset_difference_search(self, account_type, operator, operand):
|
||||
if operator not in ('<', '=', '>', '>=', '<='):
|
||||
return []
|
||||
if type(operand) not in (float, int):
|
||||
return []
|
||||
sign = 1
|
||||
if account_type == 'payable':
|
||||
sign = -1
|
||||
res = self._cr.execute('''
|
||||
SELECT partner.id
|
||||
FROM res_partner partner
|
||||
LEFT JOIN account_move_line aml ON aml.partner_id = partner.id
|
||||
RIGHT JOIN account_account acc ON aml.account_id = acc.id
|
||||
WHERE acc.internal_type = %s
|
||||
AND NOT acc.deprecated
|
||||
GROUP BY partner.id
|
||||
HAVING %s * COALESCE(SUM(aml.amount_residual), 0) ''' + operator + ''' %s''', (account_type, sign, operand))
|
||||
res = self._cr.fetchall()
|
||||
if not res:
|
||||
return [('id', '=', '0')]
|
||||
return [('id', 'in', map(itemgetter(0), res))]
|
||||
|
||||
@api.model
|
||||
def _credit_search(self, operator, operand):
|
||||
return self._asset_difference_search('receivable', operator, operand)
|
||||
|
||||
@api.model
|
||||
def _debit_search(self, operator, operand):
|
||||
return self._asset_difference_search('payable', operator, operand)
|
||||
|
||||
@api.multi
|
||||
def _invoice_total(self):
|
||||
account_invoice_report = self.env['account.invoice.report']
|
||||
if not self.ids:
|
||||
self.total_invoiced = 0.0
|
||||
return True
|
||||
|
||||
user_currency_id = self.env.user.company_id.currency_id.id
|
||||
all_partners_and_children = {}
|
||||
all_partner_ids = []
|
||||
for partner in self:
|
||||
# price_total is in the company currency
|
||||
all_partners_and_children[partner] = self.with_context(active_test=False).search([('id', 'child_of', partner.id)]).ids
|
||||
all_partner_ids += all_partners_and_children[partner]
|
||||
|
||||
# searching account.invoice.report via the orm is comparatively expensive
|
||||
# (generates queries "id in []" forcing to build the full table).
|
||||
# In simple cases where all invoices are in the same currency than the user's company
|
||||
# access directly these elements
|
||||
|
||||
# generate where clause to include multicompany rules
|
||||
where_query = account_invoice_report._where_calc([
|
||||
('partner_id', 'in', all_partner_ids), ('state', 'not in', ['draft', 'cancel']),
|
||||
('type', 'in', ('out_invoice', 'out_refund'))
|
||||
])
|
||||
account_invoice_report._apply_ir_rules(where_query, 'read')
|
||||
from_clause, where_clause, where_clause_params = where_query.get_sql()
|
||||
|
||||
# price_total is in the company currency
|
||||
query = """
|
||||
SELECT SUM(price_total) as total, partner_id
|
||||
FROM account_invoice_report account_invoice_report
|
||||
WHERE %s
|
||||
GROUP BY partner_id
|
||||
""" % where_clause
|
||||
self.env.cr.execute(query, where_clause_params)
|
||||
price_totals = self.env.cr.dictfetchall()
|
||||
for partner, child_ids in all_partners_and_children.items():
|
||||
partner.total_invoiced = sum(price['total'] for price in price_totals if price['partner_id'] in child_ids)
|
||||
|
||||
@api.multi
|
||||
def _compute_journal_item_count(self):
|
||||
AccountMoveLine = self.env['account.move.line']
|
||||
for partner in self:
|
||||
partner.journal_item_count = AccountMoveLine.search_count([('partner_id', '=', partner.id)])
|
||||
|
||||
@api.multi
|
||||
def _compute_contracts_count(self):
|
||||
AccountAnalyticAccount = self.env['account.analytic.account']
|
||||
for partner in self:
|
||||
partner.contracts_count = AccountAnalyticAccount.search_count([('partner_id', '=', partner.id)])
|
||||
|
||||
def get_followup_lines_domain(self, date, overdue_only=False, only_unblocked=False):
|
||||
domain = [('reconciled', '=', False), ('account_id.deprecated', '=', False), ('account_id.internal_type', '=', 'receivable'), '|', ('debit', '!=', 0), ('credit', '!=', 0), ('company_id', '=', self.env.user.company_id.id)]
|
||||
if only_unblocked:
|
||||
domain += [('blocked', '=', False)]
|
||||
if self.ids:
|
||||
if 'exclude_given_ids' in self._context:
|
||||
domain += [('partner_id', 'not in', self.ids)]
|
||||
else:
|
||||
domain += [('partner_id', 'in', self.ids)]
|
||||
#adding the overdue lines
|
||||
overdue_domain = ['|', '&', ('date_maturity', '!=', False), ('date_maturity', '<', date), '&', ('date_maturity', '=', False), ('date', '<', date)]
|
||||
if overdue_only:
|
||||
domain += overdue_domain
|
||||
return domain
|
||||
|
||||
@api.multi
|
||||
def _compute_issued_total(self):
|
||||
""" Returns the issued total as will be displayed on partner view """
|
||||
today = fields.Date.context_today(self)
|
||||
domain = self.get_followup_lines_domain(today, overdue_only=True)
|
||||
for aml in self.env['account.move.line'].search(domain):
|
||||
aml.partner_id.issued_total += aml.amount_residual
|
||||
|
||||
@api.one
|
||||
def _compute_has_unreconciled_entries(self):
|
||||
# Avoid useless work if has_unreconciled_entries is not relevant for this partner
|
||||
if not self.active or not self.is_company and self.parent_id:
|
||||
return
|
||||
self.env.cr.execute(
|
||||
""" SELECT 1 FROM(
|
||||
SELECT
|
||||
p.last_time_entries_checked AS last_time_entries_checked,
|
||||
MAX(l.write_date) AS max_date
|
||||
FROM
|
||||
account_move_line l
|
||||
RIGHT JOIN account_account a ON (a.id = l.account_id)
|
||||
RIGHT JOIN res_partner p ON (l.partner_id = p.id)
|
||||
WHERE
|
||||
p.id = %s
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM account_move_line l
|
||||
WHERE l.account_id = a.id
|
||||
AND l.partner_id = p.id
|
||||
AND l.amount_residual > 0
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM account_move_line l
|
||||
WHERE l.account_id = a.id
|
||||
AND l.partner_id = p.id
|
||||
AND l.amount_residual < 0
|
||||
)
|
||||
GROUP BY p.last_time_entries_checked
|
||||
) as s
|
||||
WHERE (last_time_entries_checked IS NULL OR max_date > last_time_entries_checked)
|
||||
""", (self.id,))
|
||||
self.has_unreconciled_entries = self.env.cr.rowcount == 1
|
||||
|
||||
@api.multi
|
||||
def mark_as_reconciled(self):
|
||||
self.env['account.partial.reconcile'].check_access_rights('write')
|
||||
return self.sudo().with_context(company_id=self.env.user.company_id.id).write({'last_time_entries_checked': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)})
|
||||
|
||||
@api.one
|
||||
def _get_company_currency(self):
|
||||
if self.company_id:
|
||||
self.currency_id = self.sudo().company_id.currency_id
|
||||
else:
|
||||
self.currency_id = self.env.user.company_id.currency_id
|
||||
|
||||
credit = fields.Monetary(compute='_credit_debit_get', search=_credit_search,
|
||||
string='Total Receivable', help="Total amount this customer owes you.")
|
||||
debit = fields.Monetary(compute='_credit_debit_get', search=_debit_search, string='Total Payable',
|
||||
help="Total amount you have to pay to this vendor.")
|
||||
debit_limit = fields.Monetary('Payable Limit')
|
||||
total_invoiced = fields.Monetary(compute='_invoice_total', string="Total Invoiced",
|
||||
groups='account.group_account_invoice')
|
||||
currency_id = fields.Many2one('res.currency', compute='_get_company_currency', readonly=True,
|
||||
string="Currency", help='Utility field to express amount currency')
|
||||
contracts_count = fields.Integer(compute='_compute_contracts_count', string="Contracts", type='integer')
|
||||
journal_item_count = fields.Integer(compute='_compute_journal_item_count', string="Journal Items", type="integer")
|
||||
issued_total = fields.Monetary(compute='_compute_issued_total', string="Journal Items")
|
||||
property_account_payable_id = fields.Many2one('account.account', company_dependent=True,
|
||||
string="Account Payable", oldname="property_account_payable",
|
||||
domain="[('internal_type', '=', 'payable'), ('deprecated', '=', False)]",
|
||||
help="This account will be used instead of the default one as the payable account for the current partner",
|
||||
required=True)
|
||||
property_account_receivable_id = fields.Many2one('account.account', company_dependent=True,
|
||||
string="Account Receivable", oldname="property_account_receivable",
|
||||
domain="[('internal_type', '=', 'receivable'), ('deprecated', '=', False)]",
|
||||
help="This account will be used instead of the default one as the receivable account for the current partner",
|
||||
required=True)
|
||||
property_account_position_id = fields.Many2one('account.fiscal.position', company_dependent=True,
|
||||
string="Fiscal Position",
|
||||
help="The fiscal position will determine taxes and accounts used for the partner.", oldname="property_account_position")
|
||||
property_payment_term_id = fields.Many2one('account.payment.term', company_dependent=True,
|
||||
string='Customer Payment Terms',
|
||||
help="This payment term will be used instead of the default one for sale orders and customer invoices", oldname="property_payment_term")
|
||||
property_supplier_payment_term_id = fields.Many2one('account.payment.term', company_dependent=True,
|
||||
string='Vendor Payment Terms',
|
||||
help="This payment term will be used instead of the default one for purchase orders and vendor bills", oldname="property_supplier_payment_term")
|
||||
ref_company_ids = fields.One2many('res.company', 'partner_id',
|
||||
string='Companies that refers to partner', oldname="ref_companies")
|
||||
has_unreconciled_entries = fields.Boolean(compute='_compute_has_unreconciled_entries',
|
||||
help="The partner has at least one unreconciled debit and credit since last time the invoices & payments matching was performed.")
|
||||
last_time_entries_checked = fields.Datetime(oldname='last_reconciliation_date',
|
||||
string='Latest Invoices & Payments Matching Date', readonly=True, copy=False,
|
||||
help='Last time the invoices & payments matching was performed for this partner. '
|
||||
'It is set either if there\'s not at least an unreconciled debit and an unreconciled credit '
|
||||
'or if you click the "Done" button.')
|
||||
invoice_ids = fields.One2many('account.invoice', 'partner_id', string='Invoices', readonly=True, copy=False)
|
||||
contract_ids = fields.One2many('account.analytic.account', 'partner_id', string='Contracts', readonly=True)
|
||||
bank_account_count = fields.Integer(compute='_compute_bank_count', string="Bank")
|
||||
trust = fields.Selection([('good', 'Good Debtor'), ('normal', 'Normal Debtor'), ('bad', 'Bad Debtor')], string='Degree of trust you have in this debtor', default='normal', company_dependent=True)
|
||||
invoice_warn = fields.Selection(WARNING_MESSAGE, 'Invoice', help=WARNING_HELP, required=True, default="no-message")
|
||||
invoice_warn_msg = fields.Text('Message for Invoice')
|
||||
|
||||
@api.multi
|
||||
def _compute_bank_count(self):
|
||||
bank_data = self.env['res.partner.bank'].read_group([('partner_id', 'in', self.ids)], ['partner_id'], ['partner_id'])
|
||||
mapped_data = dict([(bank['partner_id'][0], bank['partner_id_count']) for bank in bank_data])
|
||||
for partner in self:
|
||||
partner.bank_account_count = mapped_data.get(partner.id, 0)
|
||||
|
||||
def _find_accounting_partner(self, partner):
|
||||
''' Find the partner for which the accounting entries will be created '''
|
||||
return partner.commercial_partner_id
|
||||
|
||||
@api.model
|
||||
def _commercial_fields(self):
|
||||
return super(ResPartner, self)._commercial_fields() + \
|
||||
['debit_limit', 'property_account_payable_id', 'property_account_receivable_id', 'property_account_position_id',
|
||||
'property_payment_term_id', 'property_supplier_payment_term_id', 'last_time_entries_checked']
|
||||
|
||||
def open_partner_history(self):
|
||||
'''
|
||||
This function returns an action that display invoices/refunds made for the given partners.
|
||||
'''
|
||||
action = self.env.ref('account.action_invoice_refund_out_tree').read()[0]
|
||||
action['domain'] = literal_eval(action['domain'])
|
||||
action['domain'].append(('partner_id', 'child_of', self.ids))
|
||||
return action
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user