-
-
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.
ADD account_receipt_sale, ported from l10n_it_corrispettivi_sale
- Loading branch information
Showing
54 changed files
with
339 additions
and
1,570 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,72 @@ | ||
from . import models | ||
from . import wizard | ||
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", "account_receipt_sale"), | ||
], | ||
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", | ||
) | ||
|
||
if not openupgrade.is_module_installed(cr, "l10n_it_corrispettivi_sale"): | ||
return | ||
|
||
openupgrade.update_module_names( | ||
cr, | ||
[ | ||
("l10n_it_corrispettivi_sale", "account_receipt_sale"), | ||
], | ||
merge_modules=True, | ||
) | ||
|
||
if openupgrade.column_exists(cr, "sale_order", "corrispettivi"): | ||
openupgrade.logged_query( | ||
cr, | ||
"UPDATE sale_order " | ||
"SET receipts = true " | ||
"WHERE 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,34 @@ | ||
# 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", | ||
"sale", | ||
], | ||
"data": [ | ||
"views/partner_views.xml", | ||
"views/account_fiscal_position_views.xml", | ||
"sale_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,4 @@ | ||
from . import account_fiscal_position | ||
from . import partner | ||
from . import sale | ||
from . import account_move |
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,14 @@ | ||
from odoo import models, api | ||
|
||
|
||
class Move(models.Model): | ||
_inherit = "account.move" | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
if self.env.context.get("force_move_type"): | ||
move_type = self.env.context["force_move_type"] | ||
self = self.with_context(default_move_type=move_type) | ||
for vals in vals_list: | ||
vals["move_type"] = move_type | ||
return super(Move, self).create(vals_list) |
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,33 @@ | ||
from odoo import models, fields, api | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
receipts = fields.Boolean() | ||
|
||
@api.onchange('partner_id') | ||
def _onchange_partner_receipts_sale(self): | ||
self.receipts = self.partner_id.use_receipts | ||
|
||
@api.onchange('fiscal_position_id') | ||
def _onchange_fiscal_position_id_receipts(self): | ||
if self.fiscal_position_id: | ||
self.receipts = self.fiscal_position_id.receipts | ||
|
||
def _create_invoices(self, grouped=False, final=False, date=None): | ||
sale_receipts = self.filtered(lambda o: o.receipts) | ||
sale_no_receipts = self.filtered(lambda o: not o.receipts) | ||
moves = self.env["account.move"] | ||
if sale_receipts: | ||
moves |= super(SaleOrder, sale_receipts.with_context( | ||
force_move_type="out_receipt" | ||
))._create_invoices(grouped, final, date) | ||
if sale_no_receipts: | ||
moves |= super( | ||
SaleOrder, sale_no_receipts | ||
)._create_invoices(grouped, final, date) | ||
return moves | ||
|
||
|
||
class OrderLine(models.Model): | ||
_inherit = "sale.order.line" |
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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<!-- Order --> | ||
|
||
<record id="view_order_form_receipts" model="ir.ui.view"> | ||
<field name="name">sale.order.form.receipts</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
<group name="sale_info" position="inside"> | ||
<field name="receipts"/> | ||
</group> | ||
</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 @@ | ||
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> |
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 sale_make_invoice |
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,12 @@ | ||
from odoo import models | ||
|
||
|
||
class SaleAdvancePaymentInv(models.TransientModel): | ||
_inherit = "sale.advance.payment.inv" | ||
|
||
def _prepare_invoice_values(self, order, name, amount, so_line): | ||
invoice_vals = super(SaleAdvancePaymentInv, self)._prepare_invoice_values( | ||
order, name, amount, so_line) | ||
if order.receipts: | ||
invoice_vals["move_type"] = "out_receipt" | ||
return invoice_vals |
Oops, something went wrong.