Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] ADD account_receipt_journal: Define and use journals dedicated to receipts #1260

Merged
merged 72 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
444ff5f
[ADD] prima bozza
eLBati Jul 22, 2011
a077ab3
[ADD] l10n_it_corrispettivi
Feb 18, 2013
d728e2f
[REF] Set all the modules of the master branches to "installable": False
eLBati Jul 6, 2014
6a2d883
[MOV] move addons out of __unported__ (they remain not installable)
sbidoul Oct 13, 2015
8c69a20
[MIG] Rename manifest files
pedrobaeza Oct 6, 2016
a05b74b
OCA Transbot updated translations from Transifex
oca-transbot Nov 30, 2015
862bb76
manually moving module from 7.0 branch beacause
eLBati Jun 3, 2016
ff06c27
Porting l10n_it_corrispettivi to 8.0
shakin89 Jun 3, 2016
d184f4b
IMP metadata
eLBati Jun 3, 2016
d6ae132
OCA Transbot updated translations from Transifex
oca-transbot Jul 30, 2016
3d08f0a
[l10n_it_corrispettivi] Fix ValueError: "name 'partner_id' is not def…
tafaRU Aug 24, 2016
58ca07d
[FIX] remove en.po that was erroneously created by transbot
sbidoul Aug 26, 2016
a528d17
FIX
eLBati Sep 12, 2016
b90165c
OCA Transbot updated translations from Transifex
oca-transbot Nov 29, 2016
a8311c2
[FIX] Add partner on search view (#343)
Jun 23, 2017
e8e2e59
[MIG] l10n_it_corrispettivi: Migration to 10.0
SimoRubi May 22, 2018
ea90c8a
OCA Transbot updated translations from Transifex
oca-transbot Jun 2, 2018
538617a
[IMP] Added fiscal position management
SimoRubi Jun 7, 2018
4600e04
[UPD] Update l10n_it_corrispettivi.pot
oca-travis Jun 20, 2018
a40c7b4
[FIX] group accounting_entries is not visible unless user is in accou…
SimoRubi Jul 5, 2018
c20e162
[MIG] l10n_it_corrispettivi: Migration to 11.0
SimoRubi Sep 3, 2018
ed0a5de
[UPD] Update l10n_it_corrispettivi.pot
oca-travis Sep 18, 2018
c658d27
[UPD] README.rst
OCA-git-bot Sep 19, 2018
e3829dd
Translated using Weblate (Italian)
primes2h Oct 13, 2018
00e1330
Update translation files
oca-transbot Nov 25, 2018
2a55bbd
[MIG] l10n_it_corrispettivi: Migration to 12.0
monen17 Jan 19, 2019
0c986bb
[FIX] l10n_it_corrispettivi: Hide Send & Print button: it makes littl…
monen17 Jan 23, 2019
1efd63c
[FIX] l10n_it_corrispettivi: Hide partner and payment details
monen17 Jan 24, 2019
a8c27a0
[IMP] l10n_it_corrispettivi: Create a corrispettivi journal when inst…
monen17 Jan 26, 2019
cb7b9d4
[IMP] l10n_it_corrispettivi: Use Corrispettivi report for portal preview
monen17 Jan 31, 2019
b76adef
[UPD] Update l10n_it_corrispettivi.pot
oca-travis Feb 7, 2019
572dbc3
Update translation files
oca-transbot Feb 9, 2019
2703f41
Translated using Weblate (Italian)
primes2h Feb 14, 2019
8b260c5
Translated using Weblate (Italian)
primes2h Feb 18, 2019
91dacc0
[FIX] l10n_it_corrispettivi use correct term 'receipt'
primes2h Feb 12, 2019
f99008b
[UPD] Update l10n_it_corrispettivi.pot
oca-travis Feb 18, 2019
c9248bc
Update translation files
oca-transbot Mar 3, 2019
d9dc8c7
Translated using Weblate (Italian)
primes2h Mar 7, 2019
cdf0fed
[ADD] icon.png
OCA-git-bot Apr 3, 2019
a23035e
[FIX] l10n_it_corrispettivi: Find fiscal positions without company
SimoRubi Apr 3, 2019
31ed237
[IMP] l10n_it_corrispettivi: Show the corrispettivi tree view as a re…
SimoRubi Apr 3, 2019
91c60b6
[UPD] Update l10n_it_corrispettivi.pot
oca-travis Apr 19, 2019
a1d21f6
Update translation files
oca-transbot May 20, 2019
1cd3012
[UPD] README.rst
OCA-git-bot Jul 29, 2019
54650bc
Translated using Weblate (Italian)
primes2h Aug 2, 2019
9e7a55c
[12.0][FIX] l10n_it_corrispettivi, fix account report
GSLabIt Jan 8, 2020
55997f2
[UPD] README.rst
OCA-git-bot Jan 9, 2020
5375239
l10n_it_corrispettivi 12.0.1.1.3
OCA-git-bot Jan 9, 2020
40e83dc
- fix journal on partner change
GSLabIt Feb 6, 2020
b6928cb
[UPD] Update l10n_it_corrispettivi.pot
oca-travis Feb 12, 2020
45b7c59
[UPD] README.rst
OCA-git-bot Feb 12, 2020
fc10eea
l10n_it_corrispettivi 12.0.1.1.4
OCA-git-bot Feb 12, 2020
2b9744d
Update translation files
oca-transbot Feb 12, 2020
c71af48
merge PR 1264 1717 1728 1737 1739
May 13, 2020
a7d5ce5
[12.0][FIX] refund and modify invoice
sergiocorato May 26, 2020
32caa9b
l10n_it_corrispettivi 12.0.1.1.6
OCA-git-bot Jun 12, 2020
526b5f9
Translated using Weblate (Italian)
sergiocorato Jul 5, 2020
a450015
[UPD] Update l10n_it_corrispettivi.pot
oca-travis Jul 6, 2020
6d68c7f
Update translation files
oca-transbot Jul 6, 2020
77a2cac
FIX license LGPL-3 conflicts
eLBati Sep 24, 2020
ca3e172
[UPD] Update l10n_it_corrispettivi.pot
oca-travis Sep 24, 2020
750c4fb
l10n_it_corrispettivi 12.0.1.1.7
OCA-git-bot Sep 24, 2020
bf43e29
Update translation files
oca-transbot Sep 24, 2020
10508a2
[FIX][l10n_it_corrispettivi] fix partner in multi company partner
matteoopenf Apr 1, 2020
5dc4aa7
[FIX] l10n_it_corrispettivi: Get user for corrispettivi for current c…
SimoRubi Jun 17, 2021
30381dd
[UPD] Update l10n_it_corrispettivi.pot
oca-travis Dec 15, 2021
57e8ff9
l10n_it_corrispettivi 12.0.1.1.8
OCA-git-bot Dec 15, 2021
bcaaaff
Update translation files
oca-transbot Dec 15, 2021
7ed14b1
Reformatted after template update
SirTakobi Aug 5, 2022
f936d78
Manually fix manifest website key
SirTakobi Aug 5, 2022
6cb4714
ADD account_receipt_journal: Define and use journals dedicated to rec…
eLBati Oct 10, 2022
72c42fe
[IMP] account_receipt_journal: Select journal when creating receipts
SirTakobi Oct 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions account_receipt_journal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from . import models
from openupgradelib import openupgrade


def rename_old_italian_data(cr):

if not openupgrade.is_module_installed(cr, "l10n_it_corrispettivi"):
return

openupgrade.rename_xmlids(
cr,
[
(
"l10n_it_corrispettivi.corrispettivi_journal",
"account_receipt_journal.sale_receipts_journal",
),
],
)
29 changes: 29 additions & 0 deletions account_receipt_journal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022 Lorenzo Battistini - TAKOBI
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Receipts Journals",
"summary": "Define and use journals dedicated to receipts",
"version": "14.0.1.0.0",
"development_status": "Beta",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/account-invoicing",
"author": "TAKOBI, Odoo Community Association (OCA)",
"maintainers": ["eLBati"],
"license": "LGPL-3",
"application": False,
"installable": True,
"preloadable": True,
"depends": [
"account",
],
"data": [
"views/account_journal_views.xml",
"data/account_journal_data.xml",
],
"pre_init_hook": "rename_old_italian_data",
"external_dependencies": {
"python": [
"openupgradelib",
],
},
}
18 changes: 18 additions & 0 deletions account_receipt_journal/data/account_journal_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="sale_receipts_journal" model="account.journal">
<field name="name">Sale Receipts Journal</field>
<field name="code">S-REC</field>
<field name="type">sale</field>
<field name="receipts" eval="True" />
<!-- Avoid being selected as default journal -->
<field name="sequence">99</field>
</record>
<record id="purchase_receipts_journal" model="account.journal">
<field name="name">Purchase Receipts Journal</field>
<field name="code">P-REC</field>
<field name="type">purchase</field>
<field name="receipts" eval="True" />
<field name="sequence">99</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions account_receipt_journal/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_journal
from . import account_move
6 changes: 6 additions & 0 deletions account_receipt_journal/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from odoo import fields, models


