11# Copyright 2017-2021 Tecnativa - Pedro M. Baeza
22# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl
33
4- from odoo import _ , api , exceptions , fields , models
4+ from odoo import api , exceptions , fields , models
5+ from odoo .fields import Domain
56from odoo .tools import float_compare
67
78ACTIVITY_CODE_SELECTION = [
@@ -739,7 +740,7 @@ def _compute_casilla_108(self):
739740 def _check_type (self ):
740741 if "C" in self .mapped ("statement_type" ):
741742 raise exceptions .UserError (
742- _ ("You cannot make complementary reports for this model." )
743+ self . env . _ ("You cannot make complementary reports for this model." )
743744 )
744745
745746 def _calculate_casilla_85 (self , reports_303_this_year ):
@@ -776,21 +777,31 @@ def _calculate_casilla_662(self, reports_303):
776777 # Cuotas aplicadas este año
777778 applied_this_year = sum (
778779 reports_303 .filtered_domain (
779- [("period_type" , "not in" , ("1T" , "01" ))]
780+ Domain .AND (
781+ [
782+ Domain ("period_type" , "not in" , ["1T" , "01" ]),
783+ Domain ("result_type" , "in" , ["C" ]),
784+ ]
785+ )
780786 ).mapped ("cuota_compensar" )
781787 )
782788 # Compensaciones de este año
783789 compensation_this_year = abs (
784790 sum (
785791 reports_303 .filtered_domain (
786- [("period_type" , "not in" , ("4T" , "12" )), ("result_type" , "=" , "C" )]
792+ Domain .AND (
793+ [
794+ Domain ("period_type" , "not in" , ["4T" , "12" ]),
795+ Domain ("result_type" , "in" , ["C" ]),
796+ ]
797+ )
787798 ).mapped ("resultado_liquidacion" )
788799 )
789800 )
790801 # Compensaciones de años anteriores
791802 compensation_previous_years = reports_303 .filtered_domain (
792- [ ("period_type" , "in" , ("1T" , "01" ))]
793- )[: 1 ] .potential_cuota_compensar
803+ Domain ("period_type" , "in" , ("1T" , "01" ))
804+ ).potential_cuota_compensar
794805 # Si lo aplicado este año es menor que compensaciones de años anteriores
795806 # significa que no se ha aplicado todo de años anteriores, por lo que
796807 # no hay que tenerlo en cuenta para la 662.
@@ -815,12 +826,14 @@ def calculate(self):
815826 continue
816827 casilla_85 , casilla_95 , casilla_97 , casilla_98 , casilla_662 = 0 , 0 , 0 , 0 , 0
817828 reports_303_this_year = self .env ["l10n.es.aeat.mod303.report" ].search (
818- [
819- ("year" , "=" , mod390 .year ),
820- ("state" , "not in" , ("draft" , "cancelled" )),
821- ("statement_type" , "=" , "N" ),
822- ("company_id" , "=" , mod390 .company_id .id ),
823- ]
829+ Domain .AND (
830+ [
831+ Domain ("year" , "in" , [mod390 .year ]),
832+ Domain ("state" , "not in" , ["draft" , "cancelled" ]),
833+ Domain ("statement_type" , "in" , ["N" ]),
834+ Domain ("company_id" , "in" , [mod390 .company_id .id ]),
835+ ]
836+ )
824837 )
825838 if not reports_303_this_year :
826839 continue
@@ -846,6 +859,7 @@ def calculate(self):
846859 # Si salió a devolver, casilla 98 = casilla 71 del último periodo
847860 # del año si fue a devolver
848861 casilla_98 = abs (report_303_last_period .resultado_liquidacion )
862+ casilla_662 = 0.0
849863 mod390 .update (
850864 {
851865 "casilla_85" : casilla_85 ,
@@ -863,7 +877,7 @@ def button_confirm(self):
863877 summary = self .casilla_95 - self .casilla_97 - self .casilla_98 - self .casilla_662
864878 if float_compare (summary , self .casilla_86 , precision_digits = 2 ) != 0 :
865879 raise exceptions .UserError (
866- _ (
880+ self . env . _ (
867881 "The result of the manual 303 summary (fields [95], [97], [98] and "
868882 "[662] in the page '9. Resultado liquidaciones') doesn't match "
869883 "the field [86]. Please check if you have filled such fields."
@@ -873,9 +887,9 @@ def button_confirm(self):
873887
874888 def _get_move_line_domain (self , date_start , date_end , map_line ):
875889 """Consider bankrupcy proceedings or uncollectible debt."""
876- res = super ()._get_move_line_domain (date_start , date_end , map_line )
890+ domain = super ()._get_move_line_domain (date_start , date_end , map_line )
877891 if map_line .field_number in {31 , 32 , 45 , 46 }:
878- res += [ ("move_id.is_bankrupcy_uncollectible_debt" , "= " , True )]
892+ domain &= Domain ("move_id.is_bankrupcy_uncollectible_debt" , "in " , [ True ])
879893 elif map_line .field_number in {29 , 30 , 43 , 44 , 99 }:
880- res += [ ("move_id.is_bankrupcy_uncollectible_debt" , "= " , False )]
881- return res
894+ domain &= Domain ("move_id.is_bankrupcy_uncollectible_debt" , "in " , [ False ])
895+ return domain
0 commit comments