forked from OCA/l10n-spain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl10n_es_aeat_map_tax_line.py
More file actions
104 lines (91 loc) · 3.58 KB
/
Copy pathl10n_es_aeat_map_tax_line.py
File metadata and controls
104 lines (91 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright 2013-2018 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl
from odoo import fields, models
class L10nEsAeatMapTaxLine(models.Model):
_name = "l10n.es.aeat.map.tax.line"
_order = "field_number asc, id asc"
_description = "AEAT tax mapping line"
field_number = fields.Integer(required=True)
tax_xmlid_ids = fields.Many2many(
comodel_name="l10n.es.aeat.map.tax.line.tax", string="Taxes templates"
)
account_xmlid_ids = fields.Many2many(
comodel_name="l10n.es.aeat.map.tax.line.account",
string="Account Template",
)
name = fields.Char(required=True)
map_parent_id = fields.Many2one(comodel_name="l10n.es.aeat.map.tax", required=True)
move_type = fields.Selection(
selection=[("all", "All"), ("regular", "Regular"), ("refund", "Refund")],
string="Operation type",
default="all",
required=True,
)
field_type = fields.Selection(
selection=[("base", "Base"), ("amount", "Amount"), ("both", "Both")],
default="amount",
required=True,
)
sum_type = fields.Selection(
selection=[
("credit", "Credit"),
("debit", "Debit"),
("both", "Both (Credit - Debit)"),
],
string="Summarize type",
default="both",
required=True,
)
exigible_type = fields.Selection(
selection=[
("yes", "Only exigible amounts"),
("no", "Only non-exigible amounts"),
("both", "Both exigible and non-exigible amounts"),
],
required=True,
string="Exigibility",
default="yes",
)
inverse = fields.Boolean(string="Inverse summarize sign", default=False)
to_regularize = fields.Boolean()
def get_taxes_for_company(self, company):
"""Obtain the taxes corresponding to this line according the given company."""
self.ensure_one()
return company._get_taxes_from_xmlids(self.tax_xmlid_ids.mapped("name"))
def get_accounts_for_company(self, company):
"""Obtain the accounts corresponding to the line according the given company."""
self.ensure_one()
account_ids = set()
for account_xmlid in self.account_xmlid_ids:
account_id = company._get_account_id_from_xmlid(account_xmlid.name)
if account_id:
account_ids.add(account_id)
return self.env["account.account"].browse(list(account_ids))
def _get_amount_from_moves(self, move_lines):
"""
Get the amount from the given move lines according to the
configuration of the mapping line.
:param move_lines: browse_record(account.move.line)
:return: The amount calculated from the move lines.
:rtype: float
"""
self.ensure_one()
if self.sum_type == "credit":
amount = sum(move_lines.mapped("credit"))
elif self.sum_type == "debit":
amount = sum(move_lines.mapped("debit"))
else: # self.sum_type == 'both'
amount = sum(move_lines.mapped("credit")) - sum(move_lines.mapped("debit"))
if self.inverse:
amount = (-1.0) * amount
return amount
class L10nEsAeatMapTaxLineTax(models.Model):
_name = "l10n.es.aeat.map.tax.line.tax"
_order = "name, id"
_description = "AEAT tax mapping line - Tax"
name = fields.Char()
class L10nEsAeatMapTaxLineAccount(models.Model):
_name = "l10n.es.aeat.map.tax.line.account"
_order = "name, id"
_description = "AEAT tax mapping line - Account"
name = fields.Char()