(self)
This function calculate all the taxes, from issued invoices,
        received invoices and rectification invoices
This function calculate all the taxes, from issued invoices,
        received invoices and rectification invoices
This function calculate all the taxes from issued invoices received invoices and rectification invoices
def _calculate_vat_book(self):
        """
        This function calculate all the taxes, from issued invoices,
        received invoices and rectification invoices
        """
        for rec in self:
            if not rec.company_id.partner_id.vat:
                raise UserError(_("This company doesn't have VAT"))
            rec._clear_old_data()
            map_lines = self.env["aeat.vat.book.map.line"].search([])
            for map_line in map_lines:
                taxes = map_line.get_taxes(rec)
                account = rec.get_account_from_template(map_line.tax_account_id)
                lines = rec._get_account_move_lines(taxes, account=account)
                rec.create_vat_book_lines(lines, map_line.book_type, taxes)
            # Issued
            book_type = "issued"
            issued_tax_lines = rec.issued_line_ids.mapped("tax_line_ids")
            rectification_issued_tax_lines = rec.rectification_issued_line_ids.mapped(
                "tax_line_ids"
            )
            tax_summary_data_recs = rec._prepare_vat_book_tax_summary(
                issued_tax_lines + rectification_issued_tax_lines, book_type
            )
            rec._create_vat_book_tax_summary(tax_summary_data_recs)
            rec._create_vat_book_summary(rec.issued_tax_summary_ids, book_type)

            # Received
            book_type = "received"
            received_tax_lines = rec.received_line_ids.mapped("tax_line_ids")
            # flake8: noqa
            rectification_received_tax_lines = (
                rec.rectification_received_line_ids.mapped("tax_line_ids")
            )
            tax_summary_data_recs = rec._prepare_vat_book_tax_summary(
                received_tax_lines + rectification_received_tax_lines, book_type
            )
            rec._create_vat_book_tax_summary(tax_summary_data_recs)
            rec._create_vat_book_summary(rec.received_tax_summary_ids, book_type)

            # If we require to auto-renumber invoices received
            if rec.auto_renumber:
                rec_invs = self.env["l10n.es.vat.book.line"].search(
                    [("vat_book_id", "=", rec.id), ("line_type", "=", "received")],
                    order="invoice_date asc, ref asc",
                )
                i = 1
                for rec_inv in rec_invs:
                    rec_inv.entry_number = i
                    i += 1
                rec_invs = self.env["l10n.es.vat.book.line"].search(
                    [
                        ("vat_book_id", "=", rec.id),
                        ("line_type", "=", "rectification_received"),
                    ],
                    order="invoice_date asc, ref asc",
                )
                i = 1
                for rec_inv in rec_invs:
                    rec_inv.entry_number = i
                    i += 1
                # Write state and date in the report
            rec.write(
                {"state": "calculated", "calculation_date": fields.Datetime.now()}
            )
def _calculate_vat_book ( self ) : for rec in self : if not rec . company_id . partner_id . vat : raise UserError ( _ ( "This company doesn't have VAT" ) ) rec . _clear_old_data ( ) map_lines = self . env [ "aeat.vat.book.map.line" ] . search ( [ ] ) for map_line in map_lines : taxes = map_line . get_taxes ( rec ) account = rec . get_account_from_template ( map_line . tax_account_id ) lines = rec . _get_account_move_lines ( taxes , account = account ) rec . create_vat_book_lines ( lines , map_line . book_type , taxes ) # Issued book_type = "issued" issued_tax_lines = rec . issued_line_ids . mapped ( "tax_line_ids" ) rectification_issued_tax_lines = rec . rectification_issued_line_ids . mapped ( "tax_line_ids" ) tax_summary_data_recs = rec . _prepare_vat_book_tax_summary ( issued_tax_lines + rectification_issued_tax_lines , book_type ) rec . _create_vat_book_tax_summary ( tax_summary_data_recs ) rec . _create_vat_book_summary ( rec . issued_tax_summary_ids , book_type ) # Received book_type = "received" received_tax_lines = rec . received_line_ids . mapped ( "tax_line_ids" ) # flake8: noqa rectification_received_tax_lines = ( rec . rectification_received_line_ids . mapped ( "tax_line_ids" ) ) tax_summary_data_recs = rec . _prepare_vat_book_tax_summary ( received_tax_lines + rectification_received_tax_lines , book_type ) rec . _create_vat_book_tax_summary ( tax_summary_data_recs ) rec . _create_vat_book_summary ( rec . received_tax_summary_ids , book_type ) # If we require to auto-renumber invoices received if rec . auto_renumber : rec_invs = self . env [ "l10n.es.vat.book.line" ] . search ( [ ( "vat_book_id" , "=" , rec . id ) , ( "line_type" , "=" , "received" ) ] , order = "invoice_date asc, ref asc" , ) i = 1 for rec_inv in rec_invs : rec_inv . entry_number = i i += 1 rec_invs = self . env [ "l10n.es.vat.book.line" ] . search ( [ ( "vat_book_id" , "=" , rec . id ) , ( "line_type" , "=" , "rectification_received" ) , ] , order = "invoice_date asc, ref asc" , ) i = 1 for rec_inv in rec_invs : rec_inv . entry_number = i i += 1 # Write state and date in the report rec . write ( { "state" : "calculated" , "calculation_date" : fields . Datetime . now ( ) } )