class Journal(models.Model):
_inherit = "account.journal"
receipts = fields.Boolean(string="Receipts")
76 changes: 76 additions & 0 deletions account_receipt_journal/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from odoo import api, models


class Move(models.Model):
_inherit = "account.move"

@api.model
def _search_default_receipt_journal(self, journal_types):
company_id = self._context.get("default_company_id", self.env.company.id)
domain = [
("company_id", "=", company_id),
("type", "in", journal_types),
("receipts", "=", True),
]
journal = None
if self._context.get("default_currency_id"):
currency_domain = domain + [
("currency_id", "=", self._context["default_currency_id"])
]
journal = self.env["account.journal"].search(currency_domain, limit=1)
if not journal:
journal = self.env["account.journal"].search(domain, limit=1)
return journal

@api.model
def _search_default_journal(self, journal_types):
journal = super(Move, self)._search_default_journal(journal_types)
default_move_type = self.env.context.get("default_move_type")
if not journal.receipts and default_move_type in ("in_receipt", "out_receipt"):
receipt_journal = self._search_default_receipt_journal(journal_types)
if receipt_journal:
journal = receipt_journal
return journal

def _get_journal_types(self, move_type):
if move_type in self.get_sale_types(include_receipts=True):
journal_types = ["sale"]
elif move_type in self.get_purchase_types(include_receipts=True):
journal_types = ["purchase"]
else:
journal_types = self.env.context.get(
"default_move_journal_types", ["general"]
)
return journal_types

