2
2
# For copyright and license notices, see __manifest__.py file in module root
3
3
# directory
4
4
##############################################################################
5
- from odoo import models , fields , api , _
6
- from odoo .exceptions import UserError
7
5
import logging
6
+
7
+ from odoo import _ , api , fields , models
8
+ from odoo .exceptions import UserError
9
+
8
10
_logger = logging .getLogger (__name__ )
9
11
10
12
11
13
class SaleOrderLine (models .Model ):
12
14
_inherit = "sale.order.line"
13
15
14
16
report_price_unit = fields .Float (
15
- compute = ' _compute_report_prices_and_taxes' ,
16
- digits = ' Report Product Price' ,
17
+ compute = " _compute_report_prices_and_taxes" ,
18
+ digits = " Report Product Price" ,
17
19
)
18
20
price_unit_with_tax = fields .Float (
19
- compute = '_compute_report_prices_and_taxes' ,
20
- digits = 'Product Price' ,
21
- )
22
- report_price_subtotal = fields .Monetary (
23
- compute = '_compute_report_prices_and_taxes'
21
+ compute = "_compute_report_prices_and_taxes" ,
22
+ digits = "Product Price" ,
24
23
)
24
+ report_price_subtotal = fields .Monetary (compute = "_compute_report_prices_and_taxes" )
25
25
report_price_net = fields .Float (
26
- compute = ' _compute_report_prices_and_taxes' ,
27
- digits = ' Report Product Price' ,
26
+ compute = " _compute_report_prices_and_taxes" ,
27
+ digits = " Report Product Price" ,
28
28
)
29
29
report_tax_id = fields .One2many (
30
30
compute = "_compute_report_prices_and_taxes" ,
31
- comodel_name = ' account.tax' ,
31
+ comodel_name = " account.tax" ,
32
32
)
33
33
34
34
vat_tax_id = fields .Many2one (
35
- 'account.tax' ,
36
- compute = '_compute_vat_tax_id' ,
37
- )
38
- report_price_reduce = fields .Monetary (
39
- compute = '_compute_report_price_reduce'
35
+ "account.tax" ,
36
+ compute = "_compute_vat_tax_id" ,
40
37
)
38
+ report_price_reduce = fields .Monetary (compute = "_compute_report_price_reduce" )
41
39
42
- @api .depends (' price_unit' , ' price_subtotal' , ' order_id.vat_discriminated' )
40
+ @api .depends (" price_unit" , " price_subtotal" , " order_id.vat_discriminated" )
43
41
def _compute_report_price_reduce (self ):
44
42
for line in self :
45
- price_type = line .price_subtotal \
46
- if line .order_id .vat_discriminated else line .price_total
47
- line .report_price_reduce = price_type / line .product_uom_qty \
48
- if line .product_uom_qty else 0.0
43
+ price_type = line .price_subtotal if line .order_id .vat_discriminated else line .price_total
44
+ line .report_price_reduce = price_type / line .product_uom_qty if line .product_uom_qty else 0.0
49
45
50
46
@api .depends (
51
- ' tax_id.tax_group_id.l10n_ar_vat_afip_code' ,
47
+ " tax_id.tax_group_id.l10n_ar_vat_afip_code" ,
52
48
)
53
49
def _compute_vat_tax_id (self ):
54
50
for rec in self :
55
51
vat_tax_id = rec .tax_id .filtered (lambda x : x .tax_group_id .l10n_ar_vat_afip_code )
56
52
if len (vat_tax_id ) > 1 :
57
- raise UserError (_ (' Only one vat tax allowed per line' ))
53
+ raise UserError (_ (" Only one vat tax allowed per line" ))
58
54
rec .vat_tax_id = vat_tax_id
59
55
60
- @api .depends (
61
- 'price_unit' ,
62
- 'price_subtotal' ,
63
- 'order_id.vat_discriminated'
64
- )
56
+ @api .depends ("price_unit" , "price_subtotal" , "order_id.vat_discriminated" )
65
57
def _compute_report_prices_and_taxes (self ):
66
58
for line in self :
67
59
order = line .order_id
68
60
taxes_included = not order .vat_discriminated
69
61
price_unit = line .tax_id .with_context (round = False ).compute_all (
70
- line .price_unit , order .currency_id , 1.0 , line .product_id ,
71
- order . partner_shipping_id )
62
+ line .price_unit , order .currency_id , 1.0 , line .product_id , order . partner_shipping_id
63
+ )
72
64
if not taxes_included :
73
- report_price_unit = price_unit [' total_excluded' ]
65
+ report_price_unit = price_unit [" total_excluded" ]
74
66
report_price_subtotal = line .price_subtotal
75
67
not_included_taxes = line .tax_id
76
- report_price_net = report_price_unit * (
77
- 1 - (line .discount or 0.0 ) / 100.0 )
68
+ report_price_net = report_price_unit * (1 - (line .discount or 0.0 ) / 100.0 )
78
69
else :
79
70
included_taxes = line .tax_id .filtered (lambda x : x .tax_group_id .l10n_ar_vat_afip_code )
80
- not_included_taxes = (
81
- line .tax_id - included_taxes )
82
- report_price_unit = included_taxes .with_context (
83
- round = False ).compute_all (
84
- line .price_unit , order .currency_id , 1.0 , line .product_id ,
85
- order .partner_shipping_id )['total_included' ]
86
- report_price_net = report_price_unit * (
87
- 1 - (line .discount or 0.0 ) / 100.0 )
71
+ not_included_taxes = line .tax_id - included_taxes
72
+ report_price_unit = included_taxes .with_context (round = False ).compute_all (
73
+ line .price_unit , order .currency_id , 1.0 , line .product_id , order .partner_shipping_id
74
+ )["total_included" ]
75
+ report_price_net = report_price_unit * (1 - (line .discount or 0.0 ) / 100.0 )
88
76
price = line .price_unit * (1 - (line .discount or 0.0 ) / 100.0 )
89
77
report_price_subtotal = included_taxes .compute_all (
90
- price , order .currency_id , line .product_uom_qty ,
91
- line . product_id , order . partner_shipping_id )[ ' total_included' ]
78
+ price , order .currency_id , line .product_uom_qty , line . product_id , order . partner_shipping_id
79
+ )[ " total_included" ]
92
80
93
- line .price_unit_with_tax = price_unit [' total_included' ]
81
+ line .price_unit_with_tax = price_unit [" total_included" ]
94
82
line .report_price_subtotal = report_price_subtotal
95
83
line .report_price_unit = report_price_unit
96
84
line .report_price_net = report_price_net
@@ -109,32 +97,37 @@ def check_vat_tax(self):
109
97
"""
110
98
# por ahora, para no romper el install de sale_timesheet lo
111
99
# desactivamos en la instalacion
112
- if self .env .context .get (' install_mode' ):
100
+ if self .env .context .get (" install_mode" ):
113
101
return True
114
102
for rec in self .filtered (
115
- lambda x : not x .display_type and
116
- x .company_id .country_id == self .env .ref (' base.ar' ) and
117
- x .company_id .l10n_ar_company_requires_vat ):
118
- vat_taxes = rec . tax_id . filtered (
119
- lambda x : x .tax_group_id .l10n_ar_vat_afip_code )
103
+ lambda x : not x .display_type
104
+ and x .company_id .country_id == self .env .ref (" base.ar" )
105
+ and x .company_id .l10n_ar_company_requires_vat
106
+ ):
107
+ vat_taxes = rec . tax_id . filtered ( lambda x : x .tax_group_id .l10n_ar_vat_afip_code )
120
108
if len (vat_taxes ) != 1 :
121
- raise UserError (_ (
122
- 'Debe haber un único impuesto del grupo de impuestos "IVA" por línea, agréguelo a "%s". '
123
- 'En caso de tenerlo, revise la configuración del impuesto, en opciones avanzadas, '
124
- 'en el campo correspondiente "Grupo de Impuestos".' ,
125
- rec .product_id .name ))
109
+ raise UserError (
110
+ _ (
111
+ 'Debe haber un único impuesto del grupo de impuestos "IVA" por línea, agréguelo a "%s". '
112
+ "En caso de tenerlo, revise la configuración del impuesto, en opciones avanzadas, "
113
+ 'en el campo correspondiente "Grupo de Impuestos".' ,
114
+ rec .product_id .name ,
115
+ )
116
+ )
126
117
127
118
def write (self , vals ):
128
119
res = super (SaleOrderLine , self ).write (vals )
129
120
# for performance we only check if tax or company is on vals
130
- if ' tax_id' in vals or ' company_id' in vals :
121
+ if " tax_id" in vals or " company_id" in vals :
131
122
self .check_vat_tax ()
132
123
return res
133
124
134
125
def _compute_tax_id (self ):
135
- """ Agregado de taxes de modulo l10n_ar_tax segun fiscal position """
126
+ """Agregado de taxes de modulo l10n_ar_tax segun fiscal position"""
136
127
super ()._compute_tax_id ()
137
128
138
- for rec in self .filtered (' order_id.fiscal_position_id.l10n_ar_tax_ids' ):
129
+ for rec in self .filtered (" order_id.fiscal_position_id.l10n_ar_tax_ids" ):
139
130
date = rec .order_id .date_order
140
- rec .tax_id += rec .order_id .fiscal_position_id ._l10n_ar_add_taxes (rec .order_partner_id , rec .company_id , date , 'perception' )
131
+ rec .tax_id += rec .order_id .fiscal_position_id ._l10n_ar_add_taxes (
132
+ rec .order_partner_id , rec .company_id , date , "perception"
133
+ )
0 commit comments