-
-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from . import models | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def rename_old_italian_module(cr): | ||
|
||
if not openupgrade.is_module_installed(cr, "l10n_it_corrispettivi"): | ||
return | ||
|
||
openupgrade.update_module_names( | ||
cr, | ||
[ | ||
("l10n_it_corrispettivi", "l10n_it_receipt"), | ||
], | ||
merge_modules=True, | ||
) | ||
|
||
if openupgrade.column_exists( | ||
cr, "account_move", "old_invoice_id" | ||
) and openupgrade.column_exists(cr, "account_invoice", "corrispettivo"): | ||
# l10n_it_corrispettivi handled sale receipts only | ||
openupgrade.logged_query( | ||
cr, | ||
"UPDATE account_move m " | ||
"SET move_type = 'out_receipt' " | ||
"FROM account_invoice i " | ||
"WHERE i.corrispettivo = true AND i.id = m.old_invoice_id", | ||
) | ||
|
||
if openupgrade.column_exists(cr, "account_journal", "corrispettivi"): | ||
openupgrade.logged_query( | ||
cr, | ||
"UPDATE account_journal " | ||
"SET receipts = true " | ||
"WHERE corrispettivi = true", | ||
) | ||
|
||
if openupgrade.column_exists(cr, "account_fiscal_position", "corrispettivi"): | ||
openupgrade.logged_query( | ||
cr, | ||
"UPDATE account_fiscal_position " | ||
"SET receipts = true " | ||
"WHERE corrispettivi = true", | ||
) | ||
|
||
if openupgrade.column_exists(cr, "res_partner", "use_corrispettivi"): | ||
openupgrade.logged_query( | ||
cr, | ||
"UPDATE res_partner " | ||
"SET use_receipts = true " | ||
"WHERE use_corrispettivi = true", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2016-2022 Lorenzo Battistini | ||
# Copyright 2018-2019 Simone Rubino | ||
# Copyright 2019 Sergio Zanchetta (Associazione PNLUG - Gruppo Odoo) | ||
# Copyright 2020 Giovanni Serra - GSLab.it | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). | ||
{ | ||
"name": "Receipts from sales", | ||
"summary": "Generate receipts from sale orders", | ||
"version": "14.0.1.0.0", | ||
"development_status": "Beta", | ||
"category": "Sales/Sales", | ||
"website": "https://github.com/OCA/account-invoicing", | ||
"author": "TAKOBI, Agile Business Group, Odoo Community Association (OCA)", | ||
"maintainers": ["eLBati"], | ||
"license": "LGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"preloadable": True, | ||
"depends": [ | ||
"account_receipt_journal", | ||
], | ||
"data": [ | ||
"views/partner_views.xml", | ||
"views/account_fiscal_position_views.xml", | ||
], | ||
"pre_init_hook": "rename_old_italian_module", | ||
"external_dependencies": { | ||
"python": [ | ||
"openupgradelib", | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import account_fiscal_position | ||
from . import partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from odoo import models, fields, api | ||
|
||
|
||
class Position(models.Model): | ||
_inherit = "account.fiscal.position" | ||
receipts = fields.Boolean(string='Receipts') | ||
|
||
@api.model | ||
def get_receipts_fiscal_pos(self, company_id=None): | ||
if not company_id: | ||
company_id = self.env.user.company_id | ||
receipt_fiscal_pos = self.search( | ||
[ | ||
('company_id', '=', company_id.id), | ||
('receipts', '=', True), | ||
], | ||
limit=1 | ||
) | ||
if not receipt_fiscal_pos: | ||
# Fall back to fiscal positions without company | ||
receipt_fiscal_pos = self.search( | ||
[ | ||
('company_id', '=', False), | ||
('receipts', '=', True), | ||
], | ||
limit=1 | ||
) | ||
|
||
return receipt_fiscal_pos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from odoo import models, fields, api | ||
|
||
|
||
class Partner(models.Model): | ||
_inherit = "res.partner" | ||
use_receipts = fields.Boolean(string='Use Receipts') | ||
|
||
@api.onchange('use_receipts') | ||
def onchange_use_receipts(self): | ||
if self.use_receipts: | ||
# Partner is receipts, assign a receipts | ||
# fiscal position only if there is none | ||
if not self.property_account_position_id: | ||
company = self.company_id or self.env.company | ||
self.property_account_position_id = \ | ||
self.env['account.fiscal.position'] \ | ||
.get_receipts_fiscal_pos(company) | ||
else: | ||
# Unset the fiscal position only if it was receipts | ||
if self.property_account_position_id.receipts: | ||
self.property_account_position_id = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
If needed, create "receipts" fiscal positions and partners. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* Lorenzo Battistini | ||
* Simone Rubino | ||
* Sergio Zanchetta <https://github.com/primes2h> | ||
* Giovanni Serra <giovanni@gslab.it> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Based on `account_receipt_journal`, this module allows to create receipts from sale orders, configuring "receipts" fiscal positions and partners. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This module comes from modules `l10n_it_corrispettivi` and `l10n_it_corrispettivi_sale` of https://github.com/OCA/l10n-italy version 12. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_receipts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2018 Simone Rubino | ||
# Copyright 2022 Lorenzo Battistini | ||
|
||
from odoo.addons.account_receipt_journal.tests.test_receipts \ | ||
import TestReceipts | ||
from odoo.tests import tagged | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestReceiptsSale(TestReceipts): | ||
|
||
def setUp(self): | ||
super(TestReceiptsSale, self).setUp() | ||
partner_model = self.env['res.partner'] | ||
self.fiscal_pos_model = self.env['account.fiscal.position'] | ||
self.receipts_fiscal_position = self.fiscal_pos_model.create({ | ||
'name': 'receipts fiscal position', | ||
'receipts': True, | ||
'company_id': self.env.user.company_id.id | ||
}) | ||
self.no_receipts_fiscal_position = self.fiscal_pos_model.create({ | ||
'name': 'no receipts fiscal position', | ||
'receipts': False, | ||
'company_id': self.env.user.company_id.id | ||
}) | ||
self.receipts_partner = partner_model.create({ | ||
'name': 'Receipts partner', | ||
'use_receipts': True, | ||
'property_account_position_id': self.receipts_fiscal_position.id | ||
}) | ||
self.no_receipts_partner = partner_model.create({ | ||
'name': 'No receipts partner', | ||
'use_receipts': False, | ||
'property_account_position_id': self.no_receipts_fiscal_position.id | ||
}) | ||
|
||
def test_get_receipts_fiscal_pos(self): | ||
""" Test that get_receipts_fiscal_pos gets a receipts | ||
fiscal position""" | ||
receipts_fiscal_pos = self.fiscal_pos_model.get_receipts_fiscal_pos() | ||
self.assertTrue(receipts_fiscal_pos.receipts) | ||
|
||
def test_receipts_partner_onchange(self): | ||
""" Test onchange in partner. """ | ||
# If the partner uses receipts, | ||
# the fiscal position must have the flag receipts | ||
self.receipts_partner.onchange_use_receipts() | ||
self.assertTrue(self.receipts_partner | ||
.property_account_position_id.receipts) | ||
|
||
# If the partner does not use receipts | ||
# and it already has a fiscal position that is | ||
# receipts, it must be removed | ||
self.no_receipts_partner.write({ | ||
'property_account_position_id': self.receipts_fiscal_position.id}) | ||
self.no_receipts_partner.onchange_use_receipts() | ||
self.assertFalse( | ||
self.no_receipts_partner.property_account_position_id) | ||
|
||
# If the partner does not use receipts | ||
# and it already has a fiscal position that is | ||
# not receipts, it must not be removed | ||
self.no_receipts_partner.write({ | ||
'property_account_position_id': self.no_receipts_fiscal_position.id}) | ||
self.no_receipts_partner.onchange_use_receipts() | ||
self.assertEqual( | ||
self.no_receipts_partner.property_account_position_id, | ||
self.no_receipts_fiscal_position) |
14 changes: 14 additions & 0 deletions
14
account_receipt_sale/views/account_fiscal_position_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_account_position_form_receipts" model="ir.ui.view"> | ||
<field name="name">account.fiscal.position.form.receipts</field> | ||
<field name="model">account.fiscal.position</field> | ||
<field name="type">form</field> | ||
<field name="inherit_id" ref="account.view_account_position_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="company_id" position="after"> | ||
<field name="receipts"/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_partner_form_receipts" model="ir.ui.view"> | ||
<field name="name">res.partner.form.receipts</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="account.view_partner_property_form"/> | ||
<field name="groups_id" eval="[(4, ref('account.group_account_manager'))]"/> | ||
<field name="arch" type="xml"> | ||
<group name="fiscal_information" position="inside"> | ||
<field name="use_receipts"/> | ||
</group> | ||
</field> | ||
</record> | ||
</odoo> |