Skip to content

Commit

Permalink
ADD account_receipt_sale
Browse files Browse the repository at this point in the history
  • Loading branch information
eLBati committed Oct 18, 2022
1 parent 8b44354 commit 275d6a1
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 0 deletions.
52 changes: 52 additions & 0 deletions account_receipt_sale/__init__.py
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",
)
32 changes: 32 additions & 0 deletions account_receipt_sale/__manifest__.py
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",
],
},
}
2 changes: 2 additions & 0 deletions account_receipt_sale/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_fiscal_position
from . import partner
29 changes: 29 additions & 0 deletions account_receipt_sale/models/account_fiscal_position.py
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
21 changes: 21 additions & 0 deletions account_receipt_sale/models/partner.py
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
1 change: 1 addition & 0 deletions account_receipt_sale/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
If needed, create "receipts" fiscal positions and partners.
4 changes: 4 additions & 0 deletions account_receipt_sale/readme/CONTRIBUTORS.rst
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>
1 change: 1 addition & 0 deletions account_receipt_sale/readme/DESCRIPTION.rst
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.
1 change: 1 addition & 0 deletions account_receipt_sale/readme/HISTORY.rst
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.
1 change: 1 addition & 0 deletions account_receipt_sale/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_receipts
68 changes: 68 additions & 0 deletions account_receipt_sale/tests/test_receipts.py
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 account_receipt_sale/views/account_fiscal_position_views.xml
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>
14 changes: 14 additions & 0 deletions account_receipt_sale/views/partner_views.xml
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>

0 comments on commit 275d6a1

Please sign in to comment.