-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] account_fiscal_position_constraints: Migration to 11.0
- Loading branch information
1 parent
31a2ac5
commit ec1c0ac
Showing
6 changed files
with
86 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,12 @@ | ||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
:target: https://www.gnu.org/licenses/agpl | ||
:alt: License: AGPL-3 | ||
|
||
=================================== | ||
Account Fiscal Position constraints | ||
=================================== | ||
|
||
This module prohibits the removal of a fiscal position when this position | ||
is already used in invoices or partner records. | ||
|
||
The module also enforces fiscal position names to be unique per company. |
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 models |
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 @@ | ||
# Copyright 2009-2019 Noviat. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Account Fiscal Position constraints', | ||
'version': '11.0.1.0.0', | ||
'category': 'Accounting & Finance', | ||
'website': 'https://www.noviat.com', | ||
'author': 'Noviat', | ||
'license': 'AGPL-3', | ||
'installable': True, | ||
'depends': [ | ||
'account', | ||
], | ||
} |
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 account_fiscal_position |
57 changes: 57 additions & 0 deletions
57
account_fiscal_position_constraints/models/account_fiscal_position.py
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,57 @@ | ||
# Copyright 2009-2019 Noviat. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models, _ | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class AccountFiscalPosition(models.Model): | ||
_inherit = 'account.fiscal.position' | ||
|
||
company_id = fields.Many2one( | ||
required=True, default=lambda self: self.env.user.company_id) | ||
|
||
_sql_constraints = [( | ||
'name_company_uniq', | ||
'unique (name, company_id)', | ||
'The name of the fiscal position must be unique per company !')] | ||
|
||
@api.one | ||
@api.returns('self', lambda value: value.id) | ||
def copy(self, default=None): | ||
default = dict(default or {}) | ||
default.setdefault('name', _("%s (copy)") % (self.name or '')) | ||
return super().copy(default) | ||
|
||
@api.multi | ||
def unlink(self): | ||
for fpos in self: | ||
|
||
partners = self.env['res.partner'].with_context( | ||
active_test=False).search( | ||
[('property_account_position_id', '=', fpos.id)]) | ||
if partners: | ||
partner_list = [ | ||
'%s (ID:%s)' % (x.name, x.id) for x in partners] | ||
raise UserError(_( | ||
"You cannot delete a fiscal position that " | ||
"has been set on partner records" | ||
"\nAs an alterative, you can disable a " | ||
"fiscal position via the 'active' flag." | ||
"\n\nPartner records: %s") % partner_list) | ||
|
||
invoices = self.env['account.invoice'].with_context( | ||
active_test=False).search( | ||
[('fiscal_position_id', '=', fpos.id)]) | ||
if invoices: | ||
invoice_list = [ | ||
'%s (ID:%s)' % (x.number or 'n/a', x.id) | ||
for x in invoices] | ||
raise UserError(_( | ||
"You cannot delete a fiscal position that " | ||
"has been used on invoices" | ||
"\nAs an alterative, you can disable a " | ||
"fiscal position via the 'active' flag." | ||
"\n\nInvoices: %s") % invoice_list) | ||
|
||
return super().unlink() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.