@api.model
def _update_receipts_journal(self, vals_list):
"""
Update `vals_list` in place to set journal_id to the receipt journal
when move_type is receipt.

Model defaults are also considered it move_type or journal_id
are not in a `vals_list`.
"""
defaults = self.default_get(["journal_id", "move_type"])
default_journal = defaults.get("journal_id")
default_move_type = defaults.get("move_type")
for vals in vals_list:
move_type = vals.get("move_type", default_move_type)
if move_type in ("in_receipt", "out_receipt"):
selected_journal_id = vals.get("journal_id", default_journal)
selected_journal = self.env["account.journal"].browse(
selected_journal_id
)
if not selected_journal.receipts:
journal_types = self._get_journal_types(move_type)
receipt_journal = self._search_default_receipt_journal(
journal_types
)
if receipt_journal:
vals["journal_id"] = receipt_journal.id

@api.model_create_multi
def create(self, vals_list):
self._update_receipts_journal(vals_list)
return super().create(vals_list)
3 changes: 3 additions & 0 deletions account_receipt_journal/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `TAKOBI <https://takobi.online>`_:

* Lorenzo Battistini
1 change: 1 addition & 0 deletions account_receipt_journal/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Define journals dedicated to receipts and automatically use them in sale and purchase receipts
1 change: 1 addition & 0 deletions account_receipt_journal/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module partially comes from module `l10n_it_corrispettivi` of https://github.com/OCA/l10n-italy version 12.
1 change: 1 addition & 0 deletions account_receipt_journal/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_receipts
67 changes: 67 additions & 0 deletions account_receipt_journal/tests/test_receipts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from odoo.tests import tagged

from odoo.addons.account.tests.common import AccountTestInvoicingCommon


@tagged("post_install", "-at_install")
class TestReceipts(AccountTestInvoicingCommon):
def setUp(self):
super(TestReceipts, self).setUp()
self.move_model = self.env["account.move"]
self.tax_model = self.env["account.tax"]
self.journal_model = self.env["account.journal"]
self.a_sale = self.env["account.account"].search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_revenue").id,
)
],
limit=1,
)
self.tax22inc = self.tax_model.create(
{
"name": "Tax 22 INC",
"amount": 22,
"price_include": True,
}
)
self.receipt_journal = self.create_receipt_journal()

def create_receipt_journal(self):
return self.journal_model.create(
{
"name": "Sale Receipts Journal",
"code": "S-REC",
"type": "sale",
"receipts": True,
"sequence": 99,
}
)

def create_receipt(self):
receipt = self.move_model.with_context(default_move_type="out_receipt").create(
{
"invoice_line_ids": [
(
0,
0,
{
"account_id": self.a_sale.id,
"product_id": self.env.ref("product.product_product_5").id,
"name": "Receipt",
"quantity": 1,
"price_unit": 10,
"tax_ids": [(6, 0, {self.tax22inc.id})],
},
),
]
}
)
return receipt

def test_receipt_journal_default(self):
"""Test default values for receipt."""
receipt = self.create_receipt()
self.assertEqual(receipt.journal_id.id, self.receipt_journal.id)
20 changes: 20 additions & 0 deletions account_receipt_journal/views/account_journal_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_account_journal_form_receipts" model="ir.ui.view">
<field name="name">account.journal.form.receipts</field>
<field name="model">account.journal</field>
<field name="type">form</field>
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<xpath expr="//page[@name='advanced_settings']/group" position="inside">
<group
name="receipts"
string="Receipts"
attrs="{'invisible': [('type', 'not in', ('sale', 'purchase'))]}"
>
<field name="receipts" />
</group>
</xpath>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# generated from manifests external_dependencies
openupgradelib
6 changes: 6 additions & 0 deletions setup/account_receipt_journal/